Search in sources :

Example 36 with ProcessInstance

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

the class UserTaskCandidateGroupAndAssigneeTest method shouldCreateAndCompleteATaskAndDontSeeNext.

@Test
public void shouldCreateAndCompleteATaskAndDontSeeNext() {
    securityUtil.logInAs("user1");
    // given
    ProcessInstance processInstance = processOperations.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(processKey).withBusinessKey("my-business-key").withName("my-process-instance-name").build()).expectFields(processInstance().status(ProcessInstance.ProcessInstanceStatus.RUNNING), processInstance().name("my-process-instance-name"), processInstance().businessKey("my-business-key")).expect(processInstance().hasTask("Task User1", Task.TaskStatus.ASSIGNED, withAssignee("user1"))).expectEvents(processInstance().hasBeenStarted(), startEvent("StartEvent_1").hasBeenStarted(), startEvent("StartEvent_1").hasBeenCompleted(), sequenceFlow("SequenceFlow_1uccvwa").hasBeenTaken(), taskWithName("Task User1").hasBeenCreated(), taskWithName("Task User1").hasBeenAssigned()).andReturn();
    // 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
    GetTasksPayload processInstanceTasksPayload = TaskPayloadBuilder.tasks().withProcessInstanceId(processInstance.getId()).build();
    Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 50), processInstanceTasksPayload);
    assertThat(tasks.getTotalItems()).isEqualTo(1);
    Task task = tasks.getContent().get(0);
    // given
    taskOperations.complete(TaskPayloadBuilder.complete().withTaskId(task.getId()).build()).expectEvents(task().hasBeenCompleted(), sequenceFlow("SequenceFlow_151v2cg").hasBeenTaken(), taskWithName("Task Group1").hasBeenCreated()).expect(processInstance().hasTask("Task Group1", Task.TaskStatus.CREATED, createdTask -> {
        assertThat(taskRuntime.userCandidates(createdTask.getId())).isEmpty();
        assertThat(taskRuntime.groupCandidates(createdTask.getId())).contains("group1");
    }));
    // Check with user1 as he is a candidate
    tasks = taskRuntime.tasks(Pageable.of(0, 50), processInstanceTasksPayload);
    assertThat(tasks.getTotalItems()).isEqualTo(1);
    // Check with user2 candidates which is not a candidate
    securityUtil.logInAs("user2");
    tasks = taskRuntime.tasks(Pageable.of(0, 50));
    assertThat(tasks.getTotalItems()).isEqualTo(0);
    // Check with user3 candidates which is a candidate
    securityUtil.logInAs("user3");
    tasks = taskRuntime.tasks(Pageable.of(0, 50), processInstanceTasksPayload);
    assertThat(tasks.getTotalItems()).isEqualTo(1);
}
Also used : ProcessInstanceMatchers.processInstance(org.activiti.test.matchers.ProcessInstanceMatchers.processInstance) Pageable(org.activiti.api.runtime.shared.query.Pageable) BPMNStartEventMatchers.startEvent(org.activiti.test.matchers.BPMNStartEventMatchers.startEvent) Task(org.activiti.api.task.model.Task) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) RuntimeTestConfiguration(org.activiti.spring.conformance.util.RuntimeTestConfiguration) ProcessPayloadBuilder(org.activiti.api.process.model.builders.ProcessPayloadBuilder) GetTasksPayload(org.activiti.api.task.model.payloads.GetTasksPayload) ProcessRuntime(org.activiti.api.process.runtime.ProcessRuntime) TaskOperations(org.activiti.test.operations.TaskOperations) SequenceFlowMatchers.sequenceFlow(org.activiti.test.matchers.SequenceFlowMatchers.sequenceFlow) SecurityUtil(org.activiti.spring.conformance.util.security.SecurityUtil) TaskMatchers.task(org.activiti.test.matchers.TaskMatchers.task) TaskRuntime(org.activiti.api.task.runtime.TaskRuntime) ProcessOperations(org.activiti.test.operations.ProcessOperations) ProcessInstance(org.activiti.api.process.model.ProcessInstance) TaskPayloadBuilder(org.activiti.api.task.model.builders.TaskPayloadBuilder) ProcessTaskMatchers.taskWithName(org.activiti.test.matchers.ProcessTaskMatchers.taskWithName) Page(org.activiti.api.runtime.shared.query.Page) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ProcessAdminRuntime(org.activiti.api.process.runtime.ProcessAdminRuntime) TaskMatchers.withAssignee(org.activiti.test.matchers.TaskMatchers.withAssignee) Task(org.activiti.api.task.model.Task) GetTasksPayload(org.activiti.api.task.model.payloads.GetTasksPayload) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 37 with ProcessInstance

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

the class UserTaskCandidateVisibilityTest 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 38 with ProcessInstance

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

the class UserTaskCandidateVisibilityTest method shouldCreateATaskAndAddNewCandidateUser.

@Test
public void shouldCreateATaskAndAddNewCandidateUser() {
    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);
    final 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);
    // Check with user1 candidates
    securityUtil.logInAs("user1");
    taskById = taskRuntime.task(task.getId());
    List<String> candidateUsers = taskRuntime.userCandidates(task.getId());
    assertThat(candidateUsers).isEmpty();
    List<String> candidateGroups = taskRuntime.groupCandidates(task.getId());
    assertThat(candidateGroups).contains("group1");
    // This should fail because user1 is not the assignee
    throwable = catchThrowable(() -> taskRuntime.addCandidateUsers(TaskPayloadBuilder.addCandidateUsers().withTaskId(task.getId()).withCandidateUser("user2").build()));
    assertThat(throwable).isInstanceOf(IllegalStateException.class);
    taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(task.getId()).build());
    // Now it should work
    taskRuntime.addCandidateUsers(TaskPayloadBuilder.addCandidateUsers().withTaskId(task.getId()).withCandidateUser("user2").build());
    candidateUsers = taskRuntime.userCandidates(task.getId());
    assertThat(candidateUsers).contains("user2");
    // User 1 needs to release the task in order for User 2 see it as candidate
    taskRuntime.release(TaskPayloadBuilder.release().withTaskId(task.getId()).build());
    // Check with user2
    securityUtil.logInAs("user2");
    tasks = taskRuntime.tasks(Pageable.of(0, 50));
    assertThat(tasks.getTotalItems()).isEqualTo(1);
}
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 39 with ProcessInstance

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

the class SignalThrowCatchTest 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 40 with ProcessInstance

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

the class SignalThrowCatchTest method testProcessWithIntermediateCatchEventSignal.

@Test
public void testProcessWithIntermediateCatchEventSignal() {
    securityUtil.logInAs("user1");
    ProcessInstance processInstance = startIntermediateCatchEventSignalProcess();
    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);
    BPMNActivityImpl signalCatchEvent = (BPMNActivityImpl) RuntimeTestConfiguration.collectedEvents.get(5).getEntity();
    assertThat(signalCatchEvent.getActivityType()).isEqualTo("intermediateCatchEvent");
    clearEvents();
    SignalPayload signalPayload = ProcessPayloadBuilder.signal().withName("Test").withVariable("signal_variable", "test").build();
    processRuntime.signal(signalPayload);
    assertThat(RuntimeTestConfiguration.collectedEvents).extracting(RuntimeEvent::getEventType).containsExactly(BPMNSignalEvent.SignalEvents.SIGNAL_RECEIVED, VariableEvent.VariableEvents.VARIABLE_CREATED, BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, BPMNSequenceFlowTakenEvent.SequenceFlowEvents.SEQUENCE_FLOW_TAKEN, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED);
    BPMNSignalReceivedEvent event = (BPMNSignalReceivedEvent) RuntimeTestConfiguration.collectedEvents.get(0);
    assertThat(event.getEntity()).isNotNull();
    assertThat(event.getProcessInstanceId()).isEqualTo(processInstance.getId());
    assertThat(event.getEntity().getSignalPayload()).isNotNull();
    assertThat(event.getEntity().getSignalPayload().getName()).isEqualTo(signalPayload.getName());
    assertThat(event.getEntity().getSignalPayload().getVariables()).hasSize(signalPayload.getVariables().size());
    assertThat(event.getEntity().getSignalPayload().getVariables().get("signal_variable")).isEqualTo("test");
}
Also used : BPMNActivityImpl(org.activiti.api.runtime.model.impl.BPMNActivityImpl) BPMNSignalReceivedEvent(org.activiti.api.process.model.events.BPMNSignalReceivedEvent) ProcessInstance(org.activiti.api.process.model.ProcessInstance) SignalPayload(org.activiti.api.process.model.payloads.SignalPayload) 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