Testing named bean with BusinessProcess

Skip to first unread message

Bernd Varga

Mar 8, 2016, 4:29:14 AM3/8/16
to camunda BPM users
For verifying the our implementation at the named bean level for bpmn listeners I tried to test this with the proposed camunda-bpm-needle.

In the bean I try to evaluate the current business key. This work in the camunda engine but not in the tests.
In the tests the injected BusinessProcess retrieves only a mock object and not the started business process object.

Is there a possibility to get the runtime business process object?

@Named(value = "camundaListener")
public class CamundaListenerBean {

    BusinessProcess businessProcess;

    public void protocolBusinessKey() {
        System.out.println("businessProcess: " + businessProcess);
        System.out.println("processInstance: " + businessProcess.getProcessInstance());
        System.out.println("businessKey: " + businessProcess.getProcessInstance().getBusinessKey());


    @ObjectUnderTest(implementation = CamundaListenerBean.class)
    private CamundaListenerBean camundaListener;

  @Deployment(resources = "test-process.bpmn")
  public void should_deploy_and_start_process_via_starter_bean() {

    Mocks.register("serviceTask", serviceTaskMock);
      Mocks.register("camundaListener", camundaListener);

    <bpmn2:serviceTask id="service_do_it" activiti:delegateExpression="#{serviceTask}" name="Do it">
        <activiti:executionListener expression="#{camundaListener.protocolBusinessKey()}" event="start" />

The test failed with a NullPointerException:
businessProcess: Mock for BusinessProcess, hashCode: 534666530
processInstanceId: null
processInstance: null
Mär 08, 2016 9:58:42 AM org.camunda.bpm.engine.impl.interceptor.CommandContext close
SCHWERWIEGEND: Error while closing command context
org.camunda.bpm.engine.ProcessEngineException: Error while evaluating expression: #{camundaListener.protocolBusinessKey()}. Cause: java.lang.NullPointerException

For workaround it is possible add a in parameter for the execution object.

Reply all
Reply to author
0 new messages