// Root Cause Incident
ProcessInstance failingProcess = runtimeService.createProcessInstanceQuery().processDefinitionKey("failingProcess").singleResult();
assertNotNull(failingProcess);
Incident rootCauseIncident = runtimeService.createIncidentQuery().processDefinitionId(failingProcess.getProcessDefinitionId()).singleResult();
assertNotNull(rootCauseIncident);
Job job = managementService.createJobQuery().executionId(rootCauseIncident.getExecutionId()).singleResult();
assertNotNull(job);
assertNotNull(rootCauseIncident.getId());
assertNotNull(rootCauseIncident.getIncidentTimestamp());
assertEquals(FailedJobIncidentHandler.INCIDENT_HANDLER_TYPE, rootCauseIncident.getIncidentType());
assertEquals("Exception expected.", rootCauseIncident.getIncidentMessage());
assertEquals(job.getExecutionId(), rootCauseIncident.getExecutionId());
assertEquals("theServiceTask", rootCauseIncident.getActivityId());
assertEquals(failingProcess.getId(), rootCauseIncident.getProcessInstanceId());
assertEquals(rootCauseIncident.getId(), rootCauseIncident.getCauseIncidentId());
assertEquals(rootCauseIncident.getId(), rootCauseIncident.getRootCauseIncidentId());
assertEquals(job.getId(), rootCauseIncident.getConfiguration());
// Cause Incident
ProcessInstance callFailingProcess = runtimeService.createProcessInstanceQuery().processDefinitionKey("callFailingProcess").singleResult();
assertNotNull(callFailingProcess);
Incident causeIncident = runtimeService.createIncidentQuery().processDefinitionId(callFailingProcess.getProcessDefinitionId()).singleResult();
assertNotNull(causeIncident);
Execution theCallActivityExecution = runtimeService.createExecutionQuery().activityId("theCallActivity").singleResult();
assertNotNull(theCallActivityExecution);
assertNotNull(causeIncident.getId());
assertNotNull(causeIncident.getIncidentTimestamp());
assertEquals(FailedJobIncidentHandler.INCIDENT_HANDLER_TYPE, causeIncident.getIncidentType());
assertNull(causeIncident.getIncidentMessage());
assertEquals(theCallActivityExecution.getId(), causeIncident.getExecutionId());
assertEquals("theCallActivity", causeIncident.getActivityId());
assertEquals(callFailingProcess.getId(), causeIncident.getProcessInstanceId());
assertEquals(rootCauseIncident.getId(), causeIncident.getCauseIncidentId());
assertEquals(rootCauseIncident.getId(), causeIncident.getRootCauseIncidentId());
assertNull(causeIncident.getConfiguration());
// Top level incident of the startet process (recursive created incident for super super process instance)
Incident topLevelIncident = runtimeService.createIncidentQuery().processDefinitionId(processInstance.getProcessDefinitionId()).singleResult();
assertNotNull(topLevelIncident);
Execution theCallingCallActivity = runtimeService.createExecutionQuery().activityId("theCallingCallActivity").singleResult();
assertNotNull(theCallingCallActivity);
assertNotNull(topLevelIncident.getId());
assertNotNull(topLevelIncident.getIncidentTimestamp());
assertEquals(FailedJobIncidentHandler.INCIDENT_HANDLER_TYPE, topLevelIncident.getIncidentType());
assertNull(topLevelIncident.getIncidentMessage());
assertEquals(theCallingCallActivity.getId(), topLevelIncident.getExecutionId());
assertEquals("theCallingCallActivity", topLevelIncident.getActivityId());
assertEquals(processInstance.getId(), topLevelIncident.getProcessInstanceId());
assertEquals(causeIncident.getId(), topLevelIncident.getCauseIncidentId());
assertEquals(rootCauseIncident.getId(), topLevelIncident.getRootCauseIncidentId());
assertNull(topLevelIncident.getConfiguration());
}