diff options
author | Tharre <tharre3@gmail.com> | 2018-06-20 22:07:36 +0200 |
---|---|---|
committer | Tharre <tharre3@gmail.com> | 2018-06-20 22:07:36 +0200 |
commit | 0c995a05985da749d93aa56eba976c7fc621a4fa (patch) | |
tree | 5b80394920705aae5e2b6004c3dfbd839c8b8fa3 /src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/dao/RegistrationDAOTest.java | |
parent | f5bc7925a8fbbe247972a6f0e0571cc7e92fbefa (diff) | |
parent | e21feb3ac772a5394dc5381b58142c3c061de716 (diff) | |
download | sepm-groupproject-master.tar.gz sepm-groupproject-master.tar.xz sepm-groupproject-master.zip |
Diffstat (limited to 'src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/dao/RegistrationDAOTest.java')
-rw-r--r-- | src/test/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/dao/RegistrationDAOTest.java | 115 |
1 files changed, 115 insertions, 0 deletions
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..2cb54f8 --- /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.exception.PersistenceException; +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.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); + } +} |