Merge pull request 'Pull-Request: Failing Test into tests' (#42) from test-failing into tests
All checks were successful
Java CI with Maven / build (push) Successful in 46s
All checks were successful
Java CI with Maven / build (push) Successful in 46s
Reviewed-on: Sebastian/TimeManager#42
This commit is contained in:
commit
fce4ba1996
@ -4,9 +4,8 @@
|
|||||||
<option name="autoReloadType" value="SELECTIVE" />
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<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="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$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" 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/java/core/tasks/TaskServiceTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/core/tasks/TaskServiceTest.java" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
@ -86,22 +85,7 @@
|
|||||||
<recent name="$PROJECT_DIR$/src/test/java/core/taskgroups" />
|
<recent name="$PROJECT_DIR$/src/test/java/core/taskgroups" />
|
||||||
</key>
|
</key>
|
||||||
</component>
|
</component>
|
||||||
<component name="RunManager" selected="JUnit.TaskRepositoryTest">
|
<component name="RunManager" selected="JUnit.TaskServiceTest">
|
||||||
<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>
|
|
||||||
<configuration name="TaskServiceTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
|
<configuration name="TaskServiceTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
|
||||||
<module name="demo" />
|
<module name="demo" />
|
||||||
<extension name="coverage">
|
<extension name="coverage">
|
||||||
@ -117,7 +101,7 @@
|
|||||||
<option name="Make" enabled="true" />
|
<option name="Make" enabled="true" />
|
||||||
</method>
|
</method>
|
||||||
</configuration>
|
</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" />
|
<module name="demo" />
|
||||||
<extension name="coverage">
|
<extension name="coverage">
|
||||||
<pattern>
|
<pattern>
|
||||||
@ -127,7 +111,7 @@
|
|||||||
</extension>
|
</extension>
|
||||||
<option name="PACKAGE_NAME" value="core.tasks" />
|
<option name="PACKAGE_NAME" value="core.tasks" />
|
||||||
<option name="MAIN_CLASS_NAME" value="core.tasks.TaskServiceTest" />
|
<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" />
|
<option name="TEST_OBJECT" value="method" />
|
||||||
<method v="2">
|
<method v="2">
|
||||||
<option name="Make" enabled="true" />
|
<option name="Make" enabled="true" />
|
||||||
@ -149,17 +133,34 @@
|
|||||||
<option name="Make" enabled="true" />
|
<option name="Make" enabled="true" />
|
||||||
</method>
|
</method>
|
||||||
</configuration>
|
</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" />
|
<module name="demo" />
|
||||||
<extension name="coverage">
|
<extension name="coverage">
|
||||||
<pattern>
|
<pattern>
|
||||||
<option name="PATTERN" value="core.taskgroups.*" />
|
<option name="PATTERN" value="core.tasks.*" />
|
||||||
<option name="ENABLED" value="true" />
|
<option name="ENABLED" value="true" />
|
||||||
</pattern>
|
</pattern>
|
||||||
</extension>
|
</extension>
|
||||||
<option name="PACKAGE_NAME" value="core.taskgroups" />
|
<option name="PACKAGE_NAME" value="core.tasks" />
|
||||||
<option name="MAIN_CLASS_NAME" value="core.taskgroups.TaskgroupServiceTest" />
|
<option name="MAIN_CLASS_NAME" value="core.tasks.TaskServiceTest" />
|
||||||
<option name="TEST_OBJECT" value="class" />
|
<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">
|
<method v="2">
|
||||||
<option name="Make" enabled="true" />
|
<option name="Make" enabled="true" />
|
||||||
</method>
|
</method>
|
||||||
@ -173,11 +174,11 @@
|
|||||||
</configuration>
|
</configuration>
|
||||||
<recent_temporary>
|
<recent_temporary>
|
||||||
<list>
|
<list>
|
||||||
<item itemvalue="JUnit.TaskRepositoryTest" />
|
|
||||||
<item itemvalue="JUnit.TaskgroupServiceTest" />
|
|
||||||
<item itemvalue="JUnit.TaskServiceTest" />
|
<item itemvalue="JUnit.TaskServiceTest" />
|
||||||
|
<item itemvalue="JUnit.TaskServiceTest.loadAllTasks" />
|
||||||
|
<item itemvalue="JUnit.TaskServiceTest.finishTask" />
|
||||||
|
<item itemvalue="JUnit.TaskServiceTest.clearTasks" />
|
||||||
<item itemvalue="JUnit.TaskServiceTest.deleteTask" />
|
<item itemvalue="JUnit.TaskServiceTest.deleteTask" />
|
||||||
<item itemvalue="JUnit.TaskServiceTest.createTask" />
|
|
||||||
</list>
|
</list>
|
||||||
</recent_temporary>
|
</recent_temporary>
|
||||||
</component>
|
</component>
|
||||||
@ -457,16 +458,37 @@
|
|||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1699693472182</updated>
|
<updated>1699693472182</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="31" />
|
<task id="LOCAL-00031" summary="Deleting Task test">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1699694400508</created>
|
||||||
|
<option name="number" value="00031" />
|
||||||
|
<option name="presentableId" value="LOCAL-00031" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1699694400508</updated>
|
||||||
|
</task>
|
||||||
|
<task id="LOCAL-00032" summary="Consider increased number of tasks">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1699694552466</created>
|
||||||
|
<option name="number" value="00032" />
|
||||||
|
<option name="presentableId" value="LOCAL-00032" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1699694552466</updated>
|
||||||
|
</task>
|
||||||
|
<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 />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="TypeScriptGeneratedFilesManager">
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
<option name="version" value="3" />
|
<option name="version" value="3" />
|
||||||
</component>
|
</component>
|
||||||
<component name="VcsManagerConfiguration">
|
<component name="VcsManagerConfiguration">
|
||||||
<MESSAGE value="Delete Schedules" />
|
|
||||||
<MESSAGE value="Deliver Schedule Path Info when fetching Schedules" />
|
|
||||||
<MESSAGE value="Removed unused TaskgroupShortInfo.java" />
|
|
||||||
<MESSAGE value="Fix Foreign Key Constraint Fail when deleting Taskgroups" />
|
<MESSAGE value="Fix Foreign Key Constraint Fail when deleting Taskgroups" />
|
||||||
<MESSAGE value="Stop and Finish TaskSchedules" />
|
<MESSAGE value="Stop and Finish TaskSchedules" />
|
||||||
<MESSAGE value="Include TaskScheduleStopResponse" />
|
<MESSAGE value="Include TaskScheduleStopResponse" />
|
||||||
@ -489,7 +511,10 @@
|
|||||||
<MESSAGE value="Use @Sql instead of persit()" />
|
<MESSAGE value="Use @Sql instead of persit()" />
|
||||||
<MESSAGE value="Make the Test Transactional" />
|
<MESSAGE value="Make the Test Transactional" />
|
||||||
<MESSAGE value="Resolve Merge-Conflict" />
|
<MESSAGE value="Resolve Merge-Conflict" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="Resolve Merge-Conflict" />
|
<MESSAGE value="Deleting Task test" />
|
||||||
|
<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>
|
||||||
<component name="XDebuggerManager">
|
<component name="XDebuggerManager">
|
||||||
<breakpoint-manager>
|
<breakpoint-manager>
|
||||||
|
@ -11,9 +11,6 @@ import core.repositories.timemanager.TaskgroupRepository;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
|
||||||
import javax.persistence.PersistenceContext;
|
|
||||||
import javax.transaction.Transactional;
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -24,8 +21,6 @@ public class TaskService {
|
|||||||
private final TaskRepository taskRepository;
|
private final TaskRepository taskRepository;
|
||||||
private final TaskScheduleService taskScheduleService;
|
private final TaskScheduleService taskScheduleService;
|
||||||
private final TaskgroupRepository taskgroupRepository;
|
private final TaskgroupRepository taskgroupRepository;
|
||||||
@PersistenceContext
|
|
||||||
private EntityManager entityManager;
|
|
||||||
|
|
||||||
|
|
||||||
public TaskService(@Autowired TaskRepository taskRepository,
|
public TaskService(@Autowired TaskRepository taskRepository,
|
||||||
@ -79,6 +74,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
|
//Check for invalid date (deadline before start
|
||||||
if(taskFieldInfo.getStartDate() != null && taskFieldInfo.getDeadline() != null &&
|
if(taskFieldInfo.getStartDate() != null && taskFieldInfo.getDeadline() != null &&
|
||||||
taskFieldInfo.getDeadline().isBefore(taskFieldInfo.getStartDate())) {
|
taskFieldInfo.getDeadline().isBefore(taskFieldInfo.getStartDate())) {
|
||||||
@ -91,13 +92,9 @@ public class TaskService {
|
|||||||
return new ServiceResult<>(task);
|
return new ServiceResult<>(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public void deleteTask(Task task) {
|
public void deleteTask(Task task) {
|
||||||
taskScheduleService.deleteScheduleByTask(task);
|
taskScheduleService.deleteScheduleByTask(task);
|
||||||
taskRepository.deleteByTaskID(task.getTaskID());
|
taskRepository.deleteByTaskID(task.getTaskID());
|
||||||
|
|
||||||
entityManager.flush();
|
|
||||||
entityManager.detach(task);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearTasks(Taskgroup taskgroup) {
|
public void clearTasks(Taskgroup taskgroup) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package core.tasks;
|
package core.tasks;
|
||||||
|
|
||||||
import core.api.models.timemanager.tasks.TaskFieldInfo;
|
import core.api.models.timemanager.tasks.TaskFieldInfo;
|
||||||
|
import core.api.models.timemanager.tasks.TaskScope;
|
||||||
import core.entities.timemanager.Task;
|
import core.entities.timemanager.Task;
|
||||||
import core.entities.timemanager.Taskgroup;
|
import core.entities.timemanager.Taskgroup;
|
||||||
import core.repositories.timemanager.TaskRepository;
|
import core.repositories.timemanager.TaskRepository;
|
||||||
@ -17,6 +18,7 @@ import javax.persistence.EntityManager;
|
|||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
@ -184,8 +186,93 @@ public class TaskServiceTest {
|
|||||||
})
|
})
|
||||||
void deleteTask() {
|
void deleteTask() {
|
||||||
for(long i=1; i<=15; i++) {
|
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();
|
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)));
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user