test-failing #41

Merged
sebastian merged 5 commits from test-failing into tests 2023-11-11 10:25:48 +01:00
10 changed files with 349 additions and 97 deletions

View File

@ -4,8 +4,10 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<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="Resolve Merge-Conflict">
<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" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -84,7 +86,69 @@
<recent name="$PROJECT_DIR$/src/test/java/core/taskgroups" />
</key>
</component>
<component name="RunManager" selected="JUnit.TaskgroupServiceTest">
<component name="RunManager" selected="JUnit.TaskRepositoryTest">
<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">
<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="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" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="TaskServiceTest.deleteTask" 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="deleteTask" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="TaskgroupServiceTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="demo" />
<extension name="coverage">
@ -100,70 +164,6 @@
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="TaskgroupServiceTest.deleteTaskgroup" 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="deleteTaskgroup" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="TaskgroupServiceTest.deleteTaskgroupByUser" 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="deleteTaskgroupByUser" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="TaskgroupServiceTest.getTaskgroupByIDAndUsername" 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="getTaskgroupByIDAndUsername" />
<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">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="DemoApplication" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" nameIsGenerated="true">
<module name="demo" />
<option name="SPRING_BOOT_MAIN_CLASS" value="core.DemoApplication" />
@ -173,11 +173,11 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="JUnit.TaskRepositoryTest" />
<item itemvalue="JUnit.TaskgroupServiceTest" />
<item itemvalue="JUnit.TaskgroupServiceTest.getTaskgroupByIDAndUsername" />
<item itemvalue="JUnit.TaskgroupServiceTest.deleteTaskgroupByUser" />
<item itemvalue="JUnit.TaskgroupServiceTest.getTopTaskgroupsByUser" />
<item itemvalue="JUnit.TaskgroupServiceTest.deleteTaskgroup" />
<item itemvalue="JUnit.TaskServiceTest" />
<item itemvalue="JUnit.TaskServiceTest.deleteTask" />
<item itemvalue="JUnit.TaskServiceTest.createTask" />
</list>
</recent_temporary>
</component>
@ -449,15 +449,21 @@
<option name="project" value="LOCAL" />
<updated>1699646291964</updated>
</task>
<option name="localTasksCounter" value="30" />
<task id="LOCAL-00030" summary="Resolve Merge-Conflict">
<option name="closed" value="true" />
<created>1699693472182</created>
<option name="number" value="00030" />
<option name="presentableId" value="LOCAL-00030" />
<option name="project" value="LOCAL" />
<updated>1699693472182</updated>
</task>
<option name="localTasksCounter" value="31" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="Delete and clear Tasks (Frontend)" />
<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" />
@ -481,7 +487,9 @@
<MESSAGE value="Test TaskRepository" />
<MESSAGE value="Initialize Testing of Testservice" />
<MESSAGE value="Use @Sql instead of persit()" />
<option name="LAST_COMMIT_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" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>

View File

@ -14,6 +14,16 @@ public class TaskFieldInfo {
private LocalDate startDate;
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() {
return taskName;
}

View File

@ -12,7 +12,7 @@ import java.util.Set;
public class Task {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long taskID;
@ManyToOne
@ -113,19 +113,6 @@ public class Task {
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) {
this.taskID = taskID;
}
@ -150,4 +137,31 @@ public class Task {
public void increaseActiveTime(int 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 +
'}';
}
}

View File

@ -29,6 +29,7 @@ public class Taskgroup {
@JoinColumn(name = "parent_id")
private Taskgroup parent;
@OneToMany(mappedBy = "taskgroup", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private Set<Task> tasks;

View File

@ -5,5 +5,6 @@ public enum ServiceExitCode {
OK,
ENTITY_ALREADY_EXIST,
MISSING_ENTITY,
INVALID_OPERATION;
INVALID_OPERATION,
INVALID_PARAMETER;
}

View File

@ -11,6 +11,9 @@ import core.repositories.timemanager.TaskgroupRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.transaction.Transactional;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
@ -20,12 +23,17 @@ public class TaskService {
private final TaskRepository taskRepository;
private final TaskScheduleService taskScheduleService;
private final TaskgroupRepository taskgroupRepository;
@PersistenceContext
private EntityManager entityManager;
public TaskService(@Autowired TaskRepository taskRepository,
@Autowired TaskScheduleService taskScheduleService) {
@Autowired TaskScheduleService taskScheduleService,
TaskgroupRepository taskgroupRepository) {
this.taskRepository = taskRepository;
this.taskScheduleService = taskScheduleService;
this.taskgroupRepository = taskgroupRepository;
}
public ServiceResult<Task> createTask(Taskgroup taskgroup, TaskFieldInfo taskFieldInfo) {
@ -33,6 +41,11 @@ public class TaskService {
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());
taskgroup.getTasks().add(task);
@ -57,11 +70,19 @@ public class TaskService {
}
public ServiceResult<Task> editTask(Task task, TaskFieldInfo taskFieldInfo) {
if(!task.getTaskName().equals(taskFieldInfo.getTaskName()) && !existTaskByName(task.getTaskgroup().getTasks(), taskFieldInfo.getTaskName())) {
task.setTaskName(taskFieldInfo.getTaskName());
} else if(!task.getTaskName().equals(taskFieldInfo.getTaskName()) && existTaskByName(task.getTaskgroup().getTasks(), taskFieldInfo.getTaskName())) {
if(!task.getTaskName().equals(taskFieldInfo.getTaskName())) {
//taskname will be updated
if(existTaskByName(task.getTaskgroup().getTasks(), taskFieldInfo.getTaskName())) {
return new ServiceResult<>(ServiceExitCode.ENTITY_ALREADY_EXIST);
} else {
task.setTaskName(taskFieldInfo.getTaskName());
}
}
//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.setStartDate(taskFieldInfo.getStartDate());
@ -70,9 +91,13 @@ public class TaskService {
return new ServiceResult<>(task);
}
@Transactional
public void deleteTask(Task task) {
taskScheduleService.deleteScheduleByTask(task);
taskRepository.deleteByTaskID(task.getTaskID());
entityManager.flush();
entityManager.detach(task);
}
public void clearTasks(Taskgroup taskgroup) {

View File

@ -49,7 +49,7 @@ public class TaskRepositoryTest {
List<Task> tasks_user1_false = taskRepository.findAllByUser(testUser1.getUsername(), false);
List<Task> tasks_user1_true = taskRepository.findAllByUser(testUser1.getUsername(), true);
assertEquals(7, tasks_user1_true.size());
assertEquals(7, tasks_user1_false.size());
assertEquals(8, tasks_user1_false.size());
assertTrue(tasks_user1_false.contains(testEntityManager.find(Task.class, 1L)));
assertTrue(tasks_user1_false.contains(testEntityManager.find(Task.class, 3L)));
@ -149,7 +149,7 @@ public class TaskRepositoryTest {
List<Task> active = taskRepository.findAllActive(testuser1.getUsername(), referenceDate);
//1,3,5,11,12
assertEquals(5, active.size());
assertEquals(6, active.size());
assertTrue(active.contains(testEntityManager.find(Task.class, 1L)));
assertTrue(active.contains(testEntityManager.find(Task.class, 3L)));
assertTrue(active.contains(testEntityManager.find(Task.class, 5L)));

View File

@ -0,0 +1,191 @@
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
@Transactional
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")
})
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 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());
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);
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");
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);
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);
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);
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));
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);
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));
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);
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);
assertEquals(ServiceExitCode.OK, result_10.getExitCode());
assertEquals(task_10, result_10.getResult());
//Situation 11 Deadline = null
Task task_11 = entityManager.find(Task.class, 5L);
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);
assertEquals(ServiceExitCode.OK, result_11.getExitCode());
assertEquals(task_11, result_11.getResult());
}
@Test
@SqlGroup({
@Sql("classpath:taskgroupRepositoryTestEntries.sql"),
@Sql("classpath:taskRepositoryEntries.sql")
})
void deleteTask() {
for(long i=1; i<=15; i++) {
taskRepository.deleteByTaskID(entityManager.find(Task.class, i).getTaskID());
assertThat(entityManager.find(Task.class, i)).isNull();
}
}
}

View File

@ -10,3 +10,4 @@ demo.webapp.jwtSecret=demoWebappSecretKey
demo.webapp.jwtExpirationMS=86400000
spring.sql.init.mode=always
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true

View File

@ -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 (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);