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