summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Kehrer <felix.kehrer@gmail.com>2018-05-06 16:01:10 +0200
committerFelix Kehrer <felix.kehrer@gmail.com>2018-05-07 14:42:08 +0200
commit5a6c00ebc1583e0505fb795b3483f8937e7b8eb4 (patch)
tree67bfb0c8023e1f8a37a282d0b5d4bb0e50bd9779
parentf4b5613fd3c6ce8e45fb7b99d10b33bec12ad43c (diff)
downloadsepm-groupproject-5a6c00ebc1583e0505fb795b3483f8937e7b8eb4.tar.gz
sepm-groupproject-5a6c00ebc1583e0505fb795b3483f8937e7b8eb4.tar.xz
sepm-groupproject-5a6c00ebc1583e0505fb795b3483f8937e7b8eb4.zip
Added groundwork for DAO tests
-rw-r--r--pom.xml4
-rw-r--r--src/main/resources/sql/H2RegistrationDAOTest_depopulate.sql5
-rw-r--r--src/main/resources/sql/H2RegistrationDAOTest_populate.sql10
-rw-r--r--src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAOTest.java65
4 files changed, 82 insertions, 2 deletions
diff --git a/pom.xml b/pom.xml
index 42f24e7..95747aa 100644
--- a/pom.xml
+++ b/pom.xml
@@ -66,13 +66,13 @@
<version>${auto-value.version}</version>
<scope>provided</scope>
</dependency>
- <!-- runtime dependencies -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
- <scope>runtime</scope>
+ <scope>compile</scope>
</dependency>
+ <!-- runtime dependencies -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
diff --git a/src/main/resources/sql/H2RegistrationDAOTest_depopulate.sql b/src/main/resources/sql/H2RegistrationDAOTest_depopulate.sql
new file mode 100644
index 0000000..f43b641
--- /dev/null
+++ b/src/main/resources/sql/H2RegistrationDAOTest_depopulate.sql
@@ -0,0 +1,5 @@
+DELETE FROM Registration;
+DELETE FROM Vehicle;
+DELETE FROM VehicleVersion;
+DELETE FROM Employee;
+DELETE FROM EmployeeVersion; \ No newline at end of file
diff --git a/src/main/resources/sql/H2RegistrationDAOTest_populate.sql b/src/main/resources/sql/H2RegistrationDAOTest_populate.sql
new file mode 100644
index 0000000..8322479
--- /dev/null
+++ b/src/main/resources/sql/H2RegistrationDAOTest_populate.sql
@@ -0,0 +1,10 @@
+INSERT INTO EmployeeVersion (id, name, birthday, educationLevel, isDriver, isPilot) VALUES (1, 'John Doe', '2000-01-01', 'RS', TRUE, TRUE);
+INSERT INTO EmployeeVersion (id, name, birthday, educationLevel, isDriver, isPilot) VALUES (2, 'Nick "Kage" Verily', '1990-01-01', 'NKV', TRUE, FALSE);
+INSERT INTO EmployeeVersion (id, name, birthday, educationLevel, isDriver, isPilot) VALUES (3, 'Nicht Arzt', '1980-01-01', 'NA', FALSE, FALSE);
+INSERT INTO Employee (id, version) VALUES (1, 1);
+INSERT INTO Employee (id, version) VALUES (2, 2);
+INSERT INTO Employee (id, version) VALUES (3, 3);
+INSERT INTO VehicleVersion (id, name, constructionType, type) VALUES (1, 'RTW-1', 'Hochdach', 'RTW');
+INSERT INTO VehicleVersion (id, name, constructionType, type) VALUES (2, 'NEF-1', 'Normal', 'NEF');
+INSERT INTO Vehicle (id, version, status) VALUES (1, 1, 'abgemeldet');
+INSERT INTO Vehicle (id, version, status) VALUES (2, 2, 'abgemeldet'); \ No newline at end of file
diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAOTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAOTest.java
new file mode 100644
index 0000000..03b70b1
--- /dev/null
+++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/H2RegistrationDAOTest.java
@@ -0,0 +1,65 @@
+package at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.dao;
+
+import static org.junit.Assert.*;
+
+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 org.h2.tools.RunScript;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class H2RegistrationDAOTest {
+
+ // Base taken from EmployeePersistenceTest
+
+ 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 H2RegistrationDAOTest() throws PersistenceException {
+ this.registrationDAO = new H2RegistrationDAO(new JDBCConnectionManager(JDBC_URL));
+ }
+
+ @BeforeClass
+ public static void setupDatabase() throws SQLException {
+ RunScript.execute(
+ JDBC_URL,
+ USER,
+ PASSWORD,
+ "classpath:sql/database.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);
+ }
+
+ @After
+ public void tearDown() throws SQLException {
+ RunScript.execute(
+ JDBC_URL,
+ USER,
+ PASSWORD,
+ "classpath:sql/H2RegistrationDAOTest_depopulate.sql",
+ Charset.forName("UTF8"),
+ false);
+ }
+
+ @Test
+ public void add() {}
+}