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);
}
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();
}
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);
}
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();
}
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");
}
Aggregations