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