@Deployment(resources = {"org/activiti/examples/bpmn/executionlistener/ExecutionListenersProcess.bpmn20.xml"})
public void testExecutionListenersOnAllPossibleElements() {
// Process start executionListener will have executionListener class that sets 2 variables
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("executionListenersProcess", "businessKey123");
String varSetInExecutionListener = (String) runtimeService.getVariable(processInstance.getId(), "variableSetInExecutionListener");
assertNotNull(varSetInExecutionListener);
assertEquals("firstValue", varSetInExecutionListener);
// Check if business key was available in execution listener
String businessKey = (String) runtimeService.getVariable(processInstance.getId(), "businessKeyInExecution");
assertNotNull(businessKey);
assertEquals("businessKey123", businessKey);
// Transition take executionListener will set 2 variables
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);
taskService.complete(task.getId());
varSetInExecutionListener = (String) runtimeService.getVariable(processInstance.getId(), "variableSetInExecutionListener");
assertNotNull(varSetInExecutionListener);
assertEquals("secondValue", varSetInExecutionListener);
ExampleExecutionListenerPojo myPojo = new ExampleExecutionListenerPojo();
runtimeService.setVariable(processInstance.getId(), "myPojo", myPojo);
task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);
taskService.complete(task.getId());
// First usertask uses a method-expression as executionListener: ${myPojo.myMethod(execution.eventName)}
ExampleExecutionListenerPojo pojoVariable = (ExampleExecutionListenerPojo) runtimeService.getVariable(processInstance.getId(), "myPojo");
assertNotNull(pojoVariable.getReceivedEventName());
assertEquals("end", pojoVariable.getReceivedEventName());
task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);
taskService.complete(task.getId());
assertProcessEnded(processInstance.getId());
}