View Javadoc

1   /*
2    * $Id: MessagingJbpmComponentTestCase.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.api.client.MuleClient;
15  import org.mule.module.bpm.BPMS;
16  import org.mule.module.bpm.Process;
17  import org.mule.tck.FunctionalTestCase;
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  /**
23   * Tests the connector against jBPM with a process which generates 
24   * a Mule message and processes its response. jBPM is instantiated by Spring. 
25   */
26  public class MessagingJbpmComponentTestCase extends FunctionalTestCase
27  {
28      protected String getConfigResources()
29      {
30          return "jbpm-component-functional-test.xml";
31      }
32  
33      public void testSendMessageProcess() throws Exception
34      {
35          MuleClient client = muleContext.getClient();
36          BPMS bpms = muleContext.getRegistry().lookupObject(BPMS.class);
37          assertNotNull(bpms);
38  
39          // Create a new process.
40          MuleMessage response = client.send("vm://message", "data", null);
41          Object process = response.getPayload();
42          assertTrue(bpms.isProcess(process)); 
43  
44          String processId = (String)bpms.getId(process);
45          // The process should have sent a synchronous message, followed by an asynchronous message and now be in a wait state.
46          assertFalse(processId == null);
47          assertEquals("waitForResponse", bpms.getState(process));
48  
49          // Advance the process one step.
50          Map props = new HashMap<String, Object>();
51          props.put(Process.PROPERTY_PROCESS_ID, processId);
52          response = client.send("vm://message", "data", props);
53          process = response.getPayload();
54  
55          // The process should have ended.
56          assertTrue(bpms.hasEnded(process));
57      }
58  }