backend-api #6
@ -0,0 +1,51 @@
|
|||||||
|
package enseirb.myinpulse;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
|
import enseirb.myinpulse.model.Administrator;
|
||||||
|
import enseirb.myinpulse.model.Project;
|
||||||
|
import enseirb.myinpulse.service.AdminApiService;
|
||||||
|
import enseirb.myinpulse.service.database.AdministratorService;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
@Transactional
|
||||||
|
public class AdminApiServiceTest {
|
||||||
|
@Autowired private AdminApiService adminApiService;
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
static void setup(@Autowired AdministratorService administratorService) {
|
||||||
|
administratorService.addAdministrator(
|
||||||
|
new Administrator(
|
||||||
|
"admin", "admin", "testAdmin@example.com", "testAdmin@example.com", ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getProjectOfAdminIsEmpty() throws Exception {
|
||||||
|
Iterable<Project> projects = adminApiService.getProjectsOfAdmin("testAdmin@example.com");
|
||||||
|
List<Project> l = new ArrayList<>();
|
||||||
|
projects.forEach(l::add);
|
||||||
|
assertEquals(0, l.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getProjectOfInexistantAdminFails() throws Exception {
|
||||||
|
String nonExistentAdminEmail = "testInexistantAdmin@example.com";
|
||||||
|
|
||||||
|
assertThrows(
|
||||||
|
ResponseStatusException.class,
|
||||||
|
() -> {
|
||||||
|
adminApiService.getProjectsOfAdmin(nonExistentAdminEmail);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package enseirb.myinpulse;
|
package enseirb.myinpulse;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
@ -7,5 +8,6 @@ import org.springframework.boot.test.context.SpringBootTest;
|
|||||||
class MyinpulseApplicationTests {
|
class MyinpulseApplicationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisplayName("contextLoad => Test if the context can load, i.e. the application can start")
|
||||||
void contextLoads() {}
|
void contextLoads() {}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user