Compare commits
6 Commits
0b74bf5eea
...
database
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0f23b15ad4 | ||
|
|
3050405792 | ||
| e667389694 | |||
| 6ac08e2db1 | |||
| 20afbbf461 | |||
| 6ccb68285f |
40
README.md
40
README.md
@@ -1,2 +1,40 @@
|
|||||||
# Temp-Java-Gradle
|
@Author Kevin Schoenmayer, Riley Schneider, Can Oezdemir, Lasse Grosshans
|
||||||
|
|
||||||
|
Volle Dokumentation mit Bildern, Vorbereitungen und Klassendiagramm unter
|
||||||
|
https://docs.google.com/document/d/1iPl3XoZdvn1zqYCNlzHklEf_bRBGnQm41bAEaWz_s0w/edit?usp=sharing
|
||||||
|
|
||||||
|
|
||||||
|
Voraussetzungen:
|
||||||
|
Docker (inkl. Docker Compose)
|
||||||
|
Java 17
|
||||||
|
Git
|
||||||
|
|
||||||
|
Projekt bauen, testen und starten:
|
||||||
|
|
||||||
|
1. Projekt klonen:
|
||||||
|
git clone https://home.luithardt.cloud:5400/KevinSchoenmayer/GseTDDUebungKCLR
|
||||||
|
|
||||||
|
2. Zu ...\GseTDDUebungKCLR\docker in cmd navigieren
|
||||||
|
Docker starten:
|
||||||
|
docker compose up -d
|
||||||
|
|
||||||
|
3. Tabellenerstellung fuer die Testumgebung:
|
||||||
|
Verbinden Sie sich mit dem Programm Ihrer Wahl mit der Datenbank (z.B. HeidiSQL). Die Anmeldeinformationen finden Sie in der compose.yml-Datei.
|
||||||
|
Fuehren Sie nun auf der Datenbank folgende SQL-Befehle aus dieser Dateien aus:
|
||||||
|
resources\sql\createTaskTable.sql
|
||||||
|
resources\sql\createWorkerTable.sql
|
||||||
|
Sie sollten in Ihrer Datenbank nun zwei neue Tabellen sehen: Task und Worker. Wenn dem so sei, koennen Sie mit Punkt (6) fortfahren.
|
||||||
|
|
||||||
|
4. Projekt starten:
|
||||||
|
gradle cleanRun --console=plain --quiet
|
||||||
|
Jetzt werden die Tests durchgefuehrt und in
|
||||||
|
...\GseTDDUebungKCLR\build\reports\tests\index.html
|
||||||
|
gespeichert (genaue Adresse fuer .html wird automatisch angegeben),
|
||||||
|
die Jacoco Test Coverage erzeugt und in
|
||||||
|
...\GseTDDUebungKCLR\build\reports\jacoco\html\index.html
|
||||||
|
gespeichert (genaue Adresse fuer .html wird automatisch angegeben),
|
||||||
|
und das Programm in der Command Line gestartet.
|
||||||
|
|
||||||
|
Nutze ?, um dir die Befehle anzeigen zu lassen.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
105
build.gradle
105
build.gradle
@@ -1,6 +1,7 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'java'
|
||||||
id 'jacoco'
|
id 'jacoco'
|
||||||
|
id 'application'
|
||||||
}
|
}
|
||||||
|
|
||||||
group = 'hhn.temp.project'
|
group = 'hhn.temp.project'
|
||||||
@@ -17,11 +18,6 @@ dependencies {
|
|||||||
implementation 'com.mysql:mysql-connector-j:9.5.0'
|
implementation 'com.mysql:mysql-connector-j:9.5.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
jacoco {
|
|
||||||
toolVersion = '0.8.13'
|
|
||||||
reportsDirectory.set(layout.buildDirectory.dir('customJacocoReportDir'))
|
|
||||||
}
|
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
main {
|
main {
|
||||||
java {
|
java {
|
||||||
@@ -35,6 +31,7 @@ sourceSets {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test configuration
|
||||||
test {
|
test {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
testLogging {
|
testLogging {
|
||||||
@@ -42,13 +39,105 @@ test {
|
|||||||
exceptionFormat "full"
|
exceptionFormat "full"
|
||||||
showStandardStreams = true
|
showStandardStreams = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate test reports in a specific location
|
||||||
|
reports {
|
||||||
|
html.outputLocation.set(layout.buildDirectory.dir("reports/tests"))
|
||||||
|
junitXml.outputLocation.set(layout.buildDirectory.dir("reports/tests"))
|
||||||
|
}
|
||||||
|
|
||||||
finalizedBy jacocoTestReport
|
finalizedBy jacocoTestReport
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Jacoco configuration
|
||||||
|
jacoco {
|
||||||
|
toolVersion = '0.8.13'
|
||||||
|
reportsDirectory.set(layout.buildDirectory.dir('reports/jacoco'))
|
||||||
|
}
|
||||||
|
|
||||||
jacocoTestReport {
|
jacocoTestReport {
|
||||||
dependsOn test
|
dependsOn test
|
||||||
reports {
|
reports {
|
||||||
xml.required = false
|
xml.required = true
|
||||||
csv.required = false
|
csv.required = false
|
||||||
html.outputLocation.set(layout.buildDirectory.dir('jacocoHtml'))
|
html.required = true
|
||||||
|
html.outputLocation.set(layout.buildDirectory.dir("reports/jacoco/html"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Application configuration
|
||||||
|
application {
|
||||||
|
mainClass = "hhn.temp.project.Main"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Custom task to print information after build
|
||||||
|
task printInfo {
|
||||||
|
dependsOn test, jacocoTestReport
|
||||||
|
doLast {
|
||||||
|
println("\n" + "="*50)
|
||||||
|
println("BUILD AND TESTS COMPLETED SUCCESSFULLY!")
|
||||||
|
println("="*50)
|
||||||
|
println("\nTest Results Location:")
|
||||||
|
println(" HTML: ${layout.buildDirectory.get()}/reports/tests/index.html")
|
||||||
|
println(" XML: ${layout.buildDirectory.get()}/reports/tests/TEST-*.xml")
|
||||||
|
|
||||||
|
println("\nJacoco Coverage Reports:")
|
||||||
|
println(" HTML: ${layout.buildDirectory.get()}/reports/jacoco/html/index.html")
|
||||||
|
println(" XML: ${layout.buildDirectory.get()}/reports/jacoco/test/jacocoTestReport.xml")
|
||||||
|
|
||||||
|
println("\nTo run the application:")
|
||||||
|
println(" gradle run --console=plain")
|
||||||
|
println("\nTo run tests and generate coverage reports:")
|
||||||
|
println(" gradle test jacocoTestReport")
|
||||||
|
println("="*50)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Custom task that combines clean, test, jacocoTestReport
|
||||||
|
task cleanTestReport {
|
||||||
|
dependsOn clean, test, jacocoTestReport
|
||||||
|
description = 'Clean build and run tests with coverage reports'
|
||||||
|
group = 'verification'
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configure the standard run task
|
||||||
|
run {
|
||||||
|
dependsOn test, jacocoTestReport
|
||||||
|
standardInput = System.in
|
||||||
|
|
||||||
|
doFirst {
|
||||||
|
println("\n" + "="*50)
|
||||||
|
println("TESTS COMPLETED - STARTING APPLICATION...")
|
||||||
|
println("="*50)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create an alias task
|
||||||
|
task cleanRun {
|
||||||
|
dependsOn clean, run
|
||||||
|
description = 'Clean build, run tests with coverage, then run the application'
|
||||||
|
group = 'application'
|
||||||
|
}
|
||||||
|
|
||||||
|
// Alternative: Create a separate task that doesn't chain dependencies
|
||||||
|
task startApp(type: JavaExec) {
|
||||||
|
description = 'Start the application (without running tests first)'
|
||||||
|
group = 'application'
|
||||||
|
|
||||||
|
classpath = sourceSets.main.runtimeClasspath
|
||||||
|
mainClass = application.mainClass
|
||||||
|
standardInput = System.in
|
||||||
|
standardOutput = System.out
|
||||||
|
|
||||||
|
// Configure to run in foreground
|
||||||
|
systemProperties System.getProperties()
|
||||||
|
|
||||||
|
doFirst {
|
||||||
|
println("\n" + "="*50)
|
||||||
|
println("STARTING APPLICATION...")
|
||||||
|
println("="*50)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make test and jacocoTestReport trigger the info print
|
||||||
|
test.finalizedBy printInfo
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package hhn.temp.project;
|
package hhn.temp.project;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import hhn.temp.project.provider.SimpleDatabaseManager;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.sql.SQLException;
|
||||||
import java.util.Map;
|
import java.util.*;
|
||||||
|
|
||||||
public class AssignmentManager {
|
public class AssignmentManager {
|
||||||
private Map<Integer, Worker> workerMap;
|
private Map<Integer, Worker> workerMap;
|
||||||
@@ -11,22 +11,66 @@ public class AssignmentManager {
|
|||||||
private int workerIdCounter;
|
private int workerIdCounter;
|
||||||
private int taskIdCounter;
|
private int taskIdCounter;
|
||||||
private UserCommands userInterface;
|
private UserCommands userInterface;
|
||||||
|
private SimpleDatabaseManager database;
|
||||||
|
|
||||||
public AssignmentManager() {
|
public AssignmentManager() {
|
||||||
|
database = new SimpleDatabaseManager();
|
||||||
|
connect();
|
||||||
workerMap = new HashMap<>();
|
workerMap = new HashMap<>();
|
||||||
taskMap = new HashMap<>();
|
taskMap = new HashMap<>();
|
||||||
workerIdCounter = 1000;
|
workerIdCounter = 1000;
|
||||||
taskIdCounter = 0;
|
taskIdCounter = 0;
|
||||||
|
sync();
|
||||||
userInterface = new UserCommands(this);
|
userInterface = new UserCommands(this);
|
||||||
}
|
}
|
||||||
|
private void connect() {
|
||||||
|
try {
|
||||||
|
database.connect();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
System.err.println("Failed to connect to database");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void sync() {
|
||||||
|
workerMap.clear();
|
||||||
|
taskMap.clear();
|
||||||
|
try {
|
||||||
|
Collection<Worker> workers = database.getWorkers();
|
||||||
|
if (workers != null) {
|
||||||
|
for (Worker worker : workers) {
|
||||||
|
workerMap.put(worker.getId(),worker);
|
||||||
|
if (worker.getId() > workerIdCounter) {
|
||||||
|
workerIdCounter = worker.getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Collection<Task> tasks = database.getTasks();
|
||||||
|
if (tasks != null) {
|
||||||
|
for (Task task : tasks) {
|
||||||
|
taskMap.put(task.getTaskId(),task);
|
||||||
|
if (task.getTaskId() > taskIdCounter) {
|
||||||
|
taskIdCounter = task.getTaskId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
System.err.println("Failed to sync");
|
||||||
|
}
|
||||||
|
}
|
||||||
public Map<Integer, Task> getTaskMap() {
|
public Map<Integer, Task> getTaskMap() {
|
||||||
return taskMap;
|
return taskMap;
|
||||||
}
|
}
|
||||||
public Map<Integer, Worker> getWorkerMap() {return workerMap;}
|
public Map<Integer, Worker> getWorkerMap() {return workerMap;}
|
||||||
|
|
||||||
public int createWorker(String name) {
|
public int createWorker(String name) {
|
||||||
|
sync();
|
||||||
Worker worker = new Worker(name, ++workerIdCounter);
|
Worker worker = new Worker(name, ++workerIdCounter);
|
||||||
workerMap.put(workerIdCounter, worker);
|
workerMap.put(workerIdCounter, worker);
|
||||||
|
try {
|
||||||
|
database.saveWorker(worker);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
System.err.println("Failed to save worker");
|
||||||
|
}
|
||||||
return workerIdCounter;
|
return workerIdCounter;
|
||||||
}
|
}
|
||||||
public void removeWorker(int workerId) {
|
public void removeWorker(int workerId) {
|
||||||
@@ -34,6 +78,11 @@ public class AssignmentManager {
|
|||||||
throw new IllegalArgumentException("WorkerId must exist in order to remove it");
|
throw new IllegalArgumentException("WorkerId must exist in order to remove it");
|
||||||
}
|
}
|
||||||
workerMap.remove(workerId);
|
workerMap.remove(workerId);
|
||||||
|
try {
|
||||||
|
database.deleteWorker(workerId);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
System.err.println("Failed to delete worker");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public int addTask(int workerId, String name, String description) {
|
public int addTask(int workerId, String name, String description) {
|
||||||
if (!workerMap.containsKey(workerId) || name == null || description == null) {
|
if (!workerMap.containsKey(workerId) || name == null || description == null) {
|
||||||
@@ -41,6 +90,11 @@ public class AssignmentManager {
|
|||||||
}
|
}
|
||||||
Task task = new Task(++taskIdCounter, workerId, name, description);
|
Task task = new Task(++taskIdCounter, workerId, name, description);
|
||||||
taskMap.put(taskIdCounter, task);
|
taskMap.put(taskIdCounter, task);
|
||||||
|
try {
|
||||||
|
database.saveTask(task);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
System.err.println("Failed to save task");
|
||||||
|
}
|
||||||
return taskIdCounter;
|
return taskIdCounter;
|
||||||
}
|
}
|
||||||
public Task getTask(int taskId) {
|
public Task getTask(int taskId) {
|
||||||
@@ -62,12 +116,22 @@ public class AssignmentManager {
|
|||||||
Task task = taskMap.get(taskId);
|
Task task = taskMap.get(taskId);
|
||||||
task.setName(name);
|
task.setName(name);
|
||||||
task.setDescription(description);
|
task.setDescription(description);
|
||||||
|
try {
|
||||||
|
database.updateTask(task.getTaskId(),task);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
System.err.println("Failed to update Task");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public void removeTask(int taskId) {
|
public void removeTask(int taskId) {
|
||||||
if (!taskMap.containsKey(taskId)) {
|
if (!taskMap.containsKey(taskId)) {
|
||||||
throw new IllegalArgumentException("Task Id does not exist");
|
throw new IllegalArgumentException("Task Id does not exist");
|
||||||
}
|
}
|
||||||
taskMap.remove(taskId);
|
taskMap.remove(taskId);
|
||||||
|
try {
|
||||||
|
database.deleteTask(taskId);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
System.err.println("Failed to remove task");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public void finishTask(int workerId, int taskId) {
|
public void finishTask(int workerId, int taskId) {
|
||||||
if (!workerMap.containsKey(workerId) || !taskMap.containsKey(taskId)) {
|
if (!workerMap.containsKey(workerId) || !taskMap.containsKey(taskId)) {
|
||||||
@@ -75,6 +139,11 @@ public class AssignmentManager {
|
|||||||
}
|
}
|
||||||
Task task = taskMap.get(taskId);
|
Task task = taskMap.get(taskId);
|
||||||
task.setTaskState(TaskState.FINISHED);
|
task.setTaskState(TaskState.FINISHED);
|
||||||
|
try {
|
||||||
|
database.updateTask(taskId,task);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
System.err.println("Failed to finish task");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public void unfinishTask(int workerId, int taskId) {
|
public void unfinishTask(int workerId, int taskId) {
|
||||||
if (!workerMap.containsKey(workerId) || !taskMap.containsKey(taskId)) {
|
if (!workerMap.containsKey(workerId) || !taskMap.containsKey(taskId)) {
|
||||||
@@ -82,6 +151,11 @@ public class AssignmentManager {
|
|||||||
}
|
}
|
||||||
Task task = taskMap.get(taskId);
|
Task task = taskMap.get(taskId);
|
||||||
task.setTaskState(TaskState.IN_PROGRESS);
|
task.setTaskState(TaskState.IN_PROGRESS);
|
||||||
|
try {
|
||||||
|
database.updateTask(taskId,task);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
System.err.println("Failed to finish task");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public UserCommands getUserCommands() {
|
public UserCommands getUserCommands() {
|
||||||
return userInterface;
|
return userInterface;
|
||||||
|
|||||||
@@ -19,14 +19,14 @@ public class SimpleDatabaseManager implements DatabaseManager {
|
|||||||
private final static Path SELECT_TASK = Path.of("resources/sql/SelectTaskTable.sql");
|
private final static Path SELECT_TASK = Path.of("resources/sql/SelectTaskTable.sql");
|
||||||
private final static Path UPDATE_TASK = Path.of("resources/sql/UpdateTaskTable.sql");
|
private final static Path UPDATE_TASK = Path.of("resources/sql/UpdateTaskTable.sql");
|
||||||
private final static Path COUNT_ALL_TASK = Path.of("resources/sql/CountAllFieldsTask.sql");
|
private final static Path COUNT_ALL_TASK = Path.of("resources/sql/CountAllFieldsTask.sql");
|
||||||
private final static Path SELECT_ALL_TASK = Path.of("resources/sql/SelectAllFieldsTask.sql");
|
private final static Path SELECT_ALL_TASK = Path.of("resources/sql/SelectAllTask.sql");
|
||||||
private final static Path SELECT_TASK_BY_ID = Path.of("resources/sql/SelectTaskById.sql");
|
private final static Path SELECT_TASK_BY_ID = Path.of("resources/sql/SelectTaskById.sql");
|
||||||
private final static Path INSERT_WORKER = Path.of("resources/sql/InsertWorkerTable.sql");
|
private final static Path INSERT_WORKER = Path.of("resources/sql/InsertWorkerTable.sql");
|
||||||
private final static Path DELETE_WORKER = Path.of("resources/sql/DeleteWorkerTable.sql");
|
private final static Path DELETE_WORKER = Path.of("resources/sql/DeleteWorkerTable.sql");
|
||||||
private final static Path SELECT_WORKER = Path.of("resources/sql/SelectWorkerTable.sql");
|
private final static Path SELECT_WORKER = Path.of("resources/sql/SelectWorkerTable.sql");
|
||||||
private final static Path UPDATE_WORKER = Path.of("resources/sql/UpdateWorkerTable.sql");
|
private final static Path UPDATE_WORKER = Path.of("resources/sql/UpdateWorkerTable.sql");
|
||||||
private final static Path COUNT_ALL_WORKER = Path.of("resources/sql/CountAllFieldsWorker.sql");
|
private final static Path COUNT_ALL_WORKER = Path.of("resources/sql/CountAllFieldsWorker.sql");
|
||||||
private final static Path SELECT_ALL_WORKER = Path.of("resources/sql/SelectAllFieldsWorker.sql");
|
private final static Path SELECT_ALL_WORKER = Path.of("resources/sql/SelectAllWorker.sql");
|
||||||
private final static Path SELECT_WORKER_BY_ID = Path.of("resources/sql/SelectWorkerById.sql");
|
private final static Path SELECT_WORKER_BY_ID = Path.of("resources/sql/SelectWorkerById.sql");
|
||||||
|
|
||||||
public enum QueryMode {
|
public enum QueryMode {
|
||||||
@@ -46,7 +46,7 @@ public class SimpleDatabaseManager implements DatabaseManager {
|
|||||||
SELECT_WORKER_BY_ID,
|
SELECT_WORKER_BY_ID,
|
||||||
}
|
}
|
||||||
|
|
||||||
public String loadFile(QueryMode queryMode) throws IOException {
|
private String loadFile(QueryMode queryMode) throws IOException {
|
||||||
switch (queryMode) {
|
switch (queryMode) {
|
||||||
case INSERT_TASK -> {
|
case INSERT_TASK -> {
|
||||||
return Files.readString(INSERT_TASK);
|
return Files.readString(INSERT_TASK);
|
||||||
@@ -110,7 +110,7 @@ public class SimpleDatabaseManager implements DatabaseManager {
|
|||||||
try {
|
try {
|
||||||
query = loadFile(QueryMode.INSERT_TASK);
|
query = loadFile(QueryMode.INSERT_TASK);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println(e.getStackTrace());
|
e.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try (PreparedStatement preparedStatement = connection.prepareStatement(query);) {
|
try (PreparedStatement preparedStatement = connection.prepareStatement(query);) {
|
||||||
@@ -136,7 +136,7 @@ public class SimpleDatabaseManager implements DatabaseManager {
|
|||||||
try {
|
try {
|
||||||
query = loadFile(QueryMode.INSERT_WORKER);
|
query = loadFile(QueryMode.INSERT_WORKER);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println(e.getStackTrace());
|
e.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try (PreparedStatement preparedStatement = connection.prepareStatement(query);) {
|
try (PreparedStatement preparedStatement = connection.prepareStatement(query);) {
|
||||||
@@ -159,7 +159,7 @@ public class SimpleDatabaseManager implements DatabaseManager {
|
|||||||
try {
|
try {
|
||||||
query = loadFile(QueryMode.UPDATE_TASK);
|
query = loadFile(QueryMode.UPDATE_TASK);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println(e.getStackTrace());
|
e.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try (PreparedStatement preparedStatement = connection.prepareStatement(query);) {
|
try (PreparedStatement preparedStatement = connection.prepareStatement(query);) {
|
||||||
@@ -177,7 +177,7 @@ public class SimpleDatabaseManager implements DatabaseManager {
|
|||||||
try {
|
try {
|
||||||
query = loadFile(QueryMode.UPDATE_WORKER);
|
query = loadFile(QueryMode.UPDATE_WORKER);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println(e.getStackTrace());
|
e.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try (PreparedStatement preparedStatement = connection.prepareStatement(query);) {
|
try (PreparedStatement preparedStatement = connection.prepareStatement(query);) {
|
||||||
@@ -194,7 +194,7 @@ public class SimpleDatabaseManager implements DatabaseManager {
|
|||||||
try {
|
try {
|
||||||
query = loadFile(QueryMode.DELETE_TASK);
|
query = loadFile(QueryMode.DELETE_TASK);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println(e.getStackTrace());
|
e.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try (PreparedStatement preparedStatement = connection.prepareStatement(query);) {
|
try (PreparedStatement preparedStatement = connection.prepareStatement(query);) {
|
||||||
@@ -209,7 +209,7 @@ public class SimpleDatabaseManager implements DatabaseManager {
|
|||||||
try {
|
try {
|
||||||
query = loadFile(QueryMode.DELETE_WORKER);
|
query = loadFile(QueryMode.DELETE_WORKER);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println(e.getStackTrace());
|
e.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try (PreparedStatement preparedStatement = connection.prepareStatement(query);) {
|
try (PreparedStatement preparedStatement = connection.prepareStatement(query);) {
|
||||||
@@ -224,7 +224,7 @@ public class SimpleDatabaseManager implements DatabaseManager {
|
|||||||
try {
|
try {
|
||||||
query = loadFile(QueryMode.SELECT_ALL_TASK);
|
query = loadFile(QueryMode.SELECT_ALL_TASK);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println(e.getStackTrace());
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,7 +257,7 @@ public class SimpleDatabaseManager implements DatabaseManager {
|
|||||||
try {
|
try {
|
||||||
query = loadFile(QueryMode.SELECT_ALL_WORKER);
|
query = loadFile(QueryMode.SELECT_ALL_WORKER);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println(e.getStackTrace());
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,7 +286,7 @@ public class SimpleDatabaseManager implements DatabaseManager {
|
|||||||
try {
|
try {
|
||||||
query = loadFile(QueryMode.SELECT_TASK_BY_ID);
|
query = loadFile(QueryMode.SELECT_TASK_BY_ID);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println(e.getStackTrace());
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,7 +320,7 @@ public class SimpleDatabaseManager implements DatabaseManager {
|
|||||||
try {
|
try {
|
||||||
query = loadFile(QueryMode.SELECT_WORKER_BY_ID);
|
query = loadFile(QueryMode.SELECT_WORKER_BY_ID);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println(e.getStackTrace());
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,7 +350,7 @@ public class SimpleDatabaseManager implements DatabaseManager {
|
|||||||
try {
|
try {
|
||||||
query = loadFile(QueryMode.COUNT_ALL_TASK);
|
query = loadFile(QueryMode.COUNT_ALL_TASK);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println(e.getStackTrace());
|
e.printStackTrace();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
try (Statement statement = connection.createStatement();
|
try (Statement statement = connection.createStatement();
|
||||||
@@ -370,7 +370,7 @@ public class SimpleDatabaseManager implements DatabaseManager {
|
|||||||
try {
|
try {
|
||||||
query = loadFile(QueryMode.COUNT_ALL_WORKER);
|
query = loadFile(QueryMode.COUNT_ALL_WORKER);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println(e.getStackTrace());
|
e.printStackTrace();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
try (Statement statement = connection.createStatement();
|
try (Statement statement = connection.createStatement();
|
||||||
|
|||||||
@@ -5,12 +5,8 @@ import hhn.temp.project.provider.SimpleDatabaseManager;
|
|||||||
import org.junit.jupiter.api.BeforeEach;
|
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 java.io.IOException;
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
public class DatabaseBadCasesTest {
|
public class DatabaseBadCasesTest {
|
||||||
|
|
||||||
private DatabaseManager databaseManager;
|
private DatabaseManager databaseManager;
|
||||||
@@ -19,7 +15,7 @@ public class DatabaseBadCasesTest {
|
|||||||
public void setup() throws SQLException {
|
public void setup() throws SQLException {
|
||||||
databaseManager = new SimpleDatabaseManager();
|
databaseManager = new SimpleDatabaseManager();
|
||||||
databaseManager.connect();
|
databaseManager.connect();
|
||||||
databaseManager.clearDatabase();
|
//databaseManager.clearDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -31,6 +27,9 @@ public class DatabaseBadCasesTest {
|
|||||||
databaseManager.saveTask(task);
|
databaseManager.saveTask(task);
|
||||||
|
|
||||||
databaseManager.saveTask(taskFaker);
|
databaseManager.saveTask(taskFaker);
|
||||||
|
|
||||||
|
databaseManager.deleteTask(task.getTaskId());
|
||||||
|
databaseManager.deleteTask(taskFaker.getTaskId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -42,5 +41,8 @@ public class DatabaseBadCasesTest {
|
|||||||
databaseManager.saveWorker(worker);
|
databaseManager.saveWorker(worker);
|
||||||
|
|
||||||
databaseManager.saveWorker(workerFaker);
|
databaseManager.saveWorker(workerFaker);
|
||||||
|
|
||||||
|
databaseManager.deleteWorker(worker.getId());
|
||||||
|
databaseManager.deleteWorker(workerFaker.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,8 +7,6 @@ import org.junit.jupiter.api.Test;
|
|||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -21,7 +19,7 @@ public class DatabaseGoodCasesTest {
|
|||||||
public void setup() throws SQLException {
|
public void setup() throws SQLException {
|
||||||
databaseManager = new SimpleDatabaseManager();
|
databaseManager = new SimpleDatabaseManager();
|
||||||
databaseManager.connect();
|
databaseManager.connect();
|
||||||
databaseManager.clearDatabase();
|
//databaseManager.clearDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -39,7 +37,7 @@ public class DatabaseGoodCasesTest {
|
|||||||
assertEquals(task.getName(), reTask.getName());
|
assertEquals(task.getName(), reTask.getName());
|
||||||
assertEquals(task.getWorkerId(), reTask.getWorkerId());
|
assertEquals(task.getWorkerId(), reTask.getWorkerId());
|
||||||
|
|
||||||
assertEquals(1, databaseManager.getTotalNumberOfTasks());
|
databaseManager.deleteTask(task.getTaskId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -55,9 +53,11 @@ public class DatabaseGoodCasesTest {
|
|||||||
|
|
||||||
assertEquals(worker.getId(), reWorker.getId());
|
assertEquals(worker.getId(), reWorker.getId());
|
||||||
assertEquals(worker.getName(), reWorker.getName());
|
assertEquals(worker.getName(), reWorker.getName());
|
||||||
|
|
||||||
|
databaseManager.deleteWorker(worker.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
/*@Test
|
||||||
@DisplayName("Clearing the database (Task and Worker) test")
|
@DisplayName("Clearing the database (Task and Worker) test")
|
||||||
public void clearDatabaseTest() throws SQLException, InterruptedException {
|
public void clearDatabaseTest() throws SQLException, InterruptedException {
|
||||||
Task task1 = new Task(10, 5, "Hello", "World");
|
Task task1 = new Task(10, 5, "Hello", "World");
|
||||||
@@ -81,10 +81,5 @@ public class DatabaseGoodCasesTest {
|
|||||||
|
|
||||||
assertEquals(0, databaseManager.getTotalNumberOfTasks());
|
assertEquals(0, databaseManager.getTotalNumberOfTasks());
|
||||||
assertEquals(0, databaseManager.getTotalNumberOfWorkers());
|
assertEquals(0, databaseManager.getTotalNumberOfWorkers());
|
||||||
}
|
}*/
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRandom() throws IOException, URISyntaxException {
|
|
||||||
System.out.println(databaseManager.loadFile(SimpleDatabaseManager.QueryMode.INSERT_TASK));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user