From 5a6c00ebc1583e0505fb795b3483f8937e7b8eb4 Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Sun, 6 May 2018 16:01:10 +0200 Subject: Added groundwork for DAO tests --- src/main/resources/sql/H2RegistrationDAOTest_populate.sql | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/main/resources/sql/H2RegistrationDAOTest_populate.sql (limited to 'src/main/resources/sql/H2RegistrationDAOTest_populate.sql') 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 -- cgit v1.2.3-70-g09d2 From 12302ff88604440cac2257741b4502b9b173d708 Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Mon, 7 May 2018 14:53:00 +0200 Subject: Changed test data to be in sync with new database schema --- src/main/resources/sql/H2RegistrationDAOTest_populate.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main/resources/sql/H2RegistrationDAOTest_populate.sql') diff --git a/src/main/resources/sql/H2RegistrationDAOTest_populate.sql b/src/main/resources/sql/H2RegistrationDAOTest_populate.sql index 8322479..b81eb78 100644 --- a/src/main/resources/sql/H2RegistrationDAOTest_populate.sql +++ b/src/main/resources/sql/H2RegistrationDAOTest_populate.sql @@ -4,7 +4,7 @@ INSERT INTO EmployeeVersion (id, name, birthday, educationLevel, isDriver, isPil 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 VehicleVersion (id, name, hasNef, constructionType, type) VALUES (1, 'RTW-1', TRUE, 'Hochdach', 'RTW'); +INSERT INTO VehicleVersion (id, name, hasNef, constructionType, type) VALUES (2, 'NEF-1', FALSE, '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 -- cgit v1.2.3-70-g09d2 From d4d8ba884a80d0f7483efe2fb2c981023f983022 Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Mon, 7 May 2018 17:23:31 +0200 Subject: Changed enums (and similar fields) to match enum names of Java --- .../einsatzverwaltung/dao/RegistrationDatabaseDAO.java | 2 +- src/main/resources/sql/H2RegistrationDAOTest_populate.sql | 8 ++++---- src/main/resources/sql/database.sql | 10 ++++++---- 3 files changed, 11 insertions(+), 9 deletions(-) (limited to 'src/main/resources/sql/H2RegistrationDAOTest_populate.sql') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDatabaseDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDatabaseDAO.java index e4bc0ab..8fbcd18 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDatabaseDAO.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDatabaseDAO.java @@ -25,7 +25,7 @@ public class RegistrationDatabaseDAO implements RegistrationDAO { private static final String ADD_REGISTRATION = "INSERT INTO Registration (vehicleId, employeeId, start, end, active) VALUES (?,?,?,?,?);"; private static final String UPDATE_VEHICLE = - "UPDATE Vehicle SET status = 'frei_wache' WHERE id = ?;"; + "UPDATE Vehicle SET status = 'FREI_WACHE' WHERE id = ?;"; private PreparedStatement addRegistration; private PreparedStatement updateVehicle; diff --git a/src/main/resources/sql/H2RegistrationDAOTest_populate.sql b/src/main/resources/sql/H2RegistrationDAOTest_populate.sql index b81eb78..3c268a0 100644 --- a/src/main/resources/sql/H2RegistrationDAOTest_populate.sql +++ b/src/main/resources/sql/H2RegistrationDAOTest_populate.sql @@ -4,7 +4,7 @@ INSERT INTO EmployeeVersion (id, name, birthday, educationLevel, isDriver, isPil 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, hasNef, constructionType, type) VALUES (1, 'RTW-1', TRUE, 'Hochdach', 'RTW'); -INSERT INTO VehicleVersion (id, name, hasNef, constructionType, type) VALUES (2, 'NEF-1', FALSE, '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 +INSERT INTO VehicleVersion (id, name, hasNef, constructionType, type) VALUES (1, 'RTW-1', TRUE, 'HOCHDACH', 'RTW'); +INSERT INTO VehicleVersion (id, name, hasNef, constructionType, type) VALUES (2, 'NEF-1', FALSE, '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/main/resources/sql/database.sql b/src/main/resources/sql/database.sql index e775550..4f3adf7 100644 --- a/src/main/resources/sql/database.sql +++ b/src/main/resources/sql/database.sql @@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS VehicleVersion ( constructionType VARCHAR NOT NULL, type VARCHAR NOT NULL, hasNef BOOLEAN NOT NULL, - CHECK constructionType IN ('Normal', 'Hochdach', 'Mittelhochdach'), + CHECK constructionType IN ('NORMAL', 'HOCHDACH', 'MITTELHOCHDACH'), CHECK type IN ('BKTW', 'KTW-B', 'KTW', 'RTW', 'NEF', 'NAH') ); @@ -13,8 +13,8 @@ CREATE TABLE IF NOT EXISTS Vehicle ( version BIGINT NOT NULL, status VARCHAR NOT NULL, FOREIGN KEY (version) REFERENCES VehicleVersion(id), - CHECK status IN ('abgemeldet', 'frei_wache', 'zum_berufungsort', 'am_berufungsort', 'zum_zielort', - 'am_zielort', 'frei_funk', 'deleted') + CHECK status IN ('ABGEMELDET', 'FREI_WACHE', 'ZUM_BERUFUNGSORT', 'AM_BERUFUNGSORT', 'ZUM_ZIELORT', + 'AM_ZIELORT', 'FREI_FUNK', 'DELETED') ); CREATE TABLE IF NOT EXISTS EmployeeVersion ( @@ -51,7 +51,9 @@ CREATE TABLE IF NOT EXISTS Operation ( created TIMESTAMP NOT NULL, destination VARCHAR(100) NOT NULL, additionalInfo VARCHAR(100), - CHECK severity IN ('A', 'B', 'C', 'D', 'E', 'O') + status VARCHAR NOT NULL, + CHECK severity IN ('A', 'B', 'C', 'D', 'E', 'O'), + CHECK status IN ('ACTIVE', 'COMPLETED', 'CANCELLED') ); CREATE TABLE IF NOT EXISTS VehicleOperation ( -- cgit v1.2.3-70-g09d2 From 834f9b4fff11c778dbb09dc74a88d658fc094a54 Mon Sep 17 00:00:00 2001 From: Felix Kehrer Date: Mon, 7 May 2018 18:06:00 +0200 Subject: Changed test behaviour to leave "clean" database for other tests --- .../sql/H2RegistrationDAOTest_populate.sql | 5 +++++ .../dao/RegistrationDatabaseDAOTest.java | 24 ++++++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) (limited to 'src/main/resources/sql/H2RegistrationDAOTest_populate.sql') diff --git a/src/main/resources/sql/H2RegistrationDAOTest_populate.sql b/src/main/resources/sql/H2RegistrationDAOTest_populate.sql index 3c268a0..7e7b428 100644 --- a/src/main/resources/sql/H2RegistrationDAOTest_populate.sql +++ b/src/main/resources/sql/H2RegistrationDAOTest_populate.sql @@ -1,3 +1,8 @@ +DELETE FROM Registration; +DELETE FROM Vehicle; +DELETE FROM VehicleVersion; +DELETE FROM Employee; +DELETE FROM EmployeeVersion; 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); diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDatabaseDAOTest.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDatabaseDAOTest.java index 980c429..03059ff 100644 --- a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDatabaseDAOTest.java +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/RegistrationDatabaseDAOTest.java @@ -14,8 +14,7 @@ import java.time.LocalDate; import java.util.LinkedList; import java.util.List; import org.h2.tools.RunScript; -import org.junit.After; -import org.junit.Before; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; @@ -45,10 +44,6 @@ public class RegistrationDatabaseDAOTest { "classpath:sql/database.sql", Charset.forName("UTF8"), false); - } - - @Before - public void setUp() throws SQLException { RunScript.execute( JDBC_URL, USER, @@ -57,9 +52,20 @@ public class RegistrationDatabaseDAOTest { Charset.forName("UTF8"), false); } - - @After - public void tearDown() throws SQLException { + /* + @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, -- cgit v1.2.3-70-g09d2