Search in sources :

Example 1 with DelegateTask

use of org.camunda.bpm.engine.delegate.DelegateTask in project camunda-bpm-platform by camunda.

the class ProcessApplicationEventListenerTest method testTaskListener.

@Deployment
public void testTaskListener() {
    final List<String> events = new ArrayList<String>();
    EmbeddedProcessApplication processApplication = new EmbeddedProcessApplication() {

        public TaskListener getTaskListener() {
            return new TaskListener() {

                public void notify(DelegateTask delegateTask) {
                    events.add(delegateTask.getEventName());
                }
            };
        }
    };
    // register app so that it is notified about events
    managementService.registerProcessApplication(deploymentId, processApplication.getReference());
    // start process instance
    ProcessInstance taskListenerProcess = runtimeService.startProcessInstanceByKey("taskListenerProcess");
    // create event received
    assertEquals(1, events.size());
    assertEquals(TaskListener.EVENTNAME_CREATE, events.get(0));
    Task task = taskService.createTaskQuery().singleResult();
    // assign task:
    taskService.setAssignee(task.getId(), "jonny");
    assertEquals(2, events.size());
    assertEquals(TaskListener.EVENTNAME_ASSIGNMENT, events.get(1));
    // complete task
    taskService.complete(task.getId());
    assertEquals(4, events.size());
    assertEquals(TaskListener.EVENTNAME_COMPLETE, events.get(2));
    // next task was created
    assertEquals(TaskListener.EVENTNAME_CREATE, events.get(3));
    // delete process instance so last task will be deleted
    runtimeService.deleteProcessInstance(taskListenerProcess.getProcessInstanceId(), "test delete event");
    assertEquals(5, events.size());
    assertEquals(TaskListener.EVENTNAME_DELETE, events.get(4));
}
Also used : DelegateTask(org.camunda.bpm.engine.delegate.DelegateTask) Task(org.camunda.bpm.engine.task.Task) EmbeddedProcessApplication(org.camunda.bpm.application.impl.EmbeddedProcessApplication) ArrayList(java.util.ArrayList) TaskListener(org.camunda.bpm.engine.delegate.TaskListener) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) DelegateTask(org.camunda.bpm.engine.delegate.DelegateTask) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

ArrayList (java.util.ArrayList)1 EmbeddedProcessApplication (org.camunda.bpm.application.impl.EmbeddedProcessApplication)1 DelegateTask (org.camunda.bpm.engine.delegate.DelegateTask)1 TaskListener (org.camunda.bpm.engine.delegate.TaskListener)1 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)1 Task (org.camunda.bpm.engine.task.Task)1 Deployment (org.camunda.bpm.engine.test.Deployment)1