ProcessInstance callProcess = runtimeService.createProcessInstanceQuery().processDefinitionKey("callFailingProcess").singleResult();
assertNotNull(callProcess);
// Root cause incident
Incident causeIncident = runtimeService.createIncidentQuery().processDefinitionId(failingProcess.getProcessDefinitionId()).singleResult();
assertNotNull(causeIncident);
Job job = managementService.createJobQuery().executionId(causeIncident.getExecutionId()).singleResult();
assertNotNull(job);
assertNotNull(causeIncident.getId());
assertNotNull(causeIncident.getIncidentTimestamp());
assertEquals(FailedJobIncidentHandler.INCIDENT_HANDLER_TYPE, causeIncident.getIncidentType());
assertEquals("Exception expected.", causeIncident.getIncidentMessage());
assertEquals(job.getExecutionId(), causeIncident.getExecutionId());
assertEquals("theServiceTask", causeIncident.getActivityId());
assertEquals(failingProcess.getId(), causeIncident.getProcessInstanceId());
assertEquals(causeIncident.getId(), causeIncident.getCauseIncidentId());
assertEquals(causeIncident.getId(), causeIncident.getRootCauseIncidentId());
assertEquals(job.getId(), causeIncident.getConfiguration());
// Recursive created incident
Incident recursiveCreatedIncident = runtimeService.createIncidentQuery().processDefinitionId(callProcess.getProcessDefinitionId()).singleResult();
assertNotNull(recursiveCreatedIncident);
Execution theCallActivityExecution = runtimeService.createExecutionQuery().activityId("theCallActivity").singleResult();
assertNotNull(theCallActivityExecution);
assertNotNull(recursiveCreatedIncident.getId());
assertNotNull(recursiveCreatedIncident.getIncidentTimestamp());
assertEquals(FailedJobIncidentHandler.INCIDENT_HANDLER_TYPE, recursiveCreatedIncident.getIncidentType());
assertNull(recursiveCreatedIncident.getIncidentMessage());
assertEquals(theCallActivityExecution.getId(), recursiveCreatedIncident.getExecutionId());
assertEquals("theCallActivity", recursiveCreatedIncident.getActivityId());
assertEquals(processInstance.getId(), recursiveCreatedIncident.getProcessInstanceId());
assertEquals(causeIncident.getId(), recursiveCreatedIncident.getCauseIncidentId());
assertEquals(causeIncident.getId(), recursiveCreatedIncident.getRootCauseIncidentId());
assertNull(recursiveCreatedIncident.getConfiguration());
}