diff --git a/backend/.idea/workspace.xml b/backend/.idea/workspace.xml
index 6ffd214..fc7a90a 100644
--- a/backend/.idea/workspace.xml
+++ b/backend/.idea/workspace.xml
@@ -4,8 +4,9 @@
-
-
+
+
+
@@ -84,22 +85,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -115,7 +101,7 @@
-
+
@@ -125,7 +111,7 @@
-
+
@@ -147,17 +133,34 @@
-
+
-
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -171,11 +174,11 @@
-
-
-
-
+
+
+
+
@@ -471,14 +474,21 @@
1699694552466
-
+
+
+ 1699695051881
+
+
+
+ 1699695051881
+
+
-
@@ -503,7 +513,8 @@
-
+
+
diff --git a/backend/src/test/java/core/tasks/TaskServiceTest.java b/backend/src/test/java/core/tasks/TaskServiceTest.java
index 1cd88a9..0d30d8c 100644
--- a/backend/src/test/java/core/tasks/TaskServiceTest.java
+++ b/backend/src/test/java/core/tasks/TaskServiceTest.java
@@ -1,6 +1,7 @@
package core.tasks;
import core.api.models.timemanager.tasks.TaskFieldInfo;
+import core.api.models.timemanager.tasks.TaskScope;
import core.entities.timemanager.Task;
import core.entities.timemanager.Taskgroup;
import core.repositories.timemanager.TaskRepository;
@@ -17,6 +18,7 @@ import javax.persistence.EntityManager;
import javax.transaction.Transactional;
import java.time.LocalDate;
+import java.util.List;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.junit.jupiter.api.Assertions.*;
@@ -184,8 +186,93 @@ public class TaskServiceTest {
})
void deleteTask() {
for(long i=1; i<=15; i++) {
- taskRepository.deleteByTaskID(entityManager.find(Task.class, i).getTaskID());
+ taskService.deleteTask(entityManager.find(Task.class, i));
assertThat(entityManager.find(Task.class, i)).isNull();
}
}
+
+ @Test
+ @SqlGroup({
+ @Sql("classpath:taskgroupRepositoryTestEntries.sql"),
+ @Sql("classpath:taskRepositoryEntries.sql")
+ })
+ void clearTasks() {
+ //Situation 1: Delete from taskgroup with no tasks
+ taskService.clearTasks(entityManager.find(Taskgroup.class, 1L));
+ for(long i=1; i<=15; i++) {
+ assertThat(entityManager.find(Task.class, i)).isNotNull();
+ }
+ //Situation 2: Delete from taskgroup with tasks
+ taskService.clearTasks(entityManager.find(Taskgroup.class, 2L));
+ for(long i=1; i<=15; i++) {
+ assertThat(entityManager.find(Task.class, i)).isNull();
+ }
+ }
+
+ @Test
+ @SqlGroup({
+ @Sql("classpath:taskgroupRepositoryTestEntries.sql"),
+ @Sql("classpath:taskRepositoryEntries.sql")
+ })
+ void finishTask() {
+ taskService.finishTask(entityManager.find(Task.class, 1L));
+ assertTrue(entityManager.find(Task.class, 1L).isFinished());
+
+ taskService.finishTask(entityManager.find(Task.class, 2L));
+ assertTrue(entityManager.find(Task.class, 1L).isFinished());
+ }
+
+ @Test
+ @SqlGroup({
+ @Sql("classpath:taskgroupRepositoryTestEntries.sql"),
+ @Sql("classpath:taskRepositoryEntries.sql")
+ })
+ void loadAllTasks() {
+ //Situation 1: No tasks existing
+ List result_1 = taskService.loadAllTasks(username2, TaskScope.UNFINISHED);
+ assertEquals(0, result_1.size());
+
+ //Situation 2: Tasks existing, Unfinished#
+ List result_2 = taskService.loadAllTasks(username, TaskScope.UNFINISHED);
+ assertEquals(8, result_2.size());
+ assertTrue(result_2.contains(entityManager.find(Task.class, 1L)));
+ assertTrue(result_2.contains(entityManager.find(Task.class, 3L)));
+ assertTrue(result_2.contains(entityManager.find(Task.class, 5L)));
+ assertTrue(result_2.contains(entityManager.find(Task.class, 7L)));
+ assertTrue(result_2.contains(entityManager.find(Task.class, 9L)));
+ assertTrue(result_2.contains(entityManager.find(Task.class, 11L)));
+ assertTrue(result_2.contains(entityManager.find(Task.class, 12L)));
+
+ //Situation 3: Finished tasks
+ List result_3 = taskService.loadAllTasks(username, TaskScope.FINISHED);
+ assertEquals(7, result_3.size());
+ assertTrue(result_3.contains(entityManager.find(Task.class, 2L)));
+ assertTrue(result_3.contains(entityManager.find(Task.class, 4L)));
+ assertTrue(result_3.contains(entityManager.find(Task.class, 6L)));
+ assertTrue(result_3.contains(entityManager.find(Task.class, 8L)));
+ assertTrue(result_3.contains(entityManager.find(Task.class, 10L)));
+ assertTrue(result_3.contains(entityManager.find(Task.class, 13L)));
+ assertTrue(result_3.contains(entityManager.find(Task.class, 14L)));
+
+ //overdue
+ List result_4 = taskService.loadAllTasks(username, TaskScope.OVERDUE);
+ assertEquals(2, result_4.size());
+ assertTrue(result_4.contains(entityManager.find(Task.class, 3L)));
+ assertTrue(result_4.contains(entityManager.find(Task.class, 5L)));
+
+ //upcoming
+ List result_5 = taskService.loadAllTasks(username, TaskScope.UPCOMING);
+ assertEquals(2, result_5.size());
+ assertTrue(result_5.contains(entityManager.find(Task.class, 7L)));
+ assertTrue(result_5.contains(entityManager.find(Task.class, 9L)));
+ //Active
+ List result_6 = taskService.loadAllTasks(username, TaskScope.ACTIVE);
+ assertEquals(6, result_6.size());
+ assertTrue(result_6.contains(entityManager.find(Task.class, 1L)));
+ assertTrue(result_6.contains(entityManager.find(Task.class, 3L)));
+ assertTrue(result_6.contains(entityManager.find(Task.class, 5L)));
+ assertTrue(result_6.contains(entityManager.find(Task.class, 11L)));
+ assertTrue(result_6.contains(entityManager.find(Task.class, 12L)));
+
+ }
}