Hello,
I’ve a simple diagram with a service task and a bpmn error attached to it.
The service task “Deliver goods” has the “Delegate expression” configuration and delegate expression is a bean implementing java delegate.
The delegate itself is calling a service “deliveryService” that I mock in the test.
I want to test that when a BPMN error is thrown by the service then the Manage error task is activated.
But unfortunately the error is not raised and Register DB activity is triggered instead.
Is my approach correct? What am I doing wrong?
That’s my code:
public class DeliveryUnitTest {
@Mock
DeliverService deliverService;
@Deployment(resources = {"deliverybpmn"})
@Test
public void testDeliveryError() throws InterruptedException {
when(deliverService.deliver(anyInt()))
.thenThrow(new BpmnError("deliverError", "Error with delivering goods"));
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("goods", "pc");
variables.put("quantity", 3);
ProcessInstance processInstance =
runtimeService().startProcessInstanceByKey("DeliveryProcess", variables);
assertThat(processInstance).isWaitingAt(findId("Manage error"));
complete(task());
assertThat(processInstance).isEnded();
}
}
Thanks!