use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.
the class IntermediateConditionalEventTest method testVariableConditionWithVariableName.
@Test
public void testVariableConditionWithVariableName() {
// given process with boundary conditional event and defined variable name
final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY).startEvent().intermediateCatchEvent(CONDITIONAL_EVENT).conditionalEventDefinition().condition(CONDITION_EXPR).camundaVariableName(VARIABLE_NAME).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 `variable1` is set on execution
runtimeService.setVariable(procInst.getId(), VARIABLE_NAME + 1, 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 set on execution
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 testEventBasedGatewayWith2ConditionsOneIsTrue.
@Test
public void testEventBasedGatewayWith2ConditionsOneIsTrue() {
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().conditionalEventDefinition().condition(CONDITION_EXPR).conditionalEventDefinitionDone().userTask().name(TASK_AFTER_CONDITION + 1).endEvent().moveToLastGateway().intermediateCatchEvent(CONDITIONAL_EVENT).conditionalEventDefinition().condition(TRUE_CONDITION).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());
Task task = taskQuery.singleResult();
// when task before condition is completed
taskService.complete(task.getId());
// then next wait state is on user task after true conditional event
Execution execution = runtimeService.createExecutionQuery().processInstanceId(procInst.getId()).activityId(EVENT_BASED_GATEWAY_ID).singleResult();
assertNull(execution);
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 AsyncTaskTest method testFailingAsyncServiceTimer.
@Deployment
public void testFailingAsyncServiceTimer() {
// start process
runtimeService.startProcessInstanceByKey("asyncService");
// now there should be one job in the database, and it is a message
assertEquals(1, managementService.createJobQuery().count());
Job job = managementService.createJobQuery().singleResult();
if (!(job instanceof MessageEntity)) {
fail("the job must be a message");
}
executeAvailableJobs();
// the service failed: the execution is still sitting in the service task:
Execution execution = runtimeService.createExecutionQuery().singleResult();
assertNotNull(execution);
assertEquals("service", runtimeService.getActiveActivityIds(execution.getId()).get(0));
// there is still a single job because the timer was created in the same transaction as the
// service was executed (which rolled back)
assertEquals(1, managementService.createJobQuery().count());
runtimeService.deleteProcessInstance(execution.getId(), "dead");
}
use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.
the class AsyncTaskTest method FAILING_testFailingAsyncServiceTimer.
// TODO: Think about this:
@Deployment
public void FAILING_testFailingAsyncServiceTimer() {
// start process
runtimeService.startProcessInstanceByKey("asyncService");
// now there are two jobs the message and a timer:
assertEquals(2, managementService.createJobQuery().count());
// let 'max-retires' on the message be reached
executeAvailableJobs();
// the service failed: the execution is still sitting in the service task:
Execution execution = runtimeService.createExecutionQuery().singleResult();
assertNotNull(execution);
assertEquals("service", runtimeService.getActiveActivityIds(execution.getId()).get(0));
// there are two jobs, the message and the timer (the message will not be retried anymore, max retires is reached.)
assertEquals(2, managementService.createJobQuery().count());
// now the timer triggers:
ClockUtil.setCurrentTime(new Date(System.currentTimeMillis() + 10000));
executeAvailableJobs();
// and we are done:
assertNull(runtimeService.createExecutionQuery().singleResult());
// and there are no more jobs left:
assertEquals(0, managementService.createJobQuery().count());
}
use of org.camunda.bpm.engine.runtime.Execution in project camunda-bpm-platform by camunda.
the class BoundaryErrorEventTest method testCatchExceptionThrownBySignalMethodOfAbstractBpmnActivityBehavior.
@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/event/error/BoundaryErrorEventTest.testCatchErrorThrownByAbstractBpmnActivityBehavior.bpmn20.xml" })
public void testCatchExceptionThrownBySignalMethodOfAbstractBpmnActivityBehavior() {
String pi = runtimeService.startProcessInstanceByKey("testProcess").getId();
assertTrue((Boolean) runtimeService.getVariable(pi, "executed"));
assertNull(runtimeService.getVariable(pi, "signaled"));
Execution serviceTask = runtimeService.createExecutionQuery().processInstanceId(pi).activityId("serviceTask").singleResult();
assertNotNull(serviceTask);
runtimeService.setVariables(pi, throwException());
runtimeService.signal(serviceTask.getId());
assertTrue((Boolean) runtimeService.getVariable(pi, "executed"));
assertTrue((Boolean) runtimeService.getVariable(pi, "signaled"));
Task userTask = taskService.createTaskQuery().processInstanceId(pi).singleResult();
assertNotNull(userTask);
assertEquals("userTaskException", userTask.getTaskDefinitionKey());
taskService.complete(userTask.getId());
}
Aggregations