use of org.activiti.cloud.starter.tests.services.audit.AuditProducerIT.ALL_REQUIRED_HEADERS in project activiti-cloud by Activiti.
the class ExclusiveGatewayAuditProducerIT method testProcessExecutionWithExclusiveGateway.
@Test
public void testProcessExecutionWithExclusiveGateway() {
// when
streamHandler.getAllReceivedEvents().clear();
ResponseEntity<CloudProcessInstance> processInstance = processInstanceRestTemplate.startProcess(new StartProcessPayloadBuilder().withProcessDefinitionKey(EXCLUSIVE_GATEWAY_PROCESS).withProcessDefinitionId(processDefinitionIds.get(EXCLUSIVE_GATEWAY_PROCESS)).withVariable("input", 0).build());
String processInstanceId = processInstance.getBody().getId();
String processDefinitionKey = processInstance.getBody().getProcessDefinitionKey();
// then
Collection<CloudVariableInstance> variableCollection = processInstanceRestTemplate.getVariables(processInstance).getBody().getContent();
assertThat(variableCollection).isNotEmpty().extracting(CloudVariableInstance::getName, CloudVariableInstance::getValue).contains(tuple("input", 0));
// then
CloudTask task = processInstanceRestTemplate.getTasks(processInstance).getBody().iterator().next();
String taskId = task.getId();
await().untilAsserted(() -> {
List<CloudRuntimeEvent<?, ?>> receivedEvents = streamHandler.getAllReceivedEvents();
assertThat(streamHandler.getReceivedHeaders()).containsKeys(ALL_REQUIRED_HEADERS);
assertThat(receivedEvents).extracting(CloudRuntimeEvent::getEventType, CloudRuntimeEvent::getProcessInstanceId, CloudRuntimeEvent::getEntityId).containsExactly(tuple(PROCESS_CREATED, processInstanceId, processInstanceId), tuple(VARIABLE_CREATED, processInstanceId, "input"), tuple(PROCESS_UPDATED, processInstanceId, processInstanceId), tuple(PROCESS_STARTED, processInstanceId, processInstanceId), tuple(ACTIVITY_STARTED, processInstanceId, "theStart"), tuple(ACTIVITY_COMPLETED, processInstanceId, "theStart"), tuple(SEQUENCE_FLOW_TAKEN, processInstanceId, "flow1"), tuple(ACTIVITY_STARTED, processInstanceId, "task1"), tuple(VARIABLE_CREATED, processInstanceId, "input"), tuple(TASK_CANDIDATE_USER_ADDED, null, "hruser"), tuple(TASK_CREATED, processInstanceId, taskId));
});
streamHandler.getAllReceivedEvents().clear();
// when
ResponseEntity<CloudTask> claimTask = taskRestTemplate.claim(task);
assertThat(claimTask).isNotNull();
assertThat(claimTask.getBody().getStatus()).isEqualTo(TaskStatus.ASSIGNED);
// then
await().untilAsserted(() -> {
List<CloudRuntimeEvent<?, ?>> receivedEvents = streamHandler.getAllReceivedEvents();
assertThat(streamHandler.getReceivedHeaders()).containsKeys(ALL_REQUIRED_HEADERS);
assertThat(receivedEvents).extracting(CloudRuntimeEvent::getEventType, CloudRuntimeEvent::getProcessInstanceId, CloudRuntimeEvent::getEntityId).contains(tuple(TASK_ASSIGNED, processInstanceId, taskId), tuple(TASK_UPDATED, processInstanceId, taskId));
});
streamHandler.getAllReceivedEvents().clear();
// when
CompleteTaskPayload completeTaskPayload = TaskPayloadBuilder.complete().withTaskId(task.getId()).withVariables(Collections.singletonMap("input", 1)).build();
ResponseEntity<CloudTask> completeTask = taskRestTemplate.complete(task, completeTaskPayload);
// then
assertThat(completeTask).isNotNull();
assertThat(completeTask.getBody().getStatus()).isEqualTo(TaskStatus.COMPLETED);
variableCollection = processInstanceRestTemplate.getVariables(processInstance).getBody().getContent();
assertThat(variableCollection).isNotEmpty().extracting(CloudVariableInstance::getName, CloudVariableInstance::getValue).contains(tuple("input", 1));
task = processInstanceRestTemplate.getTasks(processInstance).getBody().iterator().next();
String newTaskId = task.getId();
await().untilAsserted(() -> {
List<CloudRuntimeEvent<?, ?>> receivedEvents = streamHandler.getAllReceivedEvents();
assertThat(streamHandler.getReceivedHeaders()).containsKeys(ALL_REQUIRED_HEADERS);
assertThat(receivedEvents).extracting(CloudRuntimeEvent::getEventType, CloudRuntimeEvent::getProcessInstanceId, CloudRuntimeEvent::getEntityId).contains(tuple(VARIABLE_UPDATED, processInstanceId, "input"), tuple(VARIABLE_UPDATED, processInstanceId, "input"), tuple(TASK_COMPLETED, processInstanceId, taskId), tuple(ACTIVITY_COMPLETED, processInstanceId, "task1"), tuple(SEQUENCE_FLOW_TAKEN, processInstanceId, "flow2"), tuple(ACTIVITY_STARTED, processInstanceId, "exclusiveGateway"), tuple(ACTIVITY_COMPLETED, processInstanceId, "exclusiveGateway"), tuple(SEQUENCE_FLOW_TAKEN, processInstanceId, "flow3"), tuple(ACTIVITY_STARTED, processInstanceId, "task2"), tuple(VARIABLE_CREATED, processInstanceId, "input"), tuple(TASK_CANDIDATE_USER_ADDED, null, "hruser"), tuple(TASK_CREATED, processInstanceId, newTaskId));
assertThat(receivedEvents).filteredOn(event -> (event.getEventType().equals(ACTIVITY_STARTED) || event.getEventType().equals(ACTIVITY_COMPLETED)) && ((BPMNActivity) event.getEntity()).getActivityType().equals("exclusiveGateway")).extracting(CloudRuntimeEvent::getEventType, CloudRuntimeEvent::getProcessDefinitionKey, event -> ((BPMNActivity) event.getEntity()).getActivityType(), event -> ((BPMNActivity) event.getEntity()).getProcessInstanceId()).contains(tuple(ACTIVITY_STARTED, processDefinitionKey, "exclusiveGateway", processInstanceId), tuple(ACTIVITY_COMPLETED, processDefinitionKey, "exclusiveGateway", processInstanceId));
});
streamHandler.getAllReceivedEvents().clear();
// when
claimTask = taskRestTemplate.claim(task);
// then
assertThat(claimTask).isNotNull();
assertThat(claimTask.getBody().getStatus()).isEqualTo(TaskStatus.ASSIGNED);
completeTaskPayload = TaskPayloadBuilder.complete().withTaskId(task.getId()).withVariables(Collections.singletonMap("input", 2)).build();
completeTask = taskRestTemplate.complete(task, completeTaskPayload);
// then
assertThat(completeTask).isNotNull();
assertThat(completeTask.getBody().getStatus()).isEqualTo(TaskStatus.COMPLETED);
// then
await().untilAsserted(() -> {
List<CloudRuntimeEvent<?, ?>> receivedEvents = streamHandler.getAllReceivedEvents();
assertThat(streamHandler.getReceivedHeaders()).containsKeys(ALL_REQUIRED_HEADERS);
assertThat(receivedEvents).extracting(CloudRuntimeEvent::getEventType, CloudRuntimeEvent::getProcessInstanceId, CloudRuntimeEvent::getEntityId).contains(tuple(TASK_ASSIGNED, processInstanceId, newTaskId), tuple(TASK_UPDATED, processInstanceId, newTaskId), tuple(VARIABLE_UPDATED, processInstanceId, "input"), tuple(VARIABLE_UPDATED, processInstanceId, "input"), tuple(TASK_COMPLETED, processInstanceId, newTaskId), tuple(ACTIVITY_COMPLETED, processInstanceId, "task2"), tuple(SEQUENCE_FLOW_TAKEN, processInstanceId, "flow4"), tuple(ACTIVITY_STARTED, processInstanceId, "theEnd1"), tuple(ACTIVITY_COMPLETED, processInstanceId, "theEnd1"), tuple(PROCESS_COMPLETED, processInstanceId, processInstanceId));
assertThat(receivedEvents).filteredOn(event -> event.getEventType().equals(VARIABLE_UPDATED)).extracting(CloudRuntimeEvent::getProcessDefinitionKey, event -> ((VariableInstance) event.getEntity()).getProcessInstanceId(), event -> ((VariableInstance) event.getEntity()).isTaskVariable(), event -> ((VariableInstance) event.getEntity()).getName(), event -> ((VariableInstance) event.getEntity()).getValue()).contains(tuple(processDefinitionKey, processInstanceId, true, "input", 2), tuple(processDefinitionKey, processInstanceId, false, "input", 2));
});
}
use of org.activiti.cloud.starter.tests.services.audit.AuditProducerIT.ALL_REQUIRED_HEADERS in project activiti-cloud by Activiti.
the class SignalAuditProducerIT method shouldProduceEventsWhenIntermediateSignalIsReceived.
@Test
public void shouldProduceEventsWhenIntermediateSignalIsReceived() {
// given
ResponseEntity<CloudProcessInstance> startProcessEntity1 = processInstanceRestTemplate.startProcess(new StartProcessPayloadBuilder().withProcessDefinitionKey(SIGNAL_PROCESS).withName("processInstanceName1").withBusinessKey("businessKey1").withVariables(Collections.emptyMap()).build());
ResponseEntity<CloudProcessInstance> startProcessEntity2 = processInstanceRestTemplate.startProcess(new StartProcessPayloadBuilder().withProcessDefinitionKey(SIGNAL_PROCESS).withName("processInstanceName2").withBusinessKey("businessKey2").withVariables(Collections.emptyMap()).build());
CloudProcessDefinition processWithSignalStart = processDefinitionRestTemplate.getProcessDefinitions().getBody().getContent().stream().filter(cloudProcessDefinition -> cloudProcessDefinition.getKey().equals("processWithSignalStart1")).findAny().orElse(null);
assertThat(processWithSignalStart).isNotNull();
SignalPayload signalProcessInstancesCmd = ProcessPayloadBuilder.signal().withName("Test").withVariable("signalVar", "timeToGo").build();
// when
signalRestTemplate.signal(signalProcessInstancesCmd);
await("Broadcast Signals").untilAsserted(() -> {
assertThat(streamHandler.getReceivedHeaders()).containsKeys(RUNTIME_BUNDLE_INFO_HEADERS);
assertThat(streamHandler.getReceivedHeaders()).containsKeys(ALL_REQUIRED_HEADERS);
List<CloudRuntimeEvent<?, ?>> receivedEvents = streamHandler.getLatestReceivedEvents();
String startedBySignalProcessInstanceId = Optional.ofNullable(runtimeService.createProcessInstanceQuery().processDefinitionKey("processWithSignalStart1").singleResult().getId()).orElseThrow(() -> new NoSuchElementException("processWithSignalStart1"));
List<CloudBPMNSignalReceivedEvent> signalReceivedEvents = receivedEvents.stream().filter(CloudBPMNSignalReceivedEvent.class::isInstance).map(CloudBPMNSignalReceivedEvent.class::cast).collect(Collectors.toList());
assertThat(signalReceivedEvents).filteredOn(event -> SIGNAL_RECEIVED.name().equals(event.getEventType().name())).extracting(CloudRuntimeEvent::getEventType, CloudRuntimeEvent::getProcessDefinitionId, CloudRuntimeEvent::getProcessInstanceId, CloudRuntimeEvent::getProcessDefinitionKey, CloudRuntimeEvent::getProcessDefinitionVersion, event -> event.getEntity().getProcessDefinitionId(), event -> event.getEntity().getProcessInstanceId(), event -> event.getEntity().getElementId(), event -> event.getEntity().getSignalPayload().getName(), event -> event.getEntity().getSignalPayload().getVariables()).contains(tuple(SIGNAL_RECEIVED, processWithSignalStart.getId(), startedBySignalProcessInstanceId, processWithSignalStart.getKey(), processWithSignalStart.getVersion(), processWithSignalStart.getId(), startedBySignalProcessInstanceId, "theStart", "Test", Collections.singletonMap("signalVar", "timeToGo")), tuple(SIGNAL_RECEIVED, startProcessEntity1.getBody().getProcessDefinitionId(), startProcessEntity1.getBody().getId(), startProcessEntity1.getBody().getProcessDefinitionKey(), // version
1, startProcessEntity1.getBody().getProcessDefinitionId(), startProcessEntity1.getBody().getId(), "signalintermediatecatchevent1", "Test", Collections.singletonMap("signalVar", "timeToGo")), tuple(SIGNAL_RECEIVED, startProcessEntity2.getBody().getProcessDefinitionId(), startProcessEntity2.getBody().getId(), startProcessEntity2.getBody().getProcessDefinitionKey(), // version
1, startProcessEntity2.getBody().getProcessDefinitionId(), startProcessEntity2.getBody().getId(), "signalintermediatecatchevent1", "Test", Collections.singletonMap("signalVar", "timeToGo")));
runtimeService.deleteProcessInstance(startedBySignalProcessInstanceId, "clean up");
});
}
use of org.activiti.cloud.starter.tests.services.audit.AuditProducerIT.ALL_REQUIRED_HEADERS in project activiti-cloud by Activiti.
the class SignalAuditProducerIT method testProcessExecutionWithThrowSignal.
@Test
public void testProcessExecutionWithThrowSignal() {
// when
streamHandler.getAllReceivedEvents().clear();
ResponseEntity<CloudProcessInstance> processInstance = processInstanceRestTemplate.startProcess(new StartProcessPayloadBuilder().withProcessDefinitionKey("broadcastSignalEventProcess").withBusinessKey("businessKey").build());
String processInstanceId = processInstance.getBody().getId();
// then
await("Broadcast Signals").untilAsserted(() -> {
List<CloudRuntimeEvent<?, ?>> receivedEvents = streamHandler.getAllReceivedEvents();
String startedBySignalProcessInstanceId = receivedEvents.stream().filter(it -> PROCESS_CREATED.equals(it.getEventType()) && "processWithSignalStart1".equals(it.getProcessDefinitionKey())).map(CloudRuntimeEvent::getProcessInstanceId).findFirst().orElseThrow(() -> new NoSuchElementException("processWithSignalStart1"));
assertThat(streamHandler.getReceivedHeaders()).containsKeys(ALL_REQUIRED_HEADERS);
assertThat(receivedEvents).extracting(CloudRuntimeEvent::getEventType, CloudRuntimeEvent::getProcessDefinitionKey, CloudRuntimeEvent::getBusinessKey, CloudRuntimeEvent::getEntityId).contains(tuple(PROCESS_CREATED, "broadcastSignalEventProcess", "businessKey", processInstanceId), tuple(PROCESS_STARTED, "broadcastSignalEventProcess", "businessKey", processInstanceId), tuple(ACTIVITY_STARTED, "broadcastSignalEventProcess", "businessKey", "startevent1"), tuple(ACTIVITY_COMPLETED, "broadcastSignalEventProcess", "businessKey", "startevent1"), tuple(SEQUENCE_FLOW_TAKEN, "broadcastSignalEventProcess", "businessKey", "flow5"), tuple(ACTIVITY_STARTED, "broadcastSignalEventProcess", "businessKey", "signalintermediatethrowevent1"), tuple(ACTIVITY_COMPLETED, "broadcastSignalEventProcess", "businessKey", "signalintermediatethrowevent1"), tuple(SEQUENCE_FLOW_TAKEN, "broadcastSignalEventProcess", "businessKey", "flow4"), tuple(ACTIVITY_STARTED, "broadcastSignalEventProcess", "businessKey", "endevent1"), tuple(ACTIVITY_COMPLETED, "broadcastSignalEventProcess", "businessKey", "endevent1"), tuple(PROCESS_COMPLETED, "broadcastSignalEventProcess", "businessKey", processInstanceId), tuple(PROCESS_CREATED, "processWithSignalStart1", null, startedBySignalProcessInstanceId), tuple(SIGNAL_RECEIVED, "processWithSignalStart1", null, "theStart"), tuple(PROCESS_STARTED, "processWithSignalStart1", null, startedBySignalProcessInstanceId), tuple(ACTIVITY_COMPLETED, "processWithSignalStart1", null, "theStart"), tuple(SEQUENCE_FLOW_TAKEN, "processWithSignalStart1", null, "flow1"), tuple(ACTIVITY_STARTED, "processWithSignalStart1", null, "theTask"));
runtimeService.deleteProcessInstance(startedBySignalProcessInstanceId, "clean up");
});
}
use of org.activiti.cloud.starter.tests.services.audit.AuditProducerIT.ALL_REQUIRED_HEADERS in project activiti-cloud by Activiti.
the class ParallelGatewayAuditProducerIT method testProcessExecutionWithParallelGateway.
@Test
public void testProcessExecutionWithParallelGateway() {
// when
streamHandler.getAllReceivedEvents().clear();
ResponseEntity<CloudProcessInstance> processInstance = processInstanceRestTemplate.startProcess(new StartProcessPayloadBuilder().withProcessDefinitionKey(PARALLEL_GATEWAY_PROCESS).build());
String processInstanceId = processInstance.getBody().getId();
// then
await().untilAsserted(() -> {
List<CloudRuntimeEvent<?, ?>> receivedEvents = streamHandler.getAllReceivedEvents();
assertThat(streamHandler.getReceivedHeaders()).containsKeys(ALL_REQUIRED_HEADERS);
assertThat(receivedEvents).extracting(CloudRuntimeEvent::getEventType, CloudRuntimeEvent::getProcessInstanceId, CloudRuntimeEvent::getEntityId).contains(tuple(PROCESS_CREATED, processInstanceId, processInstanceId), tuple(PROCESS_STARTED, processInstanceId, processInstanceId), tuple(ACTIVITY_STARTED, processInstanceId, "theStart"), tuple(ACTIVITY_COMPLETED, processInstanceId, "theStart"), tuple(SEQUENCE_FLOW_TAKEN, processInstanceId, "flow1"), tuple(ACTIVITY_STARTED, processInstanceId, "task1"), tuple(ACTIVITY_COMPLETED, processInstanceId, "task1"), tuple(SEQUENCE_FLOW_TAKEN, processInstanceId, "flow2"), tuple(ACTIVITY_STARTED, processInstanceId, "parallelGateway"), tuple(ACTIVITY_COMPLETED, processInstanceId, "parallelGateway"), tuple(SEQUENCE_FLOW_TAKEN, processInstanceId, "flow3"), tuple(SEQUENCE_FLOW_TAKEN, processInstanceId, "flow5"), tuple(ACTIVITY_STARTED, processInstanceId, "task2"), tuple(ACTIVITY_STARTED, processInstanceId, "task3"), tuple(ACTIVITY_COMPLETED, processInstanceId, "task2"), tuple(ACTIVITY_COMPLETED, processInstanceId, "task3"), tuple(SEQUENCE_FLOW_TAKEN, processInstanceId, "flow4"), tuple(SEQUENCE_FLOW_TAKEN, processInstanceId, "flow6"), tuple(ACTIVITY_STARTED, processInstanceId, "theEnd1"), tuple(ACTIVITY_STARTED, processInstanceId, "theEnd2"), tuple(ACTIVITY_COMPLETED, processInstanceId, "theEnd1"), tuple(ACTIVITY_COMPLETED, processInstanceId, "theEnd2"), tuple(PROCESS_COMPLETED, processInstanceId, processInstanceId));
assertThat(receivedEvents).filteredOn(event -> (event.getEventType().equals(ACTIVITY_STARTED) || event.getEventType().equals(ACTIVITY_COMPLETED)) && ((BPMNActivity) event.getEntity()).getActivityType().equals("parallelGateway")).extracting(CloudRuntimeEvent::getEventType, event -> ((BPMNActivity) event.getEntity()).getActivityType(), event -> ((BPMNActivity) event.getEntity()).getProcessInstanceId()).contains(tuple(ACTIVITY_STARTED, "parallelGateway", processInstanceId), tuple(ACTIVITY_COMPLETED, "parallelGateway", processInstanceId));
});
}
use of org.activiti.cloud.starter.tests.services.audit.AuditProducerIT.ALL_REQUIRED_HEADERS in project activiti-cloud by Activiti.
the class ErrorAuditProducerIT method should_produceBpmnErrorEvents_when_processIsExecuted.
@Test
public void should_produceBpmnErrorEvents_when_processIsExecuted() {
ResponseEntity<CloudProcessInstance> startProcessEntity = processInstanceRestTemplate.startProcess(new StartProcessPayloadBuilder().withProcessDefinitionKey(ERROR_START_EVENT_SUBPROCESS).withName("processInstanceName").withBusinessKey("businessKey").build());
assertThat(startProcessEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
CloudProcessInstance processInstance = startProcessEntity.getBody();
await().untilAsserted(() -> {
assertThat(streamHandler.getReceivedHeaders()).containsKeys(RUNTIME_BUNDLE_INFO_HEADERS);
assertThat(streamHandler.getReceivedHeaders()).containsKeys(ALL_REQUIRED_HEADERS);
List<CloudRuntimeEvent<?, ?>> receivedEvents = streamHandler.getAllReceivedEvents();
assertThat(receivedEvents).filteredOn(event -> (event.getEventType().equals(ACTIVITY_STARTED) || event.getEventType().equals(ACTIVITY_COMPLETED))).extracting(CloudRuntimeEvent::getEventType, event -> ((BPMNActivity) event.getEntity()).getActivityType(), event -> ((BPMNActivity) event.getEntity()).getElementId(), event -> ((BPMNActivity) event.getEntity()).getProcessInstanceId()).contains(tuple(ACTIVITY_STARTED, "endEvent", "subEnd", processInstance.getId()), tuple(ACTIVITY_STARTED, "startEvent", "subStart1", processInstance.getId()), tuple(ACTIVITY_COMPLETED, "startEvent", "subStart1", processInstance.getId()));
assertThat(receivedEvents).filteredOn(CloudBPMNErrorReceivedEvent.class::isInstance).extracting(CloudRuntimeEvent::getEventType, CloudRuntimeEvent::getProcessDefinitionId, CloudRuntimeEvent::getProcessInstanceId, CloudRuntimeEvent::getProcessDefinitionKey, CloudRuntimeEvent::getProcessDefinitionVersion, CloudRuntimeEvent::getBusinessKey, event -> bpmnError(event).getElementId(), event -> bpmnError(event).getProcessDefinitionId(), event -> bpmnError(event).getProcessInstanceId(), event -> bpmnError(event).getErrorCode(), event -> bpmnError(event).getErrorId(), event -> bpmnError(event).getActivityType(), event -> bpmnError(event).getActivityName()).containsExactly(tuple(ERROR_RECEIVED, processInstance.getProcessDefinitionId(), processInstance.getId(), processInstance.getProcessDefinitionKey(), processInstance.getProcessDefinitionVersion(), processInstance.getBusinessKey(), "subStart1", processInstance.getProcessDefinitionId(), processInstance.getId(), "123", "errorId", null, null));
});
}
Aggregations