From 625e089a36ac0d960be3eb24b6f354a70ec47f2a Mon Sep 17 00:00:00 2001 From: Riley Schneider <88947587+Ferryry@users.noreply.github.com> Date: Wed, 3 Dec 2025 22:10:24 +0100 Subject: [PATCH] Prepared new tests --- .../hhn/temp/project/provider/Database.java | 1 + .../project/provider/DatabaseManager.java | 4 +- .../project/provider/sql/insertTaskTable.sql | 2 +- .../temp/project/DatabaseGoodCasesTest.java | 41 ++++++++++++++++--- 4 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/main/java/hhn/temp/project/provider/Database.java b/src/main/java/hhn/temp/project/provider/Database.java index 2c44df3f..f11f507d 100644 --- a/src/main/java/hhn/temp/project/provider/Database.java +++ b/src/main/java/hhn/temp/project/provider/Database.java @@ -7,4 +7,5 @@ import java.sql.SQLException; public interface Database { public void connect() throws SQLException, IOException; public void close() throws SQLException; + public void clearDatabase() throws SQLException; } diff --git a/src/main/java/hhn/temp/project/provider/DatabaseManager.java b/src/main/java/hhn/temp/project/provider/DatabaseManager.java index e59789c4..044b9ead 100644 --- a/src/main/java/hhn/temp/project/provider/DatabaseManager.java +++ b/src/main/java/hhn/temp/project/provider/DatabaseManager.java @@ -9,6 +9,6 @@ import java.util.Collection; public interface DatabaseManager extends Database { public void saveObjects(Collection objects) throws ExecutionControl.NotImplementedException, IOException, SQLException; public Collection getObjects() throws ExecutionControl.NotImplementedException; - public void saveObject(E object) throws ExecutionControl.NotImplementedException, IOException, SQLException; - public E getObject(int id) throws ExecutionControl.NotImplementedException; + public void saveObject(E object) throws IOException, SQLException; + public E getObject(int id) throws SQLException; } \ No newline at end of file diff --git a/src/main/java/hhn/temp/project/provider/sql/insertTaskTable.sql b/src/main/java/hhn/temp/project/provider/sql/insertTaskTable.sql index bc00c911..aafc7901 100644 --- a/src/main/java/hhn/temp/project/provider/sql/insertTaskTable.sql +++ b/src/main/java/hhn/temp/project/provider/sql/insertTaskTable.sql @@ -1 +1 @@ -INSERT INTO Task (name, description, workerid, taskstate) VALUES (?, ?, ?, ?) \ No newline at end of file +INSERT INTO Task (taskid, name, description, workerid, taskstate) VALUES (?, ?, ?, ?, ?) \ No newline at end of file diff --git a/test/hhn/temp/project/DatabaseGoodCasesTest.java b/test/hhn/temp/project/DatabaseGoodCasesTest.java index 43768733..e47e0e8e 100644 --- a/test/hhn/temp/project/DatabaseGoodCasesTest.java +++ b/test/hhn/temp/project/DatabaseGoodCasesTest.java @@ -7,8 +7,12 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + import java.io.IOException; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Collection; public class DatabaseGoodCasesTest { @@ -16,23 +20,37 @@ public class DatabaseGoodCasesTest { private AssignmentManager manager; @BeforeEach - public void setup() { + public void setup() throws SQLException, IOException { databaseManager = new SimpleDatabaseManager<>(); + databaseManager.connect(); + databaseManager.clearDatabase(); manager = new AssignmentManager(); } @Test @DisplayName("Assert that the TestClass could be inserted into the database") - public void assertGetTestClass() throws SQLException, IOException, ExecutionControl.NotImplementedException { + public void assertGetTestClass() throws SQLException, IOException { databaseManager.connect(); - Task task = databaseManager.getObject(1); + + Task task = new Task(1, 1, "hi", "hi"); + + databaseManager.saveObject(task); + + Task taskNew = databaseManager.getObject(1); + + assertEquals(task.getTaskId(), taskNew.getTaskId()); + assertEquals(task.getName(), taskNew.getName()); + assertEquals(task.getDescription(), taskNew.getDescription()); + assertEquals(task.getWorkerId(), taskNew.getWorkerId()); + assertEquals(task.getTaskState(), taskNew.getTaskState()); + databaseManager.close(); } @Test @DisplayName("Assert that a simple Task could be inserted into the database") - public void assertInsertTestClass() throws SQLException, IOException, ExecutionControl.NotImplementedException { + public void assertInsertTask() throws SQLException, IOException, ExecutionControl.NotImplementedException { Task testTask = new Task(1, 1, "Hello World", "Description"); @@ -42,9 +60,20 @@ public class DatabaseGoodCasesTest { } @Test - @DisplayName("Assert connecting to database") - public void assertConnectToDatabase() throws SQLException, IOException { + @DisplayName("Assert that simple Tasks could be inserted into the database") + public void assertInsertMultipleTasks() throws SQLException, IOException, ExecutionControl.NotImplementedException { + + Task testTaskZero = new Task(1, 1, "Hello", "Description"); + Task testTaskOne = new Task(2, 2, "World", "Description"); + Task testTaskTwo = new Task(3, 3, "Hello World", "Description"); + + Collection tasks = new ArrayList<>(); + tasks.add(testTaskZero); + tasks.add(testTaskOne); + tasks.add(testTaskTwo); + databaseManager.connect(); + databaseManager.saveObjects(tasks); databaseManager.close(); } } \ No newline at end of file