Testing RecieveTask in JUnit

I’d like to test the whole bpmn process using JUnit and camunda-bpm-process-test-coverage tool. I init the process engine in a standard way found in many examples:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {InMemProcessEngineConfiguration.class}, loader = AnnotationConfigContextLoader.class)
public abstract class AbstractCoverageTest {

@Autowired
ProcessEngine processEngine;

@Rule
@ClassRule
public static ProcessEngineRule rule;

@PostConstruct
void initRule() {
	rule = TestCoverageProcessEngineRuleBuilder.create(processEngine).build();
}

Then when I test the deployment, I use a method to execute the jobs until there are no more left:

	@Test
@Deployment(resources = "myProcess.bpmn")
public void testProcess() throws Exception {
	final ProcessEngine processEngine = rule.getProcessEngine();
	final RuntimeService runtimeService = rule.getRuntimeService();
	ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("MyProcess", new HashMap());
	waitUntilNoActiveJobs(processEngine, 1000000l);
}

    public boolean waitUntilNoActiveJobs(ProcessEngine processEngine, long wait) throws InterruptedException {
	long timeout = System.currentTimeMillis() + wait;
	while (System.currentTimeMillis() < timeout) {
		long jobCount = processEngine.getManagementService().createJobQuery().active().count();
		if (jobCount == 0) {
			return true;  //This means everything is done
		}

		**//This will get me gateways and service tasks waiting to be executed, but no Receive Task**
		final List<Job> waitingJobs = processEngine.getManagementService().createJobQuery().list();
		for (final Job job : waitingJobs) {
			if (job instanceof TimerEntity && job.getDuedate().after(new Date())) {
				//Do nothing... timer not expired
			} else {
				processEngine.getManagementService().executeJob(job.getId());
			}
		}
	}
	return false;
}

The process goes flawlessly through all the timers, gateways and service tasks, but I have no idea how to find out if process is hanging on some RecieveTask, because those are not returned using processEngine.getManagementService().createJobQuery().list(). Is there some other way to get them?

Hey @neplatnyudaj,

You can use the RuntimeService#createEventSubscriptionQuery method to retrieve ReceiveTasks. There are some tests that you can use as examples here.

Cheers,
Nikola

Thanks, that’s what I was looking for!