View Javadoc

1   /*
2    * $Id: MessagingJbpmComponentTestCase.java 22552 2011-07-25 07:18:19Z claude.mamo $
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 static org.junit.Assert.assertEquals;
14  import static org.junit.Assert.assertFalse;
15  import static org.junit.Assert.assertNotNull;
16  import static org.junit.Assert.assertTrue;
17  
18  import org.mule.api.MuleMessage;
19  import org.mule.api.client.MuleClient;
20  import org.mule.module.bpm.BPMS;
21  import org.mule.module.bpm.Process;
22  import org.mule.tck.AbstractServiceAndFlowTestCase;
23  
24  import java.util.Arrays;
25  import java.util.Collection;
26  import java.util.HashMap;
27  import java.util.Map;
28  
29  import org.junit.Test;
30  import org.junit.runners.Parameterized.Parameters;
31  
32  /**
33   * Tests the connector against jBPM with a process which generates
34   * a Mule message and processes its response. jBPM is instantiated by Spring.
35   */
36  public class MessagingJbpmComponentTestCase extends AbstractServiceAndFlowTestCase
37  {
38      public MessagingJbpmComponentTestCase(ConfigVariant variant, String configResources)
39      {
40          super(variant, configResources);
41      }
42  
43      @Parameters
44      public static Collection<Object[]> parameters()
45      {
46          return Arrays.asList(new Object[][]{
47              {ConfigVariant.SERVICE, "jbpm-component-functional-test-service.xml"},
48              {ConfigVariant.FLOW, "jbpm-component-functional-test-flow.xml"}
49          });
50      }      
51      
52      @Test
53      public void testSendMessageProcess() throws Exception
54      {
55          MuleClient client = muleContext.getClient();
56          BPMS bpms = muleContext.getRegistry().lookupObject(BPMS.class);
57          assertNotNull(bpms);
58  
59          // Create a new process.
60          MuleMessage response = client.send("vm://message", "data", null);
61          Object process = response.getPayload();
62          assertTrue(bpms.isProcess(process));
63  
64          String processId = (String)bpms.getId(process);
65          // The process should have sent a synchronous message, followed by an asynchronous message and now be in a wait state.
66          assertFalse(processId == null);
67          assertEquals("waitForResponse", bpms.getState(process));
68  
69          // Advance the process one step.
70          Map<String, Object> props = new HashMap<String, Object>();
71          props.put(Process.PROPERTY_PROCESS_ID, processId);
72          response = client.send("vm://message", "data", props);
73          process = response.getPayload();
74  
75          // The process should have ended.
76          assertTrue(bpms.hasEnded(process));
77      }
78  
79  }