test-failing #41
@ -4,12 +4,16 @@
|
|||||||
<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="Use @Sql instead of persit()">
|
<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$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/core/api/models/timemanager/taskgroup/TaskgroupFieldInfo.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/api/models/timemanager/taskgroup/TaskgroupFieldInfo.java" 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/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/TaskgroupService.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/services/TaskgroupService.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/test/java/core/taskgroups/TaskgroupServiceTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/core/taskgroups/TaskgroupServiceTest.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/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>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@ -88,56 +92,71 @@
|
|||||||
<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.TaskgroupServiceTest.deleteTaskgroupByUser">
|
<component name="RunManager" selected="JUnit.TaskgroupServiceTest">
|
||||||
<configuration name="TaskgroupServiceTest.addTaskgroup" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
|
<configuration name="TaskRepositoryTest.deleteByTaskID" 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.TaskRepositoryTest" />
|
||||||
<option name="METHOD_NAME" value="addTaskgroup" />
|
<option name="METHOD_NAME" value="deleteByTaskID" />
|
||||||
<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" />
|
||||||
</method>
|
</method>
|
||||||
</configuration>
|
</configuration>
|
||||||
<configuration name="TaskgroupServiceTest.deleteTaskgroup" 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">
|
||||||
<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="METHOD_NAME" value="deleteTaskgroup" />
|
<option name="TEST_OBJECT" value="class" />
|
||||||
|
<method v="2">
|
||||||
|
<option name="Make" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
<configuration name="TaskServiceTest.createTask" 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="createTask" />
|
||||||
<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" />
|
||||||
</method>
|
</method>
|
||||||
</configuration>
|
</configuration>
|
||||||
<configuration name="TaskgroupServiceTest.deleteTaskgroupByUser" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
|
<configuration name="TaskServiceTest.deleteTask" 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="METHOD_NAME" value="deleteTaskgroupByUser" />
|
<option name="METHOD_NAME" value="deleteTask" />
|
||||||
<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" />
|
||||||
</method>
|
</method>
|
||||||
</configuration>
|
</configuration>
|
||||||
<configuration name="TaskgroupServiceTest.editTaskgroup" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
|
<configuration name="TaskgroupServiceTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
|
||||||
<module name="demo" />
|
<module name="demo" />
|
||||||
<extension name="coverage">
|
<extension name="coverage">
|
||||||
<pattern>
|
<pattern>
|
||||||
@ -147,24 +166,7 @@
|
|||||||
</extension>
|
</extension>
|
||||||
<option name="PACKAGE_NAME" value="core.taskgroups" />
|
<option name="PACKAGE_NAME" value="core.taskgroups" />
|
||||||
<option name="MAIN_CLASS_NAME" value="core.taskgroups.TaskgroupServiceTest" />
|
<option name="MAIN_CLASS_NAME" value="core.taskgroups.TaskgroupServiceTest" />
|
||||||
<option name="METHOD_NAME" value="editTaskgroup" />
|
<option name="TEST_OBJECT" value="class" />
|
||||||
<option name="TEST_OBJECT" value="method" />
|
|
||||||
<method v="2">
|
|
||||||
<option name="Make" enabled="true" />
|
|
||||||
</method>
|
|
||||||
</configuration>
|
|
||||||
<configuration name="TaskgroupServiceTest.getTopTaskgroupsByUser" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
|
|
||||||
<module name="demo" />
|
|
||||||
<extension name="coverage">
|
|
||||||
<pattern>
|
|
||||||
<option name="PATTERN" value="core.taskgroups.*" />
|
|
||||||
<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="METHOD_NAME" value="getTopTaskgroupsByUser" />
|
|
||||||
<option name="TEST_OBJECT" value="method" />
|
|
||||||
<method v="2">
|
<method v="2">
|
||||||
<option name="Make" enabled="true" />
|
<option name="Make" enabled="true" />
|
||||||
</method>
|
</method>
|
||||||
@ -178,11 +180,11 @@
|
|||||||
</configuration>
|
</configuration>
|
||||||
<recent_temporary>
|
<recent_temporary>
|
||||||
<list>
|
<list>
|
||||||
<item itemvalue="JUnit.TaskgroupServiceTest.deleteTaskgroupByUser" />
|
<item itemvalue="JUnit.TaskgroupServiceTest" />
|
||||||
<item itemvalue="JUnit.TaskgroupServiceTest.getTopTaskgroupsByUser" />
|
<item itemvalue="JUnit.TaskServiceTest" />
|
||||||
<item itemvalue="JUnit.TaskgroupServiceTest.deleteTaskgroup" />
|
<item itemvalue="JUnit.TaskServiceTest.createTask" />
|
||||||
<item itemvalue="JUnit.TaskgroupServiceTest.editTaskgroup" />
|
<item itemvalue="JUnit.TaskServiceTest.deleteTask" />
|
||||||
<item itemvalue="JUnit.TaskgroupServiceTest.addTaskgroup" />
|
<item itemvalue="JUnit.TaskRepositoryTest.deleteByTaskID" />
|
||||||
</list>
|
</list>
|
||||||
</recent_temporary>
|
</recent_temporary>
|
||||||
</component>
|
</component>
|
||||||
@ -220,7 +222,7 @@
|
|||||||
<workItem from="1699466564154" duration="6646000" />
|
<workItem from="1699466564154" duration="6646000" />
|
||||||
<workItem from="1699473376129" duration="1423000" />
|
<workItem from="1699473376129" duration="1423000" />
|
||||||
<workItem from="1699639316405" duration="9267000" />
|
<workItem from="1699639316405" duration="9267000" />
|
||||||
<workItem from="1699684493731" duration="1121000" />
|
<workItem from="1699684493731" duration="7709000" />
|
||||||
</task>
|
</task>
|
||||||
<task id="LOCAL-00001" summary="Structure Taskgroups in Hierarchies">
|
<task id="LOCAL-00001" summary="Structure Taskgroups in Hierarchies">
|
||||||
<option name="closed" value="true" />
|
<option name="closed" value="true" />
|
||||||
@ -454,14 +456,21 @@
|
|||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1699646291964</updated>
|
<updated>1699646291964</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="30" />
|
<task id="LOCAL-00030" summary="Testcases (and failing test fixes) of TaskgroupService">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1699685656297</created>
|
||||||
|
<option name="number" value="00030" />
|
||||||
|
<option name="presentableId" value="LOCAL-00030" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1699685656297</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="31" />
|
||||||
<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 and clear Tasks (Frontend)" />
|
|
||||||
<MESSAGE value="Define Entity BasicTaskSchedule and Taskcontroller" />
|
<MESSAGE value="Define Entity BasicTaskSchedule and Taskcontroller" />
|
||||||
<MESSAGE value="Delete Schedules" />
|
<MESSAGE value="Delete Schedules" />
|
||||||
<MESSAGE value="Deliver Schedule Path Info when fetching Schedules" />
|
<MESSAGE value="Deliver Schedule Path Info when fetching Schedules" />
|
||||||
@ -486,7 +495,8 @@
|
|||||||
<MESSAGE value="Test TaskRepository" />
|
<MESSAGE value="Test TaskRepository" />
|
||||||
<MESSAGE value="Initialize Testing of Testservice" />
|
<MESSAGE value="Initialize Testing of Testservice" />
|
||||||
<MESSAGE value="Use @Sql instead of persit()" />
|
<MESSAGE value="Use @Sql instead of persit()" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="Use @Sql instead of persit()" />
|
<MESSAGE value="Testcases (and failing test fixes) of TaskgroupService" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="Testcases (and failing test fixes) of TaskgroupService" />
|
||||||
</component>
|
</component>
|
||||||
<component name="XDebuggerManager">
|
<component name="XDebuggerManager">
|
||||||
<breakpoint-manager>
|
<breakpoint-manager>
|
||||||
@ -511,6 +521,11 @@
|
|||||||
<line>57</line>
|
<line>57</line>
|
||||||
<option name="timeStamp" value="12" />
|
<option name="timeStamp" value="12" />
|
||||||
</line-breakpoint>
|
</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>
|
</breakpoints>
|
||||||
</breakpoint-manager>
|
</breakpoint-manager>
|
||||||
</component>
|
</component>
|
||||||
|
@ -14,6 +14,16 @@ public class TaskFieldInfo {
|
|||||||
private LocalDate startDate;
|
private LocalDate startDate;
|
||||||
private LocalDate deadline;
|
private LocalDate deadline;
|
||||||
|
|
||||||
|
public TaskFieldInfo() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public TaskFieldInfo(String taskName, int eta, LocalDate startDate, LocalDate deadline) {
|
||||||
|
this.taskName = taskName;
|
||||||
|
this.eta = eta;
|
||||||
|
this.startDate = startDate;
|
||||||
|
this.deadline = deadline;
|
||||||
|
}
|
||||||
|
|
||||||
public String getTaskName() {
|
public String getTaskName() {
|
||||||
return taskName;
|
return taskName;
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import java.util.Set;
|
|||||||
public class Task {
|
public class Task {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private long taskID;
|
private long taskID;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@ -113,19 +113,6 @@ public class Task {
|
|||||||
this.workTime += workTime;
|
this.workTime += workTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
Task task = (Task) o;
|
|
||||||
return taskID == task.taskID;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(taskID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTaskID(long taskID) {
|
public void setTaskID(long taskID) {
|
||||||
this.taskID = taskID;
|
this.taskID = taskID;
|
||||||
}
|
}
|
||||||
@ -150,4 +137,31 @@ public class Task {
|
|||||||
public void increaseActiveTime(int minutesSpent) {
|
public void increaseActiveTime(int minutesSpent) {
|
||||||
this.workTime += minutesSpent;
|
this.workTime += minutesSpent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Task task = (Task) o;
|
||||||
|
return taskID == task.taskID && eta == task.eta && finished == task.finished && workTime == task.workTime && Objects.equals(taskgroup, task.taskgroup) && Objects.equals(taskName, task.taskName) && Objects.equals(startDate, task.startDate) && Objects.equals(deadline, task.deadline);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(taskID, taskgroup, taskName, startDate, deadline, eta, finished, workTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Task{" +
|
||||||
|
"taskID=" + taskID +
|
||||||
|
", taskgroup=" + taskgroup +
|
||||||
|
", taskName='" + taskName + '\'' +
|
||||||
|
", startDate=" + startDate +
|
||||||
|
", deadline=" + deadline +
|
||||||
|
", eta=" + eta +
|
||||||
|
", finished=" + finished +
|
||||||
|
", workTime=" + workTime +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ public class Taskgroup {
|
|||||||
@JoinColumn(name = "parent_id")
|
@JoinColumn(name = "parent_id")
|
||||||
private Taskgroup parent;
|
private Taskgroup parent;
|
||||||
|
|
||||||
|
|
||||||
@OneToMany(mappedBy = "taskgroup", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
@OneToMany(mappedBy = "taskgroup", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||||
private Set<Task> tasks;
|
private Set<Task> tasks;
|
||||||
|
|
||||||
|
@ -5,5 +5,6 @@ public enum ServiceExitCode {
|
|||||||
OK,
|
OK,
|
||||||
ENTITY_ALREADY_EXIST,
|
ENTITY_ALREADY_EXIST,
|
||||||
MISSING_ENTITY,
|
MISSING_ENTITY,
|
||||||
INVALID_OPERATION;
|
INVALID_OPERATION,
|
||||||
|
INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,9 @@ 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.*;
|
||||||
@ -20,12 +23,17 @@ public class TaskService {
|
|||||||
|
|
||||||
private final TaskRepository taskRepository;
|
private final TaskRepository taskRepository;
|
||||||
private final TaskScheduleService taskScheduleService;
|
private final TaskScheduleService taskScheduleService;
|
||||||
|
private final TaskgroupRepository taskgroupRepository;
|
||||||
|
@PersistenceContext
|
||||||
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
|
||||||
public TaskService(@Autowired TaskRepository taskRepository,
|
public TaskService(@Autowired TaskRepository taskRepository,
|
||||||
@Autowired TaskScheduleService taskScheduleService) {
|
@Autowired TaskScheduleService taskScheduleService,
|
||||||
|
TaskgroupRepository taskgroupRepository) {
|
||||||
this.taskRepository = taskRepository;
|
this.taskRepository = taskRepository;
|
||||||
this.taskScheduleService = taskScheduleService;
|
this.taskScheduleService = taskScheduleService;
|
||||||
|
this.taskgroupRepository = taskgroupRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServiceResult<Task> createTask(Taskgroup taskgroup, TaskFieldInfo taskFieldInfo) {
|
public ServiceResult<Task> createTask(Taskgroup taskgroup, TaskFieldInfo taskFieldInfo) {
|
||||||
@ -33,6 +41,11 @@ public class TaskService {
|
|||||||
return new ServiceResult<>(ServiceExitCode.ENTITY_ALREADY_EXIST);
|
return new ServiceResult<>(ServiceExitCode.ENTITY_ALREADY_EXIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//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);
|
||||||
|
}
|
||||||
|
|
||||||
Task task = new Task(taskgroup, taskFieldInfo.getTaskName(), taskFieldInfo.getStartDate(), taskFieldInfo.getDeadline(), taskFieldInfo.getEta());
|
Task task = new Task(taskgroup, taskFieldInfo.getTaskName(), taskFieldInfo.getStartDate(), taskFieldInfo.getDeadline(), taskFieldInfo.getEta());
|
||||||
taskgroup.getTasks().add(task);
|
taskgroup.getTasks().add(task);
|
||||||
@ -63,6 +76,12 @@ public class TaskService {
|
|||||||
} else if(!task.getTaskName().equals(taskFieldInfo.getTaskName()) && existTaskByName(task.getTaskgroup().getTasks(), taskFieldInfo.getTaskName())) {
|
} else if(!task.getTaskName().equals(taskFieldInfo.getTaskName()) && existTaskByName(task.getTaskgroup().getTasks(), taskFieldInfo.getTaskName())) {
|
||||||
return new ServiceResult<>(ServiceExitCode.ENTITY_ALREADY_EXIST);
|
return new ServiceResult<>(ServiceExitCode.ENTITY_ALREADY_EXIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//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);
|
||||||
|
}
|
||||||
task.setEta(taskFieldInfo.getEta());
|
task.setEta(taskFieldInfo.getEta());
|
||||||
task.setStartDate(taskFieldInfo.getStartDate());
|
task.setStartDate(taskFieldInfo.getStartDate());
|
||||||
task.setDeadline(taskFieldInfo.getDeadline());
|
task.setDeadline(taskFieldInfo.getDeadline());
|
||||||
@ -70,9 +89,13 @@ 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) {
|
||||||
|
192
backend/src/test/java/core/tasks/TaskServiceTest.java
Normal file
192
backend/src/test/java/core/tasks/TaskServiceTest.java
Normal file
@ -0,0 +1,192 @@
|
|||||||
|
package core.tasks;
|
||||||
|
|
||||||
|
import core.api.models.timemanager.tasks.TaskFieldInfo;
|
||||||
|
import core.entities.timemanager.Task;
|
||||||
|
import core.entities.timemanager.Taskgroup;
|
||||||
|
import core.repositories.timemanager.TaskRepository;
|
||||||
|
import core.repositories.timemanager.TaskgroupRepository;
|
||||||
|
import core.services.*;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.annotation.Rollback;
|
||||||
|
import org.springframework.test.context.jdbc.Sql;
|
||||||
|
import org.springframework.test.context.jdbc.SqlGroup;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
public class TaskServiceTest {
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TaskService taskService;
|
||||||
|
@Autowired
|
||||||
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
private static final String username = "Testuser1";
|
||||||
|
private static final String username2 = "Testuser2";
|
||||||
|
@Autowired
|
||||||
|
private TaskRepository taskRepository;
|
||||||
|
@Autowired
|
||||||
|
private TaskgroupRepository taskgroupRepository;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SqlGroup({
|
||||||
|
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
|
||||||
|
@Sql("classpath:taskRepositoryEntries.sql")
|
||||||
|
})
|
||||||
|
@Rollback(value = true)
|
||||||
|
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);
|
||||||
|
ServiceResult<Task> situation_1 = taskService.createTask(entityManager.find(Taskgroup.class, 2L), taskFieldInfo_1);
|
||||||
|
assertEquals(ServiceExitCode.ENTITY_ALREADY_EXIST, situation_1.getExitCode());
|
||||||
|
|
||||||
|
//Situation 2: Task with that name exists in another taskgroup
|
||||||
|
TaskFieldInfo taskFieldInfo_2 = new TaskFieldInfo(entityManager.find(Task.class, 1L).getTaskName(), 0, null, null);
|
||||||
|
ServiceResult<Task> result_2 = taskService.createTask(entityManager.find(Taskgroup.class, 1L), taskFieldInfo_2);
|
||||||
|
assertEquals(ServiceExitCode.OK, result_2.getExitCode());
|
||||||
|
assertThat(entityManager.find(Task.class, result_2.getResult().getTaskID())).isNotNull();
|
||||||
|
|
||||||
|
//Situation 3: Normal, everything fine
|
||||||
|
TaskFieldInfo taskFieldInfo_3 = new TaskFieldInfo("Situation 3", 0, null, null);
|
||||||
|
ServiceResult<Task> result_3 = taskService.createTask(entityManager.find(Taskgroup.class, 1L), taskFieldInfo_3);
|
||||||
|
assertEquals(ServiceExitCode.OK, result_3.getExitCode());
|
||||||
|
assertThat(entityManager.find(Task.class, result_3.getResult().getTaskID())).isNotNull();
|
||||||
|
|
||||||
|
//Robustness - Test for invalid dates
|
||||||
|
//Situation 4: Deadline, no start
|
||||||
|
TaskFieldInfo taskFieldInfo_4 = new TaskFieldInfo("Situation 4", 0, null, LocalDate.now());
|
||||||
|
ServiceResult<Task> result_4 = taskService.createTask(entityManager.find(Taskgroup.class, 1L), taskFieldInfo_4);
|
||||||
|
assertEquals(ServiceExitCode.OK, result_4.getExitCode());
|
||||||
|
assertThat(entityManager.find(Task.class, result_4.getResult().getTaskID())).isNotNull();
|
||||||
|
|
||||||
|
//Situation 5: Start but no deadline
|
||||||
|
TaskFieldInfo taskFieldInfo_5 = new TaskFieldInfo("Situation 5", 0, LocalDate.now(),null);
|
||||||
|
ServiceResult<Task> result_5 = taskService.createTask(entityManager.find(Taskgroup.class, 1L), taskFieldInfo_5);
|
||||||
|
assertEquals(ServiceExitCode.OK, result_5.getExitCode());
|
||||||
|
assertThat(entityManager.find(Task.class, result_5.getResult().getTaskID())).isNotNull();
|
||||||
|
|
||||||
|
//Situation 6: Deadline before start (invalid)
|
||||||
|
TaskFieldInfo taskFieldInfo_6 = new TaskFieldInfo("Situation 6", 0, LocalDate.now(),LocalDate.of(2010, 3, 20));
|
||||||
|
ServiceResult<Task> result_6= taskService.createTask(entityManager.find(Taskgroup.class, 1L), taskFieldInfo_6);
|
||||||
|
assertEquals(ServiceExitCode.INVALID_PARAMETER, result_6.getExitCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SqlGroup({
|
||||||
|
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
|
||||||
|
@Sql("classpath:taskRepositoryEntries.sql")
|
||||||
|
})
|
||||||
|
void getTaskPermissions() {
|
||||||
|
//Situation 1: correct task and username
|
||||||
|
PermissionResult<Task> permissionResult_1 = taskService.getTaskPermissions(1L, username);
|
||||||
|
assertEquals(ServiceExitCode.OK, permissionResult_1.getExitCode());
|
||||||
|
assertTrue(permissionResult_1.isHasPermissions());
|
||||||
|
assertEquals(entityManager.find(Task.class, 1L), permissionResult_1.getResult());
|
||||||
|
|
||||||
|
//Situation 2: invalid taskgroup
|
||||||
|
PermissionResult<Task> permissionResult_2 = taskService.getTaskPermissions(200L, username);
|
||||||
|
assertEquals(ServiceExitCode.MISSING_ENTITY, permissionResult_2.getExitCode());
|
||||||
|
assertFalse(permissionResult_2.isHasPermissions());
|
||||||
|
assertThat(permissionResult_2.getResult()).isNull();
|
||||||
|
|
||||||
|
//Situation 3: invalid user
|
||||||
|
PermissionResult<Task> permissionResult_3 = taskService.getTaskPermissions(1L, username2);
|
||||||
|
assertEquals(ServiceExitCode.OK, permissionResult_3.getExitCode());
|
||||||
|
assertFalse(permissionResult_2.isHasPermissions());
|
||||||
|
assertEquals(entityManager.find(Task.class, 1L), permissionResult_3.getResult());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SqlGroup({
|
||||||
|
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
|
||||||
|
@Sql("classpath:taskRepositoryEntries.sql")
|
||||||
|
})
|
||||||
|
void editTask() {
|
||||||
|
//Situation 1: Nothing is updated
|
||||||
|
Task task_1 = entityManager.find(Task.class, 1L);
|
||||||
|
TaskFieldInfo taskFieldInfo_1 = new TaskFieldInfo(entityManager.find(Task.class, 1L).getTaskName(), 0, null, null);
|
||||||
|
ServiceResult<Task> result_1 = taskService.editTask(entityManager.find(Task.class, 1L), taskFieldInfo_1);
|
||||||
|
assertEquals(ServiceExitCode.OK, result_1.getExitCode());
|
||||||
|
assertEquals(task_1, result_1.getResult());
|
||||||
|
|
||||||
|
//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);
|
||||||
|
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);
|
||||||
|
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);
|
||||||
|
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);
|
||||||
|
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);
|
||||||
|
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);
|
||||||
|
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);
|
||||||
|
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);
|
||||||
|
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);
|
||||||
|
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);
|
||||||
|
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);
|
||||||
|
assertEquals(ServiceExitCode.OK, result_10.getExitCode());
|
||||||
|
assertEquals(task_10, result_10.getResult());
|
||||||
|
|
||||||
|
//Situation 11 Deadline = null
|
||||||
|
Task task_11 = entityManager.find(Task.class, 5L);
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
@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();
|
||||||
|
}
|
||||||
|
}
|
@ -10,3 +10,4 @@ demo.webapp.jwtSecret=demoWebappSecretKey
|
|||||||
demo.webapp.jwtExpirationMS=86400000
|
demo.webapp.jwtExpirationMS=86400000
|
||||||
spring.sql.init.mode=always
|
spring.sql.init.mode=always
|
||||||
spring.jpa.hibernate.ddl-auto=create-drop
|
spring.jpa.hibernate.ddl-auto=create-drop
|
||||||
|
spring.jpa.show-sql=true
|
@ -16,3 +16,4 @@ INSERT INTO tasks (taskid, deadline, eta, start_date, task_name, taskgroup_id, f
|
|||||||
|
|
||||||
INSERT INTO tasks (taskid, deadline, eta, start_date, task_name, taskgroup_id, finished, work_time) VALUES (13, NULL, 0, '2022-03-20', 'Task 6', 2, true, 0);
|
INSERT INTO tasks (taskid, deadline, eta, start_date, task_name, taskgroup_id, finished, work_time) VALUES (13, NULL, 0, '2022-03-20', 'Task 6', 2, true, 0);
|
||||||
INSERT INTO tasks (taskid, deadline, eta, start_date, task_name, taskgroup_id, finished, work_time) VALUES (14, '2044-03-20', 0, '2022-03-20', 'Task 6', 2, true, 0);
|
INSERT INTO tasks (taskid, deadline, eta, start_date, task_name, taskgroup_id, finished, work_time) VALUES (14, '2044-03-20', 0, '2022-03-20', 'Task 6', 2, true, 0);
|
||||||
|
INSERT INTO tasks (taskid, deadline, eta, start_date, task_name, taskgroup_id, finished, work_time) VALUES (15, NULL, 0, NULL, 'Task 15', 2, false, 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user