org.camunda.bpm.engine.delegate.ExecutionListener Java Examples

The following examples show how to use org.camunda.bpm.engine.delegate.ExecutionListener. 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: TriggerConditionalEventFromDelegationCodeTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetVariableInEndListener() {
  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
    .startEvent()
    .userTask(TASK_BEFORE_CONDITION_ID)
    .name(TASK_BEFORE_CONDITION)
    .camundaExecutionListenerClass(ExecutionListener.EVENTNAME_END, specifier.getDelegateClass().getName())
    .userTask(TASK_WITH_CONDITION_ID)
    .endEvent()
    .done();
  deployConditionalEventSubProcess(modelInstance, CONDITIONAL_EVENT_PROCESS_KEY, specifier.getCondition(), true);

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

  TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());
  Task task = taskQuery.singleResult();

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

  //then end listener sets variable
  //conditional event is triggered
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(specifier.getExpectedInterruptingCount(), taskQuery.taskName(TASK_AFTER_CONDITION).count());
}
 
Example #2
Source File: HistoricVariableInstanceTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testSetVariableInEndListenerOfAsyncStartEvent () throws Exception {
  //given
  BpmnModelInstance subProcess = Bpmn.createExecutableProcess("process")
    .startEvent()
    .camundaAsyncBefore()
    .camundaExecutionListenerClass(ExecutionListener.EVENTNAME_END, SubProcessActivityStartListener.class.getName())
    .endEvent()
    .done();

  org.camunda.bpm.engine.repository.Deployment deployment = repositoryService.createDeployment()
    .addModelInstance("process.bpmn", subProcess)
    .deploy();

  //when
  runtimeService.startProcessInstanceByKey("process", Variables.createVariables().putValue("executionListenerCounter",1));
  managementService.executeJob(managementService.createJobQuery().active().singleResult().getId());

  //then
  assertThat(historyService.createHistoricVariableInstanceQuery().count(), is (2L));
  repositoryService.deleteDeployment(deployment.getId(),true);
}
 
Example #3
Source File: ProcessApplicationEventListenerTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/camunda/bpm/application/impl/event/ProcessApplicationEventListenerTest.testExecutionListener.bpmn20.xml" })
public void testShouldNotIncrementExecutionListenerCountOnStartAndEndOfProcessInstance() {
  final AtomicInteger eventCount = new AtomicInteger();

  EmbeddedProcessApplication processApplication = new EmbeddedProcessApplication() {
    public ExecutionListener getExecutionListener() {
      // this process application returns an execution listener
      return new ExecutionListener() {
        public void notify(DelegateExecution execution) throws Exception {
          if (!(((CoreExecution) execution).getEventSource() instanceof ProcessDefinitionEntity))
            eventCount.incrementAndGet();
        }
      };
    }
  };

  // register app so that it receives events
  managementService.registerProcessApplication(deploymentId, processApplication.getReference());

  // Start process instance.
  runtimeService.startProcessInstanceByKey("startToEnd");

  assertEquals(5, eventCount.get());
}
 
Example #4
Source File: ExecutionEntity.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public FlowElement getBpmnModelElementInstance() {
  BpmnModelInstance bpmnModelInstance = getBpmnModelInstance();
  if (bpmnModelInstance != null) {

    ModelElementInstance modelElementInstance = null;
    if (ExecutionListener.EVENTNAME_TAKE.equals(eventName)) {
      modelElementInstance = bpmnModelInstance.getModelElementById(transition.getId());
    } else {
      modelElementInstance = bpmnModelInstance.getModelElementById(activityId);
    }

    try {
      return (FlowElement) modelElementInstance;

    } catch (ClassCastException e) {
      ModelElementType elementType = modelElementInstance.getElementType();
      throw LOG.castModelInstanceException(modelElementInstance, "FlowElement", elementType.getTypeName(),
        elementType.getTypeNamespace(), e);
    }

  } else {
    return null;
  }
}
 
Example #5
Source File: RestartProcessInstanceSyncTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldSkipCustomListeners() {
  // given
  ProcessDefinition processDefinition = testRule.deployAndGetDefinition(modify(ProcessModels.TWO_TASKS_PROCESS).activityBuilder("userTask1")
      .camundaExecutionListenerClass(ExecutionListener.EVENTNAME_START, IncrementCounterListener.class.getName()).done());
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process");

  runtimeService.deleteProcessInstance(processInstance.getId(), "test");

  IncrementCounterListener.counter = 0;
  // when
  runtimeService.restartProcessInstances(processDefinition.getId())
  .startBeforeActivity("userTask1")
  .processInstanceIds(processInstance.getId())
  .skipCustomListeners()
  .execute();

  // then
  assertEquals(0, IncrementCounterListener.counter);
}
 
Example #6
Source File: TransientVariableTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void createTransientVariablesUsingFluentBuilder() {
  // given
  BpmnModelInstance simpleInstanceWithListener = Bpmn.createExecutableProcess("Process")
      .startEvent()
        .camundaExecutionListenerClass(ExecutionListener.EVENTNAME_END, ReadTransientVariableExecutionListener.class)
      .userTask()
      .endEvent()
      .done();
  testRule.deploy(simpleInstanceWithListener);

  // when
  runtimeService.createProcessInstanceByKey("Process")
    .setVariables(Variables.createVariables().putValue(VARIABLE_NAME, Variables.stringValue("dlsd", true)))
    .execute();

  // then
  List<VariableInstance> variableInstances = runtimeService.createVariableInstanceQuery().list();
  List<HistoricVariableInstance> historicVariableInstances = historyService.createHistoricVariableInstanceQuery().list();
  assertEquals(0, variableInstances.size());
  assertEquals(0, historicVariableInstances.size());
}
 
Example #7
Source File: TriggerConditionalEventFromDelegationCodeTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetVariableInStartAndEndListener() {
  //given process with start and end listener on user task
  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
    .startEvent()
    .userTask(TASK_BEFORE_CONDITION_ID)
    .name(TASK_BEFORE_CONDITION)
    .camundaExecutionListenerClass(ExecutionListener.EVENTNAME_START, specifier.getDelegateClass().getName())
    .camundaExecutionListenerClass(ExecutionListener.EVENTNAME_END, specifier.getDelegateClass().getName())
    .userTask(TASK_WITH_CONDITION_ID)
    .endEvent()
    .done();
  deployConditionalEventSubProcess(modelInstance, CONDITIONAL_EVENT_PROCESS_KEY, specifier.getCondition(), true);

  //when process is started
  ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);

  //then start listener sets variable and
  //execution stays in task after conditional event in event sub process
  TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());
  Task task = taskQuery.singleResult();
  assertEquals(TASK_AFTER_CONDITION, task.getName());
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(specifier.getExpectedInterruptingCount(), taskQuery.taskName(TASK_AFTER_CONDITION).count());
}
 
Example #8
Source File: MigrationCompensationAddSubProcessTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testNoListenersCalled() {
  // given
  ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(CompensationModels.ONE_COMPENSATION_TASK_MODEL);
  ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(modify(CompensationModels.COMPENSATION_ONE_TASK_SUBPROCESS_MODEL)
    .activityBuilder("subProcess")
      .camundaExecutionListenerExpression(
          ExecutionListener.EVENTNAME_START,
          "${execution.setVariable('foo', 'bar')}")
    .done());

  MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId())
      .mapActivities("userTask2", "userTask2")
      .mapActivities("compensationBoundary", "compensationBoundary")
      .build();

  ProcessInstance processInstance = rule.getRuntimeService().startProcessInstanceById(sourceProcessDefinition.getId());
  testHelper.completeTask("userTask1");

  // when
  testHelper.migrateProcessInstance(migrationPlan, processInstance);

  // then
  Assert.assertEquals(0, testHelper.snapshotAfterMigration.getVariables().size());
}
 
Example #9
Source File: MultiInstanceTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testParallelMITasksExecutionListener() {
  RecordInvocationListener.reset();

  Map<String, Object> vars = new HashMap<String, Object>();
  vars.put("nrOfLoops", 5);
  runtimeService.startProcessInstanceByKey("miSequentialListener", vars);

  assertEquals(5, (int) RecordInvocationListener.INVOCATIONS.get(ExecutionListener.EVENTNAME_START));
  assertNull(RecordInvocationListener.INVOCATIONS.get(ExecutionListener.EVENTNAME_END));

  List<Task> tasks = taskService.createTaskQuery().list();
  taskService.complete(tasks.get(0).getId());

  assertEquals(5, (int) RecordInvocationListener.INVOCATIONS.get(ExecutionListener.EVENTNAME_START));
  assertEquals(1, (int) RecordInvocationListener.INVOCATIONS.get(ExecutionListener.EVENTNAME_END));

  taskService.complete(tasks.get(1).getId());
  taskService.complete(tasks.get(2).getId());
  taskService.complete(tasks.get(3).getId());
  taskService.complete(tasks.get(4).getId());

  assertEquals(5, (int) RecordInvocationListener.INVOCATIONS.get(ExecutionListener.EVENTNAME_START));
  assertEquals(5, (int) RecordInvocationListener.INVOCATIONS.get(ExecutionListener.EVENTNAME_END));
}
 
Example #10
Source File: TriggerConditionalEventFromDelegationCodeTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testNonInterruptingSetVariableInEndListener() {
  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
    .startEvent()
    .userTask(TASK_BEFORE_CONDITION_ID)
    .name(TASK_BEFORE_CONDITION)
    .camundaExecutionListenerClass(ExecutionListener.EVENTNAME_END, specifier.getDelegateClass().getName())
    .userTask(TASK_WITH_CONDITION_ID)
    .name(TASK_WITH_CONDITION)
    .endEvent()
    .done();
  deployConditionalEventSubProcess(modelInstance, CONDITIONAL_EVENT_PROCESS_KEY, specifier.getCondition(), false);

  // given
  ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);
  TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());

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

  //then end listener sets variable
  //non interrupting event is triggered
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(1 + specifier.getExpectedNonInterruptingCount(), tasksAfterVariableIsSet.size());
  assertEquals(specifier.getExpectedNonInterruptingCount(), taskQuery.taskName(TASK_AFTER_CONDITION).count());
}
 
Example #11
Source File: HistoricVariableInstanceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testSetVariableInSubProcessStartEventWithEndListener () throws Exception {
  //given
  BpmnModelInstance topProcess = Bpmn.createExecutableProcess("topProcess")
      .startEvent()
      .callActivity()
      .calledElement("subProcess")
      .camundaIn("executionListenerCounter","executionListenerCounter")
      .endEvent()
      .done();

  BpmnModelInstance subProcess = Bpmn.createExecutableProcess("subProcess")
      .startEvent()
      .camundaAsyncBefore()
      .camundaExecutionListenerClass(ExecutionListener.EVENTNAME_END, "org.camunda.bpm.engine.test.history.SubProcessActivityStartListener")
      .endEvent()
      .done();
  org.camunda.bpm.engine.repository.Deployment deployment = repositoryService.createDeployment()
      .addModelInstance("process.bpmn", topProcess)
      .addModelInstance("subProcess.bpmn", subProcess)
      .deploy();

  //when
  runtimeService.startProcessInstanceByKey("topProcess", Variables.createVariables().putValue("executionListenerCounter",1));
  managementService.executeJob(managementService.createJobQuery().active().singleResult().getId());

  //then
  assertThat(historyService.createHistoricVariableInstanceQuery().count(), is (3L));
  repositoryService.deleteDeployment(deployment.getId(),true);
}
 
Example #12
Source File: ExecutionListenerBpmnModelExecutionContextTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testIntermediateCatchEventEndEvent() {
  deployAndStartTestProcess(CATCH_EVENT_ID, ExecutionListener.EVENTNAME_END);
  assertNotNotified();
  sendMessage();
  assertFlowElementIs(IntermediateCatchEvent.class);
  completeTask();
}
 
Example #13
Source File: MixedConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testNonInterruptingSetVariableOnStartExecutionListenerInSubProcessWithBoundary() {
  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
    .startEvent()
    .subProcess(SUB_PROCESS_ID)
    .camundaExecutionListenerExpression(ExecutionListener.EVENTNAME_START, EXPR_SET_VARIABLE)
    .embeddedSubProcess()
    .startEvent()
    .userTask(TASK_WITH_CONDITION_ID)
    .name(TASK_WITH_CONDITION)
    .endEvent()
    .subProcessDone()
    .endEvent()
    .done();

  modelInstance = addEventSubProcess(modelInstance, SUB_PROCESS_ID, TASK_AFTER_COND_START_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());

  //when start listener sets variable

  //then conditional boundary and event sub process inside the sub process should triggered via default evaluation behavior
  //and global conditional start event via delayed events
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(4, tasksAfterVariableIsSet.size());
  assertTaskNames(tasksAfterVariableIsSet,
    TASK_AFTER_CONDITIONAL_START_EVENT,
    TASK_AFTER_COND_START_EVENT_IN_SUB_PROCESS,
    TASK_AFTER_CONDITIONAL_BOUNDARY_EVENT,
    TASK_WITH_CONDITION);
}
 
Example #14
Source File: MixedConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testNonInterruptingSetVariableOnEndExecutionListenerInSubProcessWithBoundary() {

  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
    .startEvent()
    .subProcess(SUB_PROCESS_ID)
    .embeddedSubProcess()
    .startEvent()
    .userTask(TASK_WITH_CONDITION_ID)
    .camundaExecutionListenerExpression(ExecutionListener.EVENTNAME_END, EXPR_SET_VARIABLE)
    .name(TASK_WITH_CONDITION)
    .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);
  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());

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

  //then all conditional events are triggered
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(4, tasksAfterVariableIsSet.size());
}
 
Example #15
Source File: MigrationRemoveSubprocessTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testEndListenerInvocationForRemovedScope() {
  // given
  DelegateEvent.clearEvents();

  ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(modify(ProcessModels.SUBPROCESS_PROCESS)
    .activityBuilder("subProcess")
    .camundaExecutionListenerClass(ExecutionListener.EVENTNAME_END, DelegateExecutionListener.class.getName())
    .done()
  );
  ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(ProcessModels.ONE_TASK_PROCESS);

  MigrationPlan migrationPlan = rule.getRuntimeService()
    .createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId())
    .mapActivities("userTask", "userTask")
    .build();

  // when
  testHelper.createProcessInstanceAndMigrate(migrationPlan);

  // then
  List<DelegateEvent> recordedEvents = DelegateEvent.getEvents();
  assertEquals(1, recordedEvents.size());

  DelegateEvent event = recordedEvents.get(0);
  assertEquals(sourceProcessDefinition.getId(), event.getProcessDefinitionId());
  assertEquals("subProcess", event.getCurrentActivityId());
  assertEquals(testHelper.getSingleActivityInstanceBeforeMigration("subProcess").getId(), event.getActivityInstanceId());

  DelegateEvent.clearEvents();
}
 
Example #16
Source File: MixedConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetVariableOnEndExecutionListenerInSubProcessWithBoundary() {

  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
    .startEvent()
    .subProcess(SUB_PROCESS_ID)
    .embeddedSubProcess()
    .startEvent()
    .userTask(TASK_WITH_CONDITION_ID)
    .camundaExecutionListenerExpression(ExecutionListener.EVENTNAME_END, EXPR_SET_VARIABLE)
    .name(TASK_WITH_CONDITION)
    .endEvent()
    .subProcessDone()
    .endEvent()
    .done();

  modelInstance = addEventSubProcess(modelInstance, SUB_PROCESS_ID, TASK_AFTER_COND_START_EVENT_IN_SUB_PROCESS, true);
  deployMixedProcess(modelInstance, CONDITIONAL_EVENT_PROCESS_KEY, SUB_PROCESS_ID, true);

  // given
  ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);
  TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());
  Task task = taskQuery.singleResult();

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

  //then conditional boundary should not triggered but conditional start event
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(TASK_AFTER_CONDITIONAL_START_EVENT, tasksAfterVariableIsSet.get(0).getName());
}
 
Example #17
Source File: ExternalTaskServiceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testCompleteWithLocalVariables() {
  // given
  BpmnModelInstance instance = Bpmn.createExecutableProcess("Process").startEvent().serviceTask("externalTask")
      .camundaType("external").camundaTopic("foo").camundaTaskPriority("100")
      .camundaExecutionListenerClass(ExecutionListener.EVENTNAME_END, ReadLocalVariableListenerImpl.class)
      .userTask("user").endEvent().done();

  deployment(instance);
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process");

  List<LockedExternalTask> lockedTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic("foo", 1L).execute();

  // when
  externalTaskService.complete(lockedTasks.get(0).getId(), WORKER_ID, null,
      Variables.createVariables().putValue("abc", "bar"));

  // then
  VariableInstance variableInstance = runtimeService.createVariableInstanceQuery()
      .processInstanceIdIn(processInstance.getId()).singleResult();
  assertNull(variableInstance);
  if (processEngineConfiguration.getHistoryLevel() == HistoryLevel.HISTORY_LEVEL_AUDIT
      || processEngineConfiguration.getHistoryLevel() == HistoryLevel.HISTORY_LEVEL_FULL) {
    HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery()
        .activityInstanceIdIn(lockedTasks.get(0).getActivityInstanceId()).singleResult();
    assertNotNull(historicVariableInstance);
    assertEquals("abc", historicVariableInstance.getName());
    assertEquals("bar", historicVariableInstance.getValue());
  }
}
 
Example #18
Source File: SetBusinessKeyTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testNewKeyInStartExecListener() {
  // given
  String listener = ExecutionListener.EVENTNAME_START;
  BpmnModelInstance process = createModelExecutionListener(listener);
  testRule.deploy(process);

  // when
  String newBusinessKeyValue = "newBusinessKey";
  runtimeService.startProcessInstanceByKey(PROCESS_KEY, Variables.createVariables().putValue(BUSINESS_KEY_VARIABLE, newBusinessKeyValue));

  // then
  checkBusinessKeyChanged(newBusinessKeyValue);
}
 
Example #19
Source File: ConditionalEventTriggeredByExecutionListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testNonInterruptingSetVariableInStartListener() {
  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
    .startEvent(START_EVENT_ID)
    .userTask(TASK_BEFORE_CONDITION_ID)
      .name(TASK_BEFORE_CONDITION)
    .userTask(TASK_WITH_CONDITION_ID)
      .camundaExecutionListenerExpression(ExecutionListener.EVENTNAME_START, EXPR_SET_VARIABLE)
      .name(TASK_WITH_CONDITION)
    .endEvent(END_EVENT_ID)
    .done();
  modelInstance = specifier.specifyConditionalProcess(modelInstance, false);
  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());

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

  //then start listener sets variable
  //non interrupting boundary event is triggered
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(specifier.expectedTaskCount(), tasksAfterVariableIsSet.size());
  assertEquals(specifier.expectedSubscriptions(), conditionEventSubscriptionQuery.list().size());
  specifier.assertTaskNames(tasksAfterVariableIsSet, false, false);
}
 
Example #20
Source File: DeleteProcessDefinitionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private void deployTwoProcessDefinitions() {
  testHelper.deploy(
    Bpmn.createExecutableProcess("processOne")
      .startEvent()
      .userTask()
        .camundaExecutionListenerClass(ExecutionListener.EVENTNAME_END, IncrementCounterListener.class.getName())
      .endEvent()
      .done(),
    Bpmn.createExecutableProcess("processTwo")
      .startEvent()
      .userTask()
      .endEvent()
      .done());
}
 
Example #21
Source File: LocalBpmnParseListener.java    From wecube-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void parseUserTask(Element userTaskElement, ScopeImpl scope, ActivityImpl activity) {
    log.info("add listener {} {}", ExecutionListener.EVENTNAME_START, userTaskStartListener.getClass().getSimpleName());
    log.info("add listener {} {}", ExecutionListener.EVENTNAME_END, userTaskEndListener.getClass().getSimpleName());
    activity.addListener(ExecutionListener.EVENTNAME_START, userTaskStartListener);
    activity.addListener(ExecutionListener.EVENTNAME_END, userTaskEndListener);
}
 
Example #22
Source File: ExecutionListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testThrowUncaughtBpmnErrorFromEndListenerShouldNotTriggerListenerAgain() {

  // given
  BpmnModelInstance model = Bpmn.createExecutableProcess(PROCESS_KEY)
      .startEvent()
      .userTask("userTask1")
      .serviceTask("throw")
        .camundaExpression("${true}")
        .camundaExecutionListenerClass(ExecutionListener.EVENTNAME_END, ThrowBPMNErrorDelegate.class.getName())
      .endEvent()
      .done();

  testHelper.deploy(model);

  runtimeService.startProcessInstanceByKey(PROCESS_KEY);
  Task task = taskService.createTaskQuery().taskDefinitionKey("userTask1").singleResult();

  // when the listeners are invoked
  taskService.complete(task.getId());

  // then

  // the process has ended, because the error was not caught
  assertEquals(0, runtimeService.createExecutionQuery().count());

  // the listener was only called once
  assertEquals(1, ThrowBPMNErrorDelegate.INVOCATIONS);
}
 
Example #23
Source File: MixedConditionalEventTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetVariableOnEndExecutionListenerInSubProcess() {

  final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
    .startEvent()
    .subProcess(SUB_PROCESS_ID)
    .embeddedSubProcess()
    .startEvent()
    .userTask(TASK_WITH_CONDITION_ID)
    .camundaExecutionListenerExpression(ExecutionListener.EVENTNAME_END, EXPR_SET_VARIABLE)
    .name(TASK_WITH_CONDITION)
    .endEvent()
    .subProcessDone()
    .endEvent()
    .done();

  deployMixedProcess(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();

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

  //then conditional boundary should not triggered but conditional start event
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(TASK_AFTER_CONDITIONAL_START_EVENT, tasksAfterVariableIsSet.get(0).getName());
}
 
Example #24
Source File: PvmActivityInstanceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
/**
 * +-----+   +-----+   +-------+
 * | one |-->| two |-->| three |
 * +-----+   +-----+   +-------+
 */
public void testSequence() {

  ActivityInstanceVerification verifier = new ActivityInstanceVerification();

  PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
    .createActivity("one")
      .initial()
      .behavior(new Automatic())
      .executionListener(ExecutionListener.EVENTNAME_START, verifier)
      .executionListener(ExecutionListener.EVENTNAME_END, verifier)
      .transition("two")
    .endActivity()
    .createActivity("two")
      .behavior(new Automatic())
      .executionListener(ExecutionListener.EVENTNAME_START, verifier)
      .executionListener(ExecutionListener.EVENTNAME_END, verifier)
      .transition("three")
    .endActivity()
    .createActivity("three")
      .behavior(new End())
      .executionListener(ExecutionListener.EVENTNAME_START, verifier)
      .executionListener(ExecutionListener.EVENTNAME_END, verifier)
    .endActivity()
  .buildProcessDefinition();

  PvmProcessInstance processInstance = processDefinition.createProcessInstance();
  processInstance.start();

  verifier.assertStartInstanceCount(1, "one");
  verifier.assertStartInstanceCount(1, "two");
  verifier.assertStartInstanceCount(1, "three");

}
 
Example #25
Source File: ConditionalEventTriggeredByExecutionListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testNonInterruptingSetVariableOnParentScopeInStartListener() {
  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
    .startEvent(START_EVENT_ID)
    .subProcess()
    .embeddedSubProcess()
      .startEvent()
      .userTask(TASK_BEFORE_CONDITION_ID)
        .name(TASK_BEFORE_CONDITION)
      .userTask(TASK_WITH_CONDITION_ID)
        .name(TASK_WITH_CONDITION)
        .camundaExecutionListenerExpression(ExecutionListener.EVENTNAME_START, EXPR_SET_VARIABLE_ON_PARENT)
      .endEvent()
    .subProcessDone()
    .endEvent(END_EVENT_ID)
    .done();
  modelInstance = specifier.specifyConditionalProcess(modelInstance, false);
  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();
  assertNotNull(task);
  assertEquals(TASK_BEFORE_CONDITION, task.getName());

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

  //then start listener sets variable
  //non interrupting boundary event is triggered
  tasksAfterVariableIsSet = taskQuery.list();
  specifier.assertTaskNames(tasksAfterVariableIsSet, false, false);
}
 
Example #26
Source File: ConditionalEventTriggeredByExecutionListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetVariableOnParentScopeInStartListener() {
  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
    .startEvent(START_EVENT_ID)
    .subProcess()
    .embeddedSubProcess()
      .startEvent()
      .userTask(TASK_BEFORE_CONDITION_ID)
        .name(TASK_BEFORE_CONDITION)
      .userTask(TASK_WITH_CONDITION_ID)
        .name(TASK_WITH_CONDITION)
        .camundaExecutionListenerExpression(ExecutionListener.EVENTNAME_START, EXPR_SET_VARIABLE_ON_PARENT)
      .endEvent()
    .subProcessDone()
    .endEvent(END_EVENT_ID)
    .done();
  modelInstance = specifier.specifyConditionalProcess(modelInstance, true);
  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();
  assertNotNull(task);
  assertEquals(TASK_BEFORE_CONDITION, task.getName());

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

  //then start listener sets variable
  //conditional event is triggered
  tasksAfterVariableIsSet = taskQuery.list();
  specifier.assertTaskNames(tasksAfterVariableIsSet, true, false);
}
 
Example #27
Source File: ExecutionListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testThrowBpmnErrorInEndListenerOfLastEventAndSubprocessWithCatch() {
  // given
  BpmnModelInstance model = Bpmn.createExecutableProcess(PROCESS_KEY)
      .startEvent()
      .userTask("userTask1")
      .subProcess("sub")
        .embeddedSubProcess()
          .startEvent("inSub")
          .serviceTask("throw")
            .camundaExpression("${true}")
            .camundaExecutionListenerClass(ExecutionListener.EVENTNAME_END, ThrowBPMNErrorDelegate.class.getName())
      .boundaryEvent()
      .error(ERROR_CODE)
      .userTask("afterCatch")
      .moveToActivity("sub")
      .userTask("afterSub")
      .endEvent()
      .done();

  testHelper.deploy(model);

  runtimeService.startProcessInstanceByKey(PROCESS_KEY);
  Task task = taskService.createTaskQuery().taskDefinitionKey("userTask1").singleResult();
  // when the listeners are invoked
  taskService.complete(task.getId());

  // then
  verifyErrorGotCaught();
}
 
Example #28
Source File: TriggerConditionalEventFromDelegationCodeTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetVariableInStartListener() {
  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
    .startEvent()
    .userTask(TASK_BEFORE_CONDITION_ID)
    .name(TASK_BEFORE_CONDITION)
    .userTask(TASK_WITH_CONDITION_ID)
    .camundaExecutionListenerClass(ExecutionListener.EVENTNAME_START, specifier.getDelegateClass().getName())
    .endEvent()
    .done();
  deployConditionalEventSubProcess(modelInstance, CONDITIONAL_EVENT_PROCESS_KEY, specifier.getCondition(), 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 start listener sets variable
  //conditional event is triggered
  tasksAfterVariableIsSet = taskQuery.list();
  assertEquals(specifier.getExpectedInterruptingCount(), taskQuery.taskName(TASK_AFTER_CONDITION).count());
}
 
Example #29
Source File: ExecutionListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testThrowBpmnErrorInStartListenerAndEventSubprocessWithCatch() {
  // given
  BpmnModelInstance model = createModelWithCatchInEventSubprocessAndListener(ExecutionListener.EVENTNAME_START);
  testHelper.deploy(model);
  runtimeService.startProcessInstanceByKey(PROCESS_KEY);
  Task task = taskService.createTaskQuery().taskDefinitionKey("userTask1").singleResult();

  // when listeners are invoked
  taskService.complete(task.getId());

  // then
  verifyErrorGotCaught();
}
 
Example #30
Source File: ConditionalEventTriggeredByExecutionListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetVariableInTakeListener() {
  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY)
    .startEvent(START_EVENT_ID)
    .userTask(TASK_BEFORE_CONDITION_ID)
      .name(TASK_BEFORE_CONDITION)
    .sequenceFlowId(FLOW_ID)
    .userTask(TASK_WITH_CONDITION_ID)
      .name(TASK_WITH_CONDITION)
    .endEvent(END_EVENT_ID)
    .done();
  CamundaExecutionListener listener = modelInstance.newInstance(CamundaExecutionListener.class);
  listener.setCamundaEvent(ExecutionListener.EVENTNAME_TAKE);
  listener.setCamundaExpression(EXPR_SET_VARIABLE);
  modelInstance.<SequenceFlow>getModelElementById(FLOW_ID).builder().addExtensionElement(listener);
  modelInstance = specifier.specifyConditionalProcess(modelInstance, true);
  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();
  assertNotNull(task);
  assertEquals(TASK_BEFORE_CONDITION, task.getName());

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

  //then take listener sets variable
  //conditional event is triggered
  tasksAfterVariableIsSet = taskQuery.list();
  specifier.assertTaskNames(tasksAfterVariableIsSet, true, false);
}