TSK-1333: Review findings

This commit is contained in:
Joerg Heffner 2020-07-23 14:39:29 +02:00 committed by gitgoodjhe
parent b7237021e2
commit 901991e90b
4 changed files with 56 additions and 20 deletions

View File

@ -12,8 +12,6 @@ import org.junit.jupiter.api.extension.ExtendWith;
import pro.taskana.simplehistory.impl.HistoryEventImpl; import pro.taskana.simplehistory.impl.HistoryEventImpl;
import pro.taskana.simplehistory.impl.SimpleHistoryServiceImpl; import pro.taskana.simplehistory.impl.SimpleHistoryServiceImpl;
import pro.taskana.task.api.TaskService; import pro.taskana.task.api.TaskService;
import pro.taskana.task.api.TaskState;
import pro.taskana.task.api.models.Task;
@ExtendWith(JaasExtension.class) @ExtendWith(JaasExtension.class)
class CreateHistoryEventOnTaskCancellationAccTest extends AbstractAccTest { class CreateHistoryEventOnTaskCancellationAccTest extends AbstractAccTest {
@ -23,7 +21,7 @@ class CreateHistoryEventOnTaskCancellationAccTest extends AbstractAccTest {
@Test @Test
@WithAccessId(user = "admin") @WithAccessId(user = "admin")
void should_CreateCancelledHistoryEvent_When_TaskIsCancelled() throws Exception { void should_CreateCancelledHistoryEvent_When_CancelTaskInStateClaimed() throws Exception {
final String taskId = "TKI:000000000000000000000000000000000001"; final String taskId = "TKI:000000000000000000000000000000000001";
@ -31,15 +29,35 @@ class CreateHistoryEventOnTaskCancellationAccTest extends AbstractAccTest {
assertThat(listEvents).isEmpty(); assertThat(listEvents).isEmpty();
assertThat(taskService.getTask(taskId).getState()).isEqualTo(TaskState.CLAIMED); taskService.cancelTask(taskId);
Task task = taskService.cancelTask(taskId);
assertThat(task.getState()).isEqualTo(TaskState.CANCELLED);
listEvents = historyService.createHistoryQuery().taskIdIn(taskId).list(); listEvents = historyService.createHistoryQuery().taskIdIn(taskId).list();
assertThat(listEvents).hasSize(1); assertThat(listEvents).hasSize(1);
assertThat(historyService.getHistoryEvent(listEvents.get(0).getId()).getEventType())
.isEqualTo("TASK_CANCELLED"); String eventType = historyService.getHistoryEvent(listEvents.get(0).getId()).getEventType();
assertThat(eventType).isEqualTo("TASK_CANCELLED");
}
@Test
@WithAccessId(user = "admin")
void should_CreateCancelledHistoryEvent_When_CancelTaskInStateReady() throws Exception {
final String taskId = "TKI:000000000000000000000000000000000003";
List<HistoryEventImpl> listEvents = historyService.createHistoryQuery().taskIdIn(taskId).list();
assertThat(listEvents).isEmpty();
taskService.cancelTask(taskId);
listEvents = historyService.createHistoryQuery().taskIdIn(taskId).list();
assertThat(listEvents).hasSize(1);
String eventType = historyService.getHistoryEvent(listEvents.get(0).getId()).getEventType();
assertThat(eventType).isEqualTo("TASK_CANCELLED");
} }
} }

View File

@ -12,8 +12,6 @@ import org.junit.jupiter.api.extension.ExtendWith;
import pro.taskana.simplehistory.impl.HistoryEventImpl; import pro.taskana.simplehistory.impl.HistoryEventImpl;
import pro.taskana.simplehistory.impl.SimpleHistoryServiceImpl; import pro.taskana.simplehistory.impl.SimpleHistoryServiceImpl;
import pro.taskana.task.api.TaskService; import pro.taskana.task.api.TaskService;
import pro.taskana.task.api.TaskState;
import pro.taskana.task.api.models.Task;
@ExtendWith(JaasExtension.class) @ExtendWith(JaasExtension.class)
class CreateHistoryEventOnTaskTerminationAccTest extends AbstractAccTest { class CreateHistoryEventOnTaskTerminationAccTest extends AbstractAccTest {
@ -23,7 +21,7 @@ class CreateHistoryEventOnTaskTerminationAccTest extends AbstractAccTest {
@Test @Test
@WithAccessId(user = "admin") @WithAccessId(user = "admin")
void should_CreateTerminatedHistoryEvent_When_TaskIsTerminated() throws Exception { void should_CreateTerminatedHistoryEvent_When_TerminatingTaskInStateClaimed() throws Exception {
final String taskId = "TKI:000000000000000000000000000000000001"; final String taskId = "TKI:000000000000000000000000000000000001";
@ -31,15 +29,35 @@ class CreateHistoryEventOnTaskTerminationAccTest extends AbstractAccTest {
assertThat(listEvents).isEmpty(); assertThat(listEvents).isEmpty();
assertThat(taskService.getTask(taskId).getState()).isEqualTo(TaskState.CLAIMED); taskService.terminateTask(taskId);
Task task = taskService.terminateTask(taskId);
assertThat(task.getState()).isEqualTo(TaskState.TERMINATED);
listEvents = historyService.createHistoryQuery().taskIdIn(taskId).list(); listEvents = historyService.createHistoryQuery().taskIdIn(taskId).list();
assertThat(listEvents).hasSize(1); assertThat(listEvents).hasSize(1);
assertThat(historyService.getHistoryEvent(listEvents.get(0).getId()).getEventType())
.isEqualTo("TASK_TERMINATED"); String eventType = historyService.getHistoryEvent(listEvents.get(0).getId()).getEventType();
assertThat(eventType).isEqualTo("TASK_TERMINATED");
}
@Test
@WithAccessId(user = "admin")
void should_CreateTerminatedHistoryEvent_When_TerminatingTaskInStateReady() throws Exception {
final String taskId = "TKI:000000000000000000000000000000000003";
List<HistoryEventImpl> listEvents = historyService.createHistoryQuery().taskIdIn(taskId).list();
assertThat(listEvents).isEmpty();
taskService.terminateTask(taskId);
listEvents = historyService.createHistoryQuery().taskIdIn(taskId).list();
assertThat(listEvents).hasSize(1);
String eventType = historyService.getHistoryEvent(listEvents.get(0).getId()).getEventType();
assertThat(eventType).isEqualTo("TASK_TERMINATED");
} }
} }

View File

@ -8,6 +8,6 @@ public class CancelledEvent extends TaskEvent {
public CancelledEvent(String id, Task task, String userId) { public CancelledEvent(String id, Task task, String userId) {
super(id, task, userId, null); super(id, task, userId, null);
eventType = "TASK_CANCELLED"; eventType = "TASK_CANCELLED";
created = task.getModified(); created = task.getCompleted();
} }
} }

View File

@ -8,6 +8,6 @@ public class TerminatedEvent extends TaskEvent {
public TerminatedEvent(String id, Task task, String userId) { public TerminatedEvent(String id, Task task, String userId) {
super(id, task, userId, null); super(id, task, userId, null);
eventType = "TASK_TERMINATED"; eventType = "TASK_TERMINATED";
created = task.getModified(); created = task.getCompleted();
} }
} }