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.Date;
16  import java.util.HashMap;
17  import java.util.Map;
18  
19  import org.junit.Test;
20  
21  import static org.junit.Assert.assertEquals;
22  import static org.junit.Assert.assertNotNull;
23  import static org.junit.Assert.assertTrue;
24  
25  public class VariablesComponentTestCase extends FunctionalTestCase
26  {
27  
28      private final int TIMEOUT = 10000;
29      
30      @Override
31      protected String getConfigResources()
32      {
33          return "jbpm-component-functional-test.xml";
34      }
35  
36      @Test
37      public void testVariables() throws Exception
38      {
39          MuleClient client = muleContext.getClient();
40          BPMS bpms = muleContext.getRegistry().lookupObject(BPMS.class);
41          assertNotNull(bpms);
42  
43          Map<String, Object> props = new HashMap<String, Object>();
44          props.put("foo", "bar");
45          MuleMessage response = client.send("vm://variables", "data", props);
46          String processId = (String)bpms.getId(response.getPayload());
47          assertNotNull(processId);
48  
49          response = client.request("vm://queueA", TIMEOUT);
50          assertNotNull(response);
51          assertEquals("bar", response.getInboundProperty("foo"));
52          assertEquals(0.75, response.getInboundProperty("fraction"));
53  
54          // Advance the process
55          props = new HashMap<String, Object>();
56          props.put(Process.PROPERTY_PROCESS_ID, processId);
57          props.put("straw", "berry");
58          props.put("time", new Date());
59          response = client.send("vm://variables", "data", props);
60          
61          response = client.request("vm://queueB", TIMEOUT);
62          assertNotNull(response);
63          assertEquals("bar", response.getInboundProperty("foo"));
64          assertEquals(0.75, response.getInboundProperty("fraction"));
65          assertEquals("berry", response.getInboundProperty("straw"));
66          final Object o = response.getInboundProperty("time");
67          assertTrue(o instanceof Date);
68      }
69  
70  }