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 org.junit.Test;
15  
16  import static org.junit.Assert.assertEquals;
17  import static org.junit.Assert.assertFalse;
18  import static org.junit.Assert.assertNotNull;
19  import static org.junit.Assert.assertNull;
20  
21  public class JdbcMessagePropertiesCopyingTestCase extends AbstractJdbcFunctionalTestCase
22  {
23  
24      private static final String PROPERTY_KEY = "custom-key";
25      private static final String PROPERTY_VALUE = "custom-value";
26  
27      @Override
28      protected String getConfigResources()
29      {
30          return super.getConfigResources() + ", jdbc-message-properties-copying.xml";
31      }
32  
33      @Test
34      public void testMessagePropertiesCopying() throws Exception
35      {
36          MuleClient client = new MuleClient(muleContext);
37          
38          MuleMessage message = new DefaultMuleMessage(TEST_MESSAGE, muleContext);
39          // provide a valid type header so the JDBC query actually returns something
40          message.setOutboundProperty("type", 1);
41          message.setOutboundProperty(PROPERTY_KEY, PROPERTY_VALUE);
42          
43          MuleMessage result = client.send("vm://in", message);
44          assertNotNull(result);
45          assertNull(result.getExceptionPayload());
46          assertFalse(result.getPayload() instanceof NullPayload);
47          assertEquals(PROPERTY_VALUE, result.getInboundProperty(PROPERTY_KEY));
48      }
49  }