1   /*
2    * $Id: JdbcNullParamsTestCase.java 10789 2008-02-12 20:04:43Z dfeist $
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.util.Collection;
19  import java.util.Map;
20  
21  public class JdbcNullParamsTestCase extends AbstractJdbcFunctionalTestCase
22  {
23      public JdbcNullParamsTestCase()
24      {
25          setPopulateTestData(false);
26      }
27      
28      protected String getConfigResources()
29      {
30          return "jdbc-null-params.xml";
31      }
32  
33      public void testJdbcNullParams() throws Exception
34      {
35          MuleClient client = new MuleClient();
36          
37          //check that db is still empty
38          MuleMessage reply = client.request("jdbc://getTest", 1000);
39          assertTrue(reply.getPayload() instanceof Collection);
40          assertTrue(((Collection)reply.getPayload()).isEmpty());
41          
42          //execute the write query by sending a message on the jdbc://writeTest
43          //the message is a nullpayload since we are not taking any params from any object
44          //No other params will be sent to this endpoint
45          client.send("jdbc://writeTest", new DefaultMuleMessage(NullPayload.getInstance()));
46          
47          //get the data which was written by the previous statement and test it
48          reply = client.request("jdbc://getTest", 1000);
49          
50          assertNotNull(reply);
51          assertTrue(reply.getPayload() instanceof Collection);
52          Collection result = (Collection)reply.getPayload();
53          assertEquals(1, result.size());   
54          
55          Map res = (Map)result.iterator().next();
56          
57          //check that id is equal to the one set originally and all others are null
58          Integer id = (Integer)res.get("ID");
59          assertEquals(1, id.intValue());
60          assertNull(res.get("TYPE"));
61          assertNull(res.get("DATA"));
62          assertNull(res.get("RESULT"));
63      }
64  }