feat: added tests.
This commit is contained in:
parent
215d80ad70
commit
1106cf8478
@ -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;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@ -7,5 +8,6 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
class MyinpulseApplicationTests {
|
||||
|
||||
@Test
|
||||
@DisplayName("contextLoad => Test if the context can load, i.e. the application can start")
|
||||
void contextLoads() {}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user