Java Code Examples for org.camunda.bpm.engine.task.TaskQuery#singleResult()

The following examples show how to use org.camunda.bpm.engine.task.TaskQuery#singleResult() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CallActivityTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = {
  "org/camunda/bpm/engine/test/bpmn/callactivity/CallActivity.testCallSimpleSubProcess.bpmn20.xml",
  "org/camunda/bpm/engine/test/bpmn/callactivity/concurrentSubProcessParentVariableAccess.bpmn20.xml"
})
public void testAccessSuperInstanceVariablesFromConcurrentExecution() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("callSimpleSubProcess");

  // one task in the subprocess should be active after starting the process instance
  TaskQuery taskQuery = taskService.createTaskQuery();
  Task taskBeforeSubProcess = taskQuery.singleResult();
  assertEquals("Task before subprocess", taskBeforeSubProcess.getName());

  // the variable does not yet exist
  assertNull(runtimeService.getVariable(processInstance.getId(), "greeting"));

  // completing the task executed the sub process
  taskService.complete(taskBeforeSubProcess.getId());

  // now the variable exists
  assertEquals("hello", runtimeService.getVariable(processInstance.getId(), "greeting"));

}
 
Example 2
Source File: BoundaryConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment
public void testNonInterruptingVariableCondition() {
  //given process with boundary 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_WITH_CONDITION, task.getName());

  //when variable is set on task with condition
  taskService.setVariable(task.getId(), VARIABLE_NAME, 1);

  //then execution is at user task after boundary event and in the task with the boundary event
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(2, tasksAfterVariableIsSet.size());
}
 
Example 3
Source File: EventSubProcessStartConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources ={ "org/camunda/bpm/engine/test/bpmn/event/conditional/EventSubProcessStartConditionalEventTest.testVariableCondition.bpmn20.xml"})
public void testWrongVariableCondition() {
  //given process with event sub process conditional start 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());
  assertEquals(1, conditionEventSubscriptionQuery.list().size());

  //when variable is set on task with condition
  taskService.setVariable(task.getId(), VARIABLE_NAME+1, 1);

  //then execution stays at user task
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(TASK_BEFORE_CONDITION, tasksAfterVariableIsSet.get(0).getName());
  assertEquals(1, conditionEventSubscriptionQuery.list().size());
}
 
Example 4
Source File: InclusiveGatewayTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testJoinAfterEventBasedGatewayContainedInSubProcess() {
  // given
  TaskQuery taskQuery = taskService.createTaskQuery();

  runtimeService.startProcessInstanceByKey("process");
  Task task = taskQuery.singleResult();
  taskService.complete(task.getId());

  // assume
  assertNull(taskQuery.singleResult());

  // when
  runtimeService.correlateMessage("foo");

  // then
  task = taskQuery.singleResult();
  assertNotNull(task);
  assertEquals("taskAfterJoin", task.getTaskDefinitionKey());
}
 
Example 5
Source File: BoundaryConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetVariableInInMappingOfCallActivity() {
  engine.manageDeployment(repositoryService.createDeployment().addModelInstance(CONDITIONAL_MODEL, DELEGATED_PROCESS).deploy());

  final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
    .startEvent()
    .userTask(TASK_BEFORE_CONDITION_ID)
    .name(TASK_BEFORE_CONDITION)
    .callActivity(TASK_WITH_CONDITION_ID)
    .calledElement(DELEGATED_PROCESS_KEY)
    .camundaIn(VARIABLE_NAME, VARIABLE_NAME)
    .userTask().name(TASK_AFTER_OUTPUT_MAPPING)
    .endEvent()
    .done();
  deployConditionalBoundaryEventProcess(modelInstance, TASK_WITH_CONDITION_ID, true);

  // given
  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 is completed
  taskService.complete(task.getId());

  //then in mapping from call activity sets variable
  //-> interrupting conditional event is not triggered, since variable is only locally
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(TASK_AFTER_OUTPUT_MAPPING, tasksAfterVariableIsSet.get(0).getName());
}
 
Example 6
Source File: BoundaryConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetVariableInOutputMappingWithBoundary() {
  final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
                                                .startEvent()
                                                .userTask(TASK_BEFORE_CONDITION_ID)
                                                  .name(TASK_BEFORE_CONDITION)
                                                  .camundaOutputParameter(VARIABLE_NAME, "1")
                                                .userTask(TASK_WITH_CONDITION_ID).name(TASK_WITH_CONDITION)
                                                .endEvent()
                                                .done();
  deployConditionalBoundaryEventProcess(modelInstance, TASK_WITH_CONDITION_ID, true);

  // given
  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 is completed
  taskService.complete(task.getId());

  //then output mapping sets variable
  //boundary event is triggered by default evaluation behavior
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(TASK_AFTER_CONDITION, tasksAfterVariableIsSet.get(0).getName());
}
 
Example 7
Source File: EventSubProcessStartConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetVariableInOutputMappingOfCallActivity() {
  engine.manageDeployment(repositoryService.createDeployment().addModelInstance(CONDITIONAL_MODEL, DELEGATED_PROCESS).deploy());

  final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
                                                .startEvent()
                                                .userTask(TASK_BEFORE_CONDITION_ID)
                                                  .name(TASK_BEFORE_CONDITION)
                                                .callActivity(TASK_WITH_CONDITION_ID)
                                                  .calledElement(DELEGATED_PROCESS_KEY)
                                                  .camundaOutputParameter(VARIABLE_NAME, "1")
                                                .userTask()
                                                .endEvent()
                                                .done();
   deployConditionalEventSubProcess(modelInstance, CONDITIONAL_EVENT_PROCESS_KEY, true);

  // given
  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 is completed
  taskService.complete(task.getId());

  //then output mapping from call activity sets variable
  //-> interrupting conditional event is triggered
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(TASK_AFTER_CONDITION, tasksAfterVariableIsSet.get(0).getName());
}
 
Example 8
Source File: CallActivityTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
/**
 * Test case for checking deletion of process instancess in call activity subprocesses
 */
@Deployment(resources = {
  "org/camunda/bpm/engine/test/bpmn/callactivity/CallActivity.testCallSimpleSubProcess.bpmn20.xml",
  "org/camunda/bpm/engine/test/bpmn/callactivity/simpleSubProcess.bpmn20.xml"
})
public void testDeleteProcessInstanceInCallActivity() {
  // given
  runtimeService.startProcessInstanceByKey("callSimpleSubProcess");


  // one task in the subprocess should be active after starting the process instance
  TaskQuery taskQuery = taskService.createTaskQuery();
  Task taskBeforeSubProcess = taskQuery.singleResult();

  // Completing the task continues the process which leads to calling the subprocess
  taskService.complete(taskBeforeSubProcess.getId());
  Task taskInSubProcess = taskQuery.singleResult();


  List<ProcessInstance> instanceList = runtimeService.createProcessInstanceQuery().list();
  assertNotNull(instanceList);
  assertEquals(2, instanceList.size());


  // when
  // Delete the ProcessInstance in the sub process
  runtimeService.deleteProcessInstance(taskInSubProcess.getProcessInstanceId(), "Test upstream deletion");

  // then

  // How many process Instances
  instanceList = runtimeService.createProcessInstanceQuery().list();
  assertNotNull(instanceList);
  assertEquals(0, instanceList.size());
}
 
Example 9
Source File: BoundaryConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testNonInterruptingSetVariableInOutputMappingWithBoundary() {
  final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
                                                .startEvent()
                                                .userTask(TASK_WITH_CONDITION_ID)
                                                  .name(TASK_WITH_CONDITION)
                                                  .camundaOutputParameter(VARIABLE_NAME, "1")
                                                .userTask().name(TASK_AFTER_OUTPUT_MAPPING)
                                                .endEvent()
                                                .done();
  deployConditionalBoundaryEventProcess(modelInstance, TASK_WITH_CONDITION_ID, false);

  // given
  ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);

  TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());
  Task task = taskQuery.singleResult();
  assertNotNull(task);
  assertEquals(TASK_WITH_CONDITION, task.getName());

  //when task with output mapping is completed
  taskService.complete(task.getId());

  //then output mapping sets variable
  //boundary event is not triggered
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(TASK_AFTER_OUTPUT_MAPPING, tasksAfterVariableIsSet.get(0).getName());
}
 
Example 10
Source File: EventSubProcessStartConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testNonInterruptingSetVariableInOutputMappingOfCallActivity() {
  engine.manageDeployment(repositoryService.createDeployment().addModelInstance(CONDITIONAL_MODEL, DELEGATED_PROCESS).deploy());

  final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
                                                .startEvent()
                                                .userTask(TASK_BEFORE_CONDITION_ID)
                                                  .name(TASK_BEFORE_CONDITION)
                                                .callActivity(TASK_WITH_CONDITION_ID)
                                                  .calledElement(DELEGATED_PROCESS_KEY)
                                                  .camundaOutputParameter(VARIABLE_NAME, "1")
                                                .userTask()
                                                .endEvent()
                                                .done();
   deployConditionalEventSubProcess(modelInstance, CONDITIONAL_EVENT_PROCESS_KEY, false);


  // given
  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 is completed
  taskService.complete(task.getId());

  //then output mapping from call activity sets variable
  //-> non interrupting conditional event is triggered
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(2, tasksAfterVariableIsSet.size());
  assertEquals(1, conditionEventSubscriptionQuery.list().size());
}
 
Example 11
Source File: IntermediateConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testEventBasedGateway() {
  BpmnModelInstance modelInstance =
    Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
      .startEvent()
      .eventBasedGateway().id(EVENT_BASED_GATEWAY_ID)
      .intermediateCatchEvent(CONDITIONAL_EVENT)
        .conditionalEventDefinition()
        .condition(CONDITION_EXPR)
        .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());
  assertEquals(1, conditionEventSubscriptionQuery.list().size());
  Execution execution = runtimeService.createExecutionQuery()
    .processInstanceId(procInst.getId())
    .activityId(EVENT_BASED_GATEWAY_ID)
    .singleResult();
  assertNotNull(execution);

  //when variable is set on execution
  runtimeService.setVariable(procInst.getId(), VARIABLE_NAME, 1);

  //then execution is at user task after intermediate conditional event
  Task task = taskQuery.singleResult();
  assertEquals(TASK_AFTER_CONDITION, task.getName());
  assertEquals(0, conditionEventSubscriptionQuery.list().size());
}
 
Example 12
Source File: EventSubProcessStartConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetVariableInSubProcessInDelegatedCode() {

  final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
                                                .startEvent()
                                                .userTask(TASK_BEFORE_CONDITION_ID)
                                                  .name(TASK_BEFORE_CONDITION)
                                                .subProcess(SUB_PROCESS_ID)
                                                .embeddedSubProcess()
                                                  .startEvent()
                                                  .serviceTask()
                                                  .camundaExpression(EXPR_SET_VARIABLE)
                                                  .userTask().name(TASK_AFTER_SERVICE_TASK)
                                                  .endEvent()
                                                .subProcessDone()
                                                .endEvent()
                                                .done();
   deployConditionalEventSubProcess(modelInstance, SUB_PROCESS_ID, true);

  // given
  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 is completed
  taskService.complete(task.getId());

  //then service task in sub process sets variable
  //conditional event is triggered
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(TASK_AFTER_CONDITION, tasksAfterVariableIsSet.get(0).getName());
}
 
Example 13
Source File: BoundaryConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetVariableInOutputMapping() {
  final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
                                                .startEvent()
                                                .userTask(TASK_BEFORE_CONDITION_ID)
                                                  .name(TASK_BEFORE_CONDITION)
                                                  .camundaOutputParameter(VARIABLE_NAME, "1")
                                                .userTask().name(TASK_AFTER_OUTPUT_MAPPING)
                                                .endEvent()
                                                .done();
  deployConditionalBoundaryEventProcess(modelInstance, TASK_BEFORE_CONDITION_ID, true);

  // given
  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 is completed
  taskService.complete(task.getId());

  //then output mapping sets variable
  //boundary event is not triggered
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(TASK_AFTER_OUTPUT_MAPPING, tasksAfterVariableIsSet.get(0).getName());
}
 
Example 14
Source File: BoundaryConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testNonInterruptingSetVariableInDelegate() {
  final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
                                                .startEvent().userTask().name(TASK_BEFORE_CONDITION)
                                                .serviceTask(TASK_WITH_CONDITION_ID)
                                                  .camundaClass(SetVariableDelegate.class.getName())
                                                .userTask()
                                                .endEvent().done();
  deployConditionalBoundaryEventProcess(modelInstance, TASK_WITH_CONDITION_ID, false);

  // given
  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 service task is completed
  taskService.complete(task.getId());

  //then service task with delegated code is called and variable is set
  //-> non interrupting conditional event is triggered
  //execution stays at user task after condition and after service task
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(2, tasksAfterVariableIsSet.size());
}
 
Example 15
Source File: BoundaryConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testNonInterruptingSetVariableInEndListener() {
  final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
                                              .startEvent()
                                              .userTask(TASK_WITH_CONDITION_ID)
                                                .name(TASK_WITH_CONDITION)
                                                .camundaExecutionListenerExpression(ExecutionListener.EVENTNAME_END, EXPR_SET_VARIABLE)
                                              .userTask().name(AFTER_TASK)
                                              .endEvent()
                                              .done();
  deployConditionalBoundaryEventProcess(modelInstance, TASK_WITH_CONDITION_ID, false);

  // given
  ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);

  TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());
  Task task = taskQuery.singleResult();
  assertNotNull(task);
  assertEquals(TASK_WITH_CONDITION, task.getName());

  //when task is completed
  taskService.complete(task.getId());

  //then end listener sets variable
  //non interrupting boundary event is not triggered
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(AFTER_TASK, tasksAfterVariableIsSet.get(0).getName());
}
 
Example 16
Source File: EventSubProcessStartConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetVariableInDelegate() {
  final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
                                                .startEvent().userTask().name(TASK_BEFORE_CONDITION)
                                                .serviceTask()
                                                  .camundaClass(SetVariableDelegate.class.getName())
                                                .endEvent().done();
   deployConditionalEventSubProcess(modelInstance, CONDITIONAL_EVENT_PROCESS_KEY, true);

  // given process with event sub process conditional start event and service task with delegate class which sets a variable
  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());
  assertEquals(1, conditionEventSubscriptionQuery.list().size());

  //when task is completed
  taskService.complete(task.getId());

  //then service task with delegated code is called and variable is set
  //-> conditional event is triggered and execution stays at user task after condition
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(TASK_AFTER_CONDITION, tasksAfterVariableIsSet.get(0).getName());
  assertEquals(0, conditionEventSubscriptionQuery.list().size());
}
 
Example 17
Source File: IntermediateConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@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());
}
 
Example 18
Source File: MixedConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void testNonInterruptingSetVariableInOutMappingOfCallActivity() {
  engine.manageDeployment(repositoryService.createDeployment().addModelInstance(CONDITIONAL_MODEL, DELEGATED_PROCESS).deploy());

  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
    .startEvent()
    .userTask(TASK_BEFORE_CONDITION_ID)
    .name(TASK_BEFORE_CONDITION)
    .subProcess(SUB_PROCESS_ID)
    .embeddedSubProcess()
    .startEvent()
    .callActivity(TASK_WITH_CONDITION_ID)
    .calledElement(DELEGATED_PROCESS_KEY)
    .camundaOut(VARIABLE_NAME, VARIABLE_NAME)
    .userTask().name(TASK_AFTER_OUTPUT_MAPPING)
    .endEvent()
    .subProcessDone()
    .endEvent()
    .done();

  modelInstance = addEventSubProcess(modelInstance, SUB_PROCESS_ID, TASK_AFTER_COND_START_EVENT_IN_SUB_PROCESS, false);
  modelInstance = addBoundaryEvent(modelInstance, TASK_WITH_CONDITION_ID, TASK_AFTER_COND_BOUN_EVENT_IN_SUB_PROCESS, false);
  deployMixedProcess(modelInstance, CONDITIONAL_EVENT_PROCESS_KEY, SUB_PROCESS_ID, false);


  // given
  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 service task is completed
  taskService.complete(task.getId());

  //then out mapping of call activity sets a variable
  //-> all non interrupting conditional events are triggered
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(5, tasksAfterVariableIsSet.size());
  //three subscriptions: event sub process in sub process and on process instance level and boundary event of sub process
  assertEquals(3, conditionEventSubscriptionQuery.count());
}
 
Example 19
Source File: EventSubProcessStartConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void testSetVariableInTriggeredEventSubProcess() {
  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
    .startEvent()
    .userTask(TASK_WITH_CONDITION_ID).name(TASK_WITH_CONDITION)
    .serviceTask()
    .camundaClass(SetVariableDelegate.class.getName())
    .endEvent()
    .done();

  modelInstance = modify(modelInstance)
    .addSubProcessTo(CONDITIONAL_EVENT_PROCESS_KEY)
    .triggerByEvent()
    .embeddedSubProcess()
    .startEvent()
    .interrupting(true)
    .conditionalEventDefinition(CONDITIONAL_EVENT)
    .condition(CONDITION_EXPR)
    .conditionalEventDefinitionDone()
    .serviceTask()
    .camundaClass(LoopDelegate.class.getName())
    .userTask().name(TASK_AFTER_CONDITION)
    .endEvent().done();

  engine.manageDeployment(repositoryService.createDeployment().addModelInstance(CONDITIONAL_MODEL, modelInstance).deploy());


  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);
  TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(processInstance.getId());
  Task task = taskQuery.singleResult();
  assertEquals(TASK_WITH_CONDITION, task.getName());

  //when task is completed
  taskService.complete(task.getId());

  //then variable is set
  //event sub process is triggered
  //and service task in event sub process triggers again sub process
  tasksAfterVariableIsSet = taskService.createTaskQuery().list();
  assertEquals(1, tasksAfterVariableIsSet.size());
  assertEquals(TASK_AFTER_CONDITION, tasksAfterVariableIsSet.get(0).getName());
}
 
Example 20
Source File: IntermediateConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@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());
}