View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
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  import org.mule.transport.NullPayload;
13  
14  import java.util.Collection;
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.assertNull;
22  import static org.junit.Assert.assertTrue;
23  
24  public class JdbcNullParamsTestCase extends AbstractJdbcFunctionalTestCase
25  {
26      
27      public JdbcNullParamsTestCase()
28      {
29          setPopulateTestData(false);
30      }
31      
32      @Override
33      protected String getConfigResources()
34      {
35          return "jdbc-null-params.xml";
36      }
37  
38      @Test
39      public void testJdbcNullParams() throws Exception
40      {
41          MuleClient client = new MuleClient(muleContext);
42          
43          //check that db is still empty
44          MuleMessage reply = client.request("jdbc://getTest", 1000);
45          assertTrue(reply.getPayload() instanceof Collection);
46          assertTrue(((Collection)reply.getPayload()).isEmpty());
47          
48          //execute the write query by sending a message on the jdbc://writeTest
49          //the message is a nullpayload since we are not taking any params from any object
50          //No other params will be sent to this endpoint
51          client.send("jdbc://writeTest", new DefaultMuleMessage(NullPayload.getInstance(), muleContext));
52          
53          //get the data which was written by the previous statement and test it
54          reply = client.request("jdbc://getTest", 1000);
55          
56          assertNotNull(reply);
57          assertTrue(reply.getPayload() instanceof Collection);
58          Collection result = (Collection)reply.getPayload();
59          assertEquals(1, result.size());   
60          
61          Map res = (Map)result.iterator().next();
62          
63          //check that id is equal to the one set originally and all others are null
64          Integer id = (Integer)res.get("ID");
65          assertEquals(1, id.intValue());
66          assertNull(res.get("TYPE"));
67          assertNull(res.get("DATA"));
68          assertNull(res.get("RESULT"));
69      }
70  }