View Javadoc

1   /*
2    * $Id: ForkedProcessComponentTestCase.java 20121 2010-11-08 17:33:48Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.module.jbpm;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.module.bpm.BPMS;
15  import org.mule.tck.FunctionalTestCase;
16  
17  import org.jbpm.api.ProcessInstance;
18  
19  public class ForkedProcessComponentTestCase extends FunctionalTestCase
20  {
21      @Override
22      protected String getConfigResources()
23      {
24          return "jbpm-component-functional-test.xml";
25      }
26  
27      public void testForkedProcess() throws Exception 
28      {
29          BPMS bpms = muleContext.getRegistry().lookupObject(BPMS.class);
30          assertNotNull(bpms);
31  
32          // Create a new process.
33          MuleMessage response = muleContext.getClient().send("vm://fork", "data", null);                      
34          ProcessInstance process = (ProcessInstance) response.getPayload();
35          
36          // The process should be waiting for asynchronous responses from both services
37          String state = (String) bpms.getState(process);
38          assertTrue(state.contains("waitForResponseA"));
39          assertTrue(state.contains("waitForResponseB"));
40  
41          Thread.sleep(2000);
42  
43          // ServiceA is initially stopped, so we're still waiting for a response from ServiceA
44          process = (ProcessInstance) bpms.lookupProcess(process.getId());
45          assertEquals("waitForResponseA", bpms.getState(process));
46  
47          // Start ServiceA
48          muleContext.getRegistry().lookupService("ServiceA").resume();
49          Thread.sleep(2000);
50                      
51          // The process should have ended.
52          process = (ProcessInstance) bpms.lookupProcess(process.getId());
53          assertTrue("Process should have ended, but is in state " + bpms.getState(process), 
54                  bpms.hasEnded(process));
55      }
56  }