TSK-1911: Fix details of TaskHistoryEvents

This commit is contained in:
ryzheboka 2022-07-05 17:40:03 +02:00 committed by Elena Mokeeva
parent d83678ac54
commit ba5e582beb
7 changed files with 219 additions and 137 deletions

View File

@ -2,3 +2,4 @@ INSERT INTO OBJECT_REFERENCE VALUES ('ID1', 'TKI:0000000000000000000000000000000
INSERT INTO OBJECT_REFERENCE VALUES ('ID2', 'TKI:000000000000000000000000000000000000', 'Company2', 'System2', 'Instance2', 'Type2', 'Value2');
INSERT INTO OBJECT_REFERENCE VALUES ('ID3', 'TKI:000000000000000000000000000000000001', 'Company3', 'System3', 'Instance3', 'Type3', 'Value2');
INSERT INTO OBJECT_REFERENCE VALUES ('ID4', 'TKI:000000000000000000000000000000000002', 'Company1', 'System4', 'Instance4', 'Type2', 'Value2');
INSERT INTO OBJECT_REFERENCE VALUES ('ID5', 'TKI:000000000000000000000000000000000053', 'SomeCompany', 'SomeSystem', 'SomeInstance', 'SomeType', 'SomeValue');

View File

@ -1,3 +1,4 @@
INSERT INTO OBJECT_REFERENCE VALUES ('1', 'TaskId1', 'Company1', 'System1', 'Instance1', 'Type1', 'Value1');
INSERT INTO OBJECT_REFERENCE VALUES ('2', 'TaskId2', 'Company2', 'System2', 'Instance2', 'Type2', 'Value2');
INSERT INTO OBJECT_REFERENCE VALUES ('3', 'TaskId3', 'Company3', 'System3', 'Instance3', 'Type3', 'Value3');
INSERT INTO OBJECT_REFERENCE VALUES ('ID5', 'TKI:000000000000000000000000000000000053', 'SomeCompany', 'SomeSystem', 'SomeInstance', 'SomeType', 'SomeValue');

View File

@ -5,11 +5,15 @@ import static org.assertj.core.api.Assertions.assertThat;
import acceptance.AbstractAccTest;
import java.time.Instant;
import java.util.List;
import java.util.stream.Stream;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.TestFactory;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.function.ThrowingConsumer;
import pro.taskana.common.internal.util.Triplet;
import pro.taskana.common.test.security.JaasExtension;
import pro.taskana.common.test.security.WithAccessId;
import pro.taskana.simplehistory.impl.SimpleHistoryServiceImpl;
@ -28,66 +32,84 @@ class CreateHistoryEventOnTaskCancelClaimAccTest extends AbstractAccTest {
private final SimpleHistoryServiceImpl historyService = getHistoryService();
@WithAccessId(user = "admin")
@Test
void should_CreateCancelClaimedHistoryEvent_When_TaskIsCancelClaimed() throws Exception {
@TestFactory
Stream<DynamicTest> should_CreateCancelClaimedHistoryEvent_When_TaskIsCancelClaimed() {
final String taskId = "TKI:000000000000000000000000000000000043";
Task task = taskService.getTask(taskId);
final Instant oldModified = task.getModified();
final Instant oldClaimed = task.getClaimed();
List<Triplet<String, String, String>> list =
List.of(
Triplet.of(
"With Attachment and secondary Object Reference",
"TKI:000000000000000000000000000000000002",
"user-1-1"),
Triplet.of(
"Without Attachment and secondary Object References",
"TKI:000000000000000000000000000000000043",
"user-b-1"));
ThrowingConsumer<Triplet<String, String, String>> test =
t -> {
String taskId = t.getMiddle();
Task task = taskService.getTask(taskId);
final Instant oldModified = task.getModified();
final Instant oldClaimed = task.getClaimed();
TaskHistoryQueryMapper taskHistoryQueryMapper = getHistoryQueryMapper();
List<TaskHistoryEvent> events =
taskHistoryQueryMapper.queryHistoryEvents(
(TaskHistoryQueryImpl) historyService.createTaskHistoryQuery().taskIdIn(taskId));
TaskHistoryQueryMapper taskHistoryQueryMapper = getHistoryQueryMapper();
List<TaskHistoryEvent> events =
taskHistoryQueryMapper.queryHistoryEvents(
(TaskHistoryQueryImpl) historyService.createTaskHistoryQuery().taskIdIn(taskId));
assertThat(events).isEmpty();
assertThat(events).isEmpty();
assertThat(task.getState()).isEqualTo(TaskState.CLAIMED);
task = taskService.forceCancelClaim(taskId);
assertThat(task.getState()).isEqualTo(TaskState.READY);
assertThat(task.getState()).isEqualTo(TaskState.CLAIMED);
task = taskService.forceCancelClaim(taskId);
assertThat(task.getState()).isEqualTo(TaskState.READY);
events =
taskHistoryQueryMapper.queryHistoryEvents(
(TaskHistoryQueryImpl) historyService.createTaskHistoryQuery().taskIdIn(taskId));
events =
taskHistoryQueryMapper.queryHistoryEvents(
(TaskHistoryQueryImpl) historyService.createTaskHistoryQuery().taskIdIn(taskId));
assertThat(events).hasSize(1);
assertThat(events).hasSize(1);
TaskHistoryEvent event = events.get(0);
TaskHistoryEvent event = events.get(0);
assertThat(event.getEventType()).isEqualTo(TaskHistoryEventType.CLAIM_CANCELLED.getName());
assertThat(event.getEventType())
.isEqualTo(TaskHistoryEventType.CLAIM_CANCELLED.getName());
event = historyService.getTaskHistoryEvent(event.getId());
event = historyService.getTaskHistoryEvent(event.getId());
assertThat(event.getDetails()).isNotNull();
assertThat(event.getDetails()).isNotNull();
JSONArray changes = new JSONObject(event.getDetails()).getJSONArray("changes");
JSONArray changes = new JSONObject(event.getDetails()).getJSONArray("changes");
String oldOwner = t.getRight();
JSONObject expectedClaimed =
new JSONObject()
.put("newValue", "")
.put("fieldName", "claimed")
.put("oldValue", oldClaimed.toString());
JSONObject expectedModified =
new JSONObject()
.put("newValue", task.getModified().toString())
.put("fieldName", "modified")
.put("oldValue", oldModified.toString());
JSONObject expectedState =
new JSONObject()
.put("newValue", "READY")
.put("fieldName", "state")
.put("oldValue", "CLAIMED");
JSONObject expectedOwner =
new JSONObject()
.put("newValue", "")
.put("fieldName", "owner")
.put("oldValue", oldOwner);
JSONObject expectedClaimed =
new JSONObject()
.put("newValue", "")
.put("fieldName", "claimed")
.put("oldValue", oldClaimed.toString());
JSONObject expectedModified =
new JSONObject()
.put("newValue", task.getModified().toString())
.put("fieldName", "modified")
.put("oldValue", oldModified.toString());
JSONObject expectedState =
new JSONObject()
.put("newValue", "READY")
.put("fieldName", "state")
.put("oldValue", "CLAIMED");
JSONObject expectedOwner =
new JSONObject().put("newValue", "").put("fieldName", "owner").put("oldValue", "user-b-1");
JSONArray expectedChanges =
new JSONArray()
.put(expectedClaimed)
.put(expectedModified)
.put(expectedState)
.put(expectedOwner);
JSONArray expectedChanges =
new JSONArray()
.put(expectedClaimed)
.put(expectedModified)
.put(expectedState)
.put(expectedOwner);
assertThat(changes.similar(expectedChanges)).isTrue();
assertThat(changes.similar(expectedChanges)).isTrue();
};
return DynamicTest.stream(list.iterator(), Triplet::getLeft, test);
}
}

View File

@ -5,11 +5,15 @@ import static org.assertj.core.api.Assertions.assertThat;
import acceptance.AbstractAccTest;
import java.time.Instant;
import java.util.List;
import java.util.stream.Stream;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.TestFactory;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.function.ThrowingConsumer;
import pro.taskana.common.internal.util.Pair;
import pro.taskana.common.test.security.JaasExtension;
import pro.taskana.common.test.security.WithAccessId;
import pro.taskana.simplehistory.impl.SimpleHistoryServiceImpl;
@ -28,66 +32,86 @@ class CreateHistoryEventOnTaskClaimAccTest extends AbstractAccTest {
private final SimpleHistoryServiceImpl historyService = getHistoryService();
@WithAccessId(user = "admin")
@Test
void should_CreateClaimedHistoryEvent_When_TaskIsClaimed() throws Exception {
final String taskId = "TKI:000000000000000000000000000000000047";
final Instant oldModified = taskService.getTask(taskId).getModified();
@TestFactory
Stream<DynamicTest> should_CreateClaimedHistoryEvent_When_TaskIsClaimed() {
List<Pair<String, String>> list =
List.of(
Pair.of(
"With Attachment and secondary Object Reference",
"TKI:000000000000000000000000000000000053"),
Pair.of(
"Without Attachment and secondary Object References",
"TKI:000000000000000000000000000000000047"));
TaskHistoryQueryMapper taskHistoryQueryMapper = getHistoryQueryMapper();
ThrowingConsumer<Pair<String, String>> test =
pair -> {
final Instant oldModified = taskService.getTask(pair.getRight()).getModified();
List<TaskHistoryEvent> events =
taskHistoryQueryMapper.queryHistoryEvents(
(TaskHistoryQueryImpl) historyService.createTaskHistoryQuery().taskIdIn(taskId));
TaskHistoryQueryMapper taskHistoryQueryMapper = getHistoryQueryMapper();
assertThat(events).isEmpty();
List<TaskHistoryEvent> events =
taskHistoryQueryMapper.queryHistoryEvents(
(TaskHistoryQueryImpl)
historyService.createTaskHistoryQuery().taskIdIn(pair.getRight()));
assertThat(taskService.getTask(taskId).getState()).isEqualTo(TaskState.READY);
Task task = taskService.claim(taskId);
assertThat(events).isEmpty();
assertThat(task.getState()).isEqualTo(TaskState.CLAIMED);
assertThat(taskService.getTask(pair.getRight()).getState()).isEqualTo(TaskState.READY);
Task task = taskService.claim(pair.getRight());
events =
taskHistoryQueryMapper.queryHistoryEvents(
(TaskHistoryQueryImpl) historyService.createTaskHistoryQuery().taskIdIn(taskId));
assertThat(task.getState()).isEqualTo(TaskState.CLAIMED);
TaskHistoryEvent event = events.get(0);
events =
taskHistoryQueryMapper.queryHistoryEvents(
(TaskHistoryQueryImpl)
historyService.createTaskHistoryQuery().taskIdIn(pair.getRight()));
assertThat(event.getEventType()).isEqualTo(TaskHistoryEventType.CLAIMED.getName());
TaskHistoryEvent event = events.get(0);
event = historyService.getTaskHistoryEvent(event.getId());
assertThat(event.getEventType()).isEqualTo(TaskHistoryEventType.CLAIMED.getName());
assertThat(event.getDetails()).isNotNull();
event = historyService.getTaskHistoryEvent(event.getId());
JSONArray changes = new JSONObject(event.getDetails()).getJSONArray("changes");
assertThat(event.getDetails()).isNotNull();
JSONObject expectedClaimed =
new JSONObject()
.put("newValue", task.getModified().toString())
.put("fieldName", "claimed")
.put("oldValue", "");
JSONObject expectedModified =
new JSONObject()
.put("newValue", task.getModified().toString())
.put("fieldName", "modified")
.put("oldValue", oldModified.toString());
JSONObject expectedState =
new JSONObject()
.put("newValue", "CLAIMED")
.put("fieldName", "state")
.put("oldValue", "READY");
JSONObject expectedOwner =
new JSONObject().put("newValue", "admin").put("fieldName", "owner").put("oldValue", "");
JSONObject expectedIsRead =
new JSONObject().put("newValue", true).put("fieldName", "isRead").put("oldValue", false);
JSONArray changes = new JSONObject(event.getDetails()).getJSONArray("changes");
JSONArray expectedChanges =
new JSONArray()
.put(expectedClaimed)
.put(expectedModified)
.put(expectedState)
.put(expectedOwner)
.put(expectedIsRead);
JSONObject expectedClaimed =
new JSONObject()
.put("newValue", task.getModified().toString())
.put("fieldName", "claimed")
.put("oldValue", "");
JSONObject expectedModified =
new JSONObject()
.put("newValue", task.getModified().toString())
.put("fieldName", "modified")
.put("oldValue", oldModified.toString());
JSONObject expectedState =
new JSONObject()
.put("newValue", "CLAIMED")
.put("fieldName", "state")
.put("oldValue", "READY");
JSONObject expectedOwner =
new JSONObject()
.put("newValue", "admin")
.put("fieldName", "owner")
.put("oldValue", "");
JSONObject expectedIsRead =
new JSONObject()
.put("newValue", true)
.put("fieldName", "isRead")
.put("oldValue", false);
assertThat(changes.similar(expectedChanges)).isTrue();
JSONArray expectedChanges =
new JSONArray()
.put(expectedClaimed)
.put(expectedModified)
.put(expectedState)
.put(expectedOwner)
.put(expectedIsRead);
assertThat(changes.similar(expectedChanges)).isTrue();
};
return DynamicTest.stream(list.iterator(), Pair::getLeft, test);
}
}

View File

@ -4,7 +4,9 @@ import static org.assertj.core.api.Assertions.assertThat;
import static pro.taskana.common.internal.util.CheckedConsumer.wrap;
import acceptance.AbstractAccTest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.stream.Stream;
import org.json.JSONArray;
@ -14,6 +16,7 @@ import org.junit.jupiter.api.TestFactory;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.function.ThrowingConsumer;
import pro.taskana.common.internal.util.Quadruple;
import pro.taskana.common.internal.util.Triplet;
import pro.taskana.common.test.security.JaasExtension;
import pro.taskana.common.test.security.WithAccessId;
@ -35,23 +38,39 @@ class CreateHistoryEventOnTaskTransferAccTest extends AbstractAccTest {
@WithAccessId(user = "admin")
@TestFactory
Stream<DynamicTest> should_CreateTransferredHistoryEvent_When_TaskIsTransferred() {
List<Triplet<String, String, Consumer<String>>> testCases =
List<Quadruple<String, String, String, Consumer<String>>> testCases =
List.of(
Triplet.of(
"Using WorkbasketId",
/*
The workbasketId of the source Workbasket is parametrized. Putting the tested Tasks
into the same Workbasket would result in changes to the test data. This would require
changing tests that already use the tested Tasks. That's why workbasketId is
parametrized.
*/
Quadruple.of(
"Using WorkbasketId; Task doesn't have an Attachment"
+ " or any secondary Object References",
"TKI:000000000000000000000000000000000003",
"WBI:100000000000000000000000000000000001",
wrap(
(String taskId) ->
taskService.transfer(taskId, "WBI:100000000000000000000000000000000006"))),
Triplet.of(
Quadruple.of(
"Using WorkbasketId; Task has Attachment and secondary Object Reference",
"TKI:000000000000000000000000000000000053",
"WBI:100000000000000000000000000000000015",
wrap(
(String taskId) ->
taskService.transfer(taskId, "WBI:100000000000000000000000000000000006"))),
Quadruple.of(
"Using WorkbasketKey and Domain",
"TKI:000000000000000000000000000000000004",
"WBI:100000000000000000000000000000000001",
wrap((String taskId) -> taskService.transfer(taskId, "USER-1-1", "DOMAIN_A"))));
ThrowingConsumer<Triplet<String, String, Consumer<String>>> test =
t -> {
String taskId = t.getMiddle();
Consumer<String> transferMethod = t.getRight();
ThrowingConsumer<Quadruple<String, String, String, Consumer<String>>> test =
q -> {
String taskId = q.getSecond();
Consumer<String> transferMethod = q.getFourth();
TaskHistoryQueryMapper taskHistoryQueryMapper = getHistoryQueryMapper();
@ -68,42 +87,63 @@ class CreateHistoryEventOnTaskTransferAccTest extends AbstractAccTest {
(TaskHistoryQueryImpl) historyService.createTaskHistoryQuery().taskIdIn(taskId));
assertThat(events).hasSize(1);
String sourceWorkbasketId = q.getThird();
assertTransferHistoryEvent(
events.get(0).getId(),
"WBI:100000000000000000000000000000000001",
sourceWorkbasketId,
"WBI:100000000000000000000000000000000006",
"admin");
};
return DynamicTest.stream(testCases.iterator(), Triplet::getLeft, test);
return DynamicTest.stream(testCases.iterator(), Quadruple::getFirst, test);
}
@WithAccessId(user = "admin")
@TestFactory
Stream<DynamicTest> should_CreateTransferredHistoryEvents_When_TaskBulkTransfer() {
List<Triplet<String, List<String>, Consumer<List<String>>>> testCases =
List<Triplet<String, Map<String, String>, Consumer<List<String>>>> testCases =
List.of(
/*
The workbasketId of the source Workbasket is parametrized. Putting the tested Tasks
into the same Workbasket would result in changes to the test data. This would require
changing tests that already use the tested Tasks. That's why workbasketId is
parametrized.
*/
Triplet.of(
"Using WorkbasketId",
List.of(
"TKI:000000000000000000000000000000000021",
"TKI:000000000000000000000000000000000022"),
Map.ofEntries(
Map.entry(
"TKI:000000000000000000000000000000000021",
"WBI:100000000000000000000000000000000001"),
Map.entry(
"TKI:000000000000000000000000000000000022",
"WBI:100000000000000000000000000000000001"),
Map.entry(
"TKI:000000000000000000000000000000000002",
"WBI:100000000000000000000000000000000006")),
wrap(
(List<String> taskIds) ->
taskService.transferTasks(
"WBI:100000000000000000000000000000000007", taskIds))),
Triplet.of(
"Using WorkbasketKey and Domain",
List.of(
"TKI:000000000000000000000000000000000023",
"TKI:000000000000000000000000000000000024"),
Map.ofEntries(
Map.entry(
"TKI:000000000000000000000000000000000023",
"WBI:100000000000000000000000000000000001"),
Map.entry(
"TKI:000000000000000000000000000000000024",
"WBI:100000000000000000000000000000000001"),
Map.entry(
"TKI:000000000000000000000000000000000055",
"WBI:100000000000000000000000000000000015")),
wrap(
(List<String> taskIds) ->
taskService.transferTasks("USER-1-2", "DOMAIN_A", taskIds))));
ThrowingConsumer<Triplet<String, List<String>, Consumer<List<String>>>> test =
ThrowingConsumer<Triplet<String, Map<String, String>, Consumer<List<String>>>> test =
t -> {
List<String> taskIds = t.getMiddle();
Map<String, String> taskIds = t.getMiddle();
Consumer<List<String>> transferMethod = t.getRight();
TaskHistoryQueryMapper taskHistoryQueryMapper = getHistoryQueryMapper();
@ -113,27 +153,27 @@ class CreateHistoryEventOnTaskTransferAccTest extends AbstractAccTest {
(TaskHistoryQueryImpl)
historyService
.createTaskHistoryQuery()
.taskIdIn(taskIds.toArray(new String[0])));
.taskIdIn(taskIds.keySet().toArray(new String[0])));
assertThat(events).isEmpty();
transferMethod.accept(taskIds);
transferMethod.accept(new ArrayList<>(taskIds.keySet()));
events =
taskHistoryQueryMapper.queryHistoryEvents(
(TaskHistoryQueryImpl)
historyService
.createTaskHistoryQuery()
.taskIdIn(taskIds.toArray(new String[0])));
.taskIdIn(taskIds.keySet().toArray(new String[0])));
assertThat(events)
.extracting(TaskHistoryEvent::getTaskId)
.containsExactlyInAnyOrderElementsOf(taskIds);
.containsExactlyInAnyOrderElementsOf(taskIds.keySet());
for (TaskHistoryEvent event : events) {
assertTransferHistoryEvent(
event.getId(),
"WBI:100000000000000000000000000000000001",
taskIds.get(event.getTaskId()),
"WBI:100000000000000000000000000000000007",
"admin");
}

View File

@ -18,10 +18,10 @@ class QueryObjectReferenceAccTest extends AbstractAccTest {
void testQueryObjectReferenceValuesForColumnName() {
TaskQuery taskQuery = taskanaEngine.getTaskService().createTaskQuery();
List<String> columnValues = taskQuery.createObjectReferenceQuery().listValues(COMPANY, null);
assertThat(columnValues).hasSize(3);
assertThat(columnValues).hasSize(4);
columnValues = taskQuery.createObjectReferenceQuery().listValues(SYSTEM, null);
assertThat(columnValues).hasSize(3);
assertThat(columnValues).hasSize(4);
columnValues =
taskQuery.createObjectReferenceQuery().systemIn("System1").listValues(SYSTEM, null);

View File

@ -29,13 +29,13 @@ class QueryObjectReferencesWithPaginationAccTest extends AbstractAccTest {
void testGetFirstPageOfObjectRefQueryWithOffset() {
List<ObjectReference> results = objRefQuery.list(0, 5);
assertThat(results).hasSize(3);
assertThat(results).hasSize(4);
}
@Test
void testGetSecondPageOfObjectRefQueryWithOffset() {
List<ObjectReference> results = objRefQuery.list(2, 5);
assertThat(results).hasSize(1);
assertThat(results).hasSize(2);
}
@Test
@ -59,25 +59,19 @@ class QueryObjectReferencesWithPaginationAccTest extends AbstractAccTest {
int pageNumber = 1;
int pageSize = 10;
List<ObjectReference> results = objRefQuery.listPage(pageNumber, pageSize);
assertThat(results).hasSize(3);
assertThat(results).hasSize(4);
// Getting full page
pageNumber = 2;
pageSize = 2;
results = objRefQuery.listPage(pageNumber, pageSize);
assertThat(results).hasSize(1);
assertThat(results).hasSize(2);
// Getting last results on 1 big page
pageNumber = 1;
pageSize = 100;
results = objRefQuery.listPage(pageNumber, pageSize);
assertThat(results).hasSize(3);
// Getting last results on multiple pages
pageNumber = 2;
pageSize = 2;
results = objRefQuery.listPage(pageNumber, pageSize);
assertThat(results).hasSize(1);
assertThat(results).hasSize(4);
}
@Test
@ -98,12 +92,12 @@ class QueryObjectReferencesWithPaginationAccTest extends AbstractAccTest {
pageNumber = -1;
pageSize = 10;
results = objRefQuery.listPage(pageNumber, pageSize);
assertThat(results).hasSize(3);
assertThat(results).hasSize(4);
}
@Test
void testCountOfClassificationsQuery() {
long count = objRefQuery.count();
assertThat(count).isEqualTo(3L);
assertThat(count).isEqualTo(4L);
}
}