use of org.activiti.engine.runtime.ProcessInstance in project Activiti by Activiti.
the class MultiInstanceTest method testParalellEmptyCollection.
@Deployment(resources = { "org/activiti/engine/test/bpmn/multiinstance/MultiInstanceTest.testParallelEmptyCollection.bpmn20.xml" })
public void testParalellEmptyCollection() throws Exception {
Collection<String> collection = Collections.emptyList();
Map<String, Object> variableMap = new HashMap<String, Object>();
variableMap.put("collection", collection);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testParalellEmptyCollection", variableMap);
assertNotNull(processInstance);
Task task = taskService.createTaskQuery().singleResult();
assertNull(task);
assertProcessEnded(processInstance.getId());
}
use of org.activiti.engine.runtime.ProcessInstance in project Activiti by Activiti.
the class MultiInstanceTest method testSequentialSubprocessEmptyCollection.
@Deployment(resources = { "org/activiti/engine/test/bpmn/multiinstance/MultiInstanceTest.testSequentialSubprocessEmptyCollection.bpmn20.xml" })
public void testSequentialSubprocessEmptyCollection() {
Collection<String> collection = Collections.emptyList();
Map<String, Object> variableMap = new HashMap<String, Object>();
variableMap.put("collection", collection);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testSequentialSubProcessEmptyCollection", variableMap);
assertNotNull(processInstance);
Task task = taskService.createTaskQuery().singleResult();
assertNull(task);
assertProcessEnded(processInstance.getId());
}
use of org.activiti.engine.runtime.ProcessInstance in project Activiti by Activiti.
the class SubProcessTest method IGNORE_testSimpleSubProcessWithConcurrentTimer.
/**
* A test case that has a timer attached to the subprocess,
* where 2 concurrent paths are defined when the timer fires.
*/
@Deployment
public void IGNORE_testSimpleSubProcessWithConcurrentTimer() {
// After staring the process, the task in the subprocess should be active
ProcessInstance pi = runtimeService.startProcessInstanceByKey("simpleSubProcessWithConcurrentTimer");
TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(pi.getId()).orderByTaskName().asc();
Task subProcessTask = taskQuery.singleResult();
assertEquals("Task in subprocess", subProcessTask.getName());
// When the timer is fired (after 2 hours), two concurrent paths should be created
Job job = managementService.createJobQuery().singleResult();
managementService.executeJob(job.getId());
List<Task> tasksAfterTimer = taskQuery.list();
assertEquals(2, tasksAfterTimer.size());
Task taskAfterTimer1 = tasksAfterTimer.get(0);
Task taskAfterTimer2 = tasksAfterTimer.get(1);
assertEquals("Task after timer 1", taskAfterTimer1.getName());
assertEquals("Task after timer 2", taskAfterTimer2.getName());
// Completing the two tasks should end the process instance
taskService.complete(taskAfterTimer1.getId());
taskService.complete(taskAfterTimer2.getId());
assertProcessEnded(pi.getId());
}
use of org.activiti.engine.runtime.ProcessInstance in project Activiti by Activiti.
the class TransactionSubProcessTest method testCancelEndConcurrent.
@Deployment
public void testCancelEndConcurrent() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("transactionProcess");
// after the process is started, we have compensate event subscriptions:
assertEquals(5, createEventSubscriptionQuery().eventType("compensate").activityId("undoBookHotel").count());
assertEquals(1, createEventSubscriptionQuery().eventType("compensate").activityId("undoBookFlight").count());
// the task is present:
Task task = taskService.createTaskQuery().singleResult();
assertNotNull(task);
// making the tx fail:
taskService.setVariable(task.getId(), "confirmed", false);
taskService.complete(task.getId());
// now the process instance execution is sitting in the 'afterCancellation' task
// -> has left the transaction using the cancel boundary event
List<String> activeActivityIds = runtimeService.getActiveActivityIds(processInstance.getId());
assertTrue(activeActivityIds.contains("afterCancellation"));
// we have no more compensate event subscriptions
assertEquals(0, createEventSubscriptionQuery().eventType("compensate").count());
// assert that the compensation handlers have been invoked:
assertEquals(5, runtimeService.getVariable(processInstance.getId(), "undoBookHotel"));
assertEquals(1, runtimeService.getVariable(processInstance.getId(), "undoBookFlight"));
// if we have history, we check that the invocation of the compensation handlers is recorded in history.
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
assertEquals(1, historyService.createHistoricActivityInstanceQuery().activityId("undoBookFlight").count());
assertEquals(5, historyService.createHistoricActivityInstanceQuery().activityId("undoBookHotel").count());
}
// end the process instance
runtimeService.signal(processInstance.getId());
assertProcessEnded(processInstance.getId());
assertEquals(0, runtimeService.createExecutionQuery().count());
}
use of org.activiti.engine.runtime.ProcessInstance in project Activiti by Activiti.
the class TransactionSubProcessTest method testSimpleCaseTxSuccessful.
@Deployment(resources = { "org/activiti/engine/test/bpmn/subprocess/transaction/TransactionSubProcessTest.testSimpleCase.bpmn20.xml" })
public void testSimpleCaseTxSuccessful() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("transactionProcess");
// after the process is started, we have compensate event subscriptions:
assertEquals(5, createEventSubscriptionQuery().eventType("compensate").activityId("undoBookHotel").count());
assertEquals(1, createEventSubscriptionQuery().eventType("compensate").activityId("undoBookFlight").count());
// the task is present:
Task task = taskService.createTaskQuery().singleResult();
assertNotNull(task);
// making the tx succeed:
taskService.setVariable(task.getId(), "confirmed", true);
taskService.complete(task.getId());
// now the process instance execution is sitting in the 'afterSuccess' task
// -> has left the transaction using the "normal" sequence flow
List<String> activeActivityIds = runtimeService.getActiveActivityIds(processInstance.getId());
assertTrue(activeActivityIds.contains("afterSuccess"));
// there is a compensate event subscription for the transaction under the process instance
EventSubscriptionEntity eventSubscriptionEntity = createEventSubscriptionQuery().eventType("compensate").activityId("tx").executionId(processInstance.getId()).singleResult();
// there is an event-scope execution associated with the event-subscription:
assertNotNull(eventSubscriptionEntity.getConfiguration());
Execution eventScopeExecution = runtimeService.createExecutionQuery().executionId(eventSubscriptionEntity.getConfiguration()).singleResult();
assertNotNull(eventScopeExecution);
// we still have compensate event subscriptions for the compensation handlers, only now they are part of the event scope
assertEquals(5, createEventSubscriptionQuery().eventType("compensate").activityId("undoBookHotel").executionId(eventScopeExecution.getId()).count());
assertEquals(1, createEventSubscriptionQuery().eventType("compensate").activityId("undoBookFlight").executionId(eventScopeExecution.getId()).count());
assertEquals(1, createEventSubscriptionQuery().eventType("compensate").activityId("undoChargeCard").executionId(eventScopeExecution.getId()).count());
// assert that the compensation handlers have not been invoked:
assertNull(runtimeService.getVariable(processInstance.getId(), "undoBookHotel"));
assertNull(runtimeService.getVariable(processInstance.getId(), "undoBookFlight"));
assertNull(runtimeService.getVariable(processInstance.getId(), "undoChargeCard"));
// end the process instance
runtimeService.signal(processInstance.getId());
assertProcessEnded(processInstance.getId());
assertEquals(0, runtimeService.createExecutionQuery().count());
}
Aggregations