Testing named bean with BusinessProcess

64 views
Skip to first unread message

Bernd Varga

unread,
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 {

    @Inject
    BusinessProcess businessProcess;

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

TestProcessTest.java

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

  @Test
  @Deployment(resources = "test-process.bpmn")
  public void should_deploy_and_start_process_via_starter_bean() {
    Assert.assertNotNull(processEngineNeedleRule.getDeploymentId());

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

test-process.bpmn
    <bpmn2:serviceTask id="service_do_it" activiti:delegateExpression="#{serviceTask}" name="Do it">
      <bpmn2:extensionElements>
        <activiti:executionListener expression="#{camundaListener.protocolBusinessKey()}" event="start" />
      </bpmn2:extensionElements>
      <bpmn2:incoming>SequenceFlow_4</bpmn2:incoming>
      <bpmn2:outgoing>SequenceFlow_1</bpmn2:outgoing>
    </bpmn2:serviceTask>


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.

Cheers,
Bernd
Reply all
Reply to author
Forward
0 new messages