use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.
the class CreateProcessInstanceWithJsonVariablesScenario method initProcessInstance.
@DescribesScenario("initProcessInstanceWithDifferentVariables")
public static ScenarioSetup initProcessInstance() {
return new ScenarioSetup() {
public void execute(ProcessEngine engine, String scenarioName) {
// given
ProcessInstance processInstance = engine.getRuntimeService().startProcessInstanceByKey("Process", "processWithJsonVariables");
// when
Execution execution = engine.getRuntimeService().createExecutionQuery().processInstanceId(processInstance.getId()).singleResult();
engine.getRuntimeService().setVariable(execution.getId(), "objectVariable", createObjectVariable());
engine.getRuntimeService().setVariable(execution.getId(), "plainTypeArrayVariable", createPlainTypeArray());
engine.getRuntimeService().setVariable(execution.getId(), "notGenericObjectListVariable", createNotGenericObjectList());
engine.getRuntimeService().setVariable(execution.getId(), "serializedMapVariable", createSerializedMap());
}
};
}
use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.
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, runtimeService.createEventSubscriptionQuery().eventType("compensate").activityId("undoBookHotel").count());
assertEquals(1, runtimeService.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());
// we have no more compensate event subscriptions
assertEquals(0, runtimeService.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"));
// signal compensation handler completion
List<Execution> compensationHandlerExecutions = collectExecutionsFor("undoBookHotel", "undoBookFlight");
for (Execution execution : compensationHandlerExecutions) {
runtimeService.signal(execution.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"));
// if we have history, we check that the invocation of the compensation handlers is recorded in history.
if (!processEngineConfiguration.getHistory().equals(ProcessEngineConfiguration.HISTORY_NONE)) {
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.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.
the class TransactionSubProcessTest method testSimpleCaseTxSuccessful.
@Deployment(resources = { "org/camunda/bpm/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, runtimeService.createEventSubscriptionQuery().eventType("compensate").activityId("undoBookHotel").count());
assertEquals(1, runtimeService.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 = (EventSubscriptionEntity) runtimeService.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);
// there is a compensate event subscription for the miBody of 'bookHotel' activity
EventSubscriptionEntity miBodyEventSubscriptionEntity = (EventSubscriptionEntity) runtimeService.createEventSubscriptionQuery().eventType("compensate").activityId("bookHotel" + BpmnParse.MULTI_INSTANCE_BODY_ID_SUFFIX).executionId(eventScopeExecution.getId()).singleResult();
assertNotNull(miBodyEventSubscriptionEntity);
String miBodyEventScopeExecutionId = miBodyEventSubscriptionEntity.getConfiguration();
// we still have compensate event subscriptions for the compensation handlers, only now they are part of the event scope
assertEquals(5, runtimeService.createEventSubscriptionQuery().eventType("compensate").activityId("undoBookHotel").executionId(miBodyEventScopeExecutionId).count());
assertEquals(1, runtimeService.createEventSubscriptionQuery().eventType("compensate").activityId("undoBookFlight").executionId(eventScopeExecution.getId()).count());
assertEquals(1, runtimeService.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());
}
use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.
the class InputOutputEventTest method testMessageCatchEvent.
@Deployment
public void testMessageCatchEvent() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess");
Execution messageExecution = runtimeService.createExecutionQuery().activityId("messageCatch").singleResult();
Map<String, Object> localVariables = runtimeService.getVariablesLocal(messageExecution.getId());
assertEquals(1, localVariables.size());
assertEquals("mappedValue", localVariables.get("mappedVariable"));
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("messageVariable", "outValue");
runtimeService.messageEventReceived("IncomingMessage", messageExecution.getId(), variables);
// output mapping
String variable = (String) runtimeService.getVariableLocal(processInstance.getId(), "outVariable");
assertEquals("outValue", variable);
}
use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.
the class MultiInstanceTest method testParallelScriptTasksCompletionCondition.
@Deployment
public void testParallelScriptTasksCompletionCondition() {
runtimeService.startProcessInstanceByKey("miParallelScriptTaskCompletionCondition");
Execution waitStateExecution = runtimeService.createExecutionQuery().singleResult();
int sum = (Integer) runtimeService.getVariable(waitStateExecution.getId(), "sum");
assertEquals(2, sum);
}
Aggregations