aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao
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/einsatzverwaltung/dao
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/einsatzverwaltung/dao')
-rw-r--r--src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/EmployeeDAOTest.java254
-rw-r--r--src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationDAOTest.java157
-rw-r--r--src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDAOTest.java172
-rw-r--r--src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehicleDAOTest.java161
4 files changed, 0 insertions, 744 deletions
diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/EmployeeDAOTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/EmployeeDAOTest.java
deleted file mode 100644
index 585e5ea..0000000
--- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/EmployeeDAOTest.java
+++ /dev/null
@@ -1,254 +0,0 @@
-package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao;
-
-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.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() throws PersistenceException {
- 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();
-
- System.out.println(LocalDate.parse("2010-10-10"));
- 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/einsatzverwaltung/dao/OperationDAOTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationDAOTest.java
deleted file mode 100644
index f173376..0000000
--- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/OperationDAOTest.java
+++ /dev/null
@@ -1,157 +0,0 @@
-package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao;
-
-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.einsatzverwaltung.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.Set;
-import org.dbunit.dataset.DataSetException;
-import org.dbunit.dataset.IDataSet;
-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;
-
- 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.now())
- .destination("New description")
- .additionalInfo("Test")
- .build();
- }
-
- @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));
-
- // TODO: operations.list() currently doesn't set the vehicles set
- // assertEquals(Set.of(o), operationSet);
- }
-
- @Test
- public void testAddOperation() throws Exception {
- operationDAO.add(o);
-
- // TODO: won't work because id won't match
- // compareWith("operationDAOUpdateNormal.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/einsatzverwaltung/dao/RegistrationDAOTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDAOTest.java
deleted file mode 100644
index e8ea809..0000000
--- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDAOTest.java
+++ /dev/null
@@ -1,172 +0,0 @@
-package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao;
-
-import static org.junit.Assert.*;
-
-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.exception.PersistenceException;
-import at.ac.tuwien.sepm.assignment.groupphase.util.JDBCConnectionManager;
-import java.nio.charset.Charset;
-import java.sql.SQLException;
-import java.time.Instant;
-import java.time.LocalDate;
-import java.util.HashSet;
-import java.util.Set;
-import org.h2.tools.RunScript;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-public class RegistrationDAOTest {
-
- // Base taken from EmployeeDAOTest
-
- private static final String JDBC_DRIVER = org.h2.Driver.class.getName();
- private static final String JDBC_URL = "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1";
- private static final String USER = "";
- private static final String PASSWORD = "";
-
- private RegistrationDAO registrationDAO;
-
- public RegistrationDAOTest() throws PersistenceException {
- JDBCConnectionManager jdbcConnectionManager = new JDBCConnectionManager(JDBC_URL);
- this.registrationDAO =
- new RegistrationDatabaseDAO(
- jdbcConnectionManager, new EmployeeDatabaseDAO(jdbcConnectionManager));
- // TODO: Use Spring Dependency Injection here!
- }
-
- @BeforeClass
- public static void setupDatabase() throws SQLException {
- RunScript.execute(
- JDBC_URL,
- USER,
- PASSWORD,
- "classpath:sql/database.sql",
- Charset.forName("UTF8"),
- false);
- RunScript.execute(
- JDBC_URL,
- USER,
- PASSWORD,
- "classpath:sql/H2RegistrationDAOTest_populate.sql",
- Charset.forName("UTF8"),
- false);
- }
- /*
- @Before
- public void setUp() throws SQLException {
- RunScript.execute(
- JDBC_URL,
- USER,
- PASSWORD,
- "classpath:sql/H2RegistrationDAOTest_populate.sql",
- Charset.forName("UTF8"),
- false);
- }
- */
- @AfterClass
- public static void tearDown() throws SQLException {
- RunScript.execute(
- JDBC_URL,
- USER,
- PASSWORD,
- "classpath:sql/H2RegistrationDAOTest_depopulate.sql",
- Charset.forName("UTF8"),
- false);
- }
-
- @Rule public ExpectedException thrown = ExpectedException.none();
-
- @Test
- public void addRegistrationsShouldSucceed() throws PersistenceException {
- 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();
- 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.MIN)
- .end(Instant.MAX)
- .employee(employee)
- .build();
- registrations.add(registration);
- registrationDAO.add(200, registrations);
- }
-}
diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehicleDAOTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehicleDAOTest.java
deleted file mode 100644
index 1862214..0000000
--- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehicleDAOTest.java
+++ /dev/null
@@ -1,161 +0,0 @@
-package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao;
-
-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.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.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);
- }
-}