View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.module.jbpm;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.api.client.MuleClient;
11  import org.mule.module.bpm.BPMS;
12  import org.mule.module.bpm.Process;
13  import org.mule.tck.junit4.FunctionalTestCase;
14  
15  import java.util.HashMap;
16  import java.util.Map;
17  
18  import org.junit.Test;
19  
20  import static org.junit.Assert.assertEquals;
21  import static org.junit.Assert.assertFalse;
22  import static org.junit.Assert.assertNotNull;
23  import static org.junit.Assert.assertTrue;
24  
25  /**
26   * Tests the connector against jBPM with a process which generates 
27   * a Mule message and processes its response. jBPM is instantiated by Spring. 
28   */
29  public class MessagingJbpmComponentTestCase extends FunctionalTestCase
30  {
31  
32      @Override
33      protected String getConfigResources()
34      {
35          return "jbpm-component-functional-test.xml";
36      }
37  
38      @Test
39      public void testSendMessageProcess() throws Exception
40      {
41          MuleClient client = muleContext.getClient();
42          BPMS bpms = muleContext.getRegistry().lookupObject(BPMS.class);
43          assertNotNull(bpms);
44  
45          // Create a new process.
46          MuleMessage response = client.send("vm://message", "data", null);
47          Object process = response.getPayload();
48          assertTrue(bpms.isProcess(process)); 
49  
50          String processId = (String)bpms.getId(process);
51          // The process should have sent a synchronous message, followed by an asynchronous message and now be in a wait state.
52          assertFalse(processId == null);
53          assertEquals("waitForResponse", bpms.getState(process));
54  
55          // Advance the process one step.
56          Map props = new HashMap<String, Object>();
57          props.put(Process.PROPERTY_PROCESS_ID, processId);
58          response = client.send("vm://message", "data", props);
59          process = response.getPayload();
60  
61          // The process should have ended.
62          assertTrue(bpms.hasEnded(process));
63      }
64  
65  }