diff options
Diffstat (limited to 'src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDAOTest.java')
-rw-r--r-- | src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDAOTest.java | 172 |
1 files changed, 0 insertions, 172 deletions
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); - } -} |