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

The following examples show how to use org.camunda.bpm.engine.delegate.TaskListener. 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: TaskListenerTest.java    From camunda-bpm-platform with Apache License 2.0 7 votes vote down vote up
@Test
public void testUpdateTaskListenerOnSetLocalVariables() {
  // given
  createAndDeployModelWithTaskEventsRecorderOnUserTask(TaskListener.EVENTNAME_UPDATE);
  runtimeService.startProcessInstanceByKey("process");
  Task task = taskService.createTaskQuery().singleResult();

  VariableMap variables = Variables.createVariables()
      .putValue("var1", "val1")
      .putValue("var2", "val2");

  // when
  taskService.setVariablesLocal(task.getId(), variables);

  // then
  // only a single invocation of the listener is triggered
  assertEquals(1, RecorderTaskListener.getTotalEventCount());
  assertEquals(1, RecorderTaskListener.getEventCount(TaskListener.EVENTNAME_UPDATE));
}
 
Example #2
Source File: TaskListenerErrorThrowTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testThrowErrorOnCompleteAndCatchOnEventSubprocess() {
  // given
  BpmnModelInstance model = createModelThrowErrorInListenerAndCatchOnEventSubprocess(TaskListener.EVENTNAME_COMPLETE);

  testRule.deploy(model);
  runtimeService.startProcessInstanceByKey("process");

  Task firstTask = taskService.createTaskQuery().singleResult();
  assertNotNull(firstTask);

  // when
  taskService.complete(firstTask.getId());

  // then
  verifyErrorGotCaught();
}
 
Example #3
Source File: TaskListenerEventLifecycleTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldFireCompleteEventOnTaskCompletedInUpdateListener() {
  // given
  BpmnModelInstance model = createModelWithTaskEventsRecorderOnAssignedUserTask(TRACKED_EVENTS,
                                                                                null,
                                                                                TaskListener.EVENTNAME_UPDATE,
                                                                                CompletingTaskListener.class);
  testRule.deploy(model);
  runtimeService.startProcessInstanceByKey("process");
  Task task = taskService.createTaskQuery().singleResult();

  // when
  taskService.setPriority(task.getId(), 3000);

  // then
  List<String> orderedEvents = RecorderTaskListener.getOrderedEvents();

  // assignment event should not be processed
  assertThat(orderedEvents.size()).isEqualTo(3);
  assertThat(orderedEvents).containsExactly(TaskListener.EVENTNAME_CREATE,
                                            TaskListener.EVENTNAME_UPDATE,
                                            TaskListener.EVENTNAME_COMPLETE);
}
 
Example #4
Source File: UserTaskBpmnModelExecutionContextTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldGetBpmnModelElementInstanceOnAssignment() {
  String eventName = TaskListener.EVENTNAME_ASSIGNMENT;
  deployProcess(eventName);

  runtimeService.startProcessInstanceByKey(PROCESS_ID);

  assertNull(ModelExecutionContextTaskListener.modelInstance);
  assertNull(ModelExecutionContextTaskListener.userTask);

  String taskId = taskService.createTaskQuery().singleResult().getId();
  taskService.setAssignee(taskId, "demo");

  assertModelInstance();
  assertUserTask(eventName);
}
 
Example #5
Source File: TaskListenerEventLifecycleTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldFireDeleteEventLastWhenProcessDeleted() {
  // given
  createAndDeployModelWithTaskEventsRecorderOnUserTask(TRACKED_EVENTS);
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process");

  // when
  runtimeService.deleteProcessInstance(processInstance.getId(), "Canceled!");

  // then
  LinkedList<String> orderedEvents = RecorderTaskListener.getOrderedEvents();

  assertThat(orderedEvents.size()).isEqualTo(2);
  assertThat(orderedEvents.getFirst()).isEqualToIgnoringCase(TaskListener.EVENTNAME_CREATE);
  assertThat(orderedEvents.getLast()).isEqualToIgnoringCase(TaskListener.EVENTNAME_DELETE);
}
 
Example #6
Source File: SetBusinessKeyTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateKeyInEndTaskListener() {
  // given
  String listener = TaskListener.EVENTNAME_COMPLETE;
  BpmnModelInstance process = createModelTaskListener(listener);
  testRule.deploy(process);

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

  // when
  completeTask("userTask1");

  // assume
  assertNotNull(taskService.createTaskQuery().taskDefinitionKey("userTask2").singleResult());

  // then
  checkBusinessKeyChanged(newBusinessKeyValue);
}
 
Example #7
Source File: TaskListenerEventLifecycleTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldNotFireAssignmentEventOnAssigneeChangesInDeleteListener() {
  // given
  BpmnModelInstance model = createModelWithTaskEventsRecorderOnAssignedUserTask(TRACKED_EVENTS,
                                                                                null,
                                                                                TaskListener.EVENTNAME_DELETE,
                                                                                AssigneeAssignment.class);
  testRule.deploy(model);
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process");

  // when
  runtimeService.deleteProcessInstance(processInstance.getId(), "Canceled!");

  // then
  LinkedList<String> orderedEvents = RecorderTaskListener.getOrderedEvents();

  assertThat(orderedEvents.size()).isEqualTo(2);
  assertThat(orderedEvents.getFirst()).isEqualToIgnoringCase(TaskListener.EVENTNAME_CREATE);
  assertThat(orderedEvents.getLast()).isEqualToIgnoringCase(TaskListener.EVENTNAME_DELETE);
}
 
Example #8
Source File: SetBusinessKeyTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testNewKeyInEndTaskListener() {
  // given
  String listener = TaskListener.EVENTNAME_COMPLETE;
  BpmnModelInstance process = createModelTaskListener(listener);
  testRule.deploy(process);

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

  completeTask("userTask1");

  // assume
  assertNotNull(taskService.createTaskQuery().taskDefinitionKey("userTask2").singleResult());

  // then
  checkBusinessKeyChanged(newBusinessKeyValue);
}
 
Example #9
Source File: RuntimeServiceTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment
@Test
public void testDeleteProcessInstanceSkipCustomTaskListeners() {

  // given a process instance
  ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");

  // and an empty task listener invocation storage
  RecorderTaskListener.clear();

  // if we do not skip the custom listeners
  runtimeService.deleteProcessInstance(instance.getId(), null, false);

  // then the the custom listener is invoked
  assertEquals(1, RecorderTaskListener.getRecordedEvents().size());
  assertEquals(TaskListener.EVENTNAME_DELETE, RecorderTaskListener.getRecordedEvents().get(0).getEvent());

  // if we do skip the custom listeners
  instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
  RecorderTaskListener.clear();

  runtimeService.deleteProcessInstance(instance.getId(), null, true);

  // then the the custom listener is not invoked
  assertTrue(RecorderTaskListener.getRecordedEvents().isEmpty());
}
 
Example #10
Source File: SetBusinessKeyTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testNewKeyInAssignTaskListener() {
  // given
  String listener = TaskListener.EVENTNAME_ASSIGNMENT;
  BpmnModelInstance process = createModelTaskListener(listener);
  testRule.deploy(process);

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

  // when
  taskService.setAssignee(taskService.createTaskQuery().singleResult().getId(), "newUserId");

  // then
  checkBusinessKeyChanged(newBusinessKeyValue);
}
 
Example #11
Source File: ProcessDataLoggingContextTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@WatchLogger(loggerNames = CONTEXT_LOGGER, level = "ERROR")
public void shouldLogFailureFromCreateTaskListenerInTaskContext() {
  // given
  manageDeployment(Bpmn.createExecutableProcess(PROCESS)
      .startEvent("start")
      .userTask("waitState")
      .userTask("failingTask")
        .camundaTaskListenerClass(TaskListener.EVENTNAME_CREATE, FailingTaskListener.class)
      .endEvent("end")
      .done());
  ProcessInstance instance = runtimeService.startProcessInstanceByKey(PROCESS, B_KEY);
  // when
  try {
    taskService.complete(taskService.createTaskQuery().singleResult().getId());
    fail("Exception expected");
  } catch (Exception e) {
    // expected exception in the task listener that is not caught
  }
  assertFailureLogPresent(instance, "failingTask");
}
 
Example #12
Source File: UserTaskBpmnModelExecutionContextTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldGetBpmnModelElementInstanceOnComplete() {
  String eventName = TaskListener.EVENTNAME_COMPLETE;
  deployProcess(eventName);

  runtimeService.startProcessInstanceByKey(PROCESS_ID);

  assertNull(ModelExecutionContextTaskListener.modelInstance);
  assertNull(ModelExecutionContextTaskListener.userTask);

  String taskId = taskService.createTaskQuery().singleResult().getId();
  taskService.setAssignee(taskId, "demo");

  assertNull(ModelExecutionContextTaskListener.modelInstance);
  assertNull(ModelExecutionContextTaskListener.userTask);

  taskService.complete(taskId);

  assertModelInstance();
  assertUserTask(eventName);
}
 
Example #13
Source File: ProcessApplicationEventListenerDelegate.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void notifyTaskListener(DelegateTask task) throws Exception {
  ProcessApplicationReference processApp = Context.getCurrentProcessApplication();
  try {
    ProcessApplicationInterface processApplication = processApp.getProcessApplication();
    TaskListener taskListener = processApplication.getTaskListener();
    if(taskListener != null) {
      taskListener.notify(task);

    } else {
      LOG.paDoesNotProvideTaskListener(processApp.getName());

    }
  } catch (ProcessApplicationUnavailableException e) {
    // Process Application unavailable => ignore silently
    LOG.cannotInvokeListenerPaUnavailable(processApp.getName(), e);
  }
}
 
Example #14
Source File: TaskListenerEventLifecycleTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldNotFireDeleteEventOnTaskDeleteAttemptInDeleteListener() {
  // given
  thrown.expectMessage("The task cannot be deleted because is part of a running process");
  BpmnModelInstance model = createModelWithTaskEventsRecorderOnAssignedUserTask(TRACKED_EVENTS,
                                                                                null,
                                                                                TaskListener.EVENTNAME_DELETE,
                                                                                TaskDeleteTaskListener.class);
  testRule.deploy(model);
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process");

  // when
  try {
    runtimeService.deleteProcessInstance(processInstance.getId(), "Canceled!");
  } finally {
    // then
    LinkedList<String> orderedEvents = RecorderTaskListener.getOrderedEvents();

    assertThat(orderedEvents.size()).isEqualTo(2);
    assertThat(orderedEvents.getFirst()).isEqualToIgnoringCase(TaskListener.EVENTNAME_CREATE);
    assertThat(orderedEvents.getLast()).isEqualToIgnoringCase(TaskListener.EVENTNAME_DELETE);
  }
}
 
Example #15
Source File: ProcessDataLoggingContextTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@WatchLogger(loggerNames = CONTEXT_LOGGER, level = "ERROR")
public void shouldLogFailureFromAssignTaskListenerInTaskContext() {
  // given
  manageDeployment(Bpmn.createExecutableProcess(PROCESS)
      .startEvent("start")
      .userTask("failingTask")
        .camundaTaskListenerClass(TaskListener.EVENTNAME_ASSIGNMENT, FailingTaskListener.class)
      .endEvent("end")
      .done());
  ProcessInstance instance = runtimeService.startProcessInstanceByKey(PROCESS, B_KEY);
  // when
  try {
    taskService.setAssignee(taskService.createTaskQuery().singleResult().getId(), "testUser");
    fail("Exception expected");
  } catch (Exception e) {
    // expected exception in the task listener that is not caught
  }
  assertFailureLogPresent(instance, "failingTask");
}
 
Example #16
Source File: TaskListenerErrorThrowTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testThrowErrorOnAssignmentAndCatchOnSubprocess() {
  // given
  BpmnModelInstance model = createModelThrowErrorInListenerAndCatchOnSubprocess(TaskListener.EVENTNAME_ASSIGNMENT);

  testRule.deploy(model);
  runtimeService.startProcessInstanceByKey("process");

  Task firstTask = taskService.createTaskQuery().singleResult();
  assertNotNull(firstTask);

  // when
  firstTask.setAssignee("elmo");
  engineRule.getTaskService().saveTask(firstTask);

  // then
  verifyErrorGotCaught();
}
 
Example #17
Source File: TaskListenerEventLifecycleTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldNotFireCompleteEventOnTaskCompletedInCompleteListener() {
  // given
  thrown.expectMessage("invalid task state");
  BpmnModelInstance model = createModelWithTaskEventsRecorderOnAssignedUserTask(TRACKED_EVENTS,
                                                                                null,
                                                                                TaskListener.EVENTNAME_COMPLETE,
                                                                                CompletingTaskListener.class);
  testRule.deploy(model);
  runtimeService.startProcessInstanceByKey("process");
  Task task = taskService.createTaskQuery().singleResult();

  // when
  try {
    taskService.complete(task.getId());
  } finally {
    // then
    LinkedList<String> orderedEvents = RecorderTaskListener.getOrderedEvents();

    assertThat(orderedEvents.size()).isEqualTo(2);
    assertThat(orderedEvents.getFirst()).isEqualToIgnoringCase(TaskListener.EVENTNAME_CREATE);
    assertThat(orderedEvents.getLast()).isEqualToIgnoringCase(TaskListener.EVENTNAME_COMPLETE);
  }
}
 
Example #18
Source File: TaskListenerEventLifecycleTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldFireDeleteEventOnProcessInstanceDeletedInCompleteListener() {
  // given
  BpmnModelInstance model = createModelWithTaskEventsRecorderOnAssignedUserTask(TRACKED_EVENTS,
                                                                                null,
                                                                                TaskListener.EVENTNAME_COMPLETE,
                                                                                ProcessInstanceDeleteTaskListener.class);
  testRule.deploy(model);
  runtimeService.startProcessInstanceByKey("process");
  Task task = taskService.createTaskQuery().singleResult();

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

  // then
  LinkedList<String> orderedEvents = RecorderTaskListener.getOrderedEvents();

  assertThat(orderedEvents.size()).isEqualTo(3);
  assertThat(orderedEvents).containsExactly(TaskListener.EVENTNAME_CREATE,
                                            TaskListener.EVENTNAME_COMPLETE,
                                            TaskListener.EVENTNAME_DELETE);
}
 
Example #19
Source File: TaskListenerTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateTaskListenerOnPropertyUpdateOnlyOnce() {
  // given
  createAndDeployModelWithTaskEventsRecorderOnUserTask(TaskListener.EVENTNAME_UPDATE);
  runtimeService.startProcessInstanceByKey("process");
  Task task = taskService.createTaskQuery().singleResult();

  // when
  task.setAssignee("test");
  task.setDueDate(new Date());
  task.setOwner("test");
  taskService.saveTask(task);

  // then
  assertEquals(1, RecorderTaskListener.getEventCount(TaskListener.EVENTNAME_UPDATE));
}
 
Example #20
Source File: TaskListenerEventLifecycleTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldNotFireDeleteEventOnProcessDeleteAttemptInDeleteListener() {
  // given
  BpmnModelInstance model = createModelWithTaskEventsRecorderOnAssignedUserTask(TRACKED_EVENTS,
                                                                                null,
                                                                                TaskListener.EVENTNAME_DELETE,
                                                                                ProcessInstanceDeleteTaskListener.class);
  testRule.deploy(model);
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process");

  // when
  runtimeService.deleteProcessInstance(processInstance.getId(), "Canceled!");

  // then
  LinkedList<String> orderedEvents = RecorderTaskListener.getOrderedEvents();

  assertThat(orderedEvents.size()).isEqualTo(2);
  assertThat(orderedEvents.getFirst()).isEqualToIgnoringCase(TaskListener.EVENTNAME_CREATE);
  assertThat(orderedEvents.getLast()).isEqualToIgnoringCase(TaskListener.EVENTNAME_DELETE);
}
 
Example #21
Source File: TaskListenerEventLifecycleTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldNotFireUpdateEventOnPropertyChangesInDeleteListener() {
  // given
  BpmnModelInstance model = createModelWithTaskEventsRecorderOnAssignedUserTask(TRACKED_EVENTS,
                                                                                null,
                                                                                TaskListener.EVENTNAME_DELETE,
                                                                                CandidateUserAssignment.class);
  testRule.deploy(model);
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process");

  // when
  runtimeService.deleteProcessInstance(processInstance.getId(), "Canceled!");

  // then
  LinkedList<String> orderedEvents = RecorderTaskListener.getOrderedEvents();

  assertThat(orderedEvents.size()).isEqualTo(2);
  assertThat(orderedEvents.getFirst()).isEqualToIgnoringCase(TaskListener.EVENTNAME_CREATE);
  assertThat(orderedEvents.getLast()).isEqualToIgnoringCase(TaskListener.EVENTNAME_DELETE);
}
 
Example #22
Source File: TaskListenerErrorThrowTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected BpmnModelInstance createModelThrowErrorInListenerAndCatchOnSubprocess(String eventName) {
  return Bpmn.createExecutableProcess("process")
             .startEvent()
               .subProcess("sub")
               .embeddedSubProcess()
                 .startEvent("inSub")
                   .userTask("mainTask")
                     .camundaTaskListenerClass(eventName, ThrowBPMNErrorListener.class.getName())
                     .camundaTaskListenerClass(TaskListener.EVENTNAME_DELETE, RecorderTaskListener.class.getName())
                   .userTask("afterThrow")
                 .endEvent()
               .moveToActivity("sub")
                 .boundaryEvent("throw")
                   .error(ERROR_CODE)
               .userTask("afterCatch")
             .endEvent()
             .done();
}
 
Example #23
Source File: AbstractTaskListenerTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected BpmnModelInstance createModelWithTaskEventsRecorderOnAssignedUserTask(String[] eventTypes, String assignee, String customListenerEventType, Class<? extends TaskListener> taskListenerClass) {
  UserTaskBuilder userTaskModelBuilder = Bpmn.createExecutableProcess("process")
                                             .startEvent()
                                             .userTask("task");

  if (assignee != null) {
    userTaskModelBuilder.camundaAssignee("kermit");
  }

  for (String eventType : eventTypes) {
    userTaskModelBuilder.camundaTaskListenerClass(eventType, RecorderTaskListener.class);
  }

  if (taskListenerClass != null) {
    userTaskModelBuilder.camundaTaskListenerClass(customListenerEventType, taskListenerClass);
  }

  BpmnModelInstance model = userTaskModelBuilder
      .endEvent()
      .done();

  return model;
}
 
Example #24
Source File: TaskListenerDelegateCompletionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testCompletionIsNotPossibleOnDelete () {
  // expect
  thrown.expect(ProcessEngineException.class);
  thrown.expectMessage(containsString("invalid task state"));

  //given
  createProcessWithListener(TaskListener.EVENTNAME_DELETE);

  //when
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(TASK_LISTENER_PROCESS);
  runtimeService.deleteProcessInstance(processInstance.getId(),"test reason");
}
 
Example #25
Source File: HumanTaskPlanItemHandlerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateTaskListenerByExpression() {
  // given:
  ExtensionElements extensionElements = addExtensionElements(humanTask);
  CamundaTaskListener taskListener = createElement(extensionElements, null, CamundaTaskListener.class);

  String expression = "${myExpression}";
  String event = TaskListener.EVENTNAME_CREATE;
  taskListener.setCamundaEvent(event);
  taskListener.setCamundaExpression(expression);

  // when
  CmmnActivity activity = handler.handleElement(planItem, context);

  // then
  assertEquals(0, activity.getListeners().size());

  HumanTaskActivityBehavior behavior = (HumanTaskActivityBehavior) activity.getActivityBehavior();
  TaskDefinition taskDefinition = behavior.getTaskDefinition();

  assertNotNull(taskDefinition);

  assertEquals(1, taskDefinition.getTaskListeners().size());

  List<TaskListener> createListeners = taskDefinition.getTaskListeners(event);
  assertEquals(1, createListeners.size());
  TaskListener listener = createListeners.get(0);

  assertTrue(listener instanceof ExpressionTaskListener);

  ExpressionTaskListener expressionListener = (ExpressionTaskListener) listener;
  assertEquals(expression, expressionListener.getExpressionText());

}
 
Example #26
Source File: TaskListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdateTaskListenerInvokedBeforeConditionalEventsOnSetVariable() {
  // given
  BpmnModelInstance modelInstance = Bpmn.createExecutableProcess("process")
    .startEvent()
    .userTask("task")
      .camundaTaskListenerClass(TaskListener.EVENTNAME_UPDATE, RecorderTaskListener.class)
    .boundaryEvent()
      .condition("${triggerBoundaryEvent}")
    .userTask("afterBoundaryEvent")
      .camundaTaskListenerClass(TaskListener.EVENTNAME_CREATE, RecorderTaskListener.class)
    .endEvent()
    .moveToActivity("task")
    .endEvent()
    .done();

  testRule.deploy(modelInstance);

  runtimeService.startProcessInstanceByKey("process");
  Task task = taskService.createTaskQuery().singleResult();
  taskService.setVariableLocal(task.getId(), "taskLocalVariable", "bar");
  RecorderTaskListener.clear();

  VariableMap variables = Variables.createVariables().putValue("triggerBoundaryEvent", true).putValue("taskLocalVariable", "baz");

  // when
  taskService.setVariables(task.getId(), variables);

  // then
  assertThat(RecorderTaskListener.getOrderedEvents()).containsExactly(TaskListener.EVENTNAME_UPDATE, TaskListener.EVENTNAME_CREATE);
}
 
Example #27
Source File: HumanTaskPlanItemHandlerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateTaskListenerByClass() {
  // given:
  ExtensionElements extensionElements = addExtensionElements(humanTask);
  CamundaTaskListener taskListener = createElement(extensionElements, null, CamundaTaskListener.class);

  String className = "org.camunda.bpm.test.tasklistener.ABC";
  String event = TaskListener.EVENTNAME_CREATE;
  taskListener.setCamundaEvent(event);
  taskListener.setCamundaClass(className);

  // when
  CmmnActivity activity = handler.handleElement(planItem, context);

  // then
  assertEquals(0, activity.getListeners().size());

  HumanTaskActivityBehavior behavior = (HumanTaskActivityBehavior) activity.getActivityBehavior();
  TaskDefinition taskDefinition = behavior.getTaskDefinition();

  assertNotNull(taskDefinition);

  assertEquals(1, taskDefinition.getTaskListeners().size());

  List<TaskListener> createListeners = taskDefinition.getTaskListeners(event);
  assertEquals(1, createListeners.size());
  TaskListener listener = createListeners.get(0);

  assertTrue(listener instanceof ClassDelegateTaskListener);

  ClassDelegateTaskListener classDelegateListener = (ClassDelegateTaskListener) listener;
  assertEquals(className, classDelegateListener.getClassName());
  assertTrue(classDelegateListener.getFieldDeclarations().isEmpty());

}
 
Example #28
Source File: TaskListenerErrorThrowTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected BpmnModelInstance createModelThrowErrorInListenerAndCatchOnUserTask(String eventName) {
  return Bpmn.createExecutableProcess("process")
             .startEvent()
               .userTask("mainTask")
                 .camundaTaskListenerClass(eventName, ThrowBPMNErrorListener.class.getName())
                 .camundaTaskListenerClass(TaskListener.EVENTNAME_DELETE, RecorderTaskListener.class.getName())
                 .boundaryEvent("throw")
                   .error(ERROR_CODE)
               .userTask("afterCatch")
               .moveToActivity("mainTask")
               .userTask("afterThrow")
             .endEvent()
             .done();
}
 
Example #29
Source File: TaskListenerErrorThrowTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testThrowUncaughtErrorOnCompleteAndCatchOnUserTask() {
  // given
  processEngineConfiguration.setEnableExceptionsAfterUnhandledBpmnError(true);
  BpmnModelInstance model = Bpmn.createExecutableProcess("process")
                                .startEvent()
                                  .userTask("mainTask")
                                    .camundaTaskListenerClass(TaskListener.EVENTNAME_COMPLETE, ThrowBPMNErrorListener.class.getName())
                                    .camundaTaskListenerClass(TaskListener.EVENTNAME_DELETE, RecorderTaskListener.class.getName())
                                  .userTask("afterThrow")
                                .endEvent()
                                .done();

  testRule.deploy(model);
  runtimeService.startProcessInstanceByKey("process");

  Task firstTask = taskService.createTaskQuery().singleResult();
  assertNotNull(firstTask);

  try {
    // when
    taskService.complete(firstTask.getId());
  } catch (ProcessEngineException e) {
    // then
    assertTrue(e.getMessage().contains("There was an exception while invoking the TaskListener"));
    assertTrue(e.getMessage().contains("Execution with id 'mainTask' throws an error event with errorCode '208', but no error handler was defined."));
  }

  // then
  Task resultTask = taskService.createTaskQuery().singleResult();
  assertNotNull(resultTask);
  assertEquals("mainTask", resultTask.getName());
  assertEquals(1, ThrowBPMNErrorListener.INVOCATIONS);
  assertEquals(0, RecorderTaskListener.getEventCount(TaskListener.EVENTNAME_DELETE));

  // cleanup
  processEngineConfiguration.setEnableExceptionsAfterUnhandledBpmnError(false);
}
 
Example #30
Source File: TaskListenerProcessApplication.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public TaskListener getTaskListener() {
  return new TaskListener() {
    public void notify(DelegateTask delegateTask) {
      delegateTask.setVariable(delegateTask.getEventName(), true);
    }
  };
}