Search in sources :

Example 1 with IntegrationContext

use of org.activiti.api.process.model.IntegrationContext in project Activiti by Activiti.

the class DefaultServiceTaskBehavior method execute.

/**
 * We have two different implementation strategy that can be executed
 * in according if we have a connector action definition match or not.
 */
@Override
public void execute(DelegateExecution execution) {
    Connector connector = getConnector(getImplementation(execution));
    IntegrationContext integrationContext = connector.apply(integrationContextBuilder.from(execution));
    execution.setVariables(outboundVariablesProvider.calculateOutPutVariables(buildMappingExecutionContext(execution), integrationContext.getOutBoundVariables()));
    leave(execution);
}
Also used : Connector(org.activiti.api.process.runtime.connector.Connector) IntegrationContext(org.activiti.api.process.model.IntegrationContext)

Example 2 with IntegrationContext

use of org.activiti.api.process.model.IntegrationContext in project Activiti by Activiti.

the class ConformanceServiceTaskTest method shouldBeAbleToStartProcess.

/*
     * This test covers the ServiceTask with Implementation.bpmn20.xml process
     * This execution should generate 11 events:
     *   - PROCESS_CREATED
     *   - PROCESS_STARTED,
     *   - ACTIVITY_STARTED,
     *   - ACTIVITY_COMPLETED,
     *   - SEQUENCE_FLOW_TAKEN,
     *   - ACTIVITY_STARTED,
     *   - ACTIVITY_COMPLETED,
     *   - SEQUENCE_FLOW_TAKEN,
     *   - ACTIVITY_STARTED,
     *   - ACTIVITY_COMPLETED,
     *   - PROCESS_COMPLETED
     *  And the Process Instance Status should be Completed
     *  Connectors are executed in a Sync fashion, so the logic will be exexuted and the BPMN Activity completed automatically.
     *  IntegrationContext attributes shall capture and contain valid execution context of the underlying process instance.
     *  No further operation can be executed on the process due the fact that it start and finish in the same transaction
     */
@Test
public void shouldBeAbleToStartProcess() {
    securityUtil.logInAs("user1");
    // when
    ProcessInstance processInstance = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(processKey).withBusinessKey(MY_BUSINESS_KEY).withName("my-process-instance-name").build());
    // then
    assertThat(processInstance).isNotNull();
    assertThat(processInstance.getStatus()).isEqualTo(ProcessInstance.ProcessInstanceStatus.COMPLETED);
    assertThat(processInstance.getBusinessKey()).isEqualTo(MY_BUSINESS_KEY);
    assertThat(processInstance.getName()).isEqualTo("my-process-instance-name");
    // No Process Instance should be found
    Throwable throwable = catchThrowable(() -> processRuntime.processInstance(processInstance.getId()));
    assertThat(throwable).isInstanceOf(NotFoundException.class);
    // No Variable Instance should be found
    throwable = catchThrowable(() -> processRuntime.variables(ProcessPayloadBuilder.variables().withProcessInstanceId(processInstance.getId()).build()));
    assertThat(throwable).isInstanceOf(NotFoundException.class);
    assertThat(Set1RuntimeTestConfiguration.isConnector1Executed()).isTrue();
    // and then
    IntegrationContext integrationContext = Set1RuntimeTestConfiguration.getResultIntegrationContext();
    assertThat(integrationContext).isNotNull();
    assertThat(integrationContext.getBusinessKey()).isEqualTo(processInstance.getBusinessKey());
    assertThat(integrationContext.getProcessDefinitionId()).isEqualTo(processInstance.getProcessDefinitionId());
    assertThat(integrationContext.getProcessInstanceId()).isEqualTo(processInstance.getId());
    assertThat(integrationContext.getProcessDefinitionKey()).isEqualTo(processInstance.getProcessDefinitionKey());
    assertThat(integrationContext.getProcessDefinitionVersion()).isEqualTo(1);
    assertThat(integrationContext.getParentProcessInstanceId()).isNull();
    assertThat(integrationContext.getClientId()).isNotNull();
    assertThat(integrationContext.getClientName()).isEqualTo("My Service Task");
    assertThat(integrationContext.getClientType()).isEqualTo(ServiceTask.class.getSimpleName());
    // and then
    assertThat(RuntimeTestConfiguration.collectedEvents).extracting(RuntimeEvent::getEventType).containsExactly(ProcessRuntimeEvent.ProcessEvents.PROCESS_CREATED, ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, BPMNSequenceFlowTakenEvent.SequenceFlowEvents.SEQUENCE_FLOW_TAKEN, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, BPMNSequenceFlowTakenEvent.SequenceFlowEvents.SEQUENCE_FLOW_TAKEN, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED);
}
Also used : ServiceTask(org.activiti.bpmn.model.ServiceTask) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) IntegrationContext(org.activiti.api.process.model.IntegrationContext) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with IntegrationContext

use of org.activiti.api.process.model.IntegrationContext in project Activiti by Activiti.

the class IntegrationContextBuilderTest method shouldSetIdWhenIntegrationContextEntityIsProvided.

@Test
public void shouldSetIdWhenIntegrationContextEntityIsProvided() {
    // given
    ExecutionEntity execution = mock(ExecutionEntity.class);
    ExecutionEntity processInstance = mock(ExecutionEntity.class);
    ServiceTask serviceTask = mock(ServiceTask.class);
    Map<String, Object> variables = singletonMap("key", "value");
    given(inboundVariablesProvider.calculateInputVariables(execution)).willReturn(variables);
    given(serviceTask.getImplementation()).willReturn(IMPLEMENTATION);
    given(serviceTask.getName()).willReturn(SERVICE_TASK_NAME);
    given(execution.getVariables()).willReturn(variables);
    given(execution.getCurrentActivityId()).willReturn(CURRENT_ACTIVITY_ID);
    given(execution.getCurrentFlowElement()).willReturn(serviceTask);
    given(execution.getProcessInstanceId()).willReturn(PROCESS_INSTANCE_ID);
    given(execution.getProcessDefinitionId()).willReturn(PROCESS_DEFINITION_ID);
    given(execution.getCurrentActivityId()).willReturn(CURRENT_ACTIVITY_ID);
    given(execution.getProcessInstanceBusinessKey()).willReturn(PROCESS_INSTANCE_BUSINESS_KEY);
    given(execution.getProcessInstance()).willReturn(processInstance);
    given(processInstance.getParentProcessInstanceId()).willReturn(PARENT_PROCESS_INSTANCE_ID);
    IntegrationContextEntityImpl integrationContextEntity = new IntegrationContextEntityImpl();
    integrationContextEntity.setId("entityId");
    // when
    IntegrationContext integrationContext = builder.from(integrationContextEntity, execution);
    // then
    assertThat(integrationContext).isNotNull();
    assertThat(integrationContext.getId()).isEqualTo("entityId");
    assertThat(integrationContext.getConnectorType()).isEqualTo(IMPLEMENTATION);
    assertThat(integrationContext.getClientId()).isEqualTo(CURRENT_ACTIVITY_ID);
    assertThat(integrationContext.getClientName()).isEqualTo(SERVICE_TASK_NAME);
    assertThat(integrationContext.getClientType()).isEqualTo(ServiceTask.class.getSimpleName());
    assertThat(integrationContext.getBusinessKey()).isEqualTo(PROCESS_INSTANCE_BUSINESS_KEY);
    assertThat(integrationContext.getProcessDefinitionId()).isEqualTo(PROCESS_DEFINITION_ID);
    assertThat(integrationContext.getProcessInstanceId()).isEqualTo(PROCESS_INSTANCE_ID);
    assertThat(integrationContext.getProcessDefinitionKey()).isEqualTo(PROCESS_DEFINITION_KEY);
    assertThat(integrationContext.getProcessDefinitionVersion()).isEqualTo(PROCESS_DEFINITION_VERSION);
    assertThat(integrationContext.getParentProcessInstanceId()).isEqualTo(PARENT_PROCESS_INSTANCE_ID);
    assertThat(integrationContext.getInBoundVariables()).containsAllEntriesOf(variables);
}
Also used : ServiceTask(org.activiti.bpmn.model.ServiceTask) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) IntegrationContext(org.activiti.api.process.model.IntegrationContext) IntegrationContextEntityImpl(org.activiti.engine.impl.persistence.entity.integration.IntegrationContextEntityImpl) Test(org.junit.jupiter.api.Test)

Example 4 with IntegrationContext

use of org.activiti.api.process.model.IntegrationContext in project Activiti by Activiti.

the class IntegrationContextBuilderTest method shouldBuildIntegrationContextFromExecution.

@Test
public void shouldBuildIntegrationContextFromExecution() {
    // given
    ExecutionEntity execution = mock(ExecutionEntity.class);
    ExecutionEntity processInstance = mock(ExecutionEntity.class);
    ServiceTask serviceTask = mock(ServiceTask.class);
    Map<String, Object> variables = singletonMap("key", "value");
    given(inboundVariablesProvider.calculateInputVariables(execution)).willReturn(variables);
    given(serviceTask.getImplementation()).willReturn(IMPLEMENTATION);
    given(serviceTask.getName()).willReturn(SERVICE_TASK_NAME);
    given(execution.getVariables()).willReturn(variables);
    given(execution.getCurrentActivityId()).willReturn(CURRENT_ACTIVITY_ID);
    given(execution.getCurrentFlowElement()).willReturn(serviceTask);
    given(execution.getProcessInstanceId()).willReturn(PROCESS_INSTANCE_ID);
    given(execution.getProcessDefinitionId()).willReturn(PROCESS_DEFINITION_ID);
    given(execution.getCurrentActivityId()).willReturn(CURRENT_ACTIVITY_ID);
    given(execution.getProcessInstanceBusinessKey()).willReturn(PROCESS_INSTANCE_BUSINESS_KEY);
    given(execution.getProcessInstance()).willReturn(processInstance);
    given(processInstance.getParentProcessInstanceId()).willReturn(PARENT_PROCESS_INSTANCE_ID);
    // when
    IntegrationContext integrationContext = builder.from(execution);
    // then
    assertThat(integrationContext).isNotNull();
    assertThat(integrationContext.getConnectorType()).isEqualTo(IMPLEMENTATION);
    assertThat(integrationContext.getClientId()).isEqualTo(CURRENT_ACTIVITY_ID);
    assertThat(integrationContext.getClientName()).isEqualTo(SERVICE_TASK_NAME);
    assertThat(integrationContext.getClientType()).isEqualTo(ServiceTask.class.getSimpleName());
    assertThat(integrationContext.getBusinessKey()).isEqualTo(PROCESS_INSTANCE_BUSINESS_KEY);
    assertThat(integrationContext.getProcessDefinitionId()).isEqualTo(PROCESS_DEFINITION_ID);
    assertThat(integrationContext.getProcessInstanceId()).isEqualTo(PROCESS_INSTANCE_ID);
    assertThat(integrationContext.getProcessDefinitionKey()).isEqualTo(PROCESS_DEFINITION_KEY);
    assertThat(integrationContext.getProcessDefinitionVersion()).isEqualTo(PROCESS_DEFINITION_VERSION);
    assertThat(integrationContext.getParentProcessInstanceId()).isEqualTo(PARENT_PROCESS_INSTANCE_ID);
    assertThat(integrationContext.getInBoundVariables()).containsAllEntriesOf(variables);
}
Also used : ServiceTask(org.activiti.bpmn.model.ServiceTask) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) IntegrationContext(org.activiti.api.process.model.IntegrationContext) Test(org.junit.jupiter.api.Test)

Aggregations

IntegrationContext (org.activiti.api.process.model.IntegrationContext)4 ServiceTask (org.activiti.bpmn.model.ServiceTask)3 Test (org.junit.jupiter.api.Test)3 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)2 ProcessInstance (org.activiti.api.process.model.ProcessInstance)1 Connector (org.activiti.api.process.runtime.connector.Connector)1 IntegrationContextEntityImpl (org.activiti.engine.impl.persistence.entity.integration.IntegrationContextEntityImpl)1 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1