TaskServiceTest

This commit is contained in:
Sebastian Böckelmann 2023-11-11 10:47:12 +01:00
parent 94b469238d
commit cc3c16ad02
2 changed files with 137 additions and 40 deletions

View File

@ -4,8 +4,9 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="3a869f59-290a-4ab2-b036-a878ce801bc4" name="Changes" comment="Consider increased number of tasks">
<change beforePath="$PROJECT_DIR$/src/main/java/core/services/TaskService.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/services/TaskService.java" afterDir="false" />
<list default="true" id="3a869f59-290a-4ab2-b036-a878ce801bc4" name="Changes" comment="Remove entityManager from TaskService">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/test/java/core/tasks/TaskServiceTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/core/tasks/TaskServiceTest.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -84,22 +85,7 @@
<recent name="$PROJECT_DIR$/src/test/java/core/taskgroups" />
</key>
</component>
<component name="RunManager" selected="JUnit.TaskServiceTest.deleteTask">
<configuration name="TaskRepositoryTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="demo" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="core.tasks.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="core.tasks" />
<option name="MAIN_CLASS_NAME" value="core.tasks.TaskRepositoryTest" />
<option name="TEST_OBJECT" value="class" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<component name="RunManager" selected="JUnit.TaskServiceTest">
<configuration name="TaskServiceTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="demo" />
<extension name="coverage">
@ -115,7 +101,7 @@
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="TaskServiceTest.createTask" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<configuration name="TaskServiceTest.clearTasks" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="demo" />
<extension name="coverage">
<pattern>
@ -125,7 +111,7 @@
</extension>
<option name="PACKAGE_NAME" value="core.tasks" />
<option name="MAIN_CLASS_NAME" value="core.tasks.TaskServiceTest" />
<option name="METHOD_NAME" value="createTask" />
<option name="METHOD_NAME" value="clearTasks" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
@ -147,17 +133,34 @@
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="TaskgroupServiceTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<configuration name="TaskServiceTest.finishTask" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="demo" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="core.taskgroups.*" />
<option name="PATTERN" value="core.tasks.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="core.taskgroups" />
<option name="MAIN_CLASS_NAME" value="core.taskgroups.TaskgroupServiceTest" />
<option name="TEST_OBJECT" value="class" />
<option name="PACKAGE_NAME" value="core.tasks" />
<option name="MAIN_CLASS_NAME" value="core.tasks.TaskServiceTest" />
<option name="METHOD_NAME" value="finishTask" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="TaskServiceTest.loadAllTasks" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="demo" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="core.tasks.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="core.tasks" />
<option name="MAIN_CLASS_NAME" value="core.tasks.TaskServiceTest" />
<option name="METHOD_NAME" value="loadAllTasks" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
@ -171,11 +174,11 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="JUnit.TaskServiceTest.deleteTask" />
<item itemvalue="JUnit.TaskServiceTest" />
<item itemvalue="JUnit.TaskRepositoryTest" />
<item itemvalue="JUnit.TaskgroupServiceTest" />
<item itemvalue="JUnit.TaskServiceTest.createTask" />
<item itemvalue="JUnit.TaskServiceTest.loadAllTasks" />
<item itemvalue="JUnit.TaskServiceTest.finishTask" />
<item itemvalue="JUnit.TaskServiceTest.clearTasks" />
<item itemvalue="JUnit.TaskServiceTest.deleteTask" />
</list>
</recent_temporary>
</component>
@ -471,14 +474,21 @@
<option name="project" value="LOCAL" />
<updated>1699694552466</updated>
</task>
<option name="localTasksCounter" value="33" />
<task id="LOCAL-00033" summary="Remove entityManager from TaskService">
<option name="closed" value="true" />
<created>1699695051881</created>
<option name="number" value="00033" />
<option name="presentableId" value="LOCAL-00033" />
<option name="project" value="LOCAL" />
<updated>1699695051881</updated>
</task>
<option name="localTasksCounter" value="34" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="Removed unused TaskgroupShortInfo.java" />
<MESSAGE value="Fix Foreign Key Constraint Fail when deleting Taskgroups" />
<MESSAGE value="Stop and Finish TaskSchedules" />
<MESSAGE value="Include TaskScheduleStopResponse" />
@ -503,7 +513,8 @@
<MESSAGE value="Resolve Merge-Conflict" />
<MESSAGE value="Deleting Task test" />
<MESSAGE value="Consider increased number of tasks" />
<option name="LAST_COMMIT_MESSAGE" value="Consider increased number of tasks" />
<MESSAGE value="Remove entityManager from TaskService" />
<option name="LAST_COMMIT_MESSAGE" value="Remove entityManager from TaskService" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>

View File

@ -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.*;
@ -176,17 +178,101 @@ public class TaskServiceTest {
assertEquals(ServiceExitCode.OK, result_11.getExitCode());
assertEquals(task_11, result_11.getResult());
}
/*@Test
@Test
@SqlGroup({
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
@Sql("classpath:taskRepositoryEntries.sql")
})
void deleteTask() {
Task task = entityManager.find(Task.class, 1L);
task.getTaskgroup().getTasks().remove(task);
taskgroupRepository.save(task.getTaskgroup());
Task updatedTask = entityManager.find(Task.class, 1L);
taskRepository.deleteByTaskID(entityManager.find(Task.class, 1L).getTaskID());
assertThat(entityManager.find(Task.class, 1L)).isNull();
}*/
for(long i=1; i<=15; i++) {
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<Task> result_1 = taskService.loadAllTasks(username2, TaskScope.UNFINISHED);
assertEquals(0, result_1.size());
//Situation 2: Tasks existing, Unfinished#
List<Task> 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<Task> 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<Task> 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<Task> 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<Task> 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)));
}
}