Search in sources :

Example 21 with ProcessInstance

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

the class ProcessRuntimeEventsIT method shouldGetSameProcessInstanceIfForAllVariableCreatedEvents.

@Test
public void shouldGetSameProcessInstanceIfForAllVariableCreatedEvents() {
    // when
    ProcessInstance categorizeProcess = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(SINGLE_TASK_PROCESS).withVariable("name", "peter").build());
    // then
    assertThat(RuntimeTestConfiguration.variableCreatedEventsFromProcessInstance).extracting(event -> event.getProcessInstanceId()).contains(categorizeProcess.getId());
}
Also used : ProcessInstance(org.activiti.api.process.model.ProcessInstance) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SecurityUtil(org.activiti.spring.boot.security.util.SecurityUtil) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) ProcessCancelledEvent(org.activiti.api.process.runtime.events.ProcessCancelledEvent) ProcessPayloadBuilder(org.activiti.api.process.model.builders.ProcessPayloadBuilder) ProcessRuntime(org.activiti.api.process.runtime.ProcessRuntime) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) RuntimeTestConfiguration(org.activiti.spring.boot.RuntimeTestConfiguration) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ProcessCleanUpUtil(org.activiti.spring.boot.test.util.ProcessCleanUpUtil) LocalEventSource(org.activiti.test.LocalEventSource) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 22 with ProcessInstance

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

the class ProcessRuntimeEventsIT method shouldGetSameProcessInstanceIfForAllSequenceFlowTakenEvents.

@Test
public void shouldGetSameProcessInstanceIfForAllSequenceFlowTakenEvents() {
    // when
    ProcessInstance categorizeProcess = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(SINGLE_TASK_PROCESS).withVariable("name", "peter").build());
    // then
    assertThat(RuntimeTestConfiguration.sequenceFlowTakenEvents).extracting(event -> event.getProcessInstanceId()).contains(categorizeProcess.getId());
}
Also used : ProcessInstance(org.activiti.api.process.model.ProcessInstance) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SecurityUtil(org.activiti.spring.boot.security.util.SecurityUtil) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) ProcessCancelledEvent(org.activiti.api.process.runtime.events.ProcessCancelledEvent) ProcessPayloadBuilder(org.activiti.api.process.model.builders.ProcessPayloadBuilder) ProcessRuntime(org.activiti.api.process.runtime.ProcessRuntime) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) RuntimeTestConfiguration(org.activiti.spring.boot.RuntimeTestConfiguration) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ProcessCleanUpUtil(org.activiti.spring.boot.test.util.ProcessCleanUpUtil) LocalEventSource(org.activiti.test.LocalEventSource) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 23 with ProcessInstance

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

the class ProcessInstanceOperationsTest method shouldBeAbleToStartSuspendAndResumeProcessInstance.

/*
     */
@Test
public void shouldBeAbleToStartSuspendAndResumeProcessInstance() {
    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.RUNNING);
    assertThat(processInstance.getBusinessKey()).isEqualTo("my-business-key");
    assertThat(processInstance.getName()).isEqualTo("my-process-instance-name");
    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, TaskRuntimeEvent.TaskEvents.TASK_CREATED);
    clearEvents();
    ProcessInstance suspendedProcessInstance = processRuntime.suspend(ProcessPayloadBuilder.suspend(processInstance.getId()));
    assertThat(suspendedProcessInstance.getStatus()).isEqualTo(ProcessInstance.ProcessInstanceStatus.SUSPENDED);
    assertThat(RuntimeTestConfiguration.collectedEvents).extracting(RuntimeEvent::getEventType).containsExactly(ProcessRuntimeEvent.ProcessEvents.PROCESS_SUSPENDED, TaskRuntimeEvent.TaskEvents.TASK_SUSPENDED);
    clearEvents();
    ProcessInstance resumedProcessInstance = processRuntime.resume(ProcessPayloadBuilder.resume(suspendedProcessInstance.getId()));
    assertThat(resumedProcessInstance.getStatus()).isEqualTo(ProcessInstance.ProcessInstanceStatus.RUNNING);
    assertThat(RuntimeTestConfiguration.collectedEvents).extracting(RuntimeEvent::getEventType).containsExactly(ProcessRuntimeEvent.ProcessEvents.PROCESS_RESUMED);
}
Also used : ProcessInstance(org.activiti.api.process.model.ProcessInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 24 with ProcessInstance

use of org.activiti.api.process.model.ProcessInstance 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 25 with ProcessInstance

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

the class UserTaskAssigneeDeleteRuntimeTest method shouldFailOnDeleteTask.

@Test
public void shouldFailOnDeleteTask() {
    securityUtil.logInAs("user1");
    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.RUNNING);
    assertThat(processInstance.getBusinessKey()).isEqualTo("my-business-key");
    assertThat(processInstance.getName()).isEqualTo("my-process-instance-name");
    // I should be able to get the process instance from the Runtime because it is still running
    ProcessInstance processInstanceById = processRuntime.processInstance(processInstance.getId());
    assertThat(processInstanceById).isEqualTo(processInstance);
    // I should get a task for User1
    Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 50));
    assertThat(tasks.getTotalItems()).isEqualTo(1);
    Task task = tasks.getContent().get(0);
    Task taskById = taskRuntime.task(task.getId());
    assertThat(taskById.getStatus()).isEqualTo(Task.TaskStatus.ASSIGNED);
    assertThat(task).isEqualTo(taskById);
    assertThat(task.getAssignee()).isEqualTo("user1");
    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, TaskRuntimeEvent.TaskEvents.TASK_CREATED, TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED);
    clearEvents();
    Throwable throwable = catchThrowable(() -> taskRuntime.delete(TaskPayloadBuilder.delete().withTaskId(task.getId()).withReason("I don't want this task anymore").build()));
    assertThat(throwable).isInstanceOf(ActivitiException.class).hasMessage("The task cannot be deleted because is part of a running process");
}
Also used : Task(org.activiti.api.task.model.Task) ActivitiException(org.activiti.engine.ActivitiException) 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)

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