View Javadoc

1   /*
2    * $Id: VariablesTestCase.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 java.util.Date;
20  import java.util.HashMap;
21  import java.util.Map;
22  
23  /**
24   * @deprecated It is recommended to configure BPM as a component rather than a transport for 3.x
25   */
26  public class VariablesTestCase extends FunctionalTestCase
27  {
28      @Override
29      protected String getConfigResources()
30      {
31          return "jbpm-functional-test.xml";
32      }
33  
34      public void testVariables() throws Exception
35      {
36          ProcessConnector connector = (ProcessConnector) muleContext.getRegistry().lookupConnector("bpmConnector");
37          BPMS bpms = connector.getBpms();
38          assertNotNull(bpms);
39          MuleClient client = new MuleClient(muleContext);
40          try
41          {
42              Map<String, Object> props = new HashMap<String, Object>();
43              props.put("foo", "bar");
44              MuleMessage response = client.send("bpm://variables", "data", props);
45              String processId = (String)bpms.getId(response.getPayload());
46              assertNotNull(processId);
47  
48              response = client.request("vm://queueA", 3000);
49              assertNotNull(response);
50              assertEquals("bar", response.getInboundProperty("foo"));
51              assertEquals(0.75, response.getInboundProperty("fraction"));
52  
53              // Advance the process
54              props = new HashMap<String, Object>();
55              props.put("straw", "berry");
56              props.put("time", new Date());
57              response = client.send("bpm://variables/" + processId, "data", props);
58              
59              response = client.request("vm://queueB", 3000);
60              assertNotNull(response);
61              assertEquals("bar", response.getInboundProperty("foo"));
62              assertEquals(0.75, response.getInboundProperty("fraction"));
63              assertEquals("berry", response.getInboundProperty("straw"));
64              final Object o = response.getInboundProperty("time");
65              assertTrue(o instanceof Date);
66          }
67          finally
68          {
69              client.dispose();
70          }
71      }
72  }