Compare commits
18 Commits
35e22bba99
...
3050405792
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3050405792 | ||
| e667389694 | |||
| 6ac08e2db1 | |||
| 20afbbf461 | |||
| 0b74bf5eea | |||
| 6ccb68285f | |||
| 0c83baec46 | |||
| 654305f2cd | |||
| a390509f87 | |||
| 85446bc230 | |||
| f0da7b0f9a | |||
| c85d55ce7d | |||
| a875f24e83 | |||
| 760009b4d6 | |||
| bb71c7e329 | |||
| 2af4f4b7a4 | |||
| 79df3d300e | |||
| 7201f66214 |
2
.idea/gradle.xml
generated
2
.idea/gradle.xml
generated
@@ -5,6 +5,8 @@
|
|||||||
<option name="linkedExternalProjectsSettings">
|
<option name="linkedExternalProjectsSettings">
|
||||||
<GradleProjectSettings>
|
<GradleProjectSettings>
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
|
<option name="gradleHome" value="C:\Gradle\gradle-9.0.0" />
|
||||||
|
<option name="gradleJvm" value="17" />
|
||||||
<option name="modules">
|
<option name="modules">
|
||||||
<set>
|
<set>
|
||||||
<option value="$PROJECT_DIR$" />
|
<option value="$PROJECT_DIR$" />
|
||||||
|
|||||||
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -4,7 +4,7 @@
|
|||||||
<component name="FrameworkDetectionExcludesConfiguration">
|
<component name="FrameworkDetectionExcludesConfiguration">
|
||||||
<file type="web" url="file://$PROJECT_DIR$" />
|
<file type="web" url="file://$PROJECT_DIR$" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="homebrew-17" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
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.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
103
build.gradle
103
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,34 +1,100 @@
|
|||||||
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 {
|
||||||
Map<Integer, Worker> workerMap;
|
private Map<Integer, Worker> workerMap;
|
||||||
Map<Integer, Task> taskMap;
|
private Map<Integer, Task> taskMap;
|
||||||
int workerIdCounter;
|
private int workerIdCounter;
|
||||||
int taskIdCounter;
|
private int taskIdCounter;
|
||||||
|
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<>();
|
||||||
int workerIdCounter = 1000;
|
workerIdCounter = 1000;
|
||||||
int taskIdCounter = 0;
|
taskIdCounter = 0;
|
||||||
|
sync();
|
||||||
|
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() {
|
||||||
|
return taskMap;
|
||||||
|
}
|
||||||
|
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) {
|
||||||
|
if (!workerMap.containsKey(workerId)) {
|
||||||
|
throw new IllegalArgumentException("WorkerId must exist in order to remove it");
|
||||||
|
}
|
||||||
|
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) {
|
||||||
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);
|
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) {
|
||||||
@@ -37,8 +103,11 @@ public class AssignmentManager {
|
|||||||
}
|
}
|
||||||
return taskMap.get(taskId);
|
return taskMap.get(taskId);
|
||||||
}
|
}
|
||||||
public Map<Integer, Task> getTaskMap() {
|
public Worker getWorker(int workerId) {
|
||||||
return taskMap;
|
if (!workerMap.containsKey(workerId)) {
|
||||||
|
throw new IllegalArgumentException("Worker Id does not exist");
|
||||||
|
}
|
||||||
|
return workerMap.get(workerId);
|
||||||
}
|
}
|
||||||
public void editTask(int workerId, int taskId, String name, String description) {
|
public void editTask(int workerId, int taskId, String name, String description) {
|
||||||
if (!workerMap.containsKey(workerId) || !taskMap.containsKey(taskId)) {
|
if (!workerMap.containsKey(workerId) || !taskMap.containsKey(taskId)) {
|
||||||
@@ -47,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)) {
|
||||||
@@ -60,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)) {
|
||||||
@@ -67,6 +151,22 @@ 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() {
|
||||||
|
return userInterface;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startCLI() {
|
||||||
|
userInterface.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopCLI() {
|
||||||
|
userInterface.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
10
src/main/java/hhn/temp/project/Main.java
Normal file
10
src/main/java/hhn/temp/project/Main.java
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package hhn.temp.project;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
AssignmentManager manager = new AssignmentManager();
|
||||||
|
manager.startCLI();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
package hhn.temp.project;
|
package hhn.temp.project;
|
||||||
|
|
||||||
public class Task {
|
public class Task {
|
||||||
String name;
|
private String name;
|
||||||
String description;
|
private String description;
|
||||||
int taskId;
|
private int taskId;
|
||||||
int workerId;
|
private int workerId;
|
||||||
TaskState state;
|
private TaskState state;
|
||||||
public Task(int taskId, int workerId, String name, String description) {
|
public Task(int taskId, int workerId, String name, String description) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
|
|||||||
444
src/main/java/hhn/temp/project/UserCommands.java
Normal file
444
src/main/java/hhn/temp/project/UserCommands.java
Normal file
@@ -0,0 +1,444 @@
|
|||||||
|
package hhn.temp.project;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
public class UserCommands implements Runnable {
|
||||||
|
private Scanner scanner;
|
||||||
|
private AssignmentManager manager;
|
||||||
|
private Integer selectedTaskId = null;
|
||||||
|
private Integer selectedWorkerId = null;
|
||||||
|
private AtomicBoolean running = new AtomicBoolean(false);
|
||||||
|
private Thread cliThread;
|
||||||
|
|
||||||
|
private enum InputState {
|
||||||
|
MAIN_MENU,
|
||||||
|
TASK_SELECTED,
|
||||||
|
WORKER_SELECTED,
|
||||||
|
AWAITING_EDIT_INPUT,
|
||||||
|
AWAITING_CREATE_TASK_WORKER,
|
||||||
|
AWAITING_CREATE_TASK_NAME,
|
||||||
|
AWAITING_CREATE_TASK_DESC,
|
||||||
|
AWAITING_CREATE_WORKER_NAME,
|
||||||
|
AWAITING_TASK_SELECTION
|
||||||
|
}
|
||||||
|
|
||||||
|
private InputState currentState = InputState.MAIN_MENU;
|
||||||
|
private Integer tempWorkerId = null;
|
||||||
|
private String tempTaskName = null;
|
||||||
|
|
||||||
|
public UserCommands(AssignmentManager manager) {
|
||||||
|
this.manager = manager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
scanner = new Scanner(System.in);
|
||||||
|
running.set(true);
|
||||||
|
|
||||||
|
while (running.get()) {
|
||||||
|
printPrompt();
|
||||||
|
String input = scanner.nextLine().trim();
|
||||||
|
|
||||||
|
if ("exit".equalsIgnoreCase(input)) {
|
||||||
|
stop();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
handleInput(input);
|
||||||
|
}
|
||||||
|
scanner.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start() {
|
||||||
|
if (cliThread == null || !cliThread.isAlive()) {
|
||||||
|
cliThread = new Thread(this, "CLI-Thread");
|
||||||
|
cliThread.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop() {
|
||||||
|
running.set(false);
|
||||||
|
if (cliThread != null) {
|
||||||
|
cliThread.interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printPrompt() {
|
||||||
|
if (!running.get()) return;
|
||||||
|
|
||||||
|
switch (currentState) {
|
||||||
|
case MAIN_MENU:
|
||||||
|
System.out.println("Type '?' or 'help' for a list of commands");
|
||||||
|
break;
|
||||||
|
case TASK_SELECTED:
|
||||||
|
System.out.println("Task " + selectedTaskId + " selected. Commands: finish, unfinish, remove, edit, back");
|
||||||
|
break;
|
||||||
|
case WORKER_SELECTED:
|
||||||
|
if (selectedWorkerId != null) {
|
||||||
|
System.out.println("Worker " + selectedWorkerId + " selected. Commands: remove, back");
|
||||||
|
} else {
|
||||||
|
System.out.println("Enter worker ID to select (or 'back'):");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case AWAITING_EDIT_INPUT:
|
||||||
|
System.out.println("Enter new name;description:");
|
||||||
|
break;
|
||||||
|
case AWAITING_CREATE_WORKER_NAME:
|
||||||
|
System.out.println("Enter worker name:");
|
||||||
|
break;
|
||||||
|
case AWAITING_CREATE_TASK_WORKER:
|
||||||
|
System.out.println("Enter worker ID:");
|
||||||
|
break;
|
||||||
|
case AWAITING_CREATE_TASK_NAME:
|
||||||
|
System.out.println("Enter task name:");
|
||||||
|
break;
|
||||||
|
case AWAITING_CREATE_TASK_DESC:
|
||||||
|
System.out.println("Enter task description:");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
System.out.print("> ");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleInput(String input) {
|
||||||
|
if (input == null || input.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("?".equals(input) || "help".equalsIgnoreCase(input)) {
|
||||||
|
showHelp();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
switch (currentState) {
|
||||||
|
case MAIN_MENU:
|
||||||
|
handleMainMenuInput(input);
|
||||||
|
break;
|
||||||
|
case TASK_SELECTED:
|
||||||
|
handleTaskSelectionInput(input);
|
||||||
|
break;
|
||||||
|
case WORKER_SELECTED:
|
||||||
|
handleWorkerSelectionInput(input);
|
||||||
|
break;
|
||||||
|
case AWAITING_EDIT_INPUT:
|
||||||
|
handleEditInput(input);
|
||||||
|
break;
|
||||||
|
case AWAITING_CREATE_TASK_WORKER:
|
||||||
|
handleCreateTaskWorkerInput(input);
|
||||||
|
break;
|
||||||
|
case AWAITING_CREATE_TASK_NAME:
|
||||||
|
handleCreateTaskNameInput(input);
|
||||||
|
break;
|
||||||
|
case AWAITING_CREATE_TASK_DESC:
|
||||||
|
handleCreateTaskDescInput(input);
|
||||||
|
break;
|
||||||
|
case AWAITING_CREATE_WORKER_NAME:
|
||||||
|
handleCreateWorkerNameInput(input);
|
||||||
|
break;
|
||||||
|
case AWAITING_TASK_SELECTION:
|
||||||
|
handleTaskIdInput(input);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("Error: " + e.getMessage());
|
||||||
|
resetToMainMenu();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showHelp() {
|
||||||
|
System.out.println("=== Available Commands ===");
|
||||||
|
System.out.println("General:");
|
||||||
|
System.out.println(" help, ? - Show this help");
|
||||||
|
System.out.println(" exit - Exit the program");
|
||||||
|
System.out.println(" createworker - Create a new worker");
|
||||||
|
System.out.println(" createtask - Create a new task");
|
||||||
|
System.out.println(" selecttask - Select a task to work with");
|
||||||
|
System.out.println(" listworkers - List all workers");
|
||||||
|
System.out.println(" listtasks - List all tasks with status");
|
||||||
|
System.out.println(" listfinished - List only finished tasks");
|
||||||
|
System.out.println(" listunfinished - List only unfinished tasks");
|
||||||
|
|
||||||
|
System.out.println("\nWhen a task is selected:");
|
||||||
|
System.out.println(" finish - Mark task as finished");
|
||||||
|
System.out.println(" unfinish - Mark task as unfinished");
|
||||||
|
System.out.println(" remove - Remove the task");
|
||||||
|
System.out.println(" edit - Edit task name and description");
|
||||||
|
System.out.println(" back - Return to main menu");
|
||||||
|
|
||||||
|
System.out.println("\nWhen a worker is selected:");
|
||||||
|
System.out.println(" remove - Remove the worker");
|
||||||
|
System.out.println(" back - Return to main menu");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleMainMenuInput(String input) {
|
||||||
|
switch (input.toLowerCase()) {
|
||||||
|
case "createworker":
|
||||||
|
System.out.println("Enter worker name:");
|
||||||
|
currentState = InputState.AWAITING_CREATE_WORKER_NAME;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "createtask":
|
||||||
|
System.out.println("Enter worker ID:");
|
||||||
|
currentState = InputState.AWAITING_CREATE_TASK_WORKER;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "selecttask":
|
||||||
|
System.out.println("Enter task ID:");
|
||||||
|
currentState = InputState.AWAITING_TASK_SELECTION;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "listworkers":
|
||||||
|
listWorkers();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "listtasks":
|
||||||
|
listAllTasks();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "listfinished":
|
||||||
|
listTasksByStatus(TaskState.FINISHED);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "listunfinished":
|
||||||
|
listTasksByStatus(TaskState.IN_PROGRESS);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
System.out.println("Unknown command. Type 'help' for available commands.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void listWorkers() {
|
||||||
|
System.out.println("\nAvailable workers:");
|
||||||
|
if (manager.getWorkerMap().isEmpty()) {
|
||||||
|
System.out.println(" No workers found.");
|
||||||
|
} else {
|
||||||
|
for (Worker w : manager.getWorkerMap().values()) {
|
||||||
|
System.out.println(" " + w.getId() + ": " + w.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void listAllTasks() {
|
||||||
|
System.out.println("\nAll tasks:");
|
||||||
|
if (manager.getTaskMap().isEmpty()) {
|
||||||
|
System.out.println(" No tasks found.");
|
||||||
|
} else {
|
||||||
|
for (Task task : manager.getTaskMap().values()) {
|
||||||
|
Worker worker = manager.getWorker(task.getWorkerId());
|
||||||
|
String status = task.getTaskState() == TaskState.FINISHED ? "[FINISHED]" : "[IN PROGRESS]";
|
||||||
|
System.out.println(String.format(" %d: %s - %s (Worker: %d - %s)",
|
||||||
|
task.getTaskId(), status, task.getName(),
|
||||||
|
worker.getId(), worker.getName()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void listTasksByStatus(TaskState status) {
|
||||||
|
System.out.println("\nTasks with status: " + status);
|
||||||
|
boolean found = false;
|
||||||
|
|
||||||
|
for (Task task : manager.getTaskMap().values()) {
|
||||||
|
if (task.getTaskState() == status) {
|
||||||
|
Worker worker = manager.getWorker(task.getWorkerId());
|
||||||
|
System.out.println(String.format(" %d: %s (Worker: %d - %s)",
|
||||||
|
task.getTaskId(), task.getName(),
|
||||||
|
worker.getId(), worker.getName()));
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found) {
|
||||||
|
System.out.println(" No tasks found with this status.");
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleWorkerSelectionInput(String input) {
|
||||||
|
if ("back".equalsIgnoreCase(input)) {
|
||||||
|
resetToMainMenu();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
int workerId = Integer.parseInt(input.trim());
|
||||||
|
Worker worker = manager.getWorker(workerId);
|
||||||
|
if (worker != null) {
|
||||||
|
selectedWorkerId = workerId;
|
||||||
|
System.out.println("Worker " + workerId + " (" + worker.getName() + ") selected");
|
||||||
|
System.out.println("Commands: remove, back");
|
||||||
|
} else {
|
||||||
|
System.out.println("Worker not found. Please enter a valid worker ID:");
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
if (selectedWorkerId != null) {
|
||||||
|
handleWorkerCommand(input);
|
||||||
|
} else {
|
||||||
|
System.out.println("Invalid input. Please enter a worker ID or 'back':");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleWorkerCommand(String input) {
|
||||||
|
switch (input.toLowerCase()) {
|
||||||
|
case "remove":
|
||||||
|
manager.removeWorker(selectedWorkerId);
|
||||||
|
System.out.println("Worker removed");
|
||||||
|
resetToMainMenu();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "back":
|
||||||
|
resetToMainMenu();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
System.out.println("Unknown command. Available commands: remove, back");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleCreateWorkerNameInput(String input) {
|
||||||
|
int workerId = manager.createWorker(input.trim());
|
||||||
|
System.out.println("Created worker with ID: " + workerId);
|
||||||
|
resetToMainMenu();
|
||||||
|
}
|
||||||
|
private void handleTaskIdInput(String input) {
|
||||||
|
if ("back".equalsIgnoreCase(input)) {
|
||||||
|
resetToMainMenu();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
int taskId = Integer.parseInt(input.trim());
|
||||||
|
Task task = manager.getTask(taskId);
|
||||||
|
if (task != null) {
|
||||||
|
selectedTaskId = taskId;
|
||||||
|
currentState = InputState.TASK_SELECTED;
|
||||||
|
System.out.println("Task " + taskId + " (" + task.getName() + ") selected");
|
||||||
|
System.out.println("Commands: finish, unfinish, remove, edit, back");
|
||||||
|
} else {
|
||||||
|
System.out.println("Task not found. Please enter a valid task ID:");
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
System.out.println("Invalid input. Please enter a task ID or 'back':");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void handleCreateTaskWorkerInput(String input) {
|
||||||
|
try {
|
||||||
|
tempWorkerId = Integer.parseInt(input.trim());
|
||||||
|
System.out.println("Enter task name:");
|
||||||
|
currentState = InputState.AWAITING_CREATE_TASK_NAME;
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
System.out.println("Invalid worker ID. Please enter a number:");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleCreateTaskNameInput(String input) {
|
||||||
|
tempTaskName = input.trim();
|
||||||
|
System.out.println("Enter task description:");
|
||||||
|
currentState = InputState.AWAITING_CREATE_TASK_DESC;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleCreateTaskDescInput(String input) {
|
||||||
|
int taskId = manager.addTask(tempWorkerId, tempTaskName, input.trim());
|
||||||
|
System.out.println("Created task with ID: " + taskId);
|
||||||
|
resetToMainMenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resetToMainMenu() {
|
||||||
|
currentState = InputState.MAIN_MENU;
|
||||||
|
selectedTaskId = null;
|
||||||
|
selectedWorkerId = null;
|
||||||
|
tempWorkerId = null;
|
||||||
|
tempTaskName = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleTaskSelectionInput(String input) {
|
||||||
|
if ("back".equalsIgnoreCase(input)) {
|
||||||
|
resetToMainMenu();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
int taskId = Integer.parseInt(input.trim());
|
||||||
|
Task task = manager.getTask(taskId);
|
||||||
|
if (task != null) {
|
||||||
|
selectedTaskId = taskId;
|
||||||
|
currentState = InputState.TASK_SELECTED;
|
||||||
|
System.out.println("Task " + taskId + " (" + task.getName() + ") selected");
|
||||||
|
System.out.println("Commands: finish, unfinish, remove, edit, back");
|
||||||
|
} else {
|
||||||
|
System.out.println("Task not found. Please enter a valid task ID:");
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
if (selectedTaskId != null) {
|
||||||
|
handleTaskCommand(input);
|
||||||
|
} else {
|
||||||
|
System.out.println("Invalid input. Please enter a task ID or 'back':");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleTaskCommand(String input) {
|
||||||
|
switch (input.toLowerCase()) {
|
||||||
|
case "finish":
|
||||||
|
manager.finishTask(manager.getTask(selectedTaskId).getWorkerId(),selectedTaskId);
|
||||||
|
System.out.println("Task marked as finished");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "unfinish":
|
||||||
|
manager.unfinishTask(manager.getTask(selectedTaskId).getWorkerId(),selectedTaskId);
|
||||||
|
System.out.println("Task marked as unfinished");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "remove":
|
||||||
|
manager.removeTask(selectedTaskId);
|
||||||
|
System.out.println("Task removed");
|
||||||
|
resetToMainMenu();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "edit":
|
||||||
|
System.out.println("Enter new name;description:");
|
||||||
|
currentState = InputState.AWAITING_EDIT_INPUT;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "back":
|
||||||
|
resetToMainMenu();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
System.out.println("Unknown command. Type 'help' for available commands.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleEditInput(String input) {
|
||||||
|
String[] parts = input.split(";", 2);
|
||||||
|
if (parts.length == 2) {
|
||||||
|
manager.editTask(manager.getTask(selectedTaskId).getWorkerId(), selectedTaskId, parts[0], parts[1]);
|
||||||
|
System.out.println("Task edited");
|
||||||
|
} else {
|
||||||
|
System.out.println("Invalid format. Use: name;description");
|
||||||
|
System.out.println("Please try again:");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
currentState = InputState.TASK_SELECTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Scanner getScanner() {
|
||||||
|
return scanner;
|
||||||
|
}
|
||||||
|
|
||||||
|
//only for testing
|
||||||
|
public void setScanner(Scanner scanner) {
|
||||||
|
this.scanner = scanner;
|
||||||
|
}
|
||||||
|
|
||||||
|
//only for testing
|
||||||
|
public boolean isRunning() {
|
||||||
|
return running.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package hhn.temp.project;
|
package hhn.temp.project;
|
||||||
|
|
||||||
public class Worker {
|
public class Worker {
|
||||||
String name;
|
private String name;
|
||||||
int workerId;
|
private int workerId;
|
||||||
public Worker(String name, int workerId) {
|
public Worker(String name, int workerId) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.workerId = workerId;
|
this.workerId = workerId;
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
@@ -52,4 +52,20 @@ public class BadCasesTest {
|
|||||||
assertThrows(IllegalArgumentException.class, () -> manager.finishTask(20405, 21034));
|
assertThrows(IllegalArgumentException.class, () -> manager.finishTask(20405, 21034));
|
||||||
assertThrows(IllegalArgumentException.class, () -> manager.unfinishTask(20405, 21034));
|
assertThrows(IllegalArgumentException.class, () -> manager.unfinishTask(20405, 21034));
|
||||||
}
|
}
|
||||||
|
@Test
|
||||||
|
@DisplayName("Assert that removing a non-existent worker throws an Exception")
|
||||||
|
public void assertRemovingNonExistentWorkerFails() {
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> manager.removeWorker(34054));
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
@DisplayName("Assert non-existent commands are recognized as such")
|
||||||
|
public void assertInvalidCommandsDontCrash() {
|
||||||
|
int workerId = manager.createWorker("Alfred");
|
||||||
|
int taskId = manager.addTask(workerId, "Run", "Jog 10 Miles");
|
||||||
|
try {
|
||||||
|
manager.getUserCommands().handleInput("baum");
|
||||||
|
} catch (Exception e) {
|
||||||
|
fail("Should not crash just because a command is invalid");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -82,9 +80,4 @@ 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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,8 @@ 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.util.Scanner;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
public class GoodCasesTest {
|
public class GoodCasesTest {
|
||||||
@@ -13,6 +15,7 @@ public class GoodCasesTest {
|
|||||||
public void setup() {
|
public void setup() {
|
||||||
manager = new AssignmentManager();
|
manager = new AssignmentManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Assert that a Worker can add a Task")
|
@DisplayName("Assert that a Worker can add a Task")
|
||||||
public void assertWorkerCanAddTask() {
|
public void assertWorkerCanAddTask() {
|
||||||
@@ -30,6 +33,7 @@ public class GoodCasesTest {
|
|||||||
int taskId = manager.addTask(workerId, "Run", "Jog 10 Miles");
|
int taskId = manager.addTask(workerId, "Run", "Jog 10 Miles");
|
||||||
assertEquals(sizeCount + 1, manager.getTaskMap().size());
|
assertEquals(sizeCount + 1, manager.getTaskMap().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Assert existing Tasks can be edited")
|
@DisplayName("Assert existing Tasks can be edited")
|
||||||
public void assertExistingTasksCanBeEdited() {
|
public void assertExistingTasksCanBeEdited() {
|
||||||
@@ -50,6 +54,7 @@ public class GoodCasesTest {
|
|||||||
manager.removeTask(taskId);
|
manager.removeTask(taskId);
|
||||||
assertEquals(sizeCount, manager.getTaskMap().size());
|
assertEquals(sizeCount, manager.getTaskMap().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Assert deleted Tasks no longer show up in the List")
|
@DisplayName("Assert deleted Tasks no longer show up in the List")
|
||||||
public void assertDeletedTasksDisappear() {
|
public void assertDeletedTasksDisappear() {
|
||||||
@@ -58,18 +63,20 @@ public class GoodCasesTest {
|
|||||||
manager.removeTask(taskId);
|
manager.removeTask(taskId);
|
||||||
assertThrows(IllegalArgumentException.class, () -> manager.getTask(taskId));
|
assertThrows(IllegalArgumentException.class, () -> manager.getTask(taskId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Check Getters")
|
@DisplayName("Check Getters")
|
||||||
public void assertGettersWorkCorrectly() {
|
public void assertGettersWorkCorrectly() {
|
||||||
int workerId = manager.createWorker("Alfred");
|
int workerId = manager.createWorker("Alfred");
|
||||||
int taskId = manager.addTask(workerId, "Run", "Jog 10 Miles");
|
int taskId = manager.addTask(workerId, "Run", "Jog 10 Miles");
|
||||||
assertEquals("Alfred", manager.workerMap.get(workerId).getName());
|
assertEquals("Alfred", manager.getWorkerMap().get(workerId).getName());
|
||||||
//This one may be somewhat nonsensical, but it ensures the getId works so one may iterate over the workerMap
|
//This one may be somewhat nonsensical, but it ensures the getId works so one may iterate over the workerMap
|
||||||
assertEquals(manager.workerMap.get(workerId).getId(), workerId);
|
assertEquals(manager.getWorkerMap().get(workerId).getId(), workerId);
|
||||||
assertEquals(manager.getTask(taskId).getTaskId(), taskId);
|
assertEquals(manager.getTask(taskId).getTaskId(), taskId);
|
||||||
assertEquals(manager.getTask(taskId).getWorkerId(), workerId);
|
assertEquals(manager.getTask(taskId).getWorkerId(), workerId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Assert that Task State is actually changed when submitted as finished")
|
@DisplayName("Assert that Task State is actually changed when submitted as finished")
|
||||||
public void assertTaskStateChanges() {
|
public void assertTaskStateChanges() {
|
||||||
@@ -81,4 +88,68 @@ public class GoodCasesTest {
|
|||||||
assertSame(TaskState.IN_PROGRESS, manager.getTask(taskId).getTaskState());
|
assertSame(TaskState.IN_PROGRESS, manager.getTask(taskId).getTaskState());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Assert that the Scanner is actually started when AM calls start")
|
||||||
|
public void assertScannerExists() {
|
||||||
|
try {
|
||||||
|
Scanner scanner = manager.getUserCommands().getScanner();
|
||||||
|
} catch (Exception e) {
|
||||||
|
fail("Scanner does not exists or can't be gotten by getScanner()");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
@DisplayName("Check that every required surface command actually works")
|
||||||
|
public void assertCommandsAreRecognized() {
|
||||||
|
assertDoesNotThrow(() -> manager.getUserCommands().handleInput("?"));
|
||||||
|
assertDoesNotThrow(() -> manager.getUserCommands().handleInput("help"));
|
||||||
|
assertDoesNotThrow(() -> manager.getUserCommands().handleInput("createWorker"));
|
||||||
|
assertDoesNotThrow(() -> manager.getUserCommands().handleInput("createTask"));
|
||||||
|
assertDoesNotThrow(() -> manager.getUserCommands().handleInput("selectTask"));
|
||||||
|
assertDoesNotThrow(() -> manager.getUserCommands().handleInput("listWorkers"));
|
||||||
|
assertDoesNotThrow(() -> manager.getUserCommands().handleInput("exit"));
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
@DisplayName("Check that every task command works")
|
||||||
|
public void assertFinishingTasksIsPossibleThroughUi() {
|
||||||
|
int workerId = manager.createWorker("Alfred");
|
||||||
|
int taskId = manager.addTask(workerId, "Run", "Jog 10 Miles");
|
||||||
|
manager.getUserCommands().handleInput("selectTask");
|
||||||
|
assertDoesNotThrow(() -> manager.getUserCommands().handleInput(taskId + ""));
|
||||||
|
assertDoesNotThrow(() -> manager.getUserCommands().handleInput("finish"));
|
||||||
|
assertDoesNotThrow(() -> manager.getUserCommands().handleInput("unfinish"));
|
||||||
|
assertDoesNotThrow(() -> manager.getUserCommands().handleInput("remove"));
|
||||||
|
assertDoesNotThrow(() -> manager.getUserCommands().handleInput("back"));
|
||||||
|
assertDoesNotThrow(() -> manager.getUserCommands().handleInput("edit"));
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
@DisplayName("Check that editing is possible through UI")
|
||||||
|
public void assertEditingTasksIsPossibleThroughUi() {
|
||||||
|
int workerId = manager.createWorker("Alfred");
|
||||||
|
int taskId = manager.addTask(workerId, "Run", "Jog 10 Miles");
|
||||||
|
manager.getUserCommands().handleInput("selectTask");
|
||||||
|
manager.getUserCommands().handleInput(taskId + "");
|
||||||
|
manager.getUserCommands().handleInput("edit");
|
||||||
|
manager.getUserCommands().handleInput("Walk;Walk 3 Miles");
|
||||||
|
assertEquals("Walk", manager.getTask(taskId).getName());
|
||||||
|
assertEquals("Walk 3 Miles", manager.getTask(taskId).getDescription());
|
||||||
|
manager.getUserCommands().handleInput("back");
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
@DisplayName("Assert that removing Workers is possible through the UI")
|
||||||
|
public void assertRemovingWorkersIsPossibleThroughUI() {
|
||||||
|
int workerId = manager.createWorker("Alfred");
|
||||||
|
int workerId2 = manager.createWorker("Balfred");
|
||||||
|
manager.getUserCommands().handleInput("listWorkers");
|
||||||
|
manager.getUserCommands().handleInput(workerId + "");
|
||||||
|
assertDoesNotThrow(() -> manager.getUserCommands().handleInput("remove"));
|
||||||
|
manager.getUserCommands().handleInput(workerId2 + "");
|
||||||
|
assertDoesNotThrow(() -> manager.getUserCommands().handleInput("back"));
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
@DisplayName("Assert that removing a worker removes the worker from the worker list")
|
||||||
|
public void assertRemoveWorkerActuallyRemoves() {
|
||||||
|
int workerId = manager.createWorker("Alfred");
|
||||||
|
manager.removeWorker(workerId);
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> manager.getWorker(workerId)); // Use getWorker
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user