Search in sources :

Example 1 with ALL_REQUIRED_HEADERS

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));
    });
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) BeforeEach(org.junit.jupiter.api.BeforeEach) java.util(java.util) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TASK_CREATED(org.activiti.api.task.model.events.TaskRuntimeEvent.TaskEvents.TASK_CREATED) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) Autowired(org.springframework.beans.factory.annotation.Autowired) VARIABLE_CREATED(org.activiti.api.model.shared.event.VariableEvent.VariableEvents.VARIABLE_CREATED) CloudProcessInstance(org.activiti.cloud.api.process.model.CloudProcessInstance) ActiveProfiles(org.springframework.test.context.ActiveProfiles) ALL_REQUIRED_HEADERS(org.activiti.cloud.starter.tests.services.audit.AuditProducerIT.ALL_REQUIRED_HEADERS) TASK_ASSIGNED(org.activiti.api.task.model.events.TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED) CloudTask(org.activiti.cloud.api.task.model.CloudTask) PagedResources(org.springframework.hateoas.PagedResources) TaskRestTemplate(org.activiti.cloud.starter.tests.helper.TaskRestTemplate) ProcessEvents(org.activiti.api.process.model.events.ProcessRuntimeEvent.ProcessEvents) ACTIVITY_STARTED(org.activiti.api.process.model.events.BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED) CloudProcessDefinition(org.activiti.cloud.api.process.model.CloudProcessDefinition) TASK_COMPLETED(org.activiti.api.task.model.events.TaskRuntimeEvent.TaskEvents.TASK_COMPLETED) VARIABLE_UPDATED(org.activiti.api.model.shared.event.VariableEvent.VariableEvents.VARIABLE_UPDATED) Awaitility.await(org.awaitility.Awaitility.await) TASK_CANDIDATE_USER_ADDED(org.activiti.api.task.model.events.TaskCandidateUserEvent.TaskCandidateUserEvents.TASK_CANDIDATE_USER_ADDED) Assertions.tuple(org.assertj.core.api.Assertions.tuple) CloudVariableInstance(org.activiti.cloud.api.model.shared.CloudVariableInstance) TaskPayloadBuilder(org.activiti.api.task.model.builders.TaskPayloadBuilder) KeycloakTokenProducer(org.activiti.cloud.services.test.identity.keycloak.interceptor.KeycloakTokenProducer) HttpMethod(org.springframework.http.HttpMethod) TestPropertySource(org.springframework.test.context.TestPropertySource) SEQUENCE_FLOW_TAKEN(org.activiti.api.process.model.events.SequenceFlowEvent.SequenceFlowEvents.SEQUENCE_FLOW_TAKEN) TaskStatus(org.activiti.api.task.model.Task.TaskStatus) CompleteTaskPayload(org.activiti.api.task.model.payloads.CompleteTaskPayload) Test(org.junit.jupiter.api.Test) HttpStatus(org.springframework.http.HttpStatus) TASK_UPDATED(org.activiti.api.task.model.events.TaskRuntimeEvent.TaskEvents.TASK_UPDATED) ProcessInstanceRestTemplate(org.activiti.cloud.starter.tests.helper.ProcessInstanceRestTemplate) ACTIVITY_COMPLETED(org.activiti.api.process.model.events.BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) BPMNActivity(org.activiti.api.process.model.BPMNActivity) ContextConfiguration(org.springframework.test.context.ContextConfiguration) VariableInstance(org.activiti.api.model.shared.model.VariableInstance) ResponseEntity(org.springframework.http.ResponseEntity) StartProcessPayloadBuilder(org.activiti.api.process.model.builders.StartProcessPayloadBuilder) TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) CompleteTaskPayload(org.activiti.api.task.model.payloads.CompleteTaskPayload) CloudVariableInstance(org.activiti.cloud.api.model.shared.CloudVariableInstance) BPMNActivity(org.activiti.api.process.model.BPMNActivity) CloudTask(org.activiti.cloud.api.task.model.CloudTask) CloudProcessInstance(org.activiti.cloud.api.process.model.CloudProcessInstance) StartProcessPayloadBuilder(org.activiti.api.process.model.builders.StartProcessPayloadBuilder) CloudVariableInstance(org.activiti.cloud.api.model.shared.CloudVariableInstance) VariableInstance(org.activiti.api.model.shared.model.VariableInstance) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with ALL_REQUIRED_HEADERS

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");
    });
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) DirtiesContext(org.springframework.test.annotation.DirtiesContext) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) Autowired(org.springframework.beans.factory.annotation.Autowired) CloudProcessInstance(org.activiti.cloud.api.process.model.CloudProcessInstance) ActiveProfiles(org.springframework.test.context.ActiveProfiles) ALL_REQUIRED_HEADERS(org.activiti.cloud.starter.tests.services.audit.AuditProducerIT.ALL_REQUIRED_HEADERS) ProcessPayloadBuilder(org.activiti.api.process.model.builders.ProcessPayloadBuilder) SignalRestTemplate(org.activiti.cloud.starter.tests.helper.SignalRestTemplate) ProcessDefinitionRestTemplate(org.activiti.cloud.starter.tests.helper.ProcessDefinitionRestTemplate) SignalPayload(org.activiti.api.process.model.payloads.SignalPayload) ACTIVITY_STARTED(org.activiti.api.process.model.events.BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED) CloudProcessDefinition(org.activiti.cloud.api.process.model.CloudProcessDefinition) NoSuchElementException(java.util.NoSuchElementException) SIGNAL_RECEIVED(org.activiti.api.process.model.events.BPMNSignalEvent.SignalEvents.SIGNAL_RECEIVED) CloudBPMNSignalReceivedEvent(org.activiti.cloud.api.process.model.events.CloudBPMNSignalReceivedEvent) Awaitility.await(org.awaitility.Awaitility.await) PROCESS_STARTED(org.activiti.api.process.model.events.ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED) Assertions.tuple(org.assertj.core.api.Assertions.tuple) PROCESS_COMPLETED(org.activiti.api.process.model.events.ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED) TestPropertySource(org.springframework.test.context.TestPropertySource) PROCESS_CREATED(org.activiti.api.process.model.events.ProcessRuntimeEvent.ProcessEvents.PROCESS_CREATED) SEQUENCE_FLOW_TAKEN(org.activiti.api.process.model.events.SequenceFlowEvent.SequenceFlowEvents.SEQUENCE_FLOW_TAKEN) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) ProcessInstanceRestTemplate(org.activiti.cloud.starter.tests.helper.ProcessInstanceRestTemplate) List(java.util.List) ACTIVITY_COMPLETED(org.activiti.api.process.model.events.BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Optional(java.util.Optional) ResponseEntity(org.springframework.http.ResponseEntity) StartProcessPayloadBuilder(org.activiti.api.process.model.builders.StartProcessPayloadBuilder) RUNTIME_BUNDLE_INFO_HEADERS(org.activiti.cloud.starter.tests.services.audit.AuditProducerIT.RUNTIME_BUNDLE_INFO_HEADERS) Collections(java.util.Collections) CloudProcessInstance(org.activiti.cloud.api.process.model.CloudProcessInstance) StartProcessPayloadBuilder(org.activiti.api.process.model.builders.StartProcessPayloadBuilder) CloudBPMNSignalReceivedEvent(org.activiti.cloud.api.process.model.events.CloudBPMNSignalReceivedEvent) CloudProcessDefinition(org.activiti.cloud.api.process.model.CloudProcessDefinition) SignalPayload(org.activiti.api.process.model.payloads.SignalPayload) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) NoSuchElementException(java.util.NoSuchElementException) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with ALL_REQUIRED_HEADERS

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");
    });
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) DirtiesContext(org.springframework.test.annotation.DirtiesContext) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) Autowired(org.springframework.beans.factory.annotation.Autowired) CloudProcessInstance(org.activiti.cloud.api.process.model.CloudProcessInstance) ActiveProfiles(org.springframework.test.context.ActiveProfiles) ALL_REQUIRED_HEADERS(org.activiti.cloud.starter.tests.services.audit.AuditProducerIT.ALL_REQUIRED_HEADERS) ProcessPayloadBuilder(org.activiti.api.process.model.builders.ProcessPayloadBuilder) SignalRestTemplate(org.activiti.cloud.starter.tests.helper.SignalRestTemplate) ProcessDefinitionRestTemplate(org.activiti.cloud.starter.tests.helper.ProcessDefinitionRestTemplate) SignalPayload(org.activiti.api.process.model.payloads.SignalPayload) ACTIVITY_STARTED(org.activiti.api.process.model.events.BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED) CloudProcessDefinition(org.activiti.cloud.api.process.model.CloudProcessDefinition) NoSuchElementException(java.util.NoSuchElementException) SIGNAL_RECEIVED(org.activiti.api.process.model.events.BPMNSignalEvent.SignalEvents.SIGNAL_RECEIVED) CloudBPMNSignalReceivedEvent(org.activiti.cloud.api.process.model.events.CloudBPMNSignalReceivedEvent) Awaitility.await(org.awaitility.Awaitility.await) PROCESS_STARTED(org.activiti.api.process.model.events.ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED) Assertions.tuple(org.assertj.core.api.Assertions.tuple) PROCESS_COMPLETED(org.activiti.api.process.model.events.ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED) TestPropertySource(org.springframework.test.context.TestPropertySource) PROCESS_CREATED(org.activiti.api.process.model.events.ProcessRuntimeEvent.ProcessEvents.PROCESS_CREATED) SEQUENCE_FLOW_TAKEN(org.activiti.api.process.model.events.SequenceFlowEvent.SequenceFlowEvents.SEQUENCE_FLOW_TAKEN) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) ProcessInstanceRestTemplate(org.activiti.cloud.starter.tests.helper.ProcessInstanceRestTemplate) List(java.util.List) ACTIVITY_COMPLETED(org.activiti.api.process.model.events.BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Optional(java.util.Optional) ResponseEntity(org.springframework.http.ResponseEntity) StartProcessPayloadBuilder(org.activiti.api.process.model.builders.StartProcessPayloadBuilder) RUNTIME_BUNDLE_INFO_HEADERS(org.activiti.cloud.starter.tests.services.audit.AuditProducerIT.RUNTIME_BUNDLE_INFO_HEADERS) Collections(java.util.Collections) CloudProcessInstance(org.activiti.cloud.api.process.model.CloudProcessInstance) StartProcessPayloadBuilder(org.activiti.api.process.model.builders.StartProcessPayloadBuilder) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) NoSuchElementException(java.util.NoSuchElementException) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with ALL_REQUIRED_HEADERS

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));
    });
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) Awaitility.await(org.awaitility.Awaitility.await) PROCESS_STARTED(org.activiti.api.process.model.events.ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED) Assertions.tuple(org.assertj.core.api.Assertions.tuple) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) Autowired(org.springframework.beans.factory.annotation.Autowired) PROCESS_COMPLETED(org.activiti.api.process.model.events.ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED) CloudProcessInstance(org.activiti.cloud.api.process.model.CloudProcessInstance) ActiveProfiles(org.springframework.test.context.ActiveProfiles) TestPropertySource(org.springframework.test.context.TestPropertySource) PROCESS_CREATED(org.activiti.api.process.model.events.ProcessRuntimeEvent.ProcessEvents.PROCESS_CREATED) SEQUENCE_FLOW_TAKEN(org.activiti.api.process.model.events.SequenceFlowEvent.SequenceFlowEvents.SEQUENCE_FLOW_TAKEN) ALL_REQUIRED_HEADERS(org.activiti.cloud.starter.tests.services.audit.AuditProducerIT.ALL_REQUIRED_HEADERS) Test(org.junit.jupiter.api.Test) ProcessInstanceRestTemplate(org.activiti.cloud.starter.tests.helper.ProcessInstanceRestTemplate) List(java.util.List) ACTIVITY_COMPLETED(org.activiti.api.process.model.events.BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ACTIVITY_STARTED(org.activiti.api.process.model.events.BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED) BPMNActivity(org.activiti.api.process.model.BPMNActivity) ContextConfiguration(org.springframework.test.context.ContextConfiguration) ResponseEntity(org.springframework.http.ResponseEntity) StartProcessPayloadBuilder(org.activiti.api.process.model.builders.StartProcessPayloadBuilder) BPMNActivity(org.activiti.api.process.model.BPMNActivity) CloudProcessInstance(org.activiti.cloud.api.process.model.CloudProcessInstance) StartProcessPayloadBuilder(org.activiti.api.process.model.builders.StartProcessPayloadBuilder) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with ALL_REQUIRED_HEADERS

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));
    });
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) BeforeEach(org.junit.jupiter.api.BeforeEach) ERROR_RECEIVED(org.activiti.api.process.model.events.BPMNErrorReceivedEvent.ErrorEvents.ERROR_RECEIVED) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) Autowired(org.springframework.beans.factory.annotation.Autowired) CloudProcessInstance(org.activiti.cloud.api.process.model.CloudProcessInstance) ActiveProfiles(org.springframework.test.context.ActiveProfiles) ALL_REQUIRED_HEADERS(org.activiti.cloud.starter.tests.services.audit.AuditProducerIT.ALL_REQUIRED_HEADERS) ACTIVITY_STARTED(org.activiti.api.process.model.events.BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED) Awaitility.await(org.awaitility.Awaitility.await) BPMNError(org.activiti.api.process.model.BPMNError) Assertions.tuple(org.assertj.core.api.Assertions.tuple) TestPropertySource(org.springframework.test.context.TestPropertySource) Test(org.junit.jupiter.api.Test) HttpStatus(org.springframework.http.HttpStatus) ProcessInstanceRestTemplate(org.activiti.cloud.starter.tests.helper.ProcessInstanceRestTemplate) List(java.util.List) ACTIVITY_COMPLETED(org.activiti.api.process.model.events.BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED) CloudBPMNErrorReceivedEvent(org.activiti.cloud.api.process.model.events.CloudBPMNErrorReceivedEvent) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) BPMNActivity(org.activiti.api.process.model.BPMNActivity) ContextConfiguration(org.springframework.test.context.ContextConfiguration) ResponseEntity(org.springframework.http.ResponseEntity) StartProcessPayloadBuilder(org.activiti.api.process.model.builders.StartProcessPayloadBuilder) RUNTIME_BUNDLE_INFO_HEADERS(org.activiti.cloud.starter.tests.services.audit.AuditProducerIT.RUNTIME_BUNDLE_INFO_HEADERS) CloudBPMNErrorReceivedEvent(org.activiti.cloud.api.process.model.events.CloudBPMNErrorReceivedEvent) BPMNActivity(org.activiti.api.process.model.BPMNActivity) CloudProcessInstance(org.activiti.cloud.api.process.model.CloudProcessInstance) StartProcessPayloadBuilder(org.activiti.api.process.model.builders.StartProcessPayloadBuilder) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

StartProcessPayloadBuilder (org.activiti.api.process.model.builders.StartProcessPayloadBuilder)10 CloudRuntimeEvent (org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent)10 CloudProcessInstance (org.activiti.cloud.api.process.model.CloudProcessInstance)10 ProcessInstanceRestTemplate (org.activiti.cloud.starter.tests.helper.ProcessInstanceRestTemplate)10 ALL_REQUIRED_HEADERS (org.activiti.cloud.starter.tests.services.audit.AuditProducerIT.ALL_REQUIRED_HEADERS)10 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)10 Assertions.tuple (org.assertj.core.api.Assertions.tuple)10 Awaitility.await (org.awaitility.Awaitility.await)10 Test (org.junit.jupiter.api.Test)10 Autowired (org.springframework.beans.factory.annotation.Autowired)10 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)10 ResponseEntity (org.springframework.http.ResponseEntity)10 DirtiesContext (org.springframework.test.annotation.DirtiesContext)10 ActiveProfiles (org.springframework.test.context.ActiveProfiles)10 ContextConfiguration (org.springframework.test.context.ContextConfiguration)10 TestPropertySource (org.springframework.test.context.TestPropertySource)10 List (java.util.List)9 ACTIVITY_COMPLETED (org.activiti.api.process.model.events.BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED)8 ACTIVITY_STARTED (org.activiti.api.process.model.events.BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED)8 RUNTIME_BUNDLE_INFO_HEADERS (org.activiti.cloud.starter.tests.services.audit.AuditProducerIT.RUNTIME_BUNDLE_INFO_HEADERS)8