View Javadoc

1   /*
2    * $Id: JdbcNullParamsTestCase.java 22552 2011-07-25 07:18:19Z claude.mamo $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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 static org.junit.Assert.assertEquals;
14  import static org.junit.Assert.assertNotNull;
15  import static org.junit.Assert.assertNull;
16  import static org.junit.Assert.assertTrue;
17  
18  import org.mule.DefaultMuleMessage;
19  import org.mule.api.MuleMessage;
20  import org.mule.module.client.MuleClient;
21  import org.mule.transport.NullPayload;
22  
23  import java.util.Arrays;
24  import java.util.Collection;
25  import java.util.Map;
26  
27  import org.junit.Test;
28  import org.junit.runners.Parameterized.Parameters;
29  
30  public class JdbcNullParamsTestCase extends AbstractJdbcFunctionalTestCase
31  {
32      
33      public JdbcNullParamsTestCase(ConfigVariant variant, String configResources)
34      {
35          super(variant, configResources);
36          setPopulateTestData(false);
37      }
38      
39      @Parameters
40      public static Collection<Object[]> parameters()
41      {
42          return Arrays.asList(new Object[][]{            
43              {ConfigVariant.FLOW, "jdbc-null-params.xml"}
44          });
45      }      
46      
47      @Test
48      public void testJdbcNullParams() throws Exception
49      {
50          MuleClient client = new MuleClient(muleContext);
51          
52          //check that db is still empty
53          MuleMessage reply = client.request("jdbc://getTest", 1000);
54          assertTrue(reply.getPayload() instanceof Collection);
55          assertTrue(((Collection)reply.getPayload()).isEmpty());
56          
57          //execute the write query by sending a message on the jdbc://writeTest
58          //the message is a nullpayload since we are not taking any params from any object
59          //No other params will be sent to this endpoint
60          client.send("jdbc://writeTest", new DefaultMuleMessage(NullPayload.getInstance(), muleContext));
61          
62          //get the data which was written by the previous statement and test it
63          reply = client.request("jdbc://getTest", 1000);
64          
65          assertNotNull(reply);
66          assertTrue(reply.getPayload() instanceof Collection);
67          Collection result = (Collection)reply.getPayload();
68          assertEquals(1, result.size());   
69          
70          Map res = (Map)result.iterator().next();
71          
72          //check that id is equal to the one set originally and all others are null
73          Integer id = (Integer)res.get("ID");
74          assertEquals(1, id.intValue());
75          assertNull(res.get("TYPE"));
76          assertNull(res.get("DATA"));
77          assertNull(res.get("RESULT"));
78      }
79  }