Search in sources :

Example 1 with VariableUpdatedEvent

use of org.activiti.api.model.shared.event.VariableUpdatedEvent in project Activiti by Activiti.

the class ConformanceServiceTaskModifyVariableTest method shouldBeAbleToStartProcess.

/*
     * This test covers the ServiceTask with Implementation2.bpmn20.xml process
     * This execution should generate 11 events:
     *   - PROCESS_CREATED
     *   - VARIABLE_CREATED
     *   - PROCESS_STARTED,
     *   - ACTIVITY_STARTED,
     *   - ACTIVITY_COMPLETED,
     *   - SEQUENCE_FLOW_TAKEN,
     *   - ACTIVITY_STARTED,
     *   - VARIABLE_UPDATED
     *   - 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.
     *  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").withVariable("var1", "value1").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.isConnector2Executed()).isTrue();
    assertThat(RuntimeTestConfiguration.collectedEvents).extracting(RuntimeEvent::getEventType).containsExactly(ProcessRuntimeEvent.ProcessEvents.PROCESS_CREATED, VariableEvent.VariableEvents.VARIABLE_CREATED, ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, BPMNSequenceFlowTakenEvent.SequenceFlowEvents.SEQUENCE_FLOW_TAKEN, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, VariableEvent.VariableEvents.VARIABLE_UPDATED, BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, BPMNSequenceFlowTakenEvent.SequenceFlowEvents.SEQUENCE_FLOW_TAKEN, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED);
    assertThat((String) ((VariableUpdatedEvent) RuntimeTestConfiguration.collectedEvents.get(7)).getEntity().getValue()).isEqualTo("value1-modified");
}
Also used : Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) ProcessInstance(org.activiti.api.process.model.ProcessInstance) VariableUpdatedEvent(org.activiti.api.model.shared.event.VariableUpdatedEvent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

VariableUpdatedEvent (org.activiti.api.model.shared.event.VariableUpdatedEvent)1 ProcessInstance (org.activiti.api.process.model.ProcessInstance)1 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)1 Test (org.junit.jupiter.api.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1