22 Commits

Author SHA1 Message Date
4eb0f6c3bd Merge pull request 'database' (#3) from database into main
Reviewed-on: #3
2025-12-08 18:10:07 +01:00
Riley Schneider
0dd7fd4687 Provide mock-like DB manager for integration testing 2025-12-08 18:06:43 +01:00
Riley Schneider
e9b2ad0a57 Heavily refactored DatabaseManager.java and SimpleDatabaseManager.java. Fully refactored DatabaseGoodCasesTest.java and DatabaseBadCasesTest.java. 2025-12-08 17:50:21 +01:00
Riley Schneider
292d6c74c3 Implemented Update method 2025-12-03 23:17:31 +01:00
Riley Schneider
f2cc964d39 Added new tests that needs to be implemented. 2025-12-03 23:04:21 +01:00
Riley Schneider
995fba6fce Added a placeholder method to delete objects from the database. 2025-12-03 22:29:52 +01:00
Riley Schneider
daafd7d09e Fixed a typo in the query 2025-12-03 22:24:04 +01:00
Riley Schneider
41e711ab74 Added resultSet.next() 2025-12-03 22:22:30 +01:00
Riley Schneider
625e089a36 Prepared new tests 2025-12-03 22:10:24 +01:00
Riley Schneider
d9da291d45 Added first sql-queries into the SimpleDatabaseManager.java (Still failing / Red Errors) 2025-12-03 21:45:26 +01:00
Riley Schneider
b801ea7d21 Added NotImplementedException, edited some DatabaseGoodCasesTest tests. 2025-12-03 20:52:47 +01:00
Riley Schneider
8150fdbf13 Updated from origin/main 2025-12-03 20:42:23 +01:00
0db43fe51a Fixed Merge Conflicts, uploaded local main 2025-12-03 20:37:10 +01:00
90fbacadaa Merge pull request 'database' (#2) from database into main
Reviewed-on: #2
2025-12-03 20:16:49 +01:00
Riley Schneider
57144fa772 Updated MySQL Methods, Tests and Information accordingly. (High security risk btw) 2025-12-03 20:15:28 +01:00
Riley Schneider
d3488f1f1c Update connect method in SimpleDatabaseManager.java 2025-12-03 18:26:13 +01:00
Riley Schneider
382aad70f7 Updated gitignore 2025-12-03 18:24:42 +01:00
Riley Schneider
dbebcad97d First runnable tests for Database / Commented out Good/BadCasesTests (not relevant to this branch) 2025-12-03 18:23:07 +01:00
Riley Schneider
ec0abd85b9 Merge remote-tracking branch 'origin/database' into database
# Conflicts:
#	.gradle/8.14/executionHistory/executionHistory.lock
#	.gradle/8.14/fileHashes/fileHashes.bin
#	.gradle/8.14/fileHashes/fileHashes.lock
#	.gradle/buildOutputCleanup/buildOutputCleanup.lock
#	.gradle/buildOutputCleanup/cache.properties
#	build/classes/java/main/hhn/temp/project/provider/DatabaseManager.class
#	build/tmp/compileJava/previous-compilation-data.bin
#	src/main/java/hhn/temp/project/provider/SimpleDatabaseManager.java
#	test/hhn/temp/project/BadCasesTest.java
#	test/hhn/temp/project/DatabaseBadCasesTest.java
#	test/hhn/temp/project/DatabaseGoodCasesTest.java
#	test/hhn/temp/project/GoodCasesTest.java
2025-12-03 18:20:36 +01:00
Riley Schneider
04f2087456 First runnable tests for Database / Commented out Good/BadCasesTests (not relevant to this branch) 2025-12-03 18:19:48 +01:00
Riley Schneider
0c4f092312 Backup 2025-12-03 17:49:06 +01:00
Riley Schneider
bc0e30860c First database tests 2025-12-03 17:30:33 +01:00
46 changed files with 537 additions and 388 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
build/
.gradle/ .gradle/

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,2 +1,2 @@
#Wed Dec 03 17:27:55 CET 2025 #Wed Dec 03 20:34:21 CET 2025
gradle.version=8.14 gradle.version=8.14

BIN
.gradle/file-system.probe Normal file

Binary file not shown.

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/modules/Template.test.iml" filepath="$PROJECT_DIR$/.idea/modules/Template.test.iml" />
</modules>
</component>
</project>

8
.idea/modules/Template.test.iml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="AdditionalModuleElements">
<content url="file://$MODULE_DIR$/../../src/test" dumb="true">
<sourceFolder url="file://$MODULE_DIR$/../../src/test/resources" type="java-test-resource" />
</content>
</component>
</module>

View File

@@ -14,6 +14,7 @@ dependencies {
testImplementation platform('org.junit:junit-bom:5.10.0') testImplementation platform('org.junit:junit-bom:5.10.0')
testImplementation 'org.junit.jupiter:junit-jupiter' testImplementation 'org.junit.jupiter:junit-jupiter'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher' testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
implementation 'com.mysql:mysql-connector-j:9.5.0'
} }
jacoco { jacoco {

Binary file not shown.

View File

@@ -1,174 +0,0 @@
body {
margin: 0;
padding: 0;
font-family: sans-serif;
font-size: 12pt;
}
body, a, a:visited {
color: #303030;
}
#content {
padding: 30px 50px;
}
#content h1 {
font-size: 160%;
margin-bottom: 10px;
}
#footer {
margin-top: 100px;
font-size: 80%;
white-space: nowrap;
}
#footer, #footer a {
color: #a0a0a0;
}
#line-wrapping-toggle {
vertical-align: middle;
}
#label-for-line-wrapping-toggle {
vertical-align: middle;
}
ul {
margin-left: 0;
}
h1, h2, h3 {
white-space: nowrap;
}
h2 {
font-size: 120%;
}
.tab-container .tab-container {
margin-left: 8px;
}
ul.tabLinks {
padding: 0;
margin-bottom: 0;
overflow: auto;
min-width: 800px;
width: auto;
border-bottom: solid 1px #aaa;
}
ul.tabLinks li {
float: left;
height: 100%;
list-style: none;
padding: 5px 10px;
border-radius: 7px 7px 0 0;
border: solid 1px transparent;
border-bottom: none;
margin-right: 6px;
background-color: #f0f0f0;
}
ul.tabLinks li.deselected > a {
color: #6d6d6d;
}
ul.tabLinks li:hover {
background-color: #fafafa;
}
ul.tabLinks li.selected {
background-color: #c5f0f5;
border-color: #aaa;
}
ul.tabLinks a {
font-size: 120%;
display: block;
outline: none;
text-decoration: none;
margin: 0;
padding: 0;
}
ul.tabLinks li h2 {
margin: 0;
padding: 0;
}
div.tab {
}
div.selected {
display: block;
}
div.deselected {
display: none;
}
div.tab table {
min-width: 350px;
width: auto;
border-collapse: collapse;
}
div.tab th, div.tab table {
border-bottom: solid 1px #d0d0d0;
}
div.tab th {
text-align: left;
white-space: nowrap;
padding-left: 6em;
}
div.tab th:first-child {
padding-left: 0;
}
div.tab td {
white-space: nowrap;
padding-left: 6em;
padding-top: 5px;
padding-bottom: 5px;
}
div.tab td:first-child {
padding-left: 0;
}
div.tab td.numeric, div.tab th.numeric {
text-align: right;
}
span.code {
display: inline-block;
margin-top: 0;
margin-bottom: 1em;
}
span.code pre {
font-size: 11pt;
padding: 10px;
margin: 0;
background-color: #f7f7f7;
border: solid 1px #d0d0d0;
min-width: 700px;
width: auto;
}
span.wrapped pre {
word-wrap: break-word;
white-space: pre-wrap;
word-break: break-all;
}
label.hidden {
display: none;
}

View File

@@ -1,20 +0,0 @@
Manifest-Version: 1.0
Created-By: Apache Maven Bundle Plugin 6.0.0
Build-Jdk-Spec: 21
Build-Tool-Jdk-Spec: 21
Automatic-Module-Name: org.jacoco.agent
Bnd-LastModified: 1743583180503
Bundle-Description: JaCoCo Agent
Bundle-License: https://www.eclipse.org/legal/epl-2.0/
Bundle-ManifestVersion: 2
Bundle-Name: JaCoCo Agent
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-SymbolicName: org.jacoco.agent
Bundle-Vendor: Mountainminds GmbH & Co. KG
Bundle-Version: 0.8.13.202504020838
Eclipse-SourceReferences: scm:git:git://github.com/jacoco/jacoco.git;pat
h="org.jacoco.agent";commitId=78d5eff856bbe6129f05012e40c13d1840e20598
Export-Package: org.jacoco.agent;version="0.8.13"
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.5))"
Tool: Bnd-7.0.0.202310060912

View File

@@ -1,3 +0,0 @@
artifactId=org.jacoco.agent
groupId=org.jacoco
version=0.8.13

View File

@@ -1,106 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2009, 2025 Mountainminds GmbH & Co. KG and Contributors
This program and the accompanying materials are made available under
the terms of the Eclipse Public License 2.0 which is available at
http://www.eclipse.org/legal/epl-2.0
SPDX-License-Identifier: EPL-2.0
Contributors:
Evgeny Mandrikov - initial API and implementation
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.build</artifactId>
<version>0.8.13</version>
<relativePath>../org.jacoco.build</relativePath>
</parent>
<artifactId>org.jacoco.agent</artifactId>
<name>JaCoCo :: Agent</name>
<description>JaCoCo Agent</description>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>org.jacoco.agent.rt</artifactId>
<classifier>all</classifier>
<version>${project.version}</version>
<destFileName>jacocoagent.jar</destFileName>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.directory}/classes/jacocoagent.jar</file>
<type>jar</type>
<classifier>runtime</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -1,72 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>About</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body lang="EN-US">
<h2>About This Content</h2>
<p>
2025/04/02
</p>
<h3>License</h3>
<p>
All Content in this distribution is made available by Mountainminds GmbH &amp; Co.
KG, Munich. Unless otherwise indicated below, the Content is provided to you
under the terms and conditions of the Eclipse Public License Version 2.0
(&quot;EPL&quot;). A copy of the EPL is available at
<a href="https://www.eclipse.org/legal/epl-2.0/">https://www.eclipse.org/legal/epl-2.0/</a>.
For purposes of the EPL, "Program" will mean the Content.
</p>
<h3>Third Party Content</h3>
<p>
The Content includes items that have been sourced from third parties as set
out below.
</p>
<h4>ASM</h4>
<p>
<a href="https://asm.ow2.io/">ASM 9.8</a> is subject to the terms and
conditions of the following license:
</p>
<pre>
ASM: a very small and fast Java bytecode manipulation framework
Copyright (c) 2000-2011 INRIA, France Telecom
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
</pre>
</body>
</html>

View File

@@ -1,2 +0,0 @@
Manifest-Version: 1.0

View File

@@ -0,0 +1,44 @@
commit bc0e30860cb3697296a4ef6ee22735a5c83cf522 (HEAD -> database)
Author: Riley Schneider <88947587+Ferryry@users.noreply.github.com>
Date: Wed Dec 3 17:30:33 2025 +0100
First database tests
commit 26f7ecbee653b98739e75eb8c4707745f252a1a8 (origin/main, origin/HEAD, main)
Merge: 668a76e2 eed1390c
Author: Ferryry <rileymika99@gmail.com>
Date: Wed Dec 3 16:44:45 2025 +0100
Merge pull request 'Skeleton' (#1) from Skeleton into main
Reviewed-on: https://home.luithardt.cloud:5400/KevinSchoenmayer/GseTDDUebungKCLR/pulls/1
commit eed1390c6513f1b5e827fd6e09c91f54da7be463 (origin/Skeleton, Skeleton)
Author: Riley Schneider <88947587+Ferryry@users.noreply.github.com>
Date: Wed Dec 3 16:42:41 2025 +0100
Remove database folder
commit b732d8d4b50abc5893d138c6a574fef0025981e0
Author: Riley Schneider <88947587+Ferryry@users.noreply.github.com>
Date: Wed Dec 3 16:38:10 2025 +0100
Initial Commit
commit c5e26bf594b282ab3d665590d0535b61afa18247
Author: KevinSchoenmayer <kschoenmay@stud.hs-heilbronn.de>
Date: Wed Dec 3 16:28:17 2025 +0100
Rough Skeleton for Tests and Classes
commit 668a76e26cfd908499bb74a7732269206062df86
Author: KevinSchoenmayer <kschoenmay@stud.hs-heilbronn.de>
Date: Wed Dec 3 15:26:09 2025 +0100
Initial Test Push
commit 2d963c7fd8ab188625c0e2bc9203c4d55ee07aa3
Author: KevinSchoenmayer <kschoenmay@stud.hs-heilbronn.de>
Date: Wed Dec 3 15:18:41 2025 +0100
Initial commit

View File

@@ -27,7 +27,7 @@ public class AssignmentManager {
if (!workerMap.containsKey(workerId) || name == null || description == null) { if (!workerMap.containsKey(workerId) || name == null || description == null) {
throw new IllegalArgumentException("WorkerId must exist and name or description can't be null"); throw new IllegalArgumentException("WorkerId must exist and name or description can't be null");
} }
Task task = new Task(++taskIdCounter, workerId, name, description, this); Task task = new Task(++taskIdCounter, workerId, name, description);
taskMap.put(taskIdCounter, task); taskMap.put(taskIdCounter, task);
return taskIdCounter; return taskIdCounter;
} }

View File

@@ -5,10 +5,8 @@ public class Task {
String description; String description;
int taskId; int taskId;
int workerId; int workerId;
AssignmentManager manager;
TaskState state; TaskState state;
public Task(int taskId, int workerId, String name, String description, AssignmentManager manager) { public Task(int taskId, int workerId, String name, String description) {
this.manager = manager;
this.name = name; this.name = name;
this.description = description; this.description = description;
this.taskId = taskId; this.taskId = taskId;

View File

@@ -1,5 +1,29 @@
package hhn.temp.project.provider; package hhn.temp.project.provider;
import java.io.IOException;
import java.nio.file.Path;
import java.sql.SQLException;
/**
* A database interface with basic database connectivity
* @author Riley Schneider
*/
public interface Database { public interface Database {
public boolean connect(); /**
* Creates a connection to the database
* @throws SQLException Thrown if database error occurs
*/
void connect() throws SQLException;
/**
* Closes a connection to the database
* @throws SQLException Thrown if database error occurs
*/
void close() throws SQLException;
/**
* Clears the entire tables in the database and reset primary key counter to each table
* @throws SQLException Thrown if database error occurs
*/
void clearDatabase() throws SQLException;
} }

View File

@@ -1,10 +1,115 @@
package hhn.temp.project.provider; package hhn.temp.project.provider;
import hhn.temp.project.Task;
import hhn.temp.project.Worker;
import java.sql.SQLException;
import java.util.Collection; import java.util.Collection;
public interface DatabaseManager<E> extends Database { /**
public void saveObjects(Collection<E> objects); * Simple Database Manager to handle simple command such as insertion, deletion, updating of Task and Worker objects.
public Collection<E> getObjects(); * @author Riley Schneider
public void saveObject(E object); */
public E getObject(int id); public interface DatabaseManager extends Database {
/**
* Saves a Task object into the database
* @param task Task to be saved into the database
* @throws SQLException Thrown if database error occurs
*/
void saveTask(Task task) throws SQLException;
/**
* Saves a collection of Task objects into the database
* @param tasks Tasks to be saved into the database
* @throws SQLException Thrown if database error occurs
*/
void saveTasks(Collection<Task> tasks) throws SQLException;
/**
* Saves a Worker object into the database
* @param worker Worker to be saved into the database
* @throws SQLException Thrown if database error occurs
*/
void saveWorker(Worker worker) throws SQLException;
/**
* Saves a collection Worker objects into the database
* @param workers Workers to be saved into the database
* @throws SQLException Thrown if database error occurs
*/
void saveWorkers(Collection<Worker> workers) throws SQLException;
/**
* Updates a Task object that already exists in the database
* @param taskId The ID of the given task
* @param newTaskObject The new Task object that will overwrite the existent task on database
* @throws SQLException Thrown if database error occurs
*/
void updateTask(int taskId, Task newTaskObject) throws SQLException;
/**
* Updates a Worker object that already exists in the database
* @param workerId The ID of the given worker
* @param newWorkerObject The new Worker object that will overwrite the existent task on database
* @throws SQLException Thrown if database error occurs
*/
void updateWorker(int workerId, Worker newWorkerObject) throws SQLException;
/**
* Deletes a task from the database
* @param taskId The ID of the given task that needs to be deleted
* @throws SQLException Thrown if database error occurs
*/
void deleteTask(int taskId) throws SQLException;
/**
* Deletes a worker from the database
* @param workerId The ID of the given worker that needs to be deleted
* @throws SQLException Thrown if database error occurs
*/
void deleteWorker(int workerId) throws SQLException;
/**
* Gets a collection of all tasks available in the database
* @return A collection of tasks (empty if no task available)
* @throws SQLException Thrown if database error occurs
*/
Collection<Task> getTasks() throws SQLException;
/**
* Gets a collection of all workers available in the database
* @return A collection of workers (empty if no task available)
* @throws SQLException Thrown if database error occurs
*/
Collection<Worker> getWorkers() throws SQLException;
/**
* Gets a task given by its ID from the database
* @param taskId The task ID
* @return A task from the database (NULL if no task found)
* @throws SQLException Thrown if database error occurs
*/
Task getTaskByTaskId(int taskId) throws SQLException;
/**
* Gets a worker given by its ID from the database
* @param workerId The worker ID
* @return A worker from the database (NULL if no worker found)
* @throws SQLException Thrown if database error occurs
*/
Worker getWorkerByWorkerId(int workerId) throws SQLException;
/**
* Gets the total number of available tasks in the database.
* @return The total number of tasks (0 = zero entries; -1 = error)
* @throws SQLException Thrown if database error occurs
*/
int getTotalNumberOfTasks() throws SQLException;
/**
* Gets the total number of available workers in the database.
* @return The total number of workers (0 = zero entries; -1 = error)
* @throws SQLException Thrown if database error occurs
*/
int getTotalNumberOfWorkers() throws SQLException;
} }

View File

@@ -0,0 +1,193 @@
package hhn.temp.project.provider;
import hhn.temp.project.Task;
import hhn.temp.project.Worker;
import java.sql.*;
import java.util.*;
public class SimpleDatabaseManager implements DatabaseManager {
private boolean connected = false;
private Map<Integer, Task> temporaryTaskList = new HashMap();
private Map<Integer, Worker> temporaryWorkerList = new HashMap<>();
@Override
public void saveTask(Task task) throws SQLException {
if (!connected) {
throw new SQLException("[CONNECTION FAILED] Instance is not connected to database.");
}
if (!temporaryTaskList.containsKey(task.getTaskId())) {
temporaryTaskList.put(task.getTaskId(), task);
} else {
throw new SQLException("[INSERTION FAILED] Task with the same Task ID already exists.");
}
}
@Override
public void saveTasks(Collection<Task> tasks) throws SQLException {
for (Task task : tasks) {
saveTask(task);
}
}
@Override
public void saveWorker(Worker worker) throws SQLException {
if (!connected) {
throw new SQLException("[CONNECTION FAILED] Instance is not connected to database.");
}
if (!temporaryWorkerList.containsKey(worker.getId())) {
temporaryWorkerList.put(worker.getId(), worker);
} else {
throw new SQLException("[INSERTION FAILED] Task with the same Task ID already exists.");
}
}
@Override
public void saveWorkers(Collection<Worker> workers) throws SQLException {
for (Worker worker : workers) {
saveWorker(worker);
}
}
@Override
public void updateTask(int taskId, Task newTaskObject) throws SQLException {
if (!connected) {
throw new SQLException("[CONNECTION FAILED] Instance is not connected to database.");
}
if (temporaryTaskList.containsKey(taskId) && newTaskObject.getTaskId() == taskId) {
temporaryTaskList.remove(taskId);
temporaryTaskList.put(taskId, newTaskObject);
return;
}
throw new SQLException("[UPDATE FAILED] Task ID not found OR Task ID does not equal New Task ID.");
}
@Override
public void updateWorker(int workerId, Worker newWorkerObject) throws SQLException {
if (!connected) {
throw new SQLException("[CONNECTION FAILED] Instance is not connected to database.");
}
if (temporaryWorkerList.containsKey(workerId) && newWorkerObject.getId() == workerId) {
temporaryWorkerList.remove(workerId);
temporaryWorkerList.put(workerId, newWorkerObject);
return;
}
throw new SQLException("[UPDATE FAILED] Worker ID not found OR Worker ID does not equal New Worker ID.");
}
@Override
public void deleteTask(int taskId) throws SQLException {
if (!connected) {
throw new SQLException("[CONNECTION FAILED] Instance is not connected to database.");
}
if (temporaryTaskList.containsKey(taskId)) {
temporaryTaskList.remove(taskId);
return;
}
throw new SQLException("[DELETION FAILED] Could not find Task ID. Nothing to delete.");
}
@Override
public void deleteWorker(int workerId) throws SQLException {
if (!connected) {
throw new SQLException("[CONNECTION FAILED] Instance is not connected to database.");
}
if (temporaryWorkerList.containsKey(workerId)) {
temporaryWorkerList.remove(workerId);
return;
}
throw new SQLException("[DELETION FAILED] Could not find Worker ID. Nothing to delete.");
}
@Override
public Collection<Task> getTasks() throws SQLException {
if (!connected) {
throw new SQLException("[CONNECTION FAILED] Instance is not connected to database.");
}
return temporaryTaskList.values();
}
@Override
public Collection<Worker> getWorkers() throws SQLException {
if (!connected) {
throw new SQLException("[CONNECTION FAILED] Instance is not connected to database.");
}
return temporaryWorkerList.values();
}
@Override
public Task getTaskByTaskId(int taskId) throws SQLException {
if (!connected) {
throw new SQLException("[CONNECTION FAILED] Instance is not connected to database.");
}
if (temporaryTaskList.containsKey(taskId)) {
return temporaryTaskList.get(taskId);
}
throw new SQLException("[SELECTION FAILED] Could not find Task ID. Nothing to get.");
}
@Override
public Worker getWorkerByWorkerId(int workerId) throws SQLException {
if (!connected) {
throw new SQLException("[CONNECTION FAILED] Instance is not connected to database.");
}
if (temporaryWorkerList.containsKey(workerId)) {
return temporaryWorkerList.get(workerId);
}
throw new SQLException("[SELECTION FAILED] Could not find Worker ID. Nothing to get.");
}
@Override
public int getTotalNumberOfTasks() throws SQLException {
if (!connected) {
throw new SQLException("[CONNECTION FAILED] Instance is not connected to database.");
}
return temporaryTaskList.size();
}
@Override
public int getTotalNumberOfWorkers() throws SQLException {
if (!connected) {
throw new SQLException("[CONNECTION FAILED] Instance is not connected to database.");
}
return temporaryWorkerList.size();
}
public void clearDatabase() throws SQLException {
if (!connected) {
throw new SQLException("[CONNECTION FAILED] Instance is not connected to database.");
}
temporaryTaskList.clear();
temporaryWorkerList.clear();
}
@Override
public void connect() throws SQLException {
connected = true;
}
@Override
public void close() throws SQLException {
connected = false;
}
}

View File

@@ -0,0 +1,8 @@
CREATE TABLE Task (
id INT AUTO_INCREMENT PRIMARY KEY,
taskid INT,
name VARCHAR(255) NOT NULL,
description TEXT,
workerid INT,
taskstate INT
);

View File

@@ -0,0 +1 @@
DELETE FROM Task WHERE taskid = ?

View File

@@ -0,0 +1 @@
INSERT INTO Task (taskid, name, description, workerid, taskstate) VALUES (?, ?, ?, ?, ?)

View File

@@ -0,0 +1 @@
SELECT * FROM Task WHERE workerid = ?

View File

@@ -0,0 +1 @@
UPDATE Task SET name = ?, description = ?, taskstate = ? WHERE taskid = ?

View File

@@ -0,0 +1,46 @@
package hhn.temp.project;
import hhn.temp.project.provider.DatabaseManager;
import hhn.temp.project.provider.SimpleDatabaseManager;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.sql.SQLException;
import static org.junit.jupiter.api.Assertions.*;
public class DatabaseBadCasesTest {
private DatabaseManager databaseManager;
@BeforeEach
public void setup() throws SQLException {
databaseManager = new SimpleDatabaseManager();
databaseManager.connect();
databaseManager.clearDatabase();
}
@Test
@DisplayName("Inserting Tasks with the same ID")
public void insertTasksWithTheSameId() throws SQLException {
Task task = new Task(10, 10, "ABC", "XYZ");
Task taskFaker = new Task(10, 5, "ABC!", "XYZ!");
databaseManager.saveTask(task);
databaseManager.saveTask(taskFaker);
}
@Test
@DisplayName("Inserting Workers with the same ID")
public void insertWorkersWithTheSameId() throws SQLException {
Worker worker = new Worker("Worker-1", 1);
Worker workerFaker = new Worker("Worker-100", 1);
databaseManager.saveWorker(worker);
databaseManager.saveWorker(workerFaker);
}
}

View File

@@ -0,0 +1,86 @@
package hhn.temp.project;
import hhn.temp.project.provider.DatabaseManager;
import hhn.temp.project.provider.SimpleDatabaseManager;
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;
import java.util.List;
public class DatabaseGoodCasesTest {
private DatabaseManager databaseManager;
@BeforeEach
public void setup() throws SQLException {
databaseManager = new SimpleDatabaseManager();
databaseManager.connect();
databaseManager.clearDatabase();
}
@Test
@DisplayName("Inserting test task into the database and receiving back the same test task")
public void insertTaskAndReceiveItBackTest() throws SQLException {
Task task = new Task(123, 10, "Hello World", "Doing Something, hell yeah!");
databaseManager.saveTask(task);
Task reTask = databaseManager.getTaskByTaskId(task.getTaskId());
assertNotNull(reTask);
assertEquals(task.getTaskId(), reTask.getTaskId());
assertEquals(task.getDescription(), reTask.getDescription());
assertEquals(task.getName(), reTask.getName());
assertEquals(task.getWorkerId(), reTask.getWorkerId());
assertEquals(1, databaseManager.getTotalNumberOfTasks());
}
@Test
@DisplayName("Inserting test worker into the database and receiving back the same test worker")
public void insertWorkerAndReceivedItBackTest() throws SQLException {
Worker worker = new Worker("Worker-01", 12345678);
databaseManager.saveWorker(worker);
Worker reWorker = databaseManager.getWorkerByWorkerId(worker.getId());
assertNotNull(reWorker);
assertEquals(worker.getId(), reWorker.getId());
assertEquals(worker.getName(), reWorker.getName());
}
@Test
@DisplayName("Clearing the database (Task and Worker) test")
public void clearDatabaseTest() throws SQLException, InterruptedException {
Task task1 = new Task(10, 5, "Hello", "World");
Task task2 = new Task(9, 4, "Hochschule", "Heilbronn");
Task task3 = new Task(8, 9, "Gangnam", "Style");
Collection<Task> tasks = List.of(task1, task2, task3);
Worker worker1 = new Worker("ABC", 2);
Worker worker2 = new Worker("XYZ", 9);
Collection<Worker> workers = List.of(worker1, worker2);
databaseManager.saveTasks(tasks);
databaseManager.saveWorkers(workers);
Thread.sleep(500);
assertEquals(tasks.size(), databaseManager.getTotalNumberOfTasks());
assertEquals(workers.size(), databaseManager.getTotalNumberOfWorkers());
databaseManager.clearDatabase();
assertEquals(0, databaseManager.getTotalNumberOfTasks());
assertEquals(0, databaseManager.getTotalNumberOfWorkers());
}
}