View Javadoc

1   /*
2    * $Id: ForkedProcessTestCase.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.transport.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  import org.mule.transport.bpm.ProcessConnector;
18  
19  import org.jbpm.api.ProcessInstance;
20  
21  /**
22   * Tests the connector against jBPM with a simple process.
23   * 
24   * @deprecated It is recommended to configure BPM as a component rather than a transport for 3.x
25   */
26  public class ForkedProcessTestCase extends FunctionalTestCase
27  {
28      @Override
29      protected String getConfigResources()
30      {
31          return "jbpm-functional-test.xml";
32      }
33  
34      public void testForkedProcess() throws Exception 
35      {
36          ProcessConnector connector = (ProcessConnector) muleContext.getRegistry().lookupConnector("bpmConnector");
37          BPMS bpms = connector.getBpms();
38          assertNotNull(bpms);
39  
40          MuleClient client = new MuleClient(muleContext);
41          try
42          {
43              // Create a new process.
44              MuleMessage response = client.send("bpm://fork", "data", null);                      
45              ProcessInstance process = (ProcessInstance) response.getPayload();
46              
47              // The process should be waiting for asynchronous responses from both services
48              String state = (String) bpms.getState(process);
49              assertTrue(state.contains("waitForResponseA"));
50              assertTrue(state.contains("waitForResponseB"));
51  
52              Thread.sleep(2000);
53  
54              // ServiceA is initially stopped, so we're still waiting for a response from ServiceA
55              process = (ProcessInstance) bpms.lookupProcess(process.getId());
56              assertEquals("waitForResponseA", bpms.getState(process));
57  
58              // Start ServiceA
59              muleContext.getRegistry().lookupService("ServiceA").resume();
60              Thread.sleep(2000);
61                          
62              // The process should have ended.
63              process = (ProcessInstance) bpms.lookupProcess(process.getId());
64              assertTrue("Process should have ended, but is in state " + bpms.getState(process), 
65                      bpms.hasEnded(process));
66          }
67          finally
68          {
69              client.dispose();
70          }
71      }
72  }