int fired = this.processManager.fireAllRules();
// Now that I have rules being evaluated, at least one should fire
Assert.assertEquals(1, fired);
// Lets check the value of the vehicle variable it should be an Ambulance => Heart Attack
Vehicle selectedVehicle = ((Vehicle) processManager.getProcessVariable("vehicle"));
Assert.assertTrue(selectedVehicle instanceof Ambulance);
// Is the Process still Active?
Assert.assertFalse(this.processManager.isProcessInstanceCompleted());
Assert.assertEquals(ProcessInstance.STATE_ACTIVE, processManager.getProcessState());
// Is there a running node instance?
Assert.assertEquals(1, processManager.getNodeInstancesSize());
// Is the process stopped in the "Dispatch Vehicle" activity?
Assert.assertEquals("Dispatch Vehicle", processManager.getCurrentNodeName());
// Lets check the value of the emergency.getRevision(), it should be 1
Assert.assertEquals(2, ((Emergency) processManager.getProcessVariable("emergency")).getRevision());
System.out.println("Completing the second Activity");
//Complete the second human activity
humanActivitiesSimHandler.completeWorkItem();
//Start Tracking is not automatic. The external system has to finish first.
//Until then, the process will be waiting in StartTrackingSystem
Assert.assertEquals("Vehicle " + selectedVehicle.getId() + " Located at 5th and A Avenue", trackingSystem.queryVehicleStatus(selectedVehicle.getId()));
// Is the process completed? It shouldn't be because the External System didn't finish yet.
Assert.assertFalse(this.processManager.isProcessInstanceCompleted());
Assert.assertEquals(ProcessInstance.STATE_ACTIVE, this.processManager.getProcessState());
//Now complete the external system. We will wait a few seconds to
//emulate the time needed by the VehicleTrackingSystem to complete the
//job
Thread.sleep(2000);
this.trackingSystem.stopTacking(this.trackingSystem.queryVehicleTrackingId(selectedVehicle.getId()));
// Is the process completed now?
Assert.assertTrue(this.processManager.isProcessInstanceCompleted());
}