database #3
@@ -7,4 +7,5 @@ import java.sql.SQLException;
|
|||||||
public interface Database {
|
public interface Database {
|
||||||
public void connect() throws SQLException, IOException;
|
public void connect() throws SQLException, IOException;
|
||||||
public void close() throws SQLException;
|
public void close() throws SQLException;
|
||||||
|
public void clearDatabase() throws SQLException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,6 @@ import java.util.Collection;
|
|||||||
public interface DatabaseManager<E> extends Database {
|
public interface DatabaseManager<E> extends Database {
|
||||||
public void saveObjects(Collection<E> objects) throws ExecutionControl.NotImplementedException, IOException, SQLException;
|
public void saveObjects(Collection<E> objects) throws ExecutionControl.NotImplementedException, IOException, SQLException;
|
||||||
public Collection<E> getObjects() throws ExecutionControl.NotImplementedException;
|
public Collection<E> getObjects() throws ExecutionControl.NotImplementedException;
|
||||||
public void saveObject(E object) throws ExecutionControl.NotImplementedException, IOException, SQLException;
|
public void saveObject(E object) throws IOException, SQLException;
|
||||||
public E getObject(int id) throws ExecutionControl.NotImplementedException;
|
public E getObject(int id) throws SQLException;
|
||||||
}
|
}
|
||||||
@@ -1 +1 @@
|
|||||||
INSERT INTO Task (name, description, workerid, taskstate) VALUES (?, ?, ?, ?)
|
INSERT INTO Task (taskid, name, description, workerid, taskstate) VALUES (?, ?, ?, ?, ?)
|
||||||
@@ -7,8 +7,12 @@ import org.junit.jupiter.api.BeforeEach;
|
|||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
public class DatabaseGoodCasesTest {
|
public class DatabaseGoodCasesTest {
|
||||||
|
|
||||||
@@ -16,23 +20,37 @@ public class DatabaseGoodCasesTest {
|
|||||||
private AssignmentManager manager;
|
private AssignmentManager manager;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() {
|
public void setup() throws SQLException, IOException {
|
||||||
databaseManager = new SimpleDatabaseManager<>();
|
databaseManager = new SimpleDatabaseManager<>();
|
||||||
|
databaseManager.connect();
|
||||||
|
databaseManager.clearDatabase();
|
||||||
manager = new AssignmentManager();
|
manager = new AssignmentManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Assert that the TestClass could be inserted into the database")
|
@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();
|
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();
|
databaseManager.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Assert that a simple Task could be inserted into the database")
|
@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");
|
Task testTask = new Task(1, 1, "Hello World", "Description");
|
||||||
|
|
||||||
@@ -42,9 +60,20 @@ public class DatabaseGoodCasesTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Assert connecting to database")
|
@DisplayName("Assert that simple Tasks could be inserted into the database")
|
||||||
public void assertConnectToDatabase() throws SQLException, IOException {
|
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<Task> tasks = new ArrayList<>();
|
||||||
|
tasks.add(testTaskZero);
|
||||||
|
tasks.add(testTaskOne);
|
||||||
|
tasks.add(testTaskTwo);
|
||||||
|
|
||||||
databaseManager.connect();
|
databaseManager.connect();
|
||||||
|
databaseManager.saveObjects(tasks);
|
||||||
databaseManager.close();
|
databaseManager.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user