aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol
diff options
context:
space:
mode:
authorDominic Rogetzer <e1627756@student.tuwien.ac.at>2018-06-18 20:13:05 +0200
committerDominic Rogetzer <e01627756@student.tuwien.ac.at>2018-06-18 20:13:07 +0200
commit17556e5701442e9c2a7e219c5d93734812344ebe (patch)
tree02850675ba1907576a28016f8a9dacef106d1c60 /src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol
parent9056b605578fcaee29965074365b9527ba865ecd (diff)
downloadsepm-groupproject-17556e5701442e9c2a7e219c5d93734812344ebe.tar.gz
sepm-groupproject-17556e5701442e9c2a7e219c5d93734812344ebe.tar.xz
sepm-groupproject-17556e5701442e9c2a7e219c5d93734812344ebe.zip
Rename 'einsatzverwaltung' to 'missioncontrol' + remove TODO [#25963]
Diffstat (limited to 'src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol')
-rw-r--r--src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller/CreateNewEmployeeControllerTest.java87
-rw-r--r--src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller/CreateNewVehicleControllerTest.java81
-rw-r--r--src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller/GuiTestApplication.java101
-rw-r--r--src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller/RegistrationControllerTest.java22
-rw-r--r--src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/dao/EmployeeDAOTest.java253
-rw-r--r--src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/dao/OperationDAOTest.java197
-rw-r--r--src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/dao/RegistrationDAOTest.java115
-rw-r--r--src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/dao/VehicleDAOTest.java161
-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.java97
-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
13 files changed, 1600 insertions, 0 deletions
diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller/CreateNewEmployeeControllerTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller/CreateNewEmployeeControllerTest.java
new file mode 100644
index 0000000..2b0f793
--- /dev/null
+++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller/CreateNewEmployeeControllerTest.java
@@ -0,0 +1,87 @@
+package at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.controller;
+
+import static at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.controller.Helper.ALERT_TITLE_SERVICE_EXCEPTION;
+import static at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.controller.Helper.ALERT_TITLE_SUCCESS;
+import static at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.controller.Helper.ALERT_TITLE_VALIDATION_ERROR;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.service.EmployeeService;
+import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidEmployeeException;
+import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException;
+import at.ac.tuwien.sepm.assignment.groupphase.util.Helper;
+import at.ac.tuwien.sepm.assignment.groupphase.util.HighDpiAwareApplicationTest;
+import javafx.scene.control.DialogPane;
+import javafx.scene.input.MouseButton;
+import javafx.stage.Stage;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.testfx.api.FxToolkit;
+import org.testfx.robot.Motion;
+
+public class CreateNewEmployeeControllerTest extends HighDpiAwareApplicationTest {
+
+ private EmployeeService employeeService;
+
+ @Before
+ public void setup() throws Exception {
+ FxToolkit.registerPrimaryStage();
+ FxToolkit.setupApplication(GuiTestApplication.class, "createNewEmployee.fxml");
+ employeeService = GuiTestApplication.context.getBean(EmployeeService.class);
+ }
+
+ @After
+ public void cleanup() throws Exception {
+ FxToolkit.cleanupStages();
+ }
+
+ @Test
+ public void testClickAddValidEmployee() throws InvalidEmployeeException, ServiceException {
+
+ when(employeeService.add(any())).thenReturn(1L);
+
+ clickOn("#inputName", Motion.DIRECT, MouseButton.PRIMARY);
+ write("Name");
+ clickOn("#btnCreate", Motion.DIRECT, MouseButton.PRIMARY);
+
+ Stage alertDialog = Helper.getTopModalStage(robotContext());
+ Assert.assertNotNull(alertDialog);
+
+ DialogPane dialogPane = (DialogPane) alertDialog.getScene().getRoot();
+ Assert.assertEquals(ALERT_TITLE_SUCCESS, dialogPane.getHeaderText());
+ }
+
+ @Test
+ public void testClickAddInvalidEmployee() throws InvalidEmployeeException, ServiceException {
+
+ when(employeeService.add(any())).thenThrow(InvalidEmployeeException.class);
+
+ moveTo("#inputName");
+ clickOn("#btnCreate", Motion.DIRECT, MouseButton.PRIMARY);
+
+ Stage alertDialog = Helper.getTopModalStage(robotContext());
+ Assert.assertNotNull(alertDialog);
+
+ DialogPane dialogPane = (DialogPane) alertDialog.getScene().getRoot();
+ Assert.assertEquals(ALERT_TITLE_VALIDATION_ERROR, dialogPane.getHeaderText());
+ }
+
+ @Test
+ public void testClickAddEmployeeWithServiceException()
+ throws InvalidEmployeeException, ServiceException {
+
+ when(employeeService.add(any())).thenThrow(ServiceException.class);
+
+ clickOn("#inputName", Motion.DIRECT, MouseButton.PRIMARY);
+ write("Test");
+ clickOn("#btnCreate", Motion.DIRECT, MouseButton.PRIMARY);
+
+ Stage alertDialog = Helper.getTopModalStage(robotContext());
+ Assert.assertNotNull(alertDialog);
+
+ DialogPane dialogPane = (DialogPane) alertDialog.getScene().getRoot();
+ Assert.assertEquals(ALERT_TITLE_SERVICE_EXCEPTION, dialogPane.getHeaderText());
+ }
+}
diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller/CreateNewVehicleControllerTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller/CreateNewVehicleControllerTest.java
new file mode 100644
index 0000000..282c50f
--- /dev/null
+++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller/CreateNewVehicleControllerTest.java
@@ -0,0 +1,81 @@
+package at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.controller;
+
+import static at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.controller.Helper.ALERT_TITLE_SERVICE_EXCEPTION;
+import static at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.controller.Helper.ALERT_TITLE_SUCCESS;
+import static at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.controller.Helper.ALERT_TITLE_VALIDATION_ERROR;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.service.VehicleService;
+import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidVehicleException;
+import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException;
+import at.ac.tuwien.sepm.assignment.groupphase.util.Helper;
+import at.ac.tuwien.sepm.assignment.groupphase.util.HighDpiAwareApplicationTest;
+import javafx.scene.control.DialogPane;
+import javafx.scene.input.MouseButton;
+import javafx.stage.Stage;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.testfx.api.FxToolkit;
+import org.testfx.robot.Motion;
+
+public class CreateNewVehicleControllerTest extends HighDpiAwareApplicationTest {
+
+ private VehicleService vehicleService;
+
+ @Before
+ public void setup() throws Exception {
+ FxToolkit.registerPrimaryStage();
+ FxToolkit.setupApplication(GuiTestApplication.class, "createCar.fxml");
+ vehicleService = GuiTestApplication.context.getBean(VehicleService.class);
+ }
+
+ @After
+ public void cleanup() throws Exception {
+ FxToolkit.cleanupStages();
+ }
+
+ @Test
+ public void testClickAddValidVehicle() throws ServiceException, InvalidVehicleException {
+
+ when(vehicleService.add(any())).thenReturn(1L);
+
+ clickOn("#btnCreate", Motion.DIRECT, MouseButton.PRIMARY);
+
+ Stage alertDialog = Helper.getTopModalStage(robotContext());
+ Assert.assertNotNull(alertDialog);
+
+ DialogPane dialogPane = (DialogPane) alertDialog.getScene().getRoot();
+ Assert.assertEquals(ALERT_TITLE_SUCCESS, dialogPane.getHeaderText());
+ }
+
+ @Test
+ public void testClickInvalidVehicleEx() throws ServiceException, InvalidVehicleException {
+
+ when(vehicleService.add(any())).thenThrow(InvalidVehicleException.class);
+
+ clickOn("#btnCreate", Motion.DIRECT, MouseButton.PRIMARY);
+
+ Stage alertDialog = Helper.getTopModalStage(robotContext());
+ Assert.assertNotNull(alertDialog);
+
+ DialogPane dialogPane = (DialogPane) alertDialog.getScene().getRoot();
+ Assert.assertEquals(ALERT_TITLE_VALIDATION_ERROR, dialogPane.getHeaderText());
+ }
+
+ @Test
+ public void testClickInvalidServiceEx() throws ServiceException, InvalidVehicleException {
+
+ when(vehicleService.add(any())).thenThrow(ServiceException.class);
+
+ clickOn("#btnCreate", Motion.DIRECT, MouseButton.PRIMARY);
+
+ Stage alertDialog = Helper.getTopModalStage(robotContext());
+ Assert.assertNotNull(alertDialog);
+
+ DialogPane dialogPane = (DialogPane) alertDialog.getScene().getRoot();
+ Assert.assertEquals(ALERT_TITLE_SERVICE_EXCEPTION, dialogPane.getHeaderText());
+ }
+}
diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller/GuiTestApplication.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller/GuiTestApplication.java
new file mode 100644
index 0000000..968141e
--- /dev/null
+++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller/GuiTestApplication.java
@@ -0,0 +1,101 @@
+package at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.controller;
+
+import static org.mockito.Mockito.mock;
+
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.service.EmployeeService;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.service.EmployeeServiceImpl;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.service.OperationService;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.service.OperationServiceImpl;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.service.RegistrationService;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.service.RegistrationServiceImpl;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.service.VehicleService;
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.service.VehicleServiceImpl;
+import at.ac.tuwien.sepm.assignment.groupphase.util.SpringFXMLLoader;
+import java.lang.invoke.MethodHandles;
+import javafx.application.Application;
+import javafx.scene.Parent;
+import javafx.scene.Scene;
+import javafx.stage.Stage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Primary;
+import org.springframework.stereotype.Component;
+
+@Component
+@ComponentScan("at.ac.tuwien.sepm.assignment.groupphase")
+public class GuiTestApplication extends Application {
+
+ private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ public static AnnotationConfigApplicationContext context;
+
+ @Configuration
+ public static class ContextConfiguration {
+
+ @Bean
+ @Primary
+ public EmployeeService employeeService() {
+ return mock(EmployeeServiceImpl.class);
+ }
+
+ @Bean
+ @Primary
+ public VehicleService vehicleService() {
+ return mock(VehicleServiceImpl.class);
+ }
+
+ @Bean
+ @Primary
+ public OperationService operationService() {
+ return mock(OperationServiceImpl.class);
+ }
+
+ @Bean
+ @Primary
+ public RegistrationService registrationService() {
+ return mock(RegistrationServiceImpl.class);
+ }
+ }
+
+ @Override
+ public void start(Stage primaryStage) throws Exception {
+ // setup application
+ primaryStage.setTitle("Test window");
+ primaryStage.setWidth(1366);
+ primaryStage.setHeight(768);
+ primaryStage.centerOnScreen();
+ primaryStage.setOnCloseRequest(event -> LOG.debug("Application shutdown initiated"));
+
+ if (getParameters().getRaw().size() < 1) {
+ throw new UnsupportedOperationException("FXML file not set");
+ }
+
+ context = new AnnotationConfigApplicationContext(GuiTestApplication.class);
+ final var fxmlLoader = context.getBean(SpringFXMLLoader.class);
+ primaryStage.setScene(
+ new Scene(
+ (Parent)
+ fxmlLoader.load(
+ getClass()
+ .getResourceAsStream(
+ "/fxml/"
+ + getParameters()
+ .getRaw()
+ .get(0)))));
+
+ // show application
+ primaryStage.show();
+ primaryStage.toFront();
+ LOG.debug("Application startup complete");
+ }
+
+ @Override
+ public void stop() {
+ LOG.debug("Stopping application");
+ context.close();
+ }
+}
diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller/RegistrationControllerTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller/RegistrationControllerTest.java
new file mode 100644
index 0000000..97fb0e7
--- /dev/null
+++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/controller/RegistrationControllerTest.java
@@ -0,0 +1,22 @@
+package at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.controller;
+
+import at.ac.tuwien.sepm.assignment.groupphase.util.HighDpiAwareApplicationTest;
+import org.junit.After;
+import org.junit.Before;
+import org.testfx.api.FxToolkit;
+
+public class RegistrationControllerTest extends HighDpiAwareApplicationTest {
+
+ @Before
+ public void setup() throws Exception {
+ FxToolkit.registerPrimaryStage();
+ FxToolkit.setupApplication(GuiTestApplication.class, "RegistrationWindow.fxml");
+ }
+
+ @After
+ public void cleanup() throws Exception {
+ FxToolkit.cleanupStages();
+ }
+
+ // TODO: implement GUI Tests
+}
diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/dao/EmployeeDAOTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/dao/EmployeeDAOTest.java
new file mode 100644
index 0000000..8485f67
--- /dev/null
+++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/dao/EmployeeDAOTest.java
@@ -0,0 +1,253 @@
+package at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dao;
+
+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.exception.ElementNotFoundException;
+import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException;
+import at.ac.tuwien.sepm.assignment.groupphase.util.Helper;
+import at.ac.tuwien.sepm.assignment.groupphase.util.JdbcTestCase;
+import java.io.InputStream;
+import java.time.LocalDate;
+import java.util.Set;
+import org.dbunit.Assertion;
+import org.dbunit.dataset.DataSetException;
+import org.dbunit.dataset.IDataSet;
+import org.dbunit.dataset.ITable;
+import org.dbunit.dataset.filter.DefaultColumnFilter;
+import org.dbunit.dataset.xml.FlatXmlDataSetBuilder;
+import org.dbunit.util.fileloader.FlatXmlDataFileLoader;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class EmployeeDAOTest extends JdbcTestCase {
+
+ private EmployeeDAO employeePersistence;
+
+ public EmployeeDAOTest() {
+ employeePersistence = new EmployeeDatabaseDAO(getJdbcConnectionManager());
+ }
+
+ @Override
+ protected IDataSet getDataSet() throws DataSetException {
+ InputStream res =
+ getClass()
+ .getClassLoader()
+ .getResourceAsStream("EmployeePersistenceTestBaseData.xml");
+ return new FlatXmlDataSetBuilder().build(res);
+ }
+
+ @Test
+ public void testListEmployees() throws PersistenceException {
+ Set<Employee> employees = employeePersistence.list();
+
+ Employee empOne =
+ Employee.builder()
+ .id(1)
+ .name("Adam")
+ .birthday(LocalDate.parse("2010-10-10"))
+ .educationLevel(EducationLevel.RS)
+ .isDriver(true)
+ .isPilot(false)
+ .build();
+
+ Employee empTwo =
+ Employee.builder()
+ .id(2)
+ .name("Max")
+ .birthday(LocalDate.parse("1990-11-11"))
+ .educationLevel(EducationLevel.NFS)
+ .isDriver(false)
+ .isPilot(false)
+ .build();
+
+ Employee empThree =
+ Employee.builder()
+ .id(3)
+ .name("Lisa")
+ .birthday(LocalDate.parse("1999-10-16"))
+ .educationLevel(EducationLevel.NKI)
+ .isDriver(true)
+ .isPilot(false)
+ .build();
+
+ Assert.assertTrue(employees.contains(empOne));
+ Assert.assertTrue(employees.contains(empTwo));
+ Assert.assertTrue(employees.contains(empThree));
+ Assert.assertEquals(3, employees.size());
+ }
+
+ @Test
+ public void testEmployeeListNoElement() throws PersistenceException {
+ Set<Employee> employees = employeePersistence.list();
+
+ Employee empOne =
+ Employee.builder()
+ .id(10)
+ .name("Adam")
+ .birthday(LocalDate.parse("2010-10-10"))
+ .educationLevel(EducationLevel.RS)
+ .isDriver(true)
+ .isPilot(false)
+ .build();
+
+ Assert.assertFalse(employees.contains(empOne));
+ }
+
+ Employee validEmployee =
+ Employee.builder()
+ .name("Testperson")
+ .birthday(LocalDate.parse("2010-11-11"))
+ .educationLevel(EducationLevel.NA)
+ .isDriver(true)
+ .isPilot(false)
+ .build();
+
+ @Test
+ public void testAddValidEmployee_EmployeeVersion() throws Exception {
+
+ employeePersistence.add(validEmployee);
+
+ String[] excludedColumnsEmployeeVersion = new String[] {"ID"};
+ String tableEmployeeVersion = "EMPLOYEEVERSION";
+
+ // load actual and expected data set
+ IDataSet actualDataSet = getConnection().createDataSet();
+ IDataSet expectedDataSet =
+ new FlatXmlDataFileLoader().load("/testAddValidEmployee_expected.xml");
+
+ // extract employeeVersion table
+ ITable actualEmployeeVersionTable = actualDataSet.getTable(tableEmployeeVersion);
+ ITable expectedEmployeeVersionTable = expectedDataSet.getTable(tableEmployeeVersion);
+
+ // exclude 'id' column as it is an autogenerated value
+ ITable actualFilteredTable =
+ DefaultColumnFilter.excludedColumnsTable(
+ actualEmployeeVersionTable, excludedColumnsEmployeeVersion);
+ ITable expectedFilteredTable =
+ DefaultColumnFilter.excludedColumnsTable(
+ expectedEmployeeVersionTable, excludedColumnsEmployeeVersion);
+
+ Assertion.assertEquals(expectedFilteredTable, actualFilteredTable);
+ }
+
+ @Test
+ public void testAddValidEmployee_Employee() throws Exception {
+
+ employeePersistence.add(validEmployee);
+
+ String[] excludedColumnsEmployee = new String[] {"VERSION", "ID"};
+ String tableEmployee = "EMPLOYEE";
+
+ // load actual and expected data set
+ IDataSet actualDataSet = getConnection().createDataSet();
+ IDataSet expectedDataSet =
+ new FlatXmlDataFileLoader().load("/testAddValidEmployee_expected.xml");
+
+ // extract employee table
+ ITable actualEmployeeTable = actualDataSet.getTable(tableEmployee);
+ ITable expectedEmployeeTable = expectedDataSet.getTable(tableEmployee);
+
+ // exclude 'version' as it is an autogenerated value
+ ITable actualFilteredEmpTable =
+ DefaultColumnFilter.excludedColumnsTable(
+ actualEmployeeTable, excludedColumnsEmployee);
+ ITable expectedFilteredEmpTable =
+ DefaultColumnFilter.excludedColumnsTable(
+ expectedEmployeeTable, excludedColumnsEmployee);
+
+ Assertion.assertEquals(expectedFilteredEmpTable, actualFilteredEmpTable);
+ }
+
+ @Test
+ public void testAddValidEmployee_Join() throws Exception {
+
+ employeePersistence.add(validEmployee);
+
+ String[] excludedColumns = new String[] {"E_VERSION", "V_ID", "E_ID"};
+ String table = "EMP_JOIN";
+ String expectedXmlDataFileName = "testAddValidEmployeeJoin_expected.xml";
+
+ String sqlJoinEmployeeVersion =
+ "SELECT e.id AS E_ID, v.name AS V_NAME, v.birthday AS V_BIRTHDAY, "
+ + "v.educationLevel as V_EDUCATIONLEVEL, "
+ + "v.isDriver AS V_ISDRIVER, v.isPilot AS V_ISPILOT "
+ + "FROM Employee e "
+ + "JOIN EmployeeVersion v ON e.version = v.id";
+
+ ITable actualFilteredJoinData =
+ Helper.getActualFilteredQueryTableData(
+ getConnection(), table, sqlJoinEmployeeVersion, excludedColumns);
+
+ ITable expectedFilteredJoinData =
+ Helper.getExpectedFilteredTableData(
+ table, excludedColumns, expectedXmlDataFileName);
+
+ Assertion.assertEquals(expectedFilteredJoinData, actualFilteredJoinData);
+ }
+
+ Employee validUpdateEmployee =
+ Employee.builder()
+ .id(3)
+ .name("Lisa")
+ .birthday(LocalDate.parse("1999-10-16"))
+ .educationLevel(EducationLevel.NKA)
+ .isDriver(true)
+ .isPilot(true)
+ .build();
+
+ @Test
+ public void testUpdateValidEmployee_EmployeeVersion() throws Exception {
+
+ employeePersistence.update(validUpdateEmployee);
+
+ String[] excludedColumnsEmployeeVersion = new String[] {"ID"};
+ String tableEmployeeVersion = "EMPLOYEEVERSION";
+
+ ITable actualTableData =
+ Helper.getActualFilteredTableData(
+ getConnection(), tableEmployeeVersion, excludedColumnsEmployeeVersion);
+ ITable expedtedTableData =
+ Helper.getExpectedFilteredTableData(
+ tableEmployeeVersion,
+ excludedColumnsEmployeeVersion,
+ "testUpdateValidEmployee_expected.xml");
+
+ Assertion.assertEquals(expedtedTableData, actualTableData);
+ }
+
+ @Test
+ public void testUpdateValidEmployee_Employee() throws Exception {
+
+ employeePersistence.update(validUpdateEmployee);
+
+ String[] excludedColumns = new String[] {"VERSION"};
+ String tableName = "EMPLOYEE";
+ String expectedXmlDataFileName = "testUpdateValidEmployee_expected.xml";
+
+ ITable actualTableData =
+ Helper.getActualFilteredTableData(getConnection(), tableName, excludedColumns);
+
+ ITable expectedTableData =
+ Helper.getExpectedFilteredTableData(
+ tableName, excludedColumns, expectedXmlDataFileName);
+
+ Assertion.assertEquals(expectedTableData, actualTableData);
+ }
+
+ @Test(expected = ElementNotFoundException.class)
+ public void testUpdateNonExistingEmployee()
+ throws PersistenceException, ElementNotFoundException {
+
+ Employee nonExistentEmployee =
+ Employee.builder()
+ .id(1000)
+ .name("Lisa")
+ .birthday(LocalDate.parse("1999-10-16"))
+ .educationLevel(EducationLevel.NKA)
+ .isDriver(true)
+ .isPilot(true)
+ .build();
+
+ employeePersistence.update(nonExistentEmployee);
+ }
+}
diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/dao/OperationDAOTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/dao/OperationDAOTest.java
new file mode 100644
index 0000000..a4a0829
--- /dev/null
+++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/dao/OperationDAOTest.java
@@ -0,0 +1,197 @@
+package at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dao;
+
+import static org.junit.Assert.assertEquals;
+
+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 at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Vehicle.VehicleType;
+import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException;
+import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException;
+import at.ac.tuwien.sepm.assignment.groupphase.util.JdbcTestCase;
+import java.time.Instant;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.LinkedList;
+import java.util.Set;
+import java.util.TimeZone;
+import org.dbunit.dataset.DataSetException;
+import org.dbunit.dataset.IDataSet;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class OperationDAOTest extends JdbcTestCase {
+
+ private static final String[] COMPARE_TABLES =
+ new String[] {"VehicleOperation", "Operation", "Vehicle", "VehicleVersion"};
+
+ private final OperationDAO operationDAO;
+
+ private final Operation o;
+
+ private final Operation originalOperation;
+
+ public OperationDAOTest() throws PersistenceException {
+ // TODO: fix once everything properly uses dependency injection
+ EmployeeDAO employeeDAO = new EmployeeDatabaseDAO(getJdbcConnectionManager());
+ RegistrationDatabaseDAO registrationDatabaseDAO =
+ new RegistrationDatabaseDAO(getJdbcConnectionManager(), employeeDAO);
+ VehicleDAO vehicleDAO =
+ new VehicleDatabaseDAO(getJdbcConnectionManager(), registrationDatabaseDAO);
+ this.operationDAO = new OperationDatabaseDAO(getJdbcConnectionManager(), vehicleDAO);
+
+ 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()
+ .id(1)
+ .opCode("RD-2B0M")
+ .severity(Severity.B)
+ .status(Status.ACTIVE)
+ .vehicles(Set.of(v1, v2, v3))
+ .created(Instant.ofEpochSecond(1514764800)) // 2018-01-01 00:00:00.0
+ .destination("New destination")
+ .additionalInfo("New information")
+ .build();
+
+ Vehicle vehicle =
+ Vehicle.builder()
+ .id(4)
+ .name("BKTW-2")
+ .constructionType(ConstructionType.HOCHDACH)
+ .type(VehicleType.BKTW)
+ .hasNef(false)
+ .status(Vehicle.Status.ZUM_BERUFUNGSORT)
+ .registrations(new LinkedList<>())
+ .build();
+
+ originalOperation =
+ Operation.builder()
+ .id(1)
+ .opCode("ALP-95E7")
+ .severity(Severity.E)
+ .created(Instant.parse("2000-01-01T00:00:00.0Z"))
+ .destination("Wiedner Hauptstraße 35, Wien")
+ .additionalInfo("Additional information")
+ .status(Status.ACTIVE)
+ .vehicles(Set.of(vehicle))
+ .build();
+ }
+
+ @BeforeClass
+ public static void before() {
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+ }
+
+ @Override
+ protected IDataSet getDataSet() throws DataSetException {
+ return getDataSet("operationDAOUpdateSetup.xml");
+ }
+
+ @Test
+ public void testUpdateNormal() throws Exception {
+ operationDAO.update(o);
+
+ compareWith("operationDAOUpdateNormal.xml", COMPARE_TABLES);
+ }
+
+ @Test(expected = ElementNotFoundException.class)
+ public void testUpdateMissing() throws Exception {
+ Operation op = o.toBuilder().id(73).build();
+
+ operationDAO.update(op);
+ }
+
+ @Test
+ public void testUpdateRemoveVehicles() throws Exception {
+ Operation op = o.toBuilder().vehicles(Collections.emptySet()).build();
+
+ operationDAO.update(op);
+
+ compareWith("operationDAOUpdateRemoveVehicles.xml", COMPARE_TABLES);
+ }
+
+ @Test
+ public void testListOperations() throws Exception {
+ Set<Operation> operationSet = operationDAO.list(EnumSet.allOf(Status.class));
+
+ assertEquals(Set.of(originalOperation), operationSet);
+ }
+
+ @Test
+ public void testGetOperations() throws Exception {
+ Operation gotOperation = operationDAO.get(originalOperation.id());
+
+ assertEquals(originalOperation, gotOperation);
+ }
+
+ @Test
+ public void testAddOperation() throws Exception {
+ long id = operationDAO.add(o);
+ assertEquals(2, id);
+ compareWith("operationDAOAddOperation.xml", COMPARE_TABLES);
+ }
+
+ @Test(expected = PersistenceException.class)
+ public void testAddFaultyOperation() throws PersistenceException {
+ Vehicle vehicle =
+ Vehicle.builder()
+ .status(Vehicle.Status.FREI_FUNK)
+ .constructionType(ConstructionType.HOCHDACH)
+ .name("BKTW_123")
+ .hasNef(true)
+ .type(VehicleType.BKTW)
+ .build();
+
+ Operation operation =
+ Operation.builder()
+ .status(Status.ACTIVE)
+ .opCode(String.valueOf(Arrays.stream(new int[200]).map(i -> 'a')))
+ .created(Instant.now())
+ .destination("Wiedner Hauptstraße 35, Wien")
+ .additionalInfo("HTU Wien")
+ .severity(Severity.B)
+ .vehicles(Set.of(vehicle))
+ .build();
+ operationDAO.add(operation);
+ }
+
+ @Test(expected = PersistenceException.class)
+ public void testAddFaultyOperation2() throws PersistenceException {
+ Vehicle vehicle =
+ Vehicle.builder()
+ .status(Vehicle.Status.FREI_FUNK)
+ .constructionType(ConstructionType.HOCHDACH)
+ .name("BKTW_123")
+ .hasNef(true)
+ .type(VehicleType.BKTW)
+ .build();
+
+ Operation operation =
+ Operation.builder()
+ .status(Status.ACTIVE)
+ .opCode("ALP-95E7")
+ .created(Instant.now())
+ .destination(
+ "Wiednerstraße 888, 1010 Wien Wiednerstraße 888, 1010 Wien Wiednerstraße 888, 1010 Wien Wiednerstraße 888, 1010 Wien Wiednerstraße 888, 1010 Wien ")
+ .additionalInfo("HTU Wien")
+ .severity(Severity.B)
+ .vehicles(Set.of(vehicle))
+ .build();
+ operationDAO.add(operation);
+ }
+}
diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/dao/RegistrationDAOTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/dao/RegistrationDAOTest.java
new file mode 100644
index 0000000..6f7ee49
--- /dev/null
+++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/dao/RegistrationDAOTest.java
@@ -0,0 +1,115 @@
+package at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dao;
+
+import static org.junit.Assert.*;
+
+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.exception.PersistenceException;
+import at.ac.tuwien.sepm.assignment.groupphase.util.JdbcTestCase;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.util.HashSet;
+import java.util.Set;
+import org.dbunit.dataset.IDataSet;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+public class RegistrationDAOTest extends JdbcTestCase {
+
+ private RegistrationDAO registrationDAO;
+
+ public RegistrationDAOTest() throws PersistenceException {
+ this.registrationDAO =
+ new RegistrationDatabaseDAO(
+ getJdbcConnectionManager(),
+ new EmployeeDatabaseDAO(getJdbcConnectionManager()));
+ }
+
+ @Override
+ protected IDataSet getDataSet() throws Exception {
+ return getDataSet("registrationTestBaseData.xml");
+ }
+
+ @Rule public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void addRegistrationsShouldSucceed() throws PersistenceException {
+ Set<Registration> registrations = new HashSet<>();
+ 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();
+ Registration registration1 =
+ Registration.builder()
+ .start(Instant.now()) // incorrect, but should be irrelevant to outcome
+ .end(Instant.now()) // same
+ .employee(employee1)
+ .build();
+ Registration registration2 =
+ Registration.builder()
+ .start(Instant.now()) // incorrect, but should be irrelevant to outcome
+ .end(Instant.now()) // same
+ .employee(employee2)
+ .build();
+ Registration registration3 =
+ Registration.builder()
+ .start(Instant.now()) // incorrect, but should be irrelevant to outcome
+ .end(Instant.now()) // same
+ .employee(employee3)
+ .build();
+ registrations.add(registration1);
+ registrations.add(registration2);
+ registrations.add(registration3);
+
+ Set<Long> returnvalues = registrationDAO.add(1, registrations);
+ assertFalse(returnvalues.isEmpty()); // can be improved...
+ }
+
+ @Test
+ public void addRegistrationToInexistentVehicleShouldFail() throws PersistenceException {
+ thrown.expect(PersistenceException.class);
+ Set<Registration> registrations = new HashSet<>();
+ 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.now())
+ .end(Instant.now())
+ .employee(employee)
+ .build();
+ registrations.add(registration);
+ registrationDAO.add(200, registrations);
+ }
+}
diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/dao/VehicleDAOTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/dao/VehicleDAOTest.java
new file mode 100644
index 0000000..294ce10
--- /dev/null
+++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/dao/VehicleDAOTest.java
@@ -0,0 +1,161 @@
+package at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dao;
+
+import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Vehicle;
+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 at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException;
+import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException;
+import at.ac.tuwien.sepm.assignment.groupphase.util.Helper;
+import at.ac.tuwien.sepm.assignment.groupphase.util.JdbcTestCase;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Set;
+import org.dbunit.Assertion;
+import org.dbunit.dataset.IDataSet;
+import org.dbunit.dataset.ITable;
+import org.dbunit.dataset.xml.FlatXmlDataSetBuilder;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class VehicleDAOTest extends JdbcTestCase {
+
+ private VehicleDAO vehicleDAO;
+
+ private Vehicle validUpdateVehicle =
+ Vehicle.builder()
+ .hasNef(true)
+ .constructionType(ConstructionType.HOCHDACH)
+ .type(VehicleType.RTW)
+ .id(2)
+ .name("RTW-2")
+ .status(Status.ABGEMELDET)
+ .build();
+
+ public VehicleDAOTest() throws PersistenceException {
+ vehicleDAO =
+ new VehicleDatabaseDAO(
+ getJdbcConnectionManager(),
+ new RegistrationDatabaseDAO(
+ getJdbcConnectionManager(),
+ new EmployeeDatabaseDAO(getJdbcConnectionManager())));
+ // TODO: use Spring Dependency Injection!
+ }
+
+ @Override
+ protected IDataSet getDataSet() throws Exception {
+ InputStream res = getClass().getClassLoader().getResourceAsStream("vehicleTestData.xml");
+ return new FlatXmlDataSetBuilder().build(res);
+ }
+
+ @Test
+ public void testListVehicle() throws PersistenceException {
+ Set<Vehicle> vehicles = vehicleDAO.list();
+
+ Vehicle v1 =
+ Vehicle.builder()
+ .id(1)
+ .constructionType(ConstructionType.HOCHDACH)
+ .name("RTW-1")
+ .hasNef(true)
+ .status(Status.ABGEMELDET)
+ .type(VehicleType.RTW)
+ .registrations(new ArrayList<>())
+ .build();
+ Vehicle v2 =
+ Vehicle.builder()
+ .id(2)
+ .constructionType(ConstructionType.MITTELHOCHDACH)
+ .name("KTW-2")
+ .hasNef(false)
+ .status(Status.FREI_WACHE)
+ .type(VehicleType.KTW)
+ .registrations(new ArrayList<>())
+ .build();
+ Vehicle v3 =
+ Vehicle.builder()
+ .id(3)
+ .constructionType(ConstructionType.NORMAL)
+ .name("NEF-3")
+ .hasNef(false)
+ .status(Status.FREI_FUNK)
+ .type(VehicleType.NEF)
+ .registrations(new ArrayList<>())
+ .build();
+
+ Assert.assertTrue(vehicles.contains(v1));
+ Assert.assertTrue(vehicles.contains(v2));
+ Assert.assertTrue(vehicles.contains(v3));
+ Assert.assertEquals(3, vehicles.size());
+ }
+
+ @Test
+ public void testVehicleListNoElement() throws PersistenceException {
+ Set<Vehicle> vehicles = vehicleDAO.list();
+
+ Vehicle v1 =
+ Vehicle.builder()
+ .id(30)
+ .constructionType(ConstructionType.NORMAL)
+ .name("NEF-3")
+ .hasNef(false)
+ .status(Status.FREI_FUNK)
+ .type(VehicleType.NEF)
+ .build();
+
+ Assert.assertFalse(vehicles.contains(v1));
+ }
+
+ @Test
+ public void testUpdateValid_VehicleVersion() throws Exception {
+ vehicleDAO.update(validUpdateVehicle);
+
+ String[] excludedColumnsVehicleVersion = new String[] {"ID", "NAME"};
+ String tableVehicleVersion = "VEHICLEVERSION";
+
+ ITable actualTableData =
+ Helper.getActualFilteredTableData(
+ getConnection(), tableVehicleVersion, excludedColumnsVehicleVersion);
+
+ ITable expectedTableData =
+ Helper.getExpectedFilteredTableData(
+ tableVehicleVersion,
+ excludedColumnsVehicleVersion,
+ "vehicleTestUpdateExpectedData.xml");
+ Assertion.assertEquals(expectedTableData, actualTableData);
+ }
+
+ @Test
+ public void testUpdateValid_Vehicle() throws Exception {
+ vehicleDAO.update(validUpdateVehicle);
+
+ String[] excludedColumnsVehicleVersion = new String[] {"VERSION", "STATUS"};
+ String tableVehicleVersion = "VEHICLE";
+
+ ITable actualTableData =
+ Helper.getActualFilteredTableData(
+ getConnection(), tableVehicleVersion, excludedColumnsVehicleVersion);
+
+ ITable expectedTableData =
+ Helper.getExpectedFilteredTableData(
+ tableVehicleVersion,
+ excludedColumnsVehicleVersion,
+ "vehicleTestUpdateExpectedData.xml");
+ Assertion.assertEquals(expectedTableData, actualTableData);
+ }
+
+ @Test(expected = ElementNotFoundException.class)
+ public void testUpdateNonExistingVehicle()
+ throws PersistenceException, ElementNotFoundException {
+ Vehicle nonExistentVehicle =
+ Vehicle.builder()
+ .id(35)
+ .constructionType(ConstructionType.NORMAL)
+ .name("NEF-3")
+ .hasNef(false)
+ .status(Status.FREI_FUNK)
+ .type(VehicleType.NEF)
+ .build();
+ vehicleDAO.update(nonExistentVehicle);
+ }
+}
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..7a16d3e
--- /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.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 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/missioncontrol/service/OperationServiceIntegrationTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/service/OperationServiceIntegrationTest.java
new file mode 100644
index 0000000..e380850
--- /dev/null
+++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/service/OperationServiceIntegrationTest.java
@@ -0,0 +1,97 @@
+package at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.service;
+
+import static org.junit.Assert.assertEquals;
+
+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.exception.InvalidOperationException;
+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.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() throws PersistenceException {
+ EmployeeDAO employeeDAO = new EmployeeDatabaseDAO(getJdbcConnectionManager());
+ RegistrationDAO registrationDAO =
+ new RegistrationDatabaseDAO(getJdbcConnectionManager(), employeeDAO);
+ VehicleDAO vehicleDAO =
+ new VehicleDatabaseDAO(
+ getJdbcConnectionManager(), (RegistrationDatabaseDAO) registrationDAO);
+ OperationDAO operationDAO =
+ new OperationDatabaseDAO(getJdbcConnectionManager(), vehicleDAO);
+
+ 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..c232e78
--- /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.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 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/missioncontrol/service/RegistrationServiceIntegrationTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/service/RegistrationServiceIntegrationTest.java
new file mode 100644
index 0000000..bfe44aa
--- /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.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.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.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..62982ac
--- /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.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 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 {
+ 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);
+ }
+}