Search in sources :

Example 1 with WorkflowProcessInstance

use of org.drools.runtime.process.WorkflowProcessInstance in project jBPM5-Developer-Guide by Salaboy.

the class AsyncWorkItemDontWaitForCompletionTest method executorCheckInTestFinishes.

/**
     * Test executing a process with a single Task using the Executor Service
     * component to interact with a (mocked) external service. The process
     * is configured to tell the work item handler being used (AsyncGenericWorkItemHandler)
     * to not wait until the external system comes back to complete the Task.
     * The result will be a process that will be completed before the external
     * system is even invoked.
     * @throws InterruptedException 
     */
@Test
public void executorCheckInTestFinishes() throws InterruptedException {
    HashMap<String, Object> input = new HashMap<String, Object>();
    String patientName = "John Doe";
    input.put("bedrequest_patientname", patientName);
    //Registers an instance of AsyncGenericWorkItemHandler as a handler for
    //all the 'Async Work' tasks in the processes.
    AsyncGenericWorkItemHandler asyncHandler = new AsyncGenericWorkItemHandler(executor, session.getId());
    session.getWorkItemManager().registerWorkItemHandler("Async Work", asyncHandler);
    WorkflowProcessInstance pI = (WorkflowProcessInstance) session.startProcess("PatientCheckIn", input);
    //Since we are not waiting for the external system to respond before
    //completing the workiten, the process is executed in just 1 step.
    //At this point the process is completed.
    assertEquals(ProcessInstance.STATE_COMPLETED, pI.getState());
    //At this point, the command shouldn't be executed yet.
    assertEquals(0, CheckInCommand.getCheckInCount());
    Thread.sleep(1000);
    //After 1 second, the command is not yet executed.
    assertEquals(0, CheckInCommand.getCheckInCount());
    Thread.sleep(executor.getInterval() * 1000);
    //After a reasonable time, the command must be executed.
    assertEquals(1, CheckInCommand.getCheckInCount());
}
Also used : AsyncGenericWorkItemHandler(com.salaboy.jbpm5.dev.guide.workitems.AsyncGenericWorkItemHandler) HashMap(java.util.HashMap) WorkflowProcessInstance(org.drools.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Example 2 with WorkflowProcessInstance

use of org.drools.runtime.process.WorkflowProcessInstance in project jBPM5-Developer-Guide by Salaboy.

the class GenericWebServiceTaskTest method testPatientInsuranceCheckProcessFalse.

/**
     * Simple test showing the interaction between a process and a web service.
     * This method tests the case of an invalid response from the web-service.
     */
@Test
public void testPatientInsuranceCheckProcessFalse() {
    HashMap<String, Object> input = new HashMap<String, Object>();
    input.put("bedrequest_patientname", testPatients.get("brotha").getId());
    //Register a synchronous work item handler that will invoke a web service
    CXFWebServiceWorkItemHandler webServiceHandler = new CXFWebServiceWorkItemHandler();
    session.getWorkItemManager().registerWorkItemHandler("Web Service", webServiceHandler);
    WorkflowProcessInstance pI = (WorkflowProcessInstance) session.startProcess("NewPatientInsuranceCheck", input);
    //'brotha' is not inssured according to the web service we have configured.
    //The response should be invalid.
    assertEquals(ProcessInstance.STATE_COMPLETED, pI.getState());
    assertEquals(Boolean.FALSE, pI.getVariable("checkinresults_patientInsured"));
    System.out.println("-> Insurance Valid = " + pI.getVariable("checkinresults_patientInsured"));
}
Also used : HashMap(java.util.HashMap) CXFWebServiceWorkItemHandler(com.salaboy.jbpm5.dev.guide.workitems.CXFWebServiceWorkItemHandler) WorkflowProcessInstance(org.drools.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Example 3 with WorkflowProcessInstance

use of org.drools.runtime.process.WorkflowProcessInstance in project jBPM5-Developer-Guide by Salaboy.

the class SlowWebServicesInteractionsTest method testSlowWebServicesWait.

/**
     * Invokes 3 web services that take some time to be executed. The process
     * will wait for each web service to finish before continuing to the next
     * task. The process -> web service interaction is performed using the
     * Execution Service component. The Command being used is {@link CXFWebServiceCommand}
     * and the web service implementation is {@link SlowServiceImpl}.
     * @throws InterruptedException 
     */
@Test
public void testSlowWebServicesWait() throws InterruptedException {
    initializeSession("three-systems-interactions-wait.bpmn");
    SessionStoreUtil.sessionCache.put("sessionId=" + session.getId(), session);
    HashMap<String, Object> input = new HashMap<String, Object>();
    String patientName = "John Doe";
    input.put("bedrequest_patientname", patientName);
    AsyncGenericWorkItemHandler webServiceHandler = new AsyncGenericWorkItemHandler(executor, session.getId());
    session.getWorkItemManager().registerWorkItemHandler("Slow Web Service", webServiceHandler);
    WorkflowProcessInstance pI = (WorkflowProcessInstance) session.startProcess("ThreeSystemsInteractions", input);
    //No web service was invoked yet, so the process remains ACTIVE
    List<RequestInfo> resultList = executor.getExecutedRequests();
    assertEquals(0, resultList.size());
    assertEquals(ProcessInstance.STATE_ACTIVE, pI.getState());
    Thread.sleep(35000);
    //After 35 seconds we could see that the web services were invoked
    //correctly.
    resultList = executor.getExecutedRequests();
    assertEquals(3, resultList.size());
    assertEquals(ProcessInstance.STATE_COMPLETED, pI.getState());
    session.dispose();
}
Also used : AsyncGenericWorkItemHandler(com.salaboy.jbpm5.dev.guide.workitems.AsyncGenericWorkItemHandler) HashMap(java.util.HashMap) RequestInfo(org.jbpm.executor.entities.RequestInfo) WorkflowProcessInstance(org.drools.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Example 4 with WorkflowProcessInstance

use of org.drools.runtime.process.WorkflowProcessInstance in project jBPM5-Developer-Guide by Salaboy.

the class HospitalInsuranceProcessExecutorTest method testPatientNonInsuredProcessWithExecutor.

/**
     * Tests the execution path for a patient NOT having a valid insurance.
     */
@Test
public void testPatientNonInsuredProcessWithExecutor() throws InterruptedException {
    HashMap<String, Object> input = new HashMap<String, Object>();
    Patient brotha = testPatients.get("brotha");
    input.put("patientName", brotha.getId());
    SessionStoreUtil.sessionCache.put("sessionId=" + session.getId(), session);
    WorkflowProcessInstance pI = (WorkflowProcessInstance) session.startProcess("NewPatientInsuranceCheck", input);
    //Our application can continue doing other things, the executor will do the rest
    Thread.sleep(25000);
    assertEquals(ProcessInstance.STATE_COMPLETED, pI.getState());
    assertEquals(Boolean.TRUE, pI.getVariable("patientNotified"));
    assertEquals(600, ((BigDecimal) pI.getVariable("finalAmount")).intValue());
}
Also used : HashMap(java.util.HashMap) Patient(com.salaboy.jbpm5.dev.guide.model.Patient) WorkflowProcessInstance(org.drools.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Example 5 with WorkflowProcessInstance

use of org.drools.runtime.process.WorkflowProcessInstance in project jBPM5-Developer-Guide by Salaboy.

the class HospitalInsuranceProcessTest method testPatientInsuredProcess.

/**
     * Tests the execution path for a patient having a valid insurance.
     */
@Test
public void testPatientInsuredProcess() {
    HashMap<String, Object> input = new HashMap<String, Object>();
    Patient salaboy = testPatients.get("salaboy");
    input.put("patientName", salaboy.getId());
    WorkflowProcessInstance pI = (WorkflowProcessInstance) session.startProcess("NewPatientInsuranceCheck", input);
    assertEquals(ProcessInstance.STATE_COMPLETED, pI.getState());
    assertEquals(Boolean.TRUE, pI.getVariable("patientNotified"));
    assertEquals(50, ((BigDecimal) pI.getVariable("finalAmount")).intValue());
}
Also used : HashMap(java.util.HashMap) Patient(com.salaboy.jbpm5.dev.guide.model.Patient) WorkflowProcessInstance(org.drools.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)12 WorkflowProcessInstance (org.drools.runtime.process.WorkflowProcessInstance)12 Test (org.junit.Test)12 Patient (com.salaboy.jbpm5.dev.guide.model.Patient)4 AsyncGenericWorkItemHandler (com.salaboy.jbpm5.dev.guide.workitems.AsyncGenericWorkItemHandler)4 CXFWebServiceWorkItemHandler (com.salaboy.jbpm5.dev.guide.workitems.CXFWebServiceWorkItemHandler)2 ServiceTaskHandler (org.jbpm.bpmn2.handler.ServiceTaskHandler)2 RequestInfo (org.jbpm.executor.entities.RequestInfo)2