tests #43

Merged
sebastian merged 41 commits from tests into master 2023-11-11 11:20:50 +01:00
3 changed files with 95 additions and 15 deletions
Showing only changes of commit 7f09c1cefc - Show all commits

View File

@ -4,10 +4,16 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="3a869f59-290a-4ab2-b036-a878ce801bc4" name="Changes" comment="Resolve Merge-Conflict">
<list default="true" id="3a869f59-290a-4ab2-b036-a878ce801bc4" name="Changes" comment="Testcases (and failing test fixes) of TaskgroupService">
<change afterPath="$PROJECT_DIR$/src/test/java/core/tasks/TaskServiceTest.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/core/api/models/timemanager/tasks/TaskFieldInfo.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/api/models/timemanager/tasks/TaskFieldInfo.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/core/entities/timemanager/Task.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/entities/timemanager/Task.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/core/entities/timemanager/Taskgroup.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/entities/timemanager/Taskgroup.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/core/services/ServiceExitCode.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/services/ServiceExitCode.java" afterDir="false" />
<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" />
<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" />
<change beforePath="$PROJECT_DIR$/src/test/resources/application.properties" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/resources/application.properties" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/test/resources/taskRepositoryEntries.sql" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/resources/taskRepositoryEntries.sql" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -26,7 +32,7 @@
<component name="Git.Settings">
<option name="RECENT_BRANCH_BY_REPOSITORY">
<map>
<entry key="$PROJECT_DIR$/.." value="test-failing" />
<entry key="$PROJECT_DIR$/.." value="master" />
</map>
</option>
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
@ -86,8 +92,8 @@
<recent name="$PROJECT_DIR$/src/test/java/core/taskgroups" />
</key>
</component>
<component name="RunManager" selected="JUnit.TaskRepositoryTest">
<configuration name="TaskRepositoryTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<component name="RunManager" selected="JUnit.TaskgroupServiceTest">
<configuration name="TaskRepositoryTest.deleteByTaskID" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="demo" />
<extension name="coverage">
<pattern>
@ -97,7 +103,8 @@
</extension>
<option name="PACKAGE_NAME" value="core.tasks" />
<option name="MAIN_CLASS_NAME" value="core.tasks.TaskRepositoryTest" />
<option name="TEST_OBJECT" value="class" />
<option name="METHOD_NAME" value="deleteByTaskID" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
@ -173,11 +180,11 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="JUnit.TaskRepositoryTest" />
<item itemvalue="JUnit.TaskgroupServiceTest" />
<item itemvalue="JUnit.TaskServiceTest" />
<item itemvalue="JUnit.TaskServiceTest.deleteTask" />
<item itemvalue="JUnit.TaskServiceTest.createTask" />
<item itemvalue="JUnit.TaskServiceTest.deleteTask" />
<item itemvalue="JUnit.TaskRepositoryTest.deleteByTaskID" />
</list>
</recent_temporary>
</component>
@ -215,7 +222,7 @@
<workItem from="1699466564154" duration="6646000" />
<workItem from="1699473376129" duration="1423000" />
<workItem from="1699639316405" duration="9267000" />
<workItem from="1699684493731" duration="1121000" />
<workItem from="1699684493731" duration="7709000" />
</task>
<task id="LOCAL-00001" summary="Structure Taskgroups in Hierarchies">
<option name="closed" value="true" />
@ -449,13 +456,13 @@
<option name="project" value="LOCAL" />
<updated>1699646291964</updated>
</task>
<task id="LOCAL-00030" summary="Resolve Merge-Conflict">
<task id="LOCAL-00030" summary="Testcases (and failing test fixes) of TaskgroupService">
<option name="closed" value="true" />
<created>1699693472182</created>
<created>1699685656297</created>
<option name="number" value="00030" />
<option name="presentableId" value="LOCAL-00030" />
<option name="project" value="LOCAL" />
<updated>1699693472182</updated>
<updated>1699685656297</updated>
</task>
<option name="localTasksCounter" value="31" />
<servers />
@ -464,6 +471,7 @@
<option name="version" value="3" />
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="Define Entity BasicTaskSchedule and Taskcontroller" />
<MESSAGE value="Delete Schedules" />
<MESSAGE value="Deliver Schedule Path Info when fetching Schedules" />
<MESSAGE value="Removed unused TaskgroupShortInfo.java" />
@ -487,9 +495,8 @@
<MESSAGE value="Test TaskRepository" />
<MESSAGE value="Initialize Testing of Testservice" />
<MESSAGE value="Use @Sql instead of persit()" />
<MESSAGE value="Make the Test Transactional" />
<MESSAGE value="Resolve Merge-Conflict" />
<option name="LAST_COMMIT_MESSAGE" value="Resolve Merge-Conflict" />
<MESSAGE value="Testcases (and failing test fixes) of TaskgroupService" />
<option name="LAST_COMMIT_MESSAGE" value="Testcases (and failing test fixes) of TaskgroupService" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
@ -514,6 +521,11 @@
<line>57</line>
<option name="timeStamp" value="12" />
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/test/java/core/tasks/TaskServiceTest.java</url>
<line>188</line>
<option name="timeStamp" value="23" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>

View File

@ -79,6 +79,12 @@ public class TaskService {
}
}
//Check for invalid date (deadline before start
if(taskFieldInfo.getStartDate() != null && taskFieldInfo.getDeadline() != null &&
taskFieldInfo.getDeadline().isBefore(taskFieldInfo.getStartDate())) {
return new ServiceResult<>(ServiceExitCode.INVALID_PARAMETER);
}
//Check for invalid date (deadline before start
if(taskFieldInfo.getStartDate() != null && taskFieldInfo.getDeadline() != null &&
taskFieldInfo.getDeadline().isBefore(taskFieldInfo.getStartDate())) {

View File

@ -43,6 +43,10 @@ public class TaskServiceTest {
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
@Sql("classpath:taskRepositoryEntries.sql")
})
<<<<<<< HEAD
=======
@Rollback(value = true)
>>>>>>> 5e39cb1 (TaskService Test will fail)
void createTask() {
//Situation 1: Task with that name already exists in a taskgroup
TaskFieldInfo taskFieldInfo_1 = new TaskFieldInfo(entityManager.find(Task.class, 1L).getTaskName(), 0, null, null);
@ -118,58 +122,99 @@ public class TaskServiceTest {
assertEquals(ServiceExitCode.OK, result_1.getExitCode());
assertEquals(task_1, result_1.getResult());
<<<<<<< HEAD
//Situation 2: Name is updated to name that already exists within the taskgroup
Task task_2 = entityManager.find(Task.class, 1L);
TaskFieldInfo taskFieldInfo_2 = new TaskFieldInfo(entityManager.find(Task.class, 2L).getTaskName(), 0, null, null);
ServiceResult<Task> result_2 = taskService.editTask(entityManager.find(Task.class, 1L), taskFieldInfo_2);
task_2.setTaskName(entityManager.find(Task.class, 2L).getTaskName());
=======
//Situation 2: Name is updated to name that already exists within another taskgroup
Task task_2 = entityManager.find(Task.class, 1L);
task_2.setTaskName(entityManager.find(Task.class, 2L).getTaskName());
TaskFieldInfo taskFieldInfo_2 = new TaskFieldInfo(entityManager.find(Task.class, 2L).getTaskName(), 0, null, null);
ServiceResult<Task> result_2 = taskService.editTask(entityManager.find(Task.class, 1L), taskFieldInfo_2);
>>>>>>> 5e39cb1 (TaskService Test will fail)
assertEquals(ServiceExitCode.ENTITY_ALREADY_EXIST, result_2.getExitCode());
assertNotEquals(task_2, result_2.getResult());
//Situation 3: Name is updated to nonexistend Name
Task task_3 = entityManager.find(Task.class, 1L);
<<<<<<< HEAD
TaskFieldInfo taskFieldInfo_3 = new TaskFieldInfo("Situation 3", 0, null, null);
ServiceResult<Task> result_3 = taskService.editTask(entityManager.find(Task.class, 1L), taskFieldInfo_3);
task_3.setTaskName("Situation 3");
=======
task_3.setTaskName("Situation 3");
TaskFieldInfo taskFieldInfo_3 = new TaskFieldInfo("Situation 3", 0, null, null);
ServiceResult<Task> result_3 = taskService.editTask(entityManager.find(Task.class, 1L), taskFieldInfo_3);
>>>>>>> 5e39cb1 (TaskService Test will fail)
assertEquals(ServiceExitCode.OK, result_3.getExitCode());
assertEquals(task_3, result_3.getResult());
//Situation 4: eta is updated
Task task_4 = entityManager.find(Task.class, 1L);
<<<<<<< HEAD
TaskFieldInfo taskFieldInfo_4 = new TaskFieldInfo(task_4.getTaskName(), 90, null, null);
ServiceResult<Task> result_4 = taskService.editTask(entityManager.find(Task.class, 1L), taskFieldInfo_4);
task_4.setEta(90);
=======
task_4.setEta(90);
TaskFieldInfo taskFieldInfo_4 = new TaskFieldInfo(task_4.getTaskName(), 90, null, null);
ServiceResult<Task> result_4 = taskService.editTask(entityManager.find(Task.class, 1L), taskFieldInfo_4);
>>>>>>> 5e39cb1 (TaskService Test will fail)
assertEquals(ServiceExitCode.OK, result_4.getExitCode());
assertEquals(task_4, result_4.getResult());
//Situation 5: deadline and start is updated in a valid way
Task task_5 = entityManager.find(Task.class, 1L);
<<<<<<< HEAD
TaskFieldInfo taskFieldInfo_5 = new TaskFieldInfo(task_5.getTaskName(), task_5.getEta(), LocalDate.of(2023, 4, 9), LocalDate.of(2023,5,9));
ServiceResult<Task> result_5 = taskService.editTask(entityManager.find(Task.class, 1L), taskFieldInfo_5);
task_5.setStartDate(LocalDate.of(2023,4,9));
task_5.setDeadline(LocalDate.of(2023,5,9));
=======
task_5.setStartDate(LocalDate.of(2023,4,9));
task_5.setDeadline(LocalDate.of(2023,5,9));
TaskFieldInfo taskFieldInfo_5 = new TaskFieldInfo(task_5.getTaskName(), task_5.getEta(), LocalDate.of(2023, 4, 9), LocalDate.of(2023,5,9));
ServiceResult<Task> result_5 = taskService.editTask(entityManager.find(Task.class, 1L), taskFieldInfo_5);
>>>>>>> 5e39cb1 (TaskService Test will fail)
assertEquals(ServiceExitCode.OK, result_5.getExitCode());
assertEquals(task_5, result_5.getResult());
//Situation 6: Deadline and start are updated in a not valid way
Task task_6 = entityManager.find(Task.class, 1L);
<<<<<<< HEAD
TaskFieldInfo taskFieldInfo_6 = new TaskFieldInfo(task_5.getTaskName(), task_5.getEta(), LocalDate.of(2023, 5, 9), LocalDate.of(2023,4,9));
ServiceResult<Task> result_6 = taskService.editTask(entityManager.find(Task.class, 1L), taskFieldInfo_6);
task_6.setStartDate(LocalDate.of(2023,5,9));
task_6.setDeadline(LocalDate.of(2023,4,9));
=======
task_6.setStartDate(LocalDate.of(2023,5,9));
task_6.setDeadline(LocalDate.of(2023,4,9));
TaskFieldInfo taskFieldInfo_6 = new TaskFieldInfo(task_5.getTaskName(), task_5.getEta(), LocalDate.of(2023, 5, 9), LocalDate.of(2023,4,9));
ServiceResult<Task> result_6 = taskService.editTask(entityManager.find(Task.class, 1L), taskFieldInfo_6);
>>>>>>> 5e39cb1 (TaskService Test will fail)
assertEquals(ServiceExitCode.INVALID_PARAMETER, result_6.getExitCode());
assertNotEquals(task_6, result_6.getResult());
//Situation 10 Startdate = null;
Task task_10 = entityManager.find(Task.class, 5L);
<<<<<<< HEAD
TaskFieldInfo taskFieldInfo_10 = new TaskFieldInfo(task_10.getTaskName(), task_10.getEta(),null, task_10.getDeadline());
ServiceResult<Task> result_10 = taskService.editTask(entityManager.find(Task.class, 5L), taskFieldInfo_10);
task_10.setStartDate(null);
=======
task_10.setStartDate(null);
TaskFieldInfo taskFieldInfo_10 = new TaskFieldInfo(task_10.getTaskName(), task_10.getEta(),null, task_10.getDeadline());
ServiceResult<Task> result_10 = taskService.editTask(entityManager.find(Task.class, 5L), taskFieldInfo_10);
>>>>>>> 5e39cb1 (TaskService Test will fail)
assertEquals(ServiceExitCode.OK, result_10.getExitCode());
assertEquals(task_10, result_10.getResult());
//Situation 11 Deadline = null
Task task_11 = entityManager.find(Task.class, 5L);
<<<<<<< HEAD
TaskFieldInfo taskFieldInfo_11 = new TaskFieldInfo(task_11.getTaskName(), task_11.getEta(),task_11.getStartDate(), null);
ServiceResult<Task> result_11 = taskService.editTask(entityManager.find(Task.class, 5L), taskFieldInfo_11);
task_11.setDeadline(null);
@ -177,15 +222,32 @@ public class TaskServiceTest {
assertEquals(task_11, result_11.getResult());
}
=======
task_11.setDeadline(null);
TaskFieldInfo taskFieldInfo_11 = new TaskFieldInfo(task_11.getTaskName(), task_11.getEta(),task_11.getStartDate(), null);
ServiceResult<Task> result_11 = taskService.editTask(entityManager.find(Task.class, 5L), taskFieldInfo_11);
assertEquals(ServiceExitCode.OK, result_11.getExitCode());
assertEquals(task_11, result_11.getResult());
}
>>>>>>> 5e39cb1 (TaskService Test will fail)
@Test
@SqlGroup({
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
@Sql("classpath:taskRepositoryEntries.sql")
})
void deleteTask() {
<<<<<<< HEAD
for(long i=1; i<=15; i++) {
taskRepository.deleteByTaskID(entityManager.find(Task.class, i).getTaskID());
assertThat(entityManager.find(Task.class, i)).isNull();
}
=======
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();
>>>>>>> 5e39cb1 (TaskService Test will fail)
}
}