Search in sources :

Example 51 with ProcessInstance

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

the class ConformanceBasicProcessInformationTest method shouldBeAbleToStartProcess.

/*
     * This test covers the Process Information.bpmn20.xml process which contains a BPMN Start Event, a BPMN SequenceFlow and BPMN End Event
     * This execution should generate 8 events:
     *   - PROCESS_CREATED,
     *   - PROCESS_STARTED
     *   - ACTIVITY_STARTED
     *   - ACTIVITY_COMPLETED
     *   - SEQUENCE_FLOW_TAKEN
     *   - ACTIVITY_STARTED
     *   - ACTIVITY_COMPLETED
     *   - PROCESS_COMPLETED
     *  And the Process Instance Status should be Completed
     *  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);
    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, ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED);
}
Also used : Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 52 with ProcessInstance

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

the class ConformanceBasicProcessInformationTest method shouldBeAbleToStartProcessWithVariables.

/*
     * This test covers the Process Information.bpmn20.xml process which contains a BPMN Start Event, a BPMN SequenceFlow and BPMN End Event
     * This test add variables to the process and generates more events
     * This execution should generate 9 events:
     *   - PROCESS_CREATED,
     *   - VARIABLE_CREATED
     *   - PROCESS_STARTED
     *   - ACTIVITY_STARTED
     *   - ACTIVITI_COMPLETED
     *   - SEQUENCE_FLOW_TAKEN
     *   - ACTIVITY_STARTED
     *   - ACTIVITI_COMPLETED
     *   - PROCESS_COMPLETED
     *  And the Process Instance Status should be Completed
     *  No further operation can be executed on the process due the fact that it start and finish in the same transaction.
     *
     */
@Test
public void shouldBeAbleToStartProcessWithVariables() {
    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(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, BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED);
}
Also used : Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 53 with ProcessInstance

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

the class BasicExclusiveGatewayErrorTest method cleanup.

@AfterEach
public void cleanup() {
    securityUtil.logInAs("admin");
    Page<ProcessInstance> processInstancePage = processAdminRuntime.processInstances(Pageable.of(0, 50));
    for (ProcessInstance pi : processInstancePage.getContent()) {
        processAdminRuntime.delete(ProcessPayloadBuilder.delete(pi.getId()));
    }
    clearEvents();
}
Also used : ProcessInstance(org.activiti.api.process.model.ProcessInstance) AfterEach(org.junit.jupiter.api.AfterEach)

Example 54 with ProcessInstance

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

the class BasicParallelGatewayTest method cleanup.

@AfterEach
public void cleanup() {
    securityUtil.logInAs("admin");
    Page<ProcessInstance> processInstancePage = processAdminRuntime.processInstances(Pageable.of(0, 50));
    for (ProcessInstance pi : processInstancePage.getContent()) {
        processAdminRuntime.delete(ProcessPayloadBuilder.delete(pi.getId()));
    }
    clearEvents();
}
Also used : ProcessInstance(org.activiti.api.process.model.ProcessInstance) AfterEach(org.junit.jupiter.api.AfterEach)

Example 55 with ProcessInstance

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

the class BasicCallActivityTest method cleanup.

@AfterEach
public void cleanup() {
    securityUtil.logInAs("admin");
    Page<ProcessInstance> processInstancePage = processAdminRuntime.processInstances(Pageable.of(0, 50));
    for (ProcessInstance pi : processInstancePage.getContent()) {
        // We want to delete root processes instances because sub processes will be deleted automatically when the root ones are deleted
        if (pi.getParentId() == null) {
            processAdminRuntime.delete(ProcessPayloadBuilder.delete(pi.getId()));
        }
    }
    clearEvents();
}
Also used : ProcessInstance(org.activiti.api.process.model.ProcessInstance) AfterEach(org.junit.jupiter.api.AfterEach)

Aggregations

ProcessInstance (org.activiti.api.process.model.ProcessInstance)154 Test (org.junit.jupiter.api.Test)123 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)116 Task (org.activiti.api.task.model.Task)73 AfterEach (org.junit.jupiter.api.AfterEach)57 VariableInstance (org.activiti.api.model.shared.model.VariableInstance)54 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)39 Autowired (org.springframework.beans.factory.annotation.Autowired)39 BeforeEach (org.junit.jupiter.api.BeforeEach)38 Page (org.activiti.api.runtime.shared.query.Page)37 SecurityUtil (org.activiti.spring.boot.security.util.SecurityUtil)37 ProcessCleanUpUtil (org.activiti.spring.boot.test.util.ProcessCleanUpUtil)37 Import (org.springframework.context.annotation.Import)35 List (java.util.List)33 Assertions.tuple (org.assertj.core.api.Assertions.tuple)33 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)31 LocalEventSource (org.activiti.test.LocalEventSource)30 RuntimeEvent (org.activiti.api.model.shared.event.RuntimeEvent)29 ProcessRuntimeEvent (org.activiti.api.process.model.events.ProcessRuntimeEvent)29 TaskRuntimeEvent (org.activiti.api.task.model.events.TaskRuntimeEvent)29