Search in sources :

Example 1 with RUNTIME_BUNDLE_INFO_HEADERS

use of org.activiti.cloud.starter.tests.services.audit.AuditProducerIT.RUNTIME_BUNDLE_INFO_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 2 with RUNTIME_BUNDLE_INFO_HEADERS

use of org.activiti.cloud.starter.tests.services.audit.AuditProducerIT.RUNTIME_BUNDLE_INFO_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)

Example 3 with RUNTIME_BUNDLE_INFO_HEADERS

use of org.activiti.cloud.starter.tests.services.audit.AuditProducerIT.RUNTIME_BUNDLE_INFO_HEADERS in project activiti-cloud by Activiti.

the class MessageAuditProducerIT method shouldAuditBPMNEventsMessagesAreProduced.

@Test
public void shouldAuditBPMNEventsMessagesAreProduced() {
    // when
    ResponseEntity<CloudProcessInstance> startResponse = messageRestTemplate.message(start("auditStartMessage").withBusinessKey("businessId").withVariable("correlationKey", "correlationId").build());
    assertThat(startResponse.getStatusCode()).isEqualTo(HttpStatus.OK);
    assertThat(messageRestTemplate.message(receive("auditEventSubprocessMessage").withCorrelationKey("correlationId").build()).getStatusCode()).isEqualTo(HttpStatus.OK);
    assertThat(messageRestTemplate.message(receive("auditBoundaryMessage").withCorrelationKey("correlationId").withVariable("customerKey", "customerId").build()).getStatusCode()).isEqualTo(HttpStatus.OK);
    assertThat(messageRestTemplate.message(receive("auditInteremdiateCatchMessage").withCorrelationKey("customerId").withVariable("invoiceKey", "invoiceId").build()).getStatusCode()).isEqualTo(HttpStatus.OK);
    // then
    CloudProcessInstance processInstance = startResponse.getBody();
    await("Audit BPMNMessage Events").untilAsserted(() -> {
        assertThat(streamHandler.getReceivedHeaders()).containsKeys(RUNTIME_BUNDLE_INFO_HEADERS);
        assertThat(streamHandler.getReceivedHeaders()).containsKeys(ALL_REQUIRED_HEADERS);
        List<CloudRuntimeEvent<?, ?>> receivedEvents = streamHandler.getAllReceivedEvents();
        assertThat(receivedEvents).filteredOn(CloudBPMNMessageEvent.class::isInstance).extracting(CloudRuntimeEvent::getEventType, CloudRuntimeEvent::getProcessDefinitionId, CloudRuntimeEvent::getProcessInstanceId, CloudRuntimeEvent::getProcessDefinitionKey, CloudRuntimeEvent::getProcessDefinitionVersion, CloudRuntimeEvent::getBusinessKey, event -> bpmnMessage(event).getElementId(), event -> bpmnMessage(event).getProcessDefinitionId(), event -> bpmnMessage(event).getProcessInstanceId(), event -> bpmnMessage(event).getMessagePayload().getName(), event -> bpmnMessage(event).getMessagePayload().getCorrelationKey(), event -> bpmnMessage(event).getMessagePayload().getBusinessKey(), event -> bpmnMessage(event).getMessagePayload().getVariables()).containsExactly(tuple(MESSAGE_RECEIVED, processInstance.getProcessDefinitionId(), processInstance.getId(), processInstance.getProcessDefinitionKey(), // version
        1, processInstance.getBusinessKey(), "startMessageEvent", processInstance.getProcessDefinitionId(), processInstance.getId(), "auditStartMessage", null, processInstance.getBusinessKey(), Collections.singletonMap("correlationKey", "correlationId")), tuple(MESSAGE_WAITING, processInstance.getProcessDefinitionId(), processInstance.getId(), processInstance.getProcessDefinitionKey(), // version
        1, processInstance.getBusinessKey(), "startMessageEventSubprocessEvent", processInstance.getProcessDefinitionId(), processInstance.getId(), "auditEventSubprocessMessage", "correlationId", processInstance.getBusinessKey(), null), tuple(MESSAGE_SENT, processInstance.getProcessDefinitionId(), processInstance.getId(), processInstance.getProcessDefinitionKey(), // version
        1, processInstance.getBusinessKey(), "intermediateThrowMessageEvent", processInstance.getProcessDefinitionId(), processInstance.getId(), "auditIntermediateThrowMessage", "correlationId", processInstance.getBusinessKey(), Collections.singletonMap("correlationKey", "correlationId")), tuple(MESSAGE_WAITING, processInstance.getProcessDefinitionId(), processInstance.getId(), processInstance.getProcessDefinitionKey(), // version
        1, processInstance.getBusinessKey(), "boundaryMessageEvent", processInstance.getProcessDefinitionId(), processInstance.getId(), "auditBoundaryMessage", "correlationId", processInstance.getBusinessKey(), null), tuple(MESSAGE_RECEIVED, processInstance.getProcessDefinitionId(), processInstance.getId(), processInstance.getProcessDefinitionKey(), // version
        1, processInstance.getBusinessKey(), "startMessageEventSubprocessEvent", processInstance.getProcessDefinitionId(), processInstance.getId(), "auditEventSubprocessMessage", "correlationId", processInstance.getBusinessKey(), null), tuple(MESSAGE_RECEIVED, processInstance.getProcessDefinitionId(), processInstance.getId(), processInstance.getProcessDefinitionKey(), // version
        1, processInstance.getBusinessKey(), "boundaryMessageEvent", processInstance.getProcessDefinitionId(), processInstance.getId(), "auditBoundaryMessage", "correlationId", processInstance.getBusinessKey(), Collections.singletonMap("customerKey", "customerId")), tuple(MESSAGE_WAITING, processInstance.getProcessDefinitionId(), processInstance.getId(), processInstance.getProcessDefinitionKey(), // version
        1, processInstance.getBusinessKey(), "intermediateCatchMessageEvent", processInstance.getProcessDefinitionId(), processInstance.getId(), "auditInteremdiateCatchMessage", "customerId", processInstance.getBusinessKey(), null), tuple(MESSAGE_RECEIVED, processInstance.getProcessDefinitionId(), processInstance.getId(), processInstance.getProcessDefinitionKey(), // version
        1, processInstance.getBusinessKey(), "intermediateCatchMessageEvent", processInstance.getProcessDefinitionId(), processInstance.getId(), "auditInteremdiateCatchMessage", "customerId", processInstance.getBusinessKey(), Collections.singletonMap("invoiceKey", "invoiceId")), tuple(MESSAGE_SENT, processInstance.getProcessDefinitionId(), processInstance.getId(), processInstance.getProcessDefinitionKey(), // version
        1, processInstance.getBusinessKey(), "throwEndMessageEvent", processInstance.getProcessDefinitionId(), processInstance.getId(), "auditThrowEndMessage", "invoiceId", processInstance.getBusinessKey(), Maps.of("correlationKey", "correlationId", "customerKey", "customerId", "invoiceKey", "invoiceId")));
    });
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) CloudMessageSubscriptionCancelledEvent(org.activiti.cloud.api.process.model.events.CloudMessageSubscriptionCancelledEvent) BeforeEach(org.junit.jupiter.api.BeforeEach) 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) CloudBPMNMessageEvent(org.activiti.cloud.api.process.model.events.CloudBPMNMessageEvent) ActiveProfiles(org.springframework.test.context.ActiveProfiles) ALL_REQUIRED_HEADERS(org.activiti.cloud.starter.tests.services.audit.AuditProducerIT.ALL_REQUIRED_HEADERS) MessagePayloadBuilder.receive(org.activiti.api.process.model.builders.MessagePayloadBuilder.receive) Maps(org.apache.groovy.util.Maps) BPMNMessage(org.activiti.api.process.model.BPMNMessage) MessageRestTemplate(org.activiti.cloud.starter.tests.helper.MessageRestTemplate) MESSAGE_RECEIVED(org.activiti.api.process.model.events.BPMNMessageEvent.MessageEvents.MESSAGE_RECEIVED) MessageSubscriptionEvent(org.activiti.api.process.model.events.MessageSubscriptionEvent) Awaitility.await(org.awaitility.Awaitility.await) MessagePayloadBuilder.start(org.activiti.api.process.model.builders.MessagePayloadBuilder.start) Assertions.tuple(org.assertj.core.api.Assertions.tuple) TestPropertySource(org.springframework.test.context.TestPropertySource) MESSAGE_SENT(org.activiti.api.process.model.events.BPMNMessageEvent.MessageEvents.MESSAGE_SENT) MessageSubscription(org.activiti.api.process.model.MessageSubscription) Test(org.junit.jupiter.api.Test) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) ProcessInstanceRestTemplate(org.activiti.cloud.starter.tests.helper.ProcessInstanceRestTemplate) MESSAGE_WAITING(org.activiti.api.process.model.events.BPMNMessageEvent.MessageEvents.MESSAGE_WAITING) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) 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) Collections(java.util.Collections) CloudProcessInstance(org.activiti.cloud.api.process.model.CloudProcessInstance) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) CloudBPMNMessageEvent(org.activiti.cloud.api.process.model.events.CloudBPMNMessageEvent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with RUNTIME_BUNDLE_INFO_HEADERS

use of org.activiti.cloud.starter.tests.services.audit.AuditProducerIT.RUNTIME_BUNDLE_INFO_HEADERS in project activiti-cloud by Activiti.

the class MessageAuditProducerIT method should_produceCloudMessageSubscriptionCancelledEvent_when_processIsDeleted.

@Test
public void should_produceCloudMessageSubscriptionCancelledEvent_when_processIsDeleted() {
    // when
    ResponseEntity<CloudProcessInstance> startProcessEntity = processInstanceRestTemplate.startProcess(new StartProcessPayloadBuilder().withProcessDefinitionKey(CATCH_MESSAGE).withVariable("correlationKey", "foo").withName("processInstanceName").withBusinessKey("businessKey").build());
    assertThat(startProcessEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
    CloudProcessInstance processInstance = startProcessEntity.getBody();
    await("Audit BPMNMessage Events").untilAsserted(() -> {
        assertThat(streamHandler.getReceivedHeaders()).containsKeys(RUNTIME_BUNDLE_INFO_HEADERS);
        assertThat(streamHandler.getReceivedHeaders()).containsKeys(ALL_REQUIRED_HEADERS);
        List<CloudRuntimeEvent<?, ?>> receivedEvents = streamHandler.getAllReceivedEvents();
        assertThat(receivedEvents).filteredOn(CloudBPMNMessageEvent.class::isInstance).extracting(CloudRuntimeEvent::getEventType, CloudRuntimeEvent::getProcessDefinitionId, CloudRuntimeEvent::getProcessInstanceId, CloudRuntimeEvent::getProcessDefinitionKey, CloudRuntimeEvent::getProcessDefinitionVersion, CloudRuntimeEvent::getBusinessKey, event -> bpmnMessage(event).getProcessDefinitionId(), event -> bpmnMessage(event).getProcessInstanceId(), event -> bpmnMessage(event).getMessagePayload().getName(), event -> bpmnMessage(event).getMessagePayload().getCorrelationKey(), event -> bpmnMessage(event).getMessagePayload().getBusinessKey()).contains(tuple(MESSAGE_WAITING, processInstance.getProcessDefinitionId(), processInstance.getId(), processInstance.getProcessDefinitionKey(), // version
        1, processInstance.getBusinessKey(), processInstance.getProcessDefinitionId(), processInstance.getId(), "testMessage", "foo", processInstance.getBusinessKey()));
    });
    ResponseEntity<CloudProcessInstance> deleteProcessEntity = processInstanceRestTemplate.delete(startProcessEntity);
    assertThat(deleteProcessEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
    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(CloudMessageSubscriptionCancelledEvent.class::isInstance).extracting(CloudRuntimeEvent::getEventType, CloudRuntimeEvent::getProcessDefinitionId, CloudRuntimeEvent::getProcessInstanceId, CloudRuntimeEvent::getProcessDefinitionKey, CloudRuntimeEvent::getProcessDefinitionVersion, CloudRuntimeEvent::getBusinessKey, event -> messageSubscription(event).getProcessDefinitionId(), event -> messageSubscription(event).getProcessInstanceId(), event -> messageSubscription(event).getEventName(), event -> messageSubscription(event).getConfiguration(), event -> messageSubscription(event).getBusinessKey()).contains(tuple(MessageSubscriptionEvent.MessageSubscriptionEvents.MESSAGE_SUBSCRIPTION_CANCELLED, processInstance.getProcessDefinitionId(), processInstance.getId(), processInstance.getProcessDefinitionKey(), // version
        1, processInstance.getBusinessKey(), processInstance.getProcessDefinitionId(), processInstance.getId(), "testMessage", "foo", processInstance.getBusinessKey()));
    });
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) CloudMessageSubscriptionCancelledEvent(org.activiti.cloud.api.process.model.events.CloudMessageSubscriptionCancelledEvent) BeforeEach(org.junit.jupiter.api.BeforeEach) 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) CloudBPMNMessageEvent(org.activiti.cloud.api.process.model.events.CloudBPMNMessageEvent) ActiveProfiles(org.springframework.test.context.ActiveProfiles) ALL_REQUIRED_HEADERS(org.activiti.cloud.starter.tests.services.audit.AuditProducerIT.ALL_REQUIRED_HEADERS) MessagePayloadBuilder.receive(org.activiti.api.process.model.builders.MessagePayloadBuilder.receive) Maps(org.apache.groovy.util.Maps) BPMNMessage(org.activiti.api.process.model.BPMNMessage) MessageRestTemplate(org.activiti.cloud.starter.tests.helper.MessageRestTemplate) MESSAGE_RECEIVED(org.activiti.api.process.model.events.BPMNMessageEvent.MessageEvents.MESSAGE_RECEIVED) MessageSubscriptionEvent(org.activiti.api.process.model.events.MessageSubscriptionEvent) Awaitility.await(org.awaitility.Awaitility.await) MessagePayloadBuilder.start(org.activiti.api.process.model.builders.MessagePayloadBuilder.start) Assertions.tuple(org.assertj.core.api.Assertions.tuple) TestPropertySource(org.springframework.test.context.TestPropertySource) MESSAGE_SENT(org.activiti.api.process.model.events.BPMNMessageEvent.MessageEvents.MESSAGE_SENT) MessageSubscription(org.activiti.api.process.model.MessageSubscription) Test(org.junit.jupiter.api.Test) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) ProcessInstanceRestTemplate(org.activiti.cloud.starter.tests.helper.ProcessInstanceRestTemplate) MESSAGE_WAITING(org.activiti.api.process.model.events.BPMNMessageEvent.MessageEvents.MESSAGE_WAITING) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) 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) Collections(java.util.Collections) CloudMessageSubscriptionCancelledEvent(org.activiti.cloud.api.process.model.events.CloudMessageSubscriptionCancelledEvent) 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) CloudBPMNMessageEvent(org.activiti.cloud.api.process.model.events.CloudBPMNMessageEvent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with RUNTIME_BUNDLE_INFO_HEADERS

use of org.activiti.cloud.starter.tests.services.audit.AuditProducerIT.RUNTIME_BUNDLE_INFO_HEADERS in project activiti-cloud by Activiti.

the class TimerAuditProducerIT method shouldGetTimerCanceledEventByProcessDelete.

@Test
public void shouldGetTimerCanceledEventByProcessDelete() {
    // GIVEN
    ResponseEntity<CloudProcessInstance> startProcessEntity = processInstanceRestTemplate.startProcess(new StartProcessPayloadBuilder().withProcessDefinitionKey(PROCESS_INTERMEDIATE_TIMER_EVENT).withName("processInstanceName").withBusinessKey("businessKey").build());
    // WHEN
    processInstanceRestTemplate.delete(startProcessEntity);
    // when
    await().untilAsserted(() -> {
        assertThat(streamHandler.getReceivedHeaders()).containsKeys(RUNTIME_BUNDLE_INFO_HEADERS);
        assertThat(streamHandler.getReceivedHeaders()).containsKeys(ALL_REQUIRED_HEADERS);
        List<CloudRuntimeEvent<?, ?>> receivedEvents = streamHandler.getLatestReceivedEvents();
        List<CloudBPMNTimerEvent> timerEvents = receivedEvents.stream().filter(CloudBPMNTimerCancelledEvent.class::isInstance).map(CloudBPMNTimerEvent.class::cast).collect(Collectors.toList());
        assertThat(timerEvents).extracting(CloudRuntimeEvent::getEventType, CloudRuntimeEvent::getBusinessKey, CloudRuntimeEvent::getProcessDefinitionId, CloudRuntimeEvent::getProcessInstanceId, CloudRuntimeEvent::getProcessDefinitionKey, CloudRuntimeEvent::getProcessDefinitionVersion, event -> event.getEntity().getProcessDefinitionId(), event -> event.getEntity().getProcessInstanceId(), event -> event.getEntityId()).contains(tuple(BPMNTimerEvent.TimerEvents.TIMER_CANCELLED, "businessKey", startProcessEntity.getBody().getProcessDefinitionId(), startProcessEntity.getBody().getId(), startProcessEntity.getBody().getProcessDefinitionKey(), startProcessEntity.getBody().getProcessDefinitionVersion(), startProcessEntity.getBody().getProcessDefinitionId(), startProcessEntity.getBody().getId(), "timer"));
    });
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) SpringProcessEngineConfiguration(org.activiti.spring.SpringProcessEngineConfiguration) DirtiesContext(org.springframework.test.annotation.DirtiesContext) BeforeEach(org.junit.jupiter.api.BeforeEach) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AsyncExecutor(org.activiti.engine.impl.asyncexecutor.AsyncExecutor) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) LoggerFactory(org.slf4j.LoggerFactory) 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) ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) BPMNTimerEvent(org.activiti.api.process.model.events.BPMNTimerEvent) ArrayList(java.util.ArrayList) TestConfiguration(org.springframework.boot.test.context.TestConfiguration) JavaDelegate(org.activiti.engine.delegate.JavaDelegate) ACTIVITY_STARTED(org.activiti.api.process.model.events.BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED) CloudBPMNTimerCancelledEvent(org.activiti.cloud.api.process.model.events.CloudBPMNTimerCancelledEvent) CloudBPMNTimerScheduledEvent(org.activiti.cloud.api.process.model.events.CloudBPMNTimerScheduledEvent) Awaitility.await(org.awaitility.Awaitility.await) Logger(org.slf4j.Logger) Assertions.tuple(org.assertj.core.api.Assertions.tuple) TestPropertySource(org.springframework.test.context.TestPropertySource) Profile(org.springframework.context.annotation.Profile) Collectors(java.util.stream.Collectors) CloudBPMNTimerExecutedEvent(org.activiti.cloud.api.process.model.events.CloudBPMNTimerExecutedEvent) Test(org.junit.jupiter.api.Test) CloudBPMNTimerEvent(org.activiti.cloud.api.process.model.events.CloudBPMNTimerEvent) ProcessInstanceRestTemplate(org.activiti.cloud.starter.tests.helper.ProcessInstanceRestTemplate) ProcessEngineConfigurationConfigurer(org.activiti.spring.boot.ProcessEngineConfigurationConfigurer) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) ACTIVITY_COMPLETED(org.activiti.api.process.model.events.BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DelegateExecution(org.activiti.engine.delegate.DelegateExecution) ContextConfiguration(org.springframework.test.context.ContextConfiguration) ResponseEntity(org.springframework.http.ResponseEntity) StartProcessPayloadBuilder(org.activiti.api.process.model.builders.StartProcessPayloadBuilder) CloudBPMNTimerFiredEvent(org.activiti.cloud.api.process.model.events.CloudBPMNTimerFiredEvent) RUNTIME_BUNDLE_INFO_HEADERS(org.activiti.cloud.starter.tests.services.audit.AuditProducerIT.RUNTIME_BUNDLE_INFO_HEADERS) CloudProcessInstance(org.activiti.cloud.api.process.model.CloudProcessInstance) StartProcessPayloadBuilder(org.activiti.api.process.model.builders.StartProcessPayloadBuilder) CloudBPMNTimerEvent(org.activiti.cloud.api.process.model.events.CloudBPMNTimerEvent) CloudBPMNTimerCancelledEvent(org.activiti.cloud.api.process.model.events.CloudBPMNTimerCancelledEvent) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

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