1   /*
2    * $Id: JdbcSelectOnOutboundFunctionalTestCase.java 12181 2008-06-26 20:05:55Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
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  import org.mule.transport.NullPayload;
17  
18  import java.io.Serializable;
19  import java.util.List;
20  import java.util.Map;
21  
22  public class JdbcSelectOnOutboundFunctionalTestCase extends AbstractJdbcFunctionalTestCase
23  {
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();
37  //        MyMessage payload = new MyMessage(2);
38  //        MuleMessage reply = client.send("vm://terra", new DefaultMuleMessage(payload));
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();
62          MuleMessage reply = client.send(endpoint, new DefaultMuleMessage(NullPayload.getInstance()));
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  }