use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.
the class ActivityEventsTest method testActivityEvents.
/**
* Test starting and completed events for activity. Since these events are dispatched in the core
* of the PVM, not all individual activity-type is tested. Rather, we test the main types (tasks, gateways, events,
* subprocesses).
*/
@Deployment
public void testActivityEvents() throws Exception {
// We're interested in the raw events, alter the listener to keep those as well
listener.setIgnoreRawActivityEvents(false);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("activityProcess");
assertNotNull(processInstance);
assertEquals(3, listener.getEventsReceived().size());
// Start-event activity started
ActivitiActivityEvent activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ACTIVITY_STARTED, activityEvent.getType());
assertEquals("theStart", activityEvent.getActivityId());
assertEquals(processInstance.getId(), activityEvent.getExecutionId());
assertEquals(processInstance.getProcessInstanceId(), activityEvent.getProcessInstanceId());
assertEquals(processInstance.getProcessDefinitionId(), activityEvent.getProcessDefinitionId());
// Start-event finished
activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ACTIVITY_COMPLETED, activityEvent.getType());
assertEquals("theStart", activityEvent.getActivityId());
assertEquals(processInstance.getId(), activityEvent.getExecutionId());
assertEquals(processInstance.getProcessInstanceId(), activityEvent.getProcessInstanceId());
assertEquals(processInstance.getProcessDefinitionId(), activityEvent.getProcessDefinitionId());
// Usertask started
activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(2);
assertEquals(ActivitiEventType.ACTIVITY_STARTED, activityEvent.getType());
assertEquals("shipOrder", activityEvent.getActivityId());
assertEquals(processInstance.getId(), activityEvent.getExecutionId());
assertEquals(processInstance.getProcessInstanceId(), activityEvent.getProcessInstanceId());
assertEquals(processInstance.getProcessDefinitionId(), activityEvent.getProcessDefinitionId());
// Complete usertask
listener.clearEventsReceived();
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);
taskService.complete(task.getId());
// Subprocess execution is created
Execution execution = runtimeService.createExecutionQuery().parentId(processInstance.getId()).singleResult();
assertNotNull(execution);
assertEquals(5, listener.getEventsReceived().size());
activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ACTIVITY_COMPLETED, activityEvent.getType());
assertEquals("shipOrder", activityEvent.getActivityId());
assertEquals(processInstance.getId(), activityEvent.getExecutionId());
assertEquals(processInstance.getProcessInstanceId(), activityEvent.getProcessInstanceId());
assertEquals(processInstance.getProcessDefinitionId(), activityEvent.getProcessDefinitionId());
activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ACTIVITY_STARTED, activityEvent.getType());
assertEquals("subProcess", activityEvent.getActivityId());
assertEquals(execution.getId(), activityEvent.getExecutionId());
assertEquals(processInstance.getProcessInstanceId(), activityEvent.getProcessInstanceId());
assertEquals(processInstance.getProcessDefinitionId(), activityEvent.getProcessDefinitionId());
activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(2);
assertEquals(ActivitiEventType.ACTIVITY_STARTED, activityEvent.getType());
assertEquals("subProcessStart", activityEvent.getActivityId());
assertEquals(execution.getId(), activityEvent.getExecutionId());
assertEquals(processInstance.getProcessInstanceId(), activityEvent.getProcessInstanceId());
assertEquals(processInstance.getProcessDefinitionId(), activityEvent.getProcessDefinitionId());
activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(3);
assertEquals(ActivitiEventType.ACTIVITY_COMPLETED, activityEvent.getType());
assertEquals("subProcessStart", activityEvent.getActivityId());
assertEquals(execution.getId(), activityEvent.getExecutionId());
assertEquals(processInstance.getProcessInstanceId(), activityEvent.getProcessInstanceId());
assertEquals(processInstance.getProcessDefinitionId(), activityEvent.getProcessDefinitionId());
activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(4);
assertEquals(ActivitiEventType.ACTIVITY_STARTED, activityEvent.getType());
assertEquals("subTask", activityEvent.getActivityId());
assertEquals(execution.getId(), activityEvent.getExecutionId());
assertEquals(processInstance.getProcessInstanceId(), activityEvent.getProcessInstanceId());
assertEquals(processInstance.getProcessDefinitionId(), activityEvent.getProcessDefinitionId());
listener.clearEventsReceived();
// Check gateway and intermediate throw event
Task subTask = taskService.createTaskQuery().executionId(execution.getId()).singleResult();
assertNotNull(subTask);
taskService.complete(subTask.getId());
assertEquals(10, listener.getEventsReceived().size());
activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ACTIVITY_COMPLETED, activityEvent.getType());
assertEquals("subTask", activityEvent.getActivityId());
activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ACTIVITY_STARTED, activityEvent.getType());
assertEquals("gateway", activityEvent.getActivityId());
activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(2);
assertEquals(ActivitiEventType.ACTIVITY_COMPLETED, activityEvent.getType());
assertEquals("gateway", activityEvent.getActivityId());
activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(3);
assertEquals(ActivitiEventType.ACTIVITY_STARTED, activityEvent.getType());
assertEquals("throwMessageEvent", activityEvent.getActivityId());
activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(4);
assertEquals(ActivitiEventType.ACTIVITY_COMPLETED, activityEvent.getType());
assertEquals("throwMessageEvent", activityEvent.getActivityId());
activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(5);
assertEquals(ActivitiEventType.ACTIVITY_STARTED, activityEvent.getType());
assertEquals("endSubProcess", activityEvent.getActivityId());
activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(6);
assertEquals(ActivitiEventType.ACTIVITY_COMPLETED, activityEvent.getType());
assertEquals("endSubProcess", activityEvent.getActivityId());
activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(7);
assertEquals(ActivitiEventType.ACTIVITY_COMPLETED, activityEvent.getType());
assertEquals("subProcess", activityEvent.getActivityId());
activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(8);
assertEquals(ActivitiEventType.ACTIVITY_STARTED, activityEvent.getType());
assertEquals("theEnd", activityEvent.getActivityId());
activityEvent = (ActivitiActivityEvent) listener.getEventsReceived().get(9);
assertEquals(ActivitiEventType.ACTIVITY_COMPLETED, activityEvent.getType());
assertEquals("theEnd", activityEvent.getActivityId());
}
use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.
the class ActivityEventsTest method testActivityMessageBoundaryEventsOnSubProcess.
/**
* Test events related to message events, called from the API.
*/
@Deployment
public void testActivityMessageBoundaryEventsOnSubProcess() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("messageOnSubProcess");
assertNotNull(processInstance);
Execution executionWithMessage = runtimeService.createExecutionQuery().activityId("cloudformtask1").singleResult();
assertNotNull(executionWithMessage);
runtimeService.messageEventReceived("message_1", executionWithMessage.getId());
assertEquals(2, listener.getEventsReceived().size());
// First, a message-event is expected
assertTrue(listener.getEventsReceived().get(0) instanceof ActivitiMessageEvent);
ActivitiMessageEvent messageEvent = (ActivitiMessageEvent) listener.getEventsReceived().get(0);
assertEquals(ActivitiEventType.ACTIVITY_MESSAGE_RECEIVED, messageEvent.getType());
assertEquals("boundaryMessageEventCatching", messageEvent.getActivityId());
assertEquals(executionWithMessage.getId(), messageEvent.getExecutionId());
assertEquals(executionWithMessage.getProcessInstanceId(), messageEvent.getProcessInstanceId());
assertEquals(processInstance.getProcessDefinitionId(), messageEvent.getProcessDefinitionId());
assertEquals("message_1", messageEvent.getMessageName());
assertNull(messageEvent.getMessageData());
// Next, an signal-event is expected, as a result of the message
assertTrue(listener.getEventsReceived().get(1) instanceof ActivitiActivityCancelledEvent);
ActivitiActivityCancelledEvent signalEvent = (ActivitiActivityCancelledEvent) listener.getEventsReceived().get(1);
assertEquals(ActivitiEventType.ACTIVITY_CANCELLED, signalEvent.getType());
assertEquals("cloudformtask1", signalEvent.getActivityId());
assertEquals(executionWithMessage.getId(), signalEvent.getExecutionId());
assertEquals(executionWithMessage.getProcessInstanceId(), signalEvent.getProcessInstanceId());
assertEquals(processInstance.getProcessDefinitionId(), signalEvent.getProcessDefinitionId());
assertNotNull(signalEvent.getCause());
assertTrue(signalEvent.getCause() instanceof MessageEventSubscriptionEntity);
MessageEventSubscriptionEntity cause = (MessageEventSubscriptionEntity) signalEvent.getCause();
assertEquals("message_1", cause.getEventName());
assertDatabaseEventPresent(ActivitiEventType.ACTIVITY_MESSAGE_RECEIVED);
}
use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.
the class RuntimeServiceTest method testExecutionWaitingForDifferentSignal.
@Deployment(resources = { "org/activiti/engine/test/api/runtime/RuntimeServiceTest.catchAlertSignal.bpmn20.xml" })
public void testExecutionWaitingForDifferentSignal() {
runtimeService.startProcessInstanceByKey("catchAlertSignal");
Execution execution = runtimeService.createExecutionQuery().signalEventSubscriptionName("alert").singleResult();
try {
runtimeService.signalEventReceived("bogusSignal", execution.getId());
fail("exeception expected");
} catch (ActivitiException e) {
// this is good
}
}
use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.
the class RuntimeVariablesTest method testGetVariablesByExecutionIdsForScope.
@Deployment(resources = { "org/activiti/engine/test/api/runtime/variableScope.bpmn20.xml" })
public void testGetVariablesByExecutionIdsForScope() {
Map<String, Object> processVars = new HashMap<String, Object>();
processVars.put("processVar", "processVar");
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("variableScopeProcess", processVars);
Set<String> executionIds = new HashSet<String>();
List<Execution> executions = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).list();
for (Execution execution : executions) {
if (!processInstance.getId().equals(execution.getId())) {
executionIds.add(execution.getId());
runtimeService.setVariableLocal(execution.getId(), "executionVar", "executionVar");
}
}
List<Task> tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
Set<String> taskIds = new HashSet<String>();
for (Task task : tasks) {
taskService.setVariableLocal(task.getId(), "taskVar", "taskVar");
taskIds.add(task.getId());
}
List<VariableInstance> executionVariableInstances = runtimeService.getVariableInstancesByExecutionIds(executionIds);
assertEquals(executionVariableInstances.size(), 2);
assertEquals(executionVariableInstances.get(0).getName(), "executionVar");
assertEquals(executionVariableInstances.get(0).getValue(), "executionVar");
assertEquals(executionVariableInstances.get(1).getName(), "executionVar");
assertEquals(executionVariableInstances.get(1).getValue(), "executionVar");
executionIds = new HashSet<String>();
executionIds.add(processInstance.getId());
executionVariableInstances = runtimeService.getVariableInstancesByExecutionIds(executionIds);
assertEquals(executionVariableInstances.size(), 1);
assertEquals(executionVariableInstances.get(0).getName(), "processVar");
assertEquals(executionVariableInstances.get(0).getValue(), "processVar");
}
use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.
the class ExecutionQueryTest method testQueryLongVariable.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryLongVariable() {
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("longVar", 12345L);
ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
vars = new HashMap<String, Object>();
vars.put("longVar", 12345L);
vars.put("longVar2", 67890L);
ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
vars = new HashMap<String, Object>();
vars.put("longVar", 55555L);
ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
// Query on single long variable, should result in 2 matches
ExecutionQuery query = runtimeService.createExecutionQuery().variableValueEquals("longVar", 12345L);
List<Execution> executions = query.list();
assertNotNull(executions);
assertEquals(2, executions.size());
// Query on two long variables, should result in single match
query = runtimeService.createExecutionQuery().variableValueEquals("longVar", 12345L).variableValueEquals("longVar2", 67890L);
Execution execution = query.singleResult();
assertNotNull(execution);
assertEquals(processInstance2.getId(), execution.getId());
// Query with unexisting variable value
execution = runtimeService.createExecutionQuery().variableValueEquals("longVar", 999L).singleResult();
assertNull(execution);
// Test NOT_EQUALS
execution = runtimeService.createExecutionQuery().variableValueNotEquals("longVar", 12345L).singleResult();
assertNotNull(execution);
assertEquals(processInstance3.getId(), execution.getId());
// Test GREATER_THAN
execution = runtimeService.createExecutionQuery().variableValueGreaterThan("longVar", 44444L).singleResult();
assertNotNull(execution);
assertEquals(processInstance3.getId(), execution.getId());
assertEquals(0, runtimeService.createExecutionQuery().variableValueGreaterThan("longVar", 55555L).count());
assertEquals(3, runtimeService.createExecutionQuery().variableValueGreaterThan("longVar", 1L).count());
// Test GREATER_THAN_OR_EQUAL
execution = runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("longVar", 44444L).singleResult();
assertNotNull(execution);
assertEquals(processInstance3.getId(), execution.getId());
execution = runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("longVar", 55555L).singleResult();
assertNotNull(execution);
assertEquals(processInstance3.getId(), execution.getId());
assertEquals(3, runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("longVar", 1L).count());
// Test LESS_THAN
executions = runtimeService.createExecutionQuery().variableValueLessThan("longVar", 55555L).list();
assertEquals(2, executions.size());
List<String> expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId());
List<String> ids = new ArrayList<String>(Arrays.asList(executions.get(0).getId(), executions.get(1).getId()));
ids.removeAll(expecedIds);
assertTrue(ids.isEmpty());
assertEquals(0, runtimeService.createExecutionQuery().variableValueLessThan("longVar", 12345L).count());
assertEquals(3, runtimeService.createExecutionQuery().variableValueLessThan("longVar", 66666L).count());
// Test LESS_THAN_OR_EQUAL
executions = runtimeService.createExecutionQuery().variableValueLessThanOrEqual("longVar", 55555L).list();
assertEquals(3, executions.size());
assertEquals(0, runtimeService.createExecutionQuery().variableValueLessThanOrEqual("longVar", 12344L).count());
// Test value-only matching
execution = runtimeService.createExecutionQuery().variableValueEquals(55555L).singleResult();
assertNotNull(execution);
assertEquals(processInstance3.getId(), execution.getId());
executions = runtimeService.createExecutionQuery().variableValueEquals(12345L).list();
assertEquals(2, executions.size());
expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId());
ids = new ArrayList<String>(Arrays.asList(executions.get(0).getId(), executions.get(1).getId()));
ids.removeAll(expecedIds);
assertTrue(ids.isEmpty());
execution = runtimeService.createExecutionQuery().variableValueEquals(99999L).singleResult();
assertNull(execution);
runtimeService.deleteProcessInstance(processInstance1.getId(), "test");
runtimeService.deleteProcessInstance(processInstance2.getId(), "test");
runtimeService.deleteProcessInstance(processInstance3.getId(), "test");
}
Aggregations