aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/service
diff options
context:
space:
mode:
authorTharre <tharre3@gmail.com>2018-06-20 22:07:36 +0200
committerTharre <tharre3@gmail.com>2018-06-20 22:07:36 +0200
commit0c995a05985da749d93aa56eba976c7fc621a4fa (patch)
tree5b80394920705aae5e2b6004c3dfbd839c8b8fa3 /src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/service
parentf5bc7925a8fbbe247972a6f0e0571cc7e92fbefa (diff)
parente21feb3ac772a5394dc5381b58142c3c061de716 (diff)
downloadsepm-groupproject-master.tar.gz
sepm-groupproject-master.tar.xz
sepm-groupproject-master.zip
Merge branch 'develop'HEADv3.0master
Diffstat (limited to 'src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/service')
-rw-r--r--src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/service/EmployeeServiceTest.java67
-rw-r--r--src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/service/OperationServiceIntegrationTest.java99
-rw-r--r--src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/service/OperationServiceTest.java205
-rw-r--r--src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/service/RegistrationServiceIntegrationTest.java55
-rw-r--r--src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/service/RegistrationServiceTest.java159
5 files changed, 585 insertions, 0 deletions
diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/service/EmployeeServiceTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/service/EmployeeServiceTest.java
new file mode 100644
index 0000000..17c0a47
--- /dev/null
+++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/service/EmployeeServiceTest.java
@@ -0,0 +1,67 @@
+package at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.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.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 at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dao.EmployeeDAO;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dao.EmployeeDatabaseDAO;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Employee;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Employee.EducationLevel;
+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/missioncontrol/service/OperationServiceIntegrationTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/service/OperationServiceIntegrationTest.java
new file mode 100644
index 0000000..008787f
--- /dev/null
+++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/service/OperationServiceIntegrationTest.java
@@ -0,0 +1,99 @@
+package at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.service;
+
+import static org.junit.Assert.assertEquals;
+
+import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException;
+import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dao.EmployeeDAO;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dao.EmployeeDatabaseDAO;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dao.OperationDAO;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dao.OperationDatabaseDAO;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dao.RegistrationDAO;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dao.RegistrationDatabaseDAO;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dao.VehicleDAO;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dao.VehicleDatabaseDAO;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Operation;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Operation.Status;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Vehicle;
+import at.ac.tuwien.sepm.assignment.groupphase.util.Helper;
+import at.ac.tuwien.sepm.assignment.groupphase.util.JdbcTestCase;
+import java.util.Set;
+import org.dbunit.Assertion;
+import org.dbunit.dataset.IDataSet;
+import org.dbunit.dataset.ITable;
+import org.junit.Test;
+
+public class OperationServiceIntegrationTest extends JdbcTestCase {
+
+ private OperationService operationService;
+
+ private Operation o;
+
+ public OperationServiceIntegrationTest() {
+ EmployeeDAO employeeDAO = new EmployeeDatabaseDAO(getJdbcConnectionManager());
+ RegistrationDAO registrationDAO =
+ new RegistrationDatabaseDAO(getJdbcConnectionManager(), employeeDAO);
+ VehicleDAO vehicleDAO =
+ new VehicleDatabaseDAO(
+ getJdbcConnectionManager(), (RegistrationDatabaseDAO) registrationDAO);
+ OperationDAO operationDAO =
+ new OperationDatabaseDAO(
+ getJdbcConnectionManager(),
+ vehicleDAO,
+ (RegistrationDatabaseDAO) registrationDAO);
+
+ VehicleService vehicleService = new VehicleServiceImpl(vehicleDAO);
+
+ operationService = new OperationServiceImpl(operationDAO, vehicleDAO, vehicleService);
+
+ Vehicle v1 =
+ Vehicle.builder()
+ .id(1)
+ .name("RTW-1")
+ .constructionType(Vehicle.ConstructionType.HOCHDACH)
+ .type(Vehicle.VehicleType.RTW)
+ .status(Vehicle.Status.FREI_FUNK)
+ .hasNef(true)
+ .build();
+
+ Vehicle v2 = v1.toBuilder().id(2).build();
+ Vehicle v3 = v1.toBuilder().id(3).build();
+
+ o =
+ Operation.builder()
+ .opCode("RD-2B0M")
+ .status(Status.ACTIVE)
+ .vehicles(Set.of(v1, v2, v3))
+ .destination("New destination")
+ .additionalInfo("New information")
+ .build();
+ }
+
+ @Override
+ protected IDataSet getDataSet() throws Exception {
+ return getDataSet("operationDAOUpdateSetup.xml");
+ }
+
+ @Test
+ public void addValidOperation() throws Exception {
+
+ long id = operationService.add(o);
+ assertEquals(2, id);
+
+ String tableName = "Operation";
+ String[] excludedColumns = new String[] {"created"};
+
+ ITable actual =
+ Helper.getActualFilteredTableData(getConnection(), tableName, excludedColumns);
+ ITable expected =
+ Helper.getExpectedFilteredTableData(
+ tableName, excludedColumns, "operationDAOAddOperation.xml");
+
+ Assertion.assertEquals(expected, actual);
+ }
+
+ @Test(expected = InvalidOperationException.class)
+ public void addInvalidOperation() throws InvalidOperationException, ServiceException {
+ operationService.add(o.toBuilder().opCode("").build());
+ }
+}
diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/service/OperationServiceTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/service/OperationServiceTest.java
new file mode 100644
index 0000000..4c1eaf1
--- /dev/null
+++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/service/OperationServiceTest.java
@@ -0,0 +1,205 @@
+package at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.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.exception.ElementNotFoundException;
+import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException;
+import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidVehicleException;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dao.OperationDAO;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dao.VehicleDAO;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Operation;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Operation.Severity;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Operation.Status;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Vehicle;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Vehicle.ConstructionType;
+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/missioncontrol/service/RegistrationServiceIntegrationTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/service/RegistrationServiceIntegrationTest.java
new file mode 100644
index 0000000..ac5c3fb
--- /dev/null
+++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/service/RegistrationServiceIntegrationTest.java
@@ -0,0 +1,55 @@
+package at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.service;
+
+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 at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dao.EmployeeDAO;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dao.EmployeeDatabaseDAO;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dao.RegistrationDAO;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dao.RegistrationDatabaseDAO;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dao.VehicleDAO;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dao.VehicleDatabaseDAO;
+import at.ac.tuwien.sepm.assignment.groupphase.util.JdbcTestCase;
+import org.dbunit.dataset.IDataSet;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+public class RegistrationServiceIntegrationTest extends JdbcTestCase {
+
+ private RegistrationDAO registrationDAO;
+ private VehicleDAO vehicleDAO;
+
+ @Rule public ExpectedException thrown = ExpectedException.none();
+
+ @Override
+ protected IDataSet getDataSet() throws Exception {
+ return getDataSet("registrationTestBaseData.xml");
+ }
+
+ @Before
+ public void prepare() throws PersistenceException {
+
+ EmployeeDAO employeeDAO = new EmployeeDatabaseDAO(getJdbcConnectionManager());
+ registrationDAO = new RegistrationDatabaseDAO(getJdbcConnectionManager(), employeeDAO);
+ vehicleDAO =
+ new VehicleDatabaseDAO(
+ getJdbcConnectionManager(), (RegistrationDatabaseDAO) registrationDAO);
+ }
+
+ @Test
+ public void addValidRegistrationsShouldSucceed()
+ throws InvalidRegistrationException, ServiceException, InvalidVehicleException {
+ RegistrationServiceTest.addValidRegistrations(registrationDAO, vehicleDAO);
+ }
+
+ @Test
+ public void addOnlyOnePersonToRTWShouldFail()
+ throws InvalidRegistrationException, ServiceException, InvalidVehicleException {
+ RegistrationServiceTest.addOnlyOnePersonToRTW(thrown, registrationDAO, vehicleDAO);
+ }
+
+ // TODO: also test real integration, e.g. add registration and delete afterwards (feedback)
+}
diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/service/RegistrationServiceTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/service/RegistrationServiceTest.java
new file mode 100644
index 0000000..b4bcff4
--- /dev/null
+++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/service/RegistrationServiceTest.java
@@ -0,0 +1,159 @@
+package at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.service;
+
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.Mockito.when;
+
+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 at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dao.RegistrationDAO;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dao.VehicleDAO;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Employee;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Employee.EducationLevel;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Registration;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Vehicle;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Vehicle.Builder;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Vehicle.ConstructionType;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Vehicle.Status;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Vehicle.VehicleType;
+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 {
+ addValidRegistrations(registrationDAO, vehicleDAO);
+ }
+
+ @Test
+ public void addOnlyOnePersonToRTWShouldFail()
+ throws InvalidRegistrationException, ServiceException, InvalidVehicleException {
+ addOnlyOnePersonToRTW(thrown, registrationDAO, vehicleDAO);
+ }
+
+ static void addValidRegistrations(RegistrationDAO registrationDAO, VehicleDAO vehicleDAO)
+ throws InvalidVehicleException, InvalidRegistrationException, ServiceException {
+ 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);
+ }
+
+ static void addOnlyOnePersonToRTW(
+ ExpectedException thrown, RegistrationDAO registrationDAO, VehicleDAO vehicleDAO)
+ throws InvalidVehicleException, InvalidRegistrationException, ServiceException {
+ 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);
+ }
+}