1
2
3
4
5
6
7
8
9
10
11 package org.mule.module.jbpm;
12
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertNotNull;
15 import static org.junit.Assert.assertTrue;
16
17 import org.mule.api.MuleMessage;
18 import org.mule.api.client.MuleClient;
19 import org.mule.module.bpm.BPMS;
20 import org.mule.module.bpm.Process;
21 import org.mule.tck.AbstractServiceAndFlowTestCase;
22
23 import java.util.Arrays;
24 import java.util.Collection;
25 import java.util.Date;
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 public class VariablesComponentTestCase extends AbstractServiceAndFlowTestCase
33 {
34
35 private final int TIMEOUT = 10000;
36
37 public VariablesComponentTestCase(ConfigVariant variant, String configResources)
38 {
39 super(variant, configResources);
40 }
41
42 @Parameters
43 public static Collection<Object[]> parameters()
44 {
45 return Arrays.asList(new Object[][]{
46 {ConfigVariant.SERVICE, "jbpm-component-functional-test-service.xml"},
47 {ConfigVariant.FLOW, "jbpm-component-functional-test-flow.xml"}
48 });
49 }
50
51 @Test
52 public void testVariables() throws Exception
53 {
54 MuleClient client = muleContext.getClient();
55 BPMS bpms = muleContext.getRegistry().lookupObject(BPMS.class);
56 assertNotNull(bpms);
57
58 Map<String, Object> props = new HashMap<String, Object>();
59 props.put("foo", "bar");
60 MuleMessage response = client.send("vm://variables", "data", props);
61 String processId = (String)bpms.getId(response.getPayload());
62 assertNotNull(processId);
63
64 response = client.request("vm://queueA", TIMEOUT);
65 assertNotNull(response);
66 assertEquals("bar", response.getInboundProperty("foo"));
67 assertEquals(0.75, response.getInboundProperty("fraction"));
68
69
70 props = new HashMap<String, Object>();
71 props.put(Process.PROPERTY_PROCESS_ID, processId);
72 props.put("straw", "berry");
73 props.put("time", new Date());
74 response = client.send("vm://variables", "data", props);
75
76 response = client.request("vm://queueB", TIMEOUT);
77 assertNotNull(response);
78 assertEquals("bar", response.getInboundProperty("foo"));
79 assertEquals(0.75, response.getInboundProperty("fraction"));
80 assertEquals("berry", response.getInboundProperty("straw"));
81 final Object o = response.getInboundProperty("time");
82 assertTrue(o instanceof Date);
83 }
84
85 }