use of org.camunda.bpm.engine.runtime.ActivityInstance in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method testCompleteWithVariables.
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/twoExternalTaskProcess.bpmn20.xml")
public void testCompleteWithVariables() {
// given
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("twoExternalTaskProcess");
// when
List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
externalTaskService.complete(externalTasks.get(0).getId(), WORKER_ID, Variables.createVariables().putValue("var", 42));
// then
ActivityInstance activityInstance = runtimeService.getActivityInstance(processInstance.getId());
assertThat(activityInstance).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).activity("afterExternalTask").done());
assertEquals(42, runtimeService.getVariable(processInstance.getId(), "var"));
}
use of org.camunda.bpm.engine.runtime.ActivityInstance in project camunda-bpm-platform by camunda.
the class ProcessInstanceModificationTest method testStartBeforeWithVariables.
@Deployment(resources = EXCLUSIVE_GATEWAY_PROCESS)
public void testStartBeforeWithVariables() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("exclusiveGateway");
runtimeService.createProcessInstanceModification(processInstance.getId()).startBeforeActivity("task2").setVariable("procInstVar", "procInstValue").setVariableLocal("localVar", "localValue").setVariables(Variables.createVariables().putValue("procInstMapVar", "procInstMapValue")).setVariablesLocal(Variables.createVariables().putValue("localMapVar", "localMapValue")).execute();
ActivityInstance updatedTree = runtimeService.getActivityInstance(processInstance.getId());
assertNotNull(updatedTree);
assertThat(updatedTree).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).activity("task1").activity("task2").done());
ActivityInstance task2Instance = getChildInstanceForActivity(updatedTree, "task2");
assertNotNull(task2Instance);
assertEquals(1, task2Instance.getExecutionIds().length);
String task2ExecutionId = task2Instance.getExecutionIds()[0];
assertEquals(4, runtimeService.createVariableInstanceQuery().count());
assertEquals("procInstValue", runtimeService.getVariableLocal(processInstance.getId(), "procInstVar"));
assertEquals("localValue", runtimeService.getVariableLocal(task2ExecutionId, "localVar"));
assertEquals("procInstMapValue", runtimeService.getVariableLocal(processInstance.getId(), "procInstMapVar"));
assertEquals("localMapValue", runtimeService.getVariableLocal(task2ExecutionId, "localMapVar"));
completeTasksInOrder("task1", "task2");
assertProcessEnded(processInstance.getId());
}
use of org.camunda.bpm.engine.runtime.ActivityInstance in project camunda-bpm-platform by camunda.
the class ProcessInstanceModificationTest method testScopeTaskStartAfter.
@Deployment(resources = ONE_SCOPE_TASK_PROCESS)
public void testScopeTaskStartAfter() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
String processInstanceId = processInstance.getId();
// when starting after the task, essentially nothing changes in the process
// instance
runtimeService.createProcessInstanceModification(processInstance.getId()).startAfterActivity("theTask").execute();
ActivityInstance updatedTree = runtimeService.getActivityInstance(processInstanceId);
assertNotNull(updatedTree);
assertEquals(processInstanceId, updatedTree.getProcessInstanceId());
assertThat(updatedTree).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).activity("theTask").done());
ExecutionTree executionTree = ExecutionTree.forExecution(processInstanceId, processEngine);
assertThat(executionTree).matches(describeExecutionTree(null).scope().child("theTask").scope().done());
// when starting after the start event, regular concurrency happens
runtimeService.createProcessInstanceModification(processInstance.getId()).startAfterActivity("theStart").execute();
updatedTree = runtimeService.getActivityInstance(processInstanceId);
assertNotNull(updatedTree);
assertEquals(processInstanceId, updatedTree.getProcessInstanceId());
assertThat(updatedTree).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).activity("theTask").activity("theTask").done());
executionTree = ExecutionTree.forExecution(processInstanceId, processEngine);
assertThat(executionTree).matches(describeExecutionTree(null).scope().child(null).concurrent().noScope().child("theTask").scope().up().up().child(null).concurrent().noScope().child("theTask").scope().done());
completeTasksInOrder("theTask", "theTask");
assertProcessEnded(processInstanceId);
}
use of org.camunda.bpm.engine.runtime.ActivityInstance in project camunda-bpm-platform by camunda.
the class ProcessInstanceModificationTest method testStartBeforeWithAncestorInstanceIdTwoScopesUp.
@Deployment(resources = DOUBLE_NESTED_SUB_PROCESS)
public void testStartBeforeWithAncestorInstanceIdTwoScopesUp() {
// given two instances of the outer subprocess
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("doubleNestedSubprocess");
String processInstanceId = processInstance.getId();
runtimeService.createProcessInstanceModification(processInstance.getId()).startBeforeActivity("subProcess").execute();
// when I start the inner subprocess task without explicit ancestor
try {
runtimeService.createProcessInstanceModification(processInstance.getId()).startBeforeActivity("innerSubProcessTask").execute();
// then the command fails
fail("should not succeed because the ancestors are ambiguous");
} catch (ProcessEngineException e) {
// happy path
}
// when I start the inner subprocess task with an explicit ancestor activity
// instance id
ActivityInstance updatedTree = runtimeService.getActivityInstance(processInstanceId);
ActivityInstance randomSubProcessInstance = getChildInstanceForActivity(updatedTree, "subProcess");
// then the command suceeds
runtimeService.createProcessInstanceModification(processInstanceId).startBeforeActivity("innerSubProcessTask", randomSubProcessInstance.getId()).execute();
// and the trees are correct
updatedTree = runtimeService.getActivityInstance(processInstanceId);
assertNotNull(updatedTree);
assertEquals(processInstanceId, updatedTree.getProcessInstanceId());
assertThat(updatedTree).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).beginScope("subProcess").activity("subProcessTask").endScope().beginScope("subProcess").activity("subProcessTask").beginScope("innerSubProcess").activity("innerSubProcessTask").done());
ActivityInstance innerSubProcessInstance = getChildInstanceForActivity(updatedTree, "innerSubProcess");
assertEquals(randomSubProcessInstance.getId(), innerSubProcessInstance.getParentActivityInstanceId());
ExecutionTree executionTree = ExecutionTree.forExecution(processInstanceId, processEngine);
assertThat(executionTree).matches(describeExecutionTree(null).scope().child(null).concurrent().noScope().child("subProcessTask").scope().up().up().child(null).concurrent().noScope().child(null).scope().child("subProcessTask").concurrent().noScope().up().child(null).concurrent().noScope().child("innerSubProcessTask").scope().done());
assertEquals(3, taskService.createTaskQuery().count());
// complete the process
completeTasksInOrder("subProcessTask", "subProcessTask", "innerSubProcessTask", "innerSubProcessTask", "innerSubProcessTask");
assertProcessEnded(processInstanceId);
}
use of org.camunda.bpm.engine.runtime.ActivityInstance in project camunda-bpm-platform by camunda.
the class ProcessInstanceModificationTest method testStartTransition.
@Deployment(resources = EXCLUSIVE_GATEWAY_PROCESS)
public void testStartTransition() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("exclusiveGateway");
String processInstanceId = processInstance.getId();
runtimeService.createProcessInstanceModification(processInstance.getId()).startTransition("flow4").execute();
ActivityInstance updatedTree = runtimeService.getActivityInstance(processInstanceId);
assertNotNull(updatedTree);
assertEquals(processInstanceId, updatedTree.getProcessInstanceId());
assertThat(updatedTree).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).activity("task1").activity("task2").done());
ExecutionTree executionTree = ExecutionTree.forExecution(processInstanceId, processEngine);
assertThat(executionTree).matches(describeExecutionTree(null).scope().child("task1").concurrent().noScope().up().child("task2").concurrent().noScope().done());
assertEquals(2, taskService.createTaskQuery().count());
// complete the process
completeTasksInOrder("task1", "task2");
assertProcessEnded(processInstanceId);
}
Aggregations