use of org.activiti.api.process.model.ProcessInstance in project Activiti by Activiti.
the class ProcessRuntimeBPMNMessageIT method shouldReceiveCatchMessageWithCorrelationKey.
@Test
public void shouldReceiveCatchMessageWithCorrelationKey() {
ProcessInstance process = processRuntime.start(ProcessPayloadBuilder.start().withBusinessKey("businessKey").withVariable("correlationKey", "foo").withProcessDefinitionKey(CATCH_MESSAGE).build());
// when
processRuntime.receive(MessagePayloadBuilder.receive(TEST_MESSAGE).withVariable("key", "value").withCorrelationKey("foo").build());
// then
assertThat(MessageTestConfiguration.messageEvents).isNotEmpty().extracting(BPMNMessageEvent::getEventType, BPMNMessageEvent::getProcessDefinitionId, BPMNMessageEvent::getProcessInstanceId, event -> event.getEntity().getProcessDefinitionId(), event -> event.getEntity().getProcessInstanceId(), event -> event.getEntity().getMessagePayload().getName(), event -> event.getEntity().getMessagePayload().getCorrelationKey(), event -> event.getEntity().getMessagePayload().getBusinessKey(), event -> event.getEntity().getMessagePayload().getVariables()).contains(Tuple.tuple(BPMNMessageEvent.MessageEvents.MESSAGE_WAITING, process.getProcessDefinitionId(), process.getId(), process.getProcessDefinitionId(), process.getId(), "testMessage", "foo", process.getBusinessKey(), null), Tuple.tuple(BPMNMessageEvent.MessageEvents.MESSAGE_RECEIVED, process.getProcessDefinitionId(), process.getId(), process.getProcessDefinitionId(), process.getId(), "testMessage", "foo", process.getBusinessKey(), singletonMap("key", "value")));
}
use of org.activiti.api.process.model.ProcessInstance in project Activiti by Activiti.
the class ProcessRuntimeBPMNMessageIT method should_cancelTask_when_interruptedMessageReceived.
@Test
public void should_cancelTask_when_interruptedMessageReceived() {
ProcessInstance processInstance = processRuntime.start(ProcessPayloadBuilder.start().withBusinessKey("businessKey").withVariable("correlationKey", "correlationKey").withProcessDefinitionKey("messageInterruptingSubProcess").build());
List<Task> allTasks = taskRuntime.tasks(Pageable.of(0, 2), TaskPayloadBuilder.tasks().withProcessInstanceId(processInstance.getId()).build()).getContent();
assertThat(allTasks.size()).isEqualTo(1);
assertThat(MessageTestConfiguration.messageEvents).isNotEmpty().extracting(BPMNMessageEvent::getEventType, BPMNMessageEvent::getProcessDefinitionId, BPMNMessageEvent::getProcessInstanceId, event -> event.getEntity().getProcessDefinitionId(), event -> event.getEntity().getProcessInstanceId(), event -> event.getEntity().getMessagePayload().getName(), event -> event.getEntity().getMessagePayload().getCorrelationKey(), event -> event.getEntity().getMessagePayload().getBusinessKey(), event -> event.getEntity().getMessagePayload().getVariables()).contains(Tuple.tuple(BPMNMessageEvent.MessageEvents.MESSAGE_WAITING, processInstance.getProcessDefinitionId(), processInstance.getId(), processInstance.getProcessDefinitionId(), processInstance.getId(), "interruptedMessage", "correlationKey", processInstance.getBusinessKey(), null));
assertThat(localEventSource.getEvents()).filteredOn(event -> event.getEventType().equals(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED)).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName()).containsExactly(tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, allTasks.get(0).getName()));
// sending the Interrupted Start Message to process
processRuntime.receive(MessagePayloadBuilder.receive("interruptedMessage").withCorrelationKey("correlationKey").build());
// then
assertThat(MessageTestConfiguration.messageEvents).isNotEmpty().extracting(BPMNMessageEvent::getEventType, BPMNMessageEvent::getProcessDefinitionId, BPMNMessageEvent::getProcessInstanceId, event -> event.getEntity().getProcessDefinitionId(), event -> event.getEntity().getProcessInstanceId(), event -> event.getEntity().getMessagePayload().getName(), event -> event.getEntity().getMessagePayload().getCorrelationKey(), event -> event.getEntity().getMessagePayload().getBusinessKey(), event -> event.getEntity().getMessagePayload().getVariables()).contains(Tuple.tuple(BPMNMessageEvent.MessageEvents.MESSAGE_WAITING, processInstance.getProcessDefinitionId(), processInstance.getId(), processInstance.getProcessDefinitionId(), processInstance.getId(), "interruptedMessage", "correlationKey", processInstance.getBusinessKey(), null), Tuple.tuple(BPMNMessageEvent.MessageEvents.MESSAGE_RECEIVED, processInstance.getProcessDefinitionId(), processInstance.getId(), processInstance.getProcessDefinitionId(), processInstance.getId(), "interruptedMessage", "correlationKey", processInstance.getBusinessKey(), null));
// then
assertThat(taskBaseRuntime.getTasksByProcessInstanceId(processInstance.getId())).isEmpty();
assertThat(localEventSource.getEvents()).filteredOn(event -> event.getEventType().equals(TaskRuntimeEvent.TaskEvents.TASK_CANCELLED)).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName()).containsExactly(tuple(TaskRuntimeEvent.TaskEvents.TASK_CANCELLED, allTasks.get(0).getName()));
assertThat(localEventSource.getEvents()).extracting(RuntimeEvent::getEventType, RuntimeEvent::getProcessInstanceId).contains(tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED, processInstance.getId()));
}
use of org.activiti.api.process.model.ProcessInstance in project Activiti by Activiti.
the class ProcessRuntimeIT method should_startProcessViaSignal.
@Test
public void should_startProcessViaSignal() {
// when
SignalPayload signalPayload = ProcessPayloadBuilder.signal().withName("The Signal").withVariable("signalVar", "from signal").build();
processRuntimeMock.signal(signalPayload);
Page<ProcessInstance> processInstancePage = processRuntimeMock.processInstances(PAGEABLE);
// then
assertThat(processInstancePage).isNotNull();
assertThat(processInstancePage.getContent()).hasSize(1);
assertThat(processInstancePage.getContent().get(0).getProcessDefinitionKey()).isEqualTo("processWithSignalStart1");
verify(eventPublisher).publishEvent(signalPayload);
// when
List<VariableInstance> variables = processRuntime.variables(ProcessPayloadBuilder.variables().withProcessInstance(processInstancePage.getContent().get(0)).build());
assertThat(variables).extracting(VariableInstance::getName, VariableInstance::getValue).containsExactly(tuple("signalVar", "from signal"));
processRuntimeMock.delete(ProcessPayloadBuilder.delete(processInstancePage.getContent().get(0).getId()));
}
use of org.activiti.api.process.model.ProcessInstance in project Activiti by Activiti.
the class ProcessRuntimeIT method getSubprocesses.
@Test
public void getSubprocesses() {
Page<ProcessInstance> processInstancePage;
ProcessInstance parentProcess, subProcess;
// given
// start a process with a business key to check filters
parentProcess = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(SUPER_PROCESS).withBusinessKey("my superprocess key").build());
// when
processInstancePage = processRuntime.processInstances(PAGEABLE, ProcessPayloadBuilder.processInstances().build());
// Check that we have parent process and subprocess
assertThat(processInstancePage).isNotNull();
assertThat(processInstancePage.getContent()).hasSize(2);
assertThat(processInstancePage.getContent().get(0).getProcessDefinitionKey()).isEqualTo(SUPER_PROCESS);
assertThat(processInstancePage.getContent().get(1).getProcessDefinitionKey()).isEqualTo(SUB_PROCESS);
// Check that parentProcess has 1 subprocess
processInstancePage = processRuntime.processInstances(PAGEABLE, ProcessPayloadBuilder.subprocesses(parentProcess.getId()));
assertThat(processInstancePage).isNotNull();
assertThat(processInstancePage.getContent()).hasSize(1);
subProcess = processInstancePage.getContent().get(0);
assertThat(subProcess.getProcessDefinitionKey()).isEqualTo(SUB_PROCESS);
assertThat(subProcess.getParentId()).isEqualTo(parentProcess.getId());
assertThat(subProcess.getProcessDefinitionVersion()).isEqualTo(1);
processRuntime.delete(ProcessPayloadBuilder.delete(subProcess));
processRuntime.delete(ProcessPayloadBuilder.delete(parentProcess));
}
use of org.activiti.api.process.model.ProcessInstance in project Activiti by Activiti.
the class ProcessRuntimeIT method updateProcessInstanceAdmin.
@Test
public void updateProcessInstanceAdmin() {
securityUtil.logInAs("admin");
Page<ProcessDefinition> processDefinitionPage = processAdminRuntime.processDefinitions(Pageable.of(0, 50));
assertThat(processDefinitionPage.getContent()).isNotNull();
assertThat(processDefinitionPage.getContent()).extracting(ProcessDefinition::getKey).contains(CATEGORIZE_HUMAN_PROCESS);
// start a process with a business key to check filters
ProcessInstance categorizeProcess = processAdminRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(CATEGORIZE_HUMAN_PROCESS).withVariable("expectedKey", true).withBusinessKey("my business key").withName("my process name").build());
assertThat(categorizeProcess).isNotNull();
assertThat(categorizeProcess.getStatus()).isEqualTo(ProcessInstance.ProcessInstanceStatus.RUNNING);
assertThat(categorizeProcess.getName()).isEqualTo("my process name");
// update a process
Page<ProcessInstance> processInstancePage = processAdminRuntime.processInstances(PAGEABLE);
ProcessInstance processInstance = processInstancePage.getContent().get(0);
UpdateProcessPayload updateProcessPayload = ProcessPayloadBuilder.update().withProcessInstanceId(processInstance.getId()).withBusinessKey(processInstance.getBusinessKey() + " UPDATED").withName(processInstance.getName() + " UPDATED").build();
ProcessInstance updatedProcessInstance = processAdminRuntime.update(updateProcessPayload);
assertThat(updatedProcessInstance).isNotNull();
processInstancePage = processAdminRuntime.processInstances(PAGEABLE);
assertThat(processInstancePage).isNotNull();
assertThat(processInstancePage.getContent()).hasSize(1);
processInstance = processInstancePage.getContent().get(0);
assertThat(processInstance.getName()).isEqualTo("my process name UPDATED");
assertThat(processInstance.getBusinessKey()).isEqualTo("my business key UPDATED");
// delete a process to avoid possible problems with other tests
ProcessInstance deletedProcessInstance = processAdminRuntime.delete(ProcessPayloadBuilder.delete(categorizeProcess));
assertThat(deletedProcessInstance).isNotNull();
assertThat(deletedProcessInstance.getStatus()).isEqualTo(ProcessInstance.ProcessInstanceStatus.CANCELLED);
}
Aggregations