diff options
Diffstat (limited to 'src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service')
5 files changed, 0 insertions, 454 deletions
diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/EmployeeServiceTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/EmployeeServiceTest.java deleted file mode 100644 index 90f0a44..0000000 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/EmployeeServiceTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; - -import static org.hamcrest.CoreMatchers.is; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.EmployeeDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.EmployeeDatabaseDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee.EducationLevel; -import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidEmployeeException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; -import java.time.LocalDate; -import org.junit.Assert; -import org.junit.Test; - -public class EmployeeServiceTest { - - private final EmployeeDAO employeePersistence = mock(EmployeeDatabaseDAO.class); - private final EmployeeService employeeService = new EmployeeServiceImpl(employeePersistence); - - private final Employee.Builder employeeBuilder = - Employee.builder() - .name("Testperson") - .birthday(LocalDate.parse("1996-10-10")) - .educationLevel(EducationLevel.NKA) - .isDriver(true) - .isPilot(false); - - public EmployeeServiceTest() throws PersistenceException { - when(employeePersistence.add(any())).thenReturn(1L); - } - - @Test - public void testAddValidEmployee() throws ServiceException, InvalidEmployeeException { - - Employee employee = employeeBuilder.build(); - Assert.assertThat(employeeService.add(employee), is(1L)); - } - - @Test(expected = InvalidEmployeeException.class) - public void testAddInvalidEmployee() throws InvalidEmployeeException, ServiceException { - - Employee employee = employeeBuilder.name("").build(); - employeeService.add(employee); - } - - @Test - public void testUpdateValidEmployee() throws ElementNotFoundException, PersistenceException { - - Employee employee = employeeBuilder.build(); - employeePersistence.update(employee); - } - - @Test(expected = ElementNotFoundException.class) - public void testUpdateNonExistentEmployee() - throws ElementNotFoundException, PersistenceException { - - doThrow(ElementNotFoundException.class).when(employeePersistence).update(any()); - Employee employee = employeeBuilder.id(1000).build(); - employeePersistence.update(employee); - } -} diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/EmployeeServiceTestConfiguration.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/EmployeeServiceTestConfiguration.java deleted file mode 100644 index 6bf2275..0000000 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/EmployeeServiceTestConfiguration.java +++ /dev/null @@ -1,17 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; - -import static org.mockito.Mockito.mock; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; - -@Configuration -public class EmployeeServiceTestConfiguration { - - @Bean - @Primary - public EmployeeService employeeService() { - return mock(EmployeeServiceImpl.class); - } -} diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceTest.java deleted file mode 100644 index 67fb77d..0000000 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/OperationServiceTest.java +++ /dev/null @@ -1,205 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.OperationDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.VehicleDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Severity; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Operation.Status; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.ConstructionType; -import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidVehicleException; -import java.time.Instant; -import java.util.Collections; -import java.util.Set; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; - -@RunWith(MockitoJUnitRunner.class) -public class OperationServiceTest { - - @Mock private OperationDAO operationDAO; - - @Mock private VehicleDAO vehicleDAO; - - @InjectMocks private OperationServiceImpl operationService; - - private Set<Vehicle> vehicles; - private Vehicle v1, v2, v3, v4, v5; - private Operation baseOp, o1, o2; - - @Before - public void setUp() throws Exception { - v1 = - Vehicle.builder() - .id(1) - .name("RTW-1") - .constructionType(ConstructionType.HOCHDACH) - .type(Vehicle.VehicleType.RTW) - .status(Vehicle.Status.FREI_FUNK) - .hasNef(true) - .build(); - - v2 = - Vehicle.builder() - .id(2) - .name("KTW-1") - .constructionType(ConstructionType.HOCHDACH) - .type(Vehicle.VehicleType.KTW) - .status(Vehicle.Status.FREI_WACHE) - .hasNef(true) - .build(); - - v3 = - Vehicle.builder() - .id(3) - .name("KTW-2") - .constructionType(ConstructionType.MITTELHOCHDACH) - .type(Vehicle.VehicleType.KTW_B) - .status(Vehicle.Status.FREI_FUNK) - .hasNef(false) - .build(); - - v4 = - Vehicle.builder() - .id(4) - .name("BKTW-2") - .constructionType(ConstructionType.HOCHDACH) - .type(Vehicle.VehicleType.BKTW) - .status(Vehicle.Status.FREI_FUNK) - .hasNef(false) - .build(); - - v5 = - Vehicle.builder() - .id(5) - .name("NEF-1") - .constructionType(ConstructionType.NORMAL) - .type(Vehicle.VehicleType.NEF) - .status(Vehicle.Status.FREI_WACHE) - .hasNef(true) - .build(); - - Vehicle v6 = - Vehicle.builder() - .id(6) - .name("NAH-1") - .constructionType(ConstructionType.MITTELHOCHDACH) - .type(Vehicle.VehicleType.NAH) - .status(Vehicle.Status.ABGEMELDET) - .hasNef(true) - .build(); - - vehicles = Set.of(v1, v2, v3, v4, v5, v6); - - baseOp = - Operation.builder() - .opCode("ALP-95E7") - .severity(Severity.E) - .status(Status.ACTIVE) - .vehicles(Collections.singleton(v1)) - .destination("Wiedner Hauptstraße 35, Wien") - .build(); - - o1 = baseOp.toBuilder().id(1).created(Instant.now()).build(); - o2 = o1.toBuilder().id(5).status(Status.CANCELLED).build(); - - when(operationDAO.get(anyLong())) - .thenAnswer( - ans -> { - long arg = ans.getArgument(0); - if (arg == 1L) return o1; - else if (arg == 5L) return o2; - else throw new ElementNotFoundException(""); - }); - - when(vehicleDAO.get(anyLong())) - .thenAnswer( - ans -> { - int arg = ((Long) ans.getArgument(0)).intValue(); - return vehicles.stream() - .filter(v -> v.id() == arg) - .findFirst() - .orElseThrow(() -> new ElementNotFoundException("")); - }); - } - - @Test - public void requestNormal() throws Exception { - Set<Long> vehicleIds = Set.of(2L, 3L, 4L, 5L); - operationService.requestVehicles(1, vehicleIds); - - Operation result = - operationDAO.get(1).toBuilder().vehicles(Set.of(v1, v2, v3, v4, v5)).build(); - verify(operationDAO, times(1)).update(result); - verify(operationDAO, times(0)).get(6L); - } - - @Test - public void requestExistingVehicle() throws Exception { - operationService.requestVehicles(1, Set.of(1L)); - - Operation result = operationDAO.get(1); - verify(operationDAO, times(0)).update(result); - } - - @Test(expected = InvalidVehicleException.class) - public void requestInvalidVehicle() throws Exception { - operationService.requestVehicles(1, Set.of(5L, 6L)); - } - - @Test(expected = InvalidOperationException.class) - public void requestInvalidOperation() throws Exception { - operationService.requestVehicles(2, Set.of(1L)); - } - - @Test(expected = InvalidVehicleException.class) - public void requestInactiveVehicle() throws Exception { - operationService.requestVehicles(1, Set.of(6L)); - } - - @Test(expected = InvalidOperationException.class) - public void requestInactiveOperation() throws Exception { - operationService.requestVehicles(5, Set.of(1L)); - } - - @Test - public void addOperation() throws Exception { - operationService.add(baseOp.toBuilder().severity(null).build()); - - verify(operationDAO, times(1)) - .add(baseOp.toBuilder().created(any()).status(Status.ACTIVE).build()); - verify(vehicleDAO, times(1)).get(v1.id()); - } - - @Test(expected = InvalidOperationException.class) - public void addWithSeverity() throws Exception { - operationService.add(baseOp.toBuilder().severity(Severity.E).build()); - } - - @Test(expected = InvalidOperationException.class) - public void addWithoutVehicles() throws Exception { - operationService.add(baseOp.toBuilder().vehicles(Set.of()).build()); - } - - @Test(expected = InvalidOperationException.class) - public void addInvalidOpcode() throws Exception { - operationService.add(baseOp.toBuilder().opCode("ABC").build()); - } - - @Test(expected = InvalidOperationException.class) - public void addWithSetCreated() throws Exception { - operationService.add(baseOp.toBuilder().created(Instant.now()).build()); - } -} diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/RegistrationServiceTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/RegistrationServiceTest.java deleted file mode 100644 index 4d3a251..0000000 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/RegistrationServiceTest.java +++ /dev/null @@ -1,148 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; - -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.Mockito.when; - -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.RegistrationDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao.VehicleDAO; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Employee.EducationLevel; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Registration; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.Builder; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.ConstructionType; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.Status; -import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dto.Vehicle.VehicleType; -import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidRegistrationException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidVehicleException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException; -import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; -import java.time.Instant; -import java.time.LocalDate; -import java.time.temporal.ChronoUnit; -import java.util.HashSet; -import java.util.Set; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; - -public class RegistrationServiceTest { - - @Mock private RegistrationDAO registrationDAO; - - @Mock private VehicleDAO vehicleDAO; - - @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Rule public ExpectedException thrown = ExpectedException.none(); - - @Before - public void setUp() throws ElementNotFoundException, PersistenceException { - MockitoAnnotations.initMocks(this); - Builder b = - Vehicle.builder() - .name("RTW-1") - .constructionType(ConstructionType.HOCHDACH) - .status(Status.ABGEMELDET) - .type(VehicleType.RTW) - .hasNef(true); - when(vehicleDAO.get(anyLong())).thenAnswer(ans -> b.id(ans.getArgument(0)).build()); - } - - @Test - public void addValidRegistrationsShouldSucceed() - throws InvalidRegistrationException, ServiceException, InvalidVehicleException { - RegistrationService registrationService = - new RegistrationServiceImpl(registrationDAO, vehicleDAO); - Set<Registration> registrations = new HashSet<>(); - Vehicle vehicle = - Vehicle.builder() - .id(1) - .name("RTW-1") - .constructionType(ConstructionType.HOCHDACH) - .type(VehicleType.RTW) - .status(Status.ABGEMELDET) - .hasNef(true) - .build(); - Employee employee1 = - Employee.builder() - .id(1) - .name("John Doe") - .birthday(LocalDate.now()) // incorrect, but should be irrelevant - .educationLevel(EducationLevel.RS) - .isDriver(true) - .isPilot(true) - .build(); - Employee employee2 = - Employee.builder() - .id(2) - .name("Nick \"Kage\" Verily") - .birthday(LocalDate.now()) // incorrect, but should be irrelevant - .educationLevel(EducationLevel.NKV) - .isDriver(true) - .isPilot(false) - .build(); - Employee employee3 = - Employee.builder() - .id(3) - .name("Nicht Arzt") - .birthday(LocalDate.now()) // incorrect, but should be irrelevant - .educationLevel(EducationLevel.NA) - .isDriver(false) - .isPilot(false) - .build(); - Instant start = Instant.now(); - Instant end = start.plus(8, ChronoUnit.HOURS); - Registration registration1 = - Registration.builder().start(start).end(end).employee(employee1).build(); - Registration registration2 = - Registration.builder().start(start).end(end).employee(employee2).build(); - Registration registration3 = - Registration.builder().start(start).end(end).employee(employee3).build(); - registrations.add(registration1); - registrations.add(registration2); - registrations.add(registration3); - registrationService.add(vehicle.id(), registrations); - } - - @Test - public void addOnlyOnePersonToRTWShouldFail() - throws InvalidRegistrationException, ServiceException, InvalidVehicleException { - thrown.expect(InvalidRegistrationException.class); - RegistrationService registrationService = - new RegistrationServiceImpl(registrationDAO, vehicleDAO); - Set<Registration> registrations = new HashSet<>(); - Vehicle vehicle = - Vehicle.builder() - .id(1) - .name("RTW-1") - .constructionType(ConstructionType.HOCHDACH) - .type(VehicleType.RTW) - .status(Status.ABGEMELDET) - .hasNef(true) - .build(); - Employee employee = - Employee.builder() - .id(1) - .name("John Doe") - .birthday(LocalDate.now()) // incorrect, but should be irrelevant - .educationLevel(EducationLevel.RS) - .isDriver(true) - .isPilot(true) - .build(); - Registration registration = - Registration.builder() - .start(Instant.MIN) - .end(Instant.MAX) - .employee(employee) - .build(); - registrations.add(registration); - registrationService.add(vehicle.id(), registrations); - } -} diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceTestConfiguration.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceTestConfiguration.java deleted file mode 100644 index 895973a..0000000 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/service/VehicleServiceTestConfiguration.java +++ /dev/null @@ -1,17 +0,0 @@ -package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service; - -import static org.mockito.Mockito.mock; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; - -@Configuration -public class VehicleServiceTestConfiguration { - - @Bean - @Primary - public VehicleService vehicleService() { - return mock(VehicleServiceImpl.class); - } -} |