1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.jdbc.functional;
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.DefaultMuleMessage;
18 import org.mule.api.MuleMessage;
19 import org.mule.module.client.MuleClient;
20
21 import java.io.Serializable;
22 import java.util.Arrays;
23 import java.util.Collection;
24 import java.util.List;
25 import java.util.Map;
26
27 import org.junit.Test;
28 import org.junit.runners.Parameterized.Parameters;
29
30 public class JdbcSelectOnOutboundFunctionalTestCase extends AbstractJdbcFunctionalTestCase
31 {
32 public JdbcSelectOnOutboundFunctionalTestCase(ConfigVariant variant, String configResources)
33 {
34 super(variant, configResources);
35 }
36
37 @Parameters
38 public static Collection<Object[]> parameters()
39 {
40 return Arrays.asList(new Object[][]{
41 {ConfigVariant.SERVICE, AbstractJdbcFunctionalTestCase.getConfig() + ",jdbc-select-outbound-service.xml"},
42 {ConfigVariant.FLOW, AbstractJdbcFunctionalTestCase.getConfig() + ",jdbc-select-outbound-flow.xml"}
43 });
44 }
45
46 @Test
47 public void testSelectOnOutbound() throws Exception
48 {
49 doSelectOnOutbound("vm://jdbc.test");
50 }
51
52 @Test
53 public void testSelectOnOutboundByExpression() throws Exception
54 {
55 MuleClient client = new MuleClient(muleContext);
56 MyMessage payload = new MyMessage(2);
57 MuleMessage reply = client.send("vm://terra", new DefaultMuleMessage(payload, muleContext));
58 assertNotNull(reply.getPayload());
59 assertTrue(reply.getPayload() instanceof List);
60 List resultList = (List)reply.getPayload();
61 assertTrue(resultList.size() == 1);
62 assertTrue(resultList.get(0) instanceof Map);
63 Map resultMap = (Map) resultList.get(0);
64 assertEquals(new Integer(2), resultMap.get("TYPE"));
65 assertEquals(TEST_VALUES[1], resultMap.get("DATA"));
66 }
67
68 @Test
69 public void testChain2SelectAlwaysBegin() throws Exception
70 {
71 doSelectOnOutbound("vm://chain.always.begin");
72 }
73
74 @Test
75 public void testChain2SelectBeginOrJoin() throws Exception
76 {
77 doSelectOnOutbound("vm://chain.begin.or.join");
78 }
79
80 private void doSelectOnOutbound(String endpoint) throws Exception
81 {
82 MuleClient client = new MuleClient(muleContext);
83 MuleMessage reply = client.send(endpoint, new Object(), null);
84 assertNotNull(reply.getPayload());
85 assertTrue(reply.getPayload() instanceof List);
86 List resultList = (List) reply.getPayload();
87 assertTrue(resultList.size() == 1);
88 assertTrue(resultList.get(0) instanceof Map);
89 Map resultMap = (Map) resultList.get(0);
90 assertEquals(new Integer(1), resultMap.get("TYPE"));
91 assertEquals(TEST_VALUES[0], resultMap.get("DATA"));
92 }
93
94 public static class MyMessage implements Serializable
95 {
96 public MyMessage(int type)
97 {
98 this.type = type;
99 }
100
101 private int type;
102
103 public int getType()
104 {
105 return type;
106 }
107
108 public void setType(int type)
109 {
110 this.type = type;
111 }
112 }
113 }