Search in sources :

Example 1 with StartProcessPayloadBuilder

use of org.activiti.api.process.model.builders.StartProcessPayloadBuilder in project activiti-cloud by Activiti.

the class ProcessRuntimeBundleSteps method startProcess.

@Step
public CloudProcessInstance startProcess(String process, boolean variables, String businessKey) throws IOException {
    StartProcessPayloadBuilder payload = ProcessPayloadBuilder.start().withProcessDefinitionKey(process).withName("processInstanceName").withBusinessKey(businessKey);
    if (variables) {
        payload.withVariable("test_variable_name", "test-variable-value");
        payload.withVariable("test_int_variable_name", 7);
        payload.withVariable("test_bool_variable_name", true);
        payload.withVariable("test_json_variable_name", objectMapper.readTree("{ \"test-json-variable-element1\":\"test-json-variable-value1\"}"));
        payload.withVariable("test_long_json_variable_name", objectMapper.readTree("{ \"verylongjson\":\"" + StringUtils.repeat("a", 4000) + "\"}"));
    }
    return startProcess(payload.build());
}
Also used : StartProcessPayloadBuilder(org.activiti.api.process.model.builders.StartProcessPayloadBuilder) Step(net.thucydides.core.annotations.Step)

Example 2 with StartProcessPayloadBuilder

use of org.activiti.api.process.model.builders.StartProcessPayloadBuilder 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 3 with StartProcessPayloadBuilder

use of org.activiti.api.process.model.builders.StartProcessPayloadBuilder 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 4 with StartProcessPayloadBuilder

use of org.activiti.api.process.model.builders.StartProcessPayloadBuilder 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 5 with StartProcessPayloadBuilder

use of org.activiti.api.process.model.builders.StartProcessPayloadBuilder in project activiti-cloud by Activiti.

the class InclusiveGatewayAuditProducerIT method testProcessExecutionWithInclusiveGateway.

@Test
public void testProcessExecutionWithInclusiveGateway() {
    // when
    streamHandler.getAllReceivedEvents().clear();
    ResponseEntity<CloudProcessInstance> processInstance = processInstanceRestTemplate.startProcess(new StartProcessPayloadBuilder().withProcessDefinitionKey(INCLUSIVE_GATEWAY_PROCESS).withProcessDefinitionId(processDefinitionIds.get(INCLUSIVE_GATEWAY_PROCESS)).withVariable("input", 1).build());
    String processInstanceId = processInstance.getBody().getId();
    // then task0 is started
    CloudTask task = processInstanceRestTemplate.getTasks(processInstance).getBody().iterator().next();
    String taskId = task.getId();
    streamHandler.getAllReceivedEvents().clear();
    // when
    ResponseEntity<CloudTask> claimTask = taskRestTemplate.claim(task);
    assertThat(claimTask).isNotNull();
    assertThat(claimTask.getBody().getStatus()).isEqualTo(TaskStatus.ASSIGNED);
    streamHandler.getAllReceivedEvents().clear();
    // when
    CompleteTaskPayload completeTaskPayload = TaskPayloadBuilder.complete().withTaskId(task.getId()).build();
    ResponseEntity<CloudTask> completeTask = taskRestTemplate.complete(task, completeTaskPayload);
    // then
    assertThat(completeTask).isNotNull();
    assertThat(completeTask.getBody().getStatus()).isEqualTo(TaskStatus.COMPLETED);
    // then - two tasks should be available
    Iterator<CloudTask> tasks = processInstanceRestTemplate.getTasks(processInstance).getBody().getContent().iterator();
    CloudTask task1 = tasks.hasNext() ? tasks.next() : null;
    CloudTask task2 = tasks.hasNext() ? tasks.next() : null;
    assertThat(task1).isNotNull();
    assertThat(task2).isNotNull();
    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_COMPLETED, processInstanceId, taskId), tuple(ACTIVITY_COMPLETED, processInstanceId, "task0"), tuple(SEQUENCE_FLOW_TAKEN, processInstanceId, "flow2"), tuple(ACTIVITY_STARTED, processInstanceId, "inclusiveGateway"), tuple(ACTIVITY_COMPLETED, processInstanceId, "inclusiveGateway"), tuple(SEQUENCE_FLOW_TAKEN, processInstanceId, "flow3"), tuple(ACTIVITY_STARTED, processInstanceId, "theTask1"), tuple(VARIABLE_CREATED, processInstanceId, "input"), tuple(TASK_CANDIDATE_USER_ADDED, null, "hruser"), tuple(TASK_CREATED, processInstanceId, task1.getId()), tuple(SEQUENCE_FLOW_TAKEN, processInstanceId, "flow4"), tuple(ACTIVITY_STARTED, processInstanceId, "theTask2"), tuple(VARIABLE_CREATED, processInstanceId, "input"), tuple(TASK_CANDIDATE_USER_ADDED, null, "hruser"), tuple(TASK_CREATED, processInstanceId, task2.getId()));
    });
    streamHandler.getAllReceivedEvents().clear();
    // when - complete first task
    claimTask = taskRestTemplate.claim(task1);
    assertThat(claimTask).isNotNull();
    assertThat(claimTask.getBody().getStatus()).isEqualTo(TaskStatus.ASSIGNED);
    completeTaskPayload = TaskPayloadBuilder.complete().withTaskId(task.getId()).build();
    completeTask = taskRestTemplate.complete(task1, completeTaskPayload);
    assertThat(completeTask.getBody().getStatus()).isEqualTo(TaskStatus.COMPLETED);
    // then - first task should be completed, second should be available
    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, task1.getId()), tuple(TASK_UPDATED, processInstanceId, task1.getId()), tuple(TASK_COMPLETED, processInstanceId, task1.getId()), tuple(ACTIVITY_COMPLETED, processInstanceId, "theTask1"), tuple(SEQUENCE_FLOW_TAKEN, processInstanceId, "flow6"), tuple(ACTIVITY_STARTED, processInstanceId, "inclusiveGatewayEnd"));
    });
    tasks = processInstanceRestTemplate.getTasks(processInstance).getBody().getContent().iterator();
    assertThat(tasks).toIterable().hasSize(1);
    streamHandler.getAllReceivedEvents().clear();
    // when - complete second task
    claimTask = taskRestTemplate.claim(task2);
    assertThat(claimTask).isNotNull();
    assertThat(claimTask.getBody().getStatus()).isEqualTo(TaskStatus.ASSIGNED);
    completeTaskPayload = TaskPayloadBuilder.complete().withTaskId(task2.getId()).build();
    completeTask = taskRestTemplate.complete(task2, completeTaskPayload);
    assertThat(completeTask.getBody().getStatus()).isEqualTo(TaskStatus.COMPLETED);
    // then - second task should be completed, process should be completed
    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, task2.getId()), tuple(TASK_UPDATED, processInstanceId, task2.getId()), tuple(TASK_COMPLETED, processInstanceId, task2.getId()), tuple(ACTIVITY_COMPLETED, processInstanceId, "theTask2"), tuple(SEQUENCE_FLOW_TAKEN, processInstanceId, "flow7"), tuple(ACTIVITY_STARTED, processInstanceId, "inclusiveGatewayEnd"), tuple(ACTIVITY_COMPLETED, processInstanceId, "inclusiveGatewayEnd"), tuple(SEQUENCE_FLOW_TAKEN, processInstanceId, "flow9"), tuple(ACTIVITY_STARTED, processInstanceId, "theEnd"), tuple(ACTIVITY_COMPLETED, processInstanceId, "theEnd"), tuple(PROCESS_COMPLETED, processInstanceId, processInstanceId));
    });
}
Also used : CloudTask(org.activiti.cloud.api.task.model.CloudTask) CompleteTaskPayload(org.activiti.api.task.model.payloads.CompleteTaskPayload) 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)11 CloudRuntimeEvent (org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent)10 CloudProcessInstance (org.activiti.cloud.api.process.model.CloudProcessInstance)10 Test (org.junit.jupiter.api.Test)10 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)10 ProcessInstanceRestTemplate (org.activiti.cloud.starter.tests.helper.ProcessInstanceRestTemplate)9 ALL_REQUIRED_HEADERS (org.activiti.cloud.starter.tests.services.audit.AuditProducerIT.ALL_REQUIRED_HEADERS)9 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)9 Assertions.tuple (org.assertj.core.api.Assertions.tuple)9 Awaitility.await (org.awaitility.Awaitility.await)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 ResponseEntity (org.springframework.http.ResponseEntity)9 DirtiesContext (org.springframework.test.annotation.DirtiesContext)9 ActiveProfiles (org.springframework.test.context.ActiveProfiles)9 ContextConfiguration (org.springframework.test.context.ContextConfiguration)9 TestPropertySource (org.springframework.test.context.TestPropertySource)9 List (java.util.List)8 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)7