use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.
the class IntermediateConditionalEventTest method testEventBasedGatewayTrueCondition.
@Test
public void testEventBasedGatewayTrueCondition() {
BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY).startEvent().userTask(TASK_BEFORE_CONDITION_ID).name(TASK_BEFORE_CONDITION).eventBasedGateway().id(EVENT_BASED_GATEWAY_ID).intermediateCatchEvent(CONDITIONAL_EVENT).conditionalEventDefinition().condition(TRUE_CONDITION).conditionalEventDefinitionDone().userTask().name(TASK_AFTER_CONDITION).endEvent().done();
engine.manageDeployment(repositoryService.createDeployment().addModelInstance(CONDITIONAL_MODEL, modelInstance).deploy());
// given
ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);
TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());
Task task = taskQuery.singleResult();
// when task before condition is completed
taskService.complete(task.getId());
// then next wait state is on user task after conditional event, since condition was true
Execution execution = runtimeService.createExecutionQuery().processInstanceId(procInst.getId()).activityId(EVENT_BASED_GATEWAY_ID).singleResult();
assertNull(execution);
task = taskQuery.singleResult();
assertNotNull(task);
assertEquals(TASK_AFTER_CONDITION, task.getName());
}
use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.
the class IntermediateConditionalEventTest method testTrueCondition.
@Test
@Deployment
public void testTrueCondition() {
// given process with intermediate conditional event
ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);
TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());
Task task = taskQuery.singleResult();
assertNotNull(task);
assertEquals(TASK_BEFORE_CONDITION, task.getName());
// when task before condition is completed
taskService.complete(task.getId());
// then next wait state is on user task after conditional event, since condition was true
Execution execution = runtimeService.createExecutionQuery().processInstanceId(procInst.getId()).activityId(CONDITIONAL_EVENT).singleResult();
assertNull(execution);
task = taskQuery.singleResult();
assertNotNull(task);
assertEquals(TASK_AFTER_CONDITION, task.getName());
}
use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.
the class IntermediateConditionalEventTest method testVariableConditionWithVariableNameAndEvent.
@Test
public void testVariableConditionWithVariableNameAndEvent() {
// given process with boundary conditional event and defined variable name and event
final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY).startEvent().intermediateCatchEvent(CONDITIONAL_EVENT).conditionalEventDefinition().condition(CONDITION_EXPR).camundaVariableName(VARIABLE_NAME).camundaVariableEvents(CONDITIONAL_VAR_EVENT_UPDATE).conditionalEventDefinitionDone().userTask().name(TASK_AFTER_CONDITION).endEvent().done();
engine.manageDeployment(repositoryService.createDeployment().addModelInstance(CONDITIONAL_MODEL, modelInstance).deploy());
ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);
TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());
Execution execution = runtimeService.createExecutionQuery().processInstanceId(procInst.getId()).activityId(CONDITIONAL_EVENT).singleResult();
assertNotNull(execution);
assertEquals(1, conditionEventSubscriptionQuery.list().size());
// when variable with name `variable` is set on execution
runtimeService.setVariable(procInst.getId(), VARIABLE_NAME, 1);
// then nothing happens
execution = runtimeService.createExecutionQuery().processInstanceId(procInst.getId()).activityId(CONDITIONAL_EVENT).singleResult();
assertNotNull(execution);
assertEquals(1, conditionEventSubscriptionQuery.list().size());
// when variable with name `variable` is updated
runtimeService.setVariable(procInst.getId(), VARIABLE_NAME, 1);
// then execution is at user task after conditional intermediate event
Task task = taskQuery.singleResult();
assertEquals(TASK_AFTER_CONDITION, task.getName());
assertEquals(0, conditionEventSubscriptionQuery.list().size());
// and task can be completed which ends process instance
taskService.complete(task.getId());
assertNull(taskService.createTaskQuery().singleResult());
assertNull(runtimeService.createProcessInstanceQuery().singleResult());
}
use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.
the class IntermediateConditionalEventTest method testEventBasedGatewayWith2VarConditions.
@Test
public void testEventBasedGatewayWith2VarConditions() {
BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY).startEvent().eventBasedGateway().id(EVENT_BASED_GATEWAY_ID).intermediateCatchEvent().conditionalEventDefinition().condition(CONDITION_EXPR).conditionalEventDefinitionDone().userTask().name(TASK_AFTER_CONDITION + 1).endEvent().moveToLastGateway().intermediateCatchEvent(CONDITIONAL_EVENT).conditionalEventDefinition().condition("${var==2}").conditionalEventDefinitionDone().userTask().name(TASK_AFTER_CONDITION + 2).endEvent().done();
engine.manageDeployment(repositoryService.createDeployment().addModelInstance(CONDITIONAL_MODEL, modelInstance).deploy());
// given
ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);
TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());
Execution execution = runtimeService.createExecutionQuery().processInstanceId(procInst.getId()).activityId(EVENT_BASED_GATEWAY_ID).singleResult();
assertNotNull(execution);
// when wrong value of variable `var` is set
runtimeService.setVariable(procInst.getId(), "var", 1);
// then nothing happens
execution = runtimeService.createExecutionQuery().processInstanceId(procInst.getId()).activityId(EVENT_BASED_GATEWAY_ID).singleResult();
assertNotNull(execution);
assertEquals(0, taskQuery.count());
// when right value is set
runtimeService.setVariable(procInst.getId(), "var", 2);
// then next wait state is on user task after second conditional event
Task task = taskQuery.singleResult();
assertNotNull(task);
assertEquals(TASK_AFTER_CONDITION + 2, task.getName());
}
use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.
the class IntermediateConditionalEventTest method testSubProcessVariableValue.
@Test
@Deployment
public void testSubProcessVariableValue() {
// given process with intermediate conditional event and variable with wrong value
Map<String, Object> variables = Variables.createVariables();
variables.put(VARIABLE_NAME, 0);
ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY, variables);
Execution execution = runtimeService.createExecutionQuery().processInstanceId(procInst.getId()).activityId(CONDITIONAL_EVENT).singleResult();
assertNotNull(execution);
// when variable is set to correct value
runtimeService.setVariableLocal(execution.getId(), VARIABLE_NAME, 1);
// then execution and process instance is ended, since condition was true
execution = runtimeService.createExecutionQuery().processInstanceId(procInst.getId()).activityId(CONDITIONAL_EVENT).singleResult();
assertNull(execution);
procInst = runtimeService.createProcessInstanceQuery().processDefinitionKey(CONDITIONAL_EVENT_PROCESS_KEY).singleResult();
assertNull(procInst);
}
Aggregations