Search in sources :

Example 6 with WorkflowProcessInstance

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

the class HospitalInsuranceProcessTest method testPatientNotInsuredProcess.

/**
     * Tests the execution path for a patient NOT having a valid insurance.
     */
@Test
public void testPatientNotInsuredProcess() {
    HashMap<String, Object> input = new HashMap<String, Object>();
    Patient brotha = testPatients.get("brotha");
    input.put("patientName", brotha.getId());
    WorkflowProcessInstance pI = (WorkflowProcessInstance) session.startProcess("NewPatientInsuranceCheck", input);
    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 7 with WorkflowProcessInstance

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

the class ServiceTaskTest method testPatientInsuranceCheckProcessTrue.

/**
     * 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 testPatientInsuranceCheckProcessTrue() {
    HashMap<String, Object> input = new HashMap<String, Object>();
    input.put("bedrequest_patientname", testPatients.get("salaboy").getId());
    //Register a synchronous work item handler that will invoke a web service.
    //This work item handler is provided by jBPM5.
    session.getWorkItemManager().registerWorkItemHandler("Service Task", new ServiceTaskHandler());
    WorkflowProcessInstance pI = (WorkflowProcessInstance) session.startProcess("NewPatientInsuranceCheck", input);
    //'salaboy' is correctly inssured according to the web service we have configured.
    //The response should be valid.
    assertEquals(ProcessInstance.STATE_COMPLETED, pI.getState());
    assertEquals(Boolean.TRUE, pI.getVariable("checkinresults_patientInsured"));
    System.out.println("-> Insurance Valid = " + pI.getVariable("checkinresults_patientInsured"));
}
Also used : ServiceTaskHandler(org.jbpm.bpmn2.handler.ServiceTaskHandler) HashMap(java.util.HashMap) WorkflowProcessInstance(org.drools.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Example 8 with WorkflowProcessInstance

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

the class ServiceTaskTest 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.
    //This work item handler is provided by jBPM5.
    session.getWorkItemManager().registerWorkItemHandler("Service Task", new ServiceTaskHandler());
    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 : ServiceTaskHandler(org.jbpm.bpmn2.handler.ServiceTaskHandler) HashMap(java.util.HashMap) WorkflowProcessInstance(org.drools.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Example 9 with WorkflowProcessInstance

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

the class SlowWebServicesInteractionsTest method testSlowWebServicesNoWait.

/**
     * Invokes 3 web services that take some time to be executed. The process
     * will continue with its execution without waiting for each web service to
     * finish. 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 testSlowWebServicesNoWait() throws InterruptedException {
    initializeSession("three-systems-interactions-nowait.bpmn");
    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);
    //Even if the requests are not executed yet, the process is completed.
    List<RequestInfo> resultList = executor.getExecutedRequests();
    assertEquals(0, resultList.size());
    assertEquals(ProcessInstance.STATE_COMPLETED, 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());
    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 10 with WorkflowProcessInstance

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

the class AsyncWorkItemWaitForCompletionTest method executorCheckInTestFinishesWithoutHandler.

/**
     * AsyncWorkItemWaitForCompletionTest: 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 wait until the external system comes 
     * back before completing the Task. The result will be a process that will is not 
     * going to be completed until the external system comes back with a response.
     * @throws InterruptedException 
     */
@Test
public void executorCheckInTestFinishesWithoutHandler() 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);
    //No command was executed yet.
    assertEquals(0, CheckInCommand.getCheckInCount());
    //Since we are waiting for the execution of the external system to be done,
    //the process is still ACTIVE.
    assertEquals(ProcessInstance.STATE_ACTIVE, pI.getState());
    Thread.sleep(1000);
    //After 1 second, the command is not yet executed meaning that the process
    //is still ACTIVE.
    assertEquals(0, CheckInCommand.getCheckInCount());
    assertEquals(ProcessInstance.STATE_ACTIVE, pI.getState());
    Thread.sleep(executor.getInterval() * 1000);
    //After a reasonable time, the command must be executed. This should
    //have caused the execution of the callback and hence the completion
    //of the work item and thus the process.
    assertEquals(1, CheckInCommand.getCheckInCount());
    assertEquals(ProcessInstance.STATE_COMPLETED, pI.getState());
}
Also used : AsyncGenericWorkItemHandler(com.salaboy.jbpm5.dev.guide.workitems.AsyncGenericWorkItemHandler) HashMap(java.util.HashMap) 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