Search in sources :

Example 31 with ProcessInstance

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

the class TaskRuntimeFormKeyTest method processTaskHasFormKeyAndTaskDefinitionKey.

@Test
public void processTaskHasFormKeyAndTaskDefinitionKey() {
    securityUtil.logInAs("garth");
    ProcessInstance process = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(SINGLE_TASK_PROCESS).build());
    Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 50));
    assertThat(tasks.getContent()).hasSize(1);
    Task task = tasks.getContent().get(0);
    assertThat(task.getFormKey()).isEqualTo("taskForm");
    assertThat(task.getTaskDefinitionKey()).isEqualTo("Task_03l0zc2");
    processRuntime.delete(ProcessPayloadBuilder.delete().withProcessInstance(process).build());
}
Also used : Task(org.activiti.api.task.model.Task) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 32 with ProcessInstance

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

the class UserTaskAssigneeRuntimeTest method shouldStartAProcessCreateAndCompleteAssignedTask.

@Test
public void shouldStartAProcessCreateAndCompleteAssignedTask() {
    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");
    // Check with user2
    securityUtil.logInAs("user2");
    tasks = taskRuntime.tasks(Pageable.of(0, 50));
    assertThat(tasks.getTotalItems()).isEqualTo(0);
    Throwable throwable = catchThrowable(() -> taskRuntime.task(task.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, TaskRuntimeEvent.TaskEvents.TASK_CREATED, TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED);
    clearEvents();
    // complete with user1
    securityUtil.logInAs("user1");
    Task completedTask = taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task.getId()).build());
    assertThat(completedTask.getStatus()).isEqualTo(Task.TaskStatus.COMPLETED);
    assertThat(RuntimeTestConfiguration.collectedEvents).extracting(RuntimeEvent::getEventType).containsExactly(TaskRuntimeEvent.TaskEvents.TASK_COMPLETED, BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, BPMNSequenceFlowTakenEvent.SequenceFlowEvents.SEQUENCE_FLOW_TAKEN, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED);
}
Also used : Task(org.activiti.api.task.model.Task) 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 33 with ProcessInstance

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

the class UserTaskCandidateUserRuntimeTest 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 34 with ProcessInstance

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

the class UserTaskCandidateUserRuntimeTest method shouldCreateClaimAndCompleteTask.

@Test
public void shouldCreateClaimAndCompleteTask() {
    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.CREATED);
    assertThat(task).isEqualTo(taskById);
    assertThat(task.getAssignee()).isNull();
    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();
    // Check with user2
    securityUtil.logInAs("user2");
    tasks = taskRuntime.tasks(Pageable.of(0, 50));
    assertThat(tasks.getTotalItems()).isEqualTo(0);
    Throwable throwable = catchThrowable(() -> taskRuntime.task(task.getId()));
    assertThat(throwable).isInstanceOf(NotFoundException.class);
    // Try to complete without claim should error
    securityUtil.logInAs("user1");
    throwable = catchThrowable(() -> taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task.getId()).build()));
    assertThat(throwable).isInstanceOf(IllegalStateException.class);
    // Claim should be allowed
    Task claimedTask = taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(task.getId()).build());
    assertThat(claimedTask.getStatus()).isEqualTo(Task.TaskStatus.ASSIGNED);
    assertThat(claimedTask.getAssignee()).isEqualTo("user1");
    assertThat(RuntimeTestConfiguration.collectedEvents).extracting(RuntimeEvent::getEventType).containsExactly(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, TaskRuntimeEvent.TaskEvents.TASK_UPDATED);
    clearEvents();
    // complete task now should work
    Task completedTask = taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(claimedTask.getId()).build());
    assertThat(completedTask.getStatus()).isEqualTo(Task.TaskStatus.COMPLETED);
    assertThat(RuntimeTestConfiguration.collectedEvents).extracting(RuntimeEvent::getEventType).containsExactly(TaskRuntimeEvent.TaskEvents.TASK_COMPLETED, BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, BPMNSequenceFlowTakenEvent.SequenceFlowEvents.SEQUENCE_FLOW_TAKEN, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED);
}
Also used : Task(org.activiti.api.task.model.Task) 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 35 with ProcessInstance

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

the class UserTaskCandidateGroupAndAssigneeTest 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)

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