View Javadoc

1   /*
2    * $Id: ForkedProcessComponentTestCase.java 19710 2010-09-23 16:29:07Z 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.module.client.MuleClient;
16  import org.mule.tck.FunctionalTestCase;
17  
18  import org.jbpm.api.ProcessInstance;
19  
20  public class ForkedProcessComponentTestCase extends FunctionalTestCase
21  {
22      @Override
23      protected String getConfigResources()
24      {
25          return "jbpm-component-functional-test.xml";
26      }
27  
28      public void testForkedProcess() throws Exception 
29      {
30          BPMS bpms = muleContext.getRegistry().lookupObject(BPMS.class);
31          assertNotNull(bpms);
32  
33          MuleClient client = new MuleClient(muleContext);
34          try
35          {
36              // Create a new process.
37              MuleMessage response = client.send("vm://fork", "data", null);                      
38              ProcessInstance process = (ProcessInstance) response.getPayload();
39              
40              // The process should be waiting for asynchronous responses from both services
41              String state = (String) bpms.getState(process);
42              assertTrue(state.contains("waitForResponseA"));
43              assertTrue(state.contains("waitForResponseB"));
44  
45              Thread.sleep(2000);
46  
47              // ServiceA is initially stopped, so we're still waiting for a response from ServiceA
48              process = (ProcessInstance) bpms.lookupProcess(process.getId());
49              assertEquals("waitForResponseA", bpms.getState(process));
50  
51              // Start ServiceA
52              muleContext.getRegistry().lookupService("ServiceA").resume();
53              Thread.sleep(2000);
54                          
55              // The process should have ended.
56              process = (ProcessInstance) bpms.lookupProcess(process.getId());
57              assertTrue("Process should have ended, but is in state " + bpms.getState(process), 
58                      bpms.hasEnded(process));
59          }
60          finally
61          {
62              client.dispose();
63          }
64      }
65  }