currently I´am developing a possibility to test Camunda BPM processes altogether with a running Java EE infrastructure (namely CDI) without the need of Arquillian (due to the configuration nightmare etc. etc.) as suggested in Testing Guide... I´am applying the testing scope 2.
Concretely I´am using Camunda´s @ProcessEngineRule altogether with Camunda-BPM-Assert API to have a running embbeded Camunda inside the test setup (StandaloneInMemoryProcessEngineConfiguration). On the other hand, I´am using DeltaSpike´s "Test-Control" module for providing a CDI environment (using Weld-SE) during the tests. Finally I´am joining them via a custom ExpressionManager, which resolves for EL expressions the corresponding deployed CDI Beans (using DeltaSpike´s BeanProvider).
Problem statement
How do I trigger BoundaryEvents (Timer-Events) declared inside a ServiceTask inside the "Unit Tests"? I already tried to fetch and execute the BoundaryEvents via the JobQuery API (but the corresponding job is not listed) and to trigger them implicitly via a "timeout" using the ClockUtil (I know nasty idea :])(also not working)
Peace,
Qaiser
The corresponding JUnit test for the positive path goes as following:
@RunWith(CdiTestRunner.class)
public class Important$Test {
@Rule
public ProcessEngineRule processEngineRule = new ProcessEngineRule();
@Test
@Deployment(resources = "bla.bpmn")
public void should_Successfully_End_In_Green_State() {
ProcessInstance processInstance = processEngine().getRuntimeService()
.startProcessInstanceByKey("bla");
assertThat(processInstance)
.isStarted()
.isWaitingAt(taskA)
.variables()
.containsExactly(
MapEntry.entry("standardTime", "PT10M"),
MapEntry.entry("state", State.GREEN),
MapEntry.entry("timeout", "PT5M"));
execute(job());
assertThat(processInstance).isWaitingAt(taskB);
execute(job());
assertThat(processInstance).isWaitingAt(taskC);
execute(job());
assertThat(processInstance).isWaitingAt(taskD);
execute(job());
assertThat(processInstance)
.isWaitingAt(taskStatusGreen)
.variables().containsEntry(Camunda.STATE, State.GREEN);
execute(job());
assertThat(processInstance)
.isEnded()
.hasPassedInOrder(taskA, taskB, taskC
taskD, taskStatusGreen);
}
@Test
@Deployment(resources = "bla.bpmn")
public void when_Standard_Timeout_Occurs_Should_End_In_Yellow_State() {
ProcessInstance processInstance = processEngine().getRuntimeService()
.startProcessInstanceByKey("bla");
assertThat(processInstance)
.isWaitingAt(taskA)
/** Trying to trigger BoundaryEvent "BoundaryEventA" */
// as stated this will have no effect on triggering of the boundary event
processEngineRule.setCurrentTime(new Date(currentDate + timeout));
// jobQuery also doesn´t work here -> will return null
execute(jobQuery().jobId("BoundaryEventA").singleResult());
// will return exactly one message event and not a timer event
jobQuery().active().list();
// fails
assertThat(processInstance)
.isWaitingAt(taskTimeoutA);
}