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.api.annotations.param;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.module.client.MuleClient;
11  import org.mule.tck.junit4.FunctionalTestCase;
12  
13  import java.util.Map;
14  
15  import org.junit.Test;
16  
17  import static org.junit.Assert.assertEquals;
18  import static org.junit.Assert.assertNotNull;
19  import static org.junit.Assert.assertTrue;
20  
21  public class OutboundHeadersAnnotationTestCase extends FunctionalTestCase
22  {
23      public OutboundHeadersAnnotationTestCase()
24      {
25          setDisposeContextPerClass(true);
26      }
27  
28      @Override
29      protected String getConfigResources()
30      {
31          return "org/mule/test/annotations/outbound-headers-annotation.xml";
32      }
33  
34      @Test
35      public void testProcessHeader() throws Exception
36      {
37          MuleClient client = new MuleClient(muleContext);
38          MuleMessage message = client.send("vm://header", null, null);
39          assertNotNull("return message from MuleClient.send() should not be null", message);
40          assertTrue("Message payload should be a Map", message.getPayload() instanceof Map);
41          Map<?, ?> result = (Map<?, ?>) message.getPayload();
42          assertEquals("barValue", result.get("bar"));
43      }
44  
45      @Test
46      public void testProcessHeaderWithExistingOutHeaders() throws Exception
47      {
48          MuleClient client = new MuleClient(muleContext);
49          MuleMessage message = client.send("vm://header2", null, null);
50          assertNotNull("return message from MuleClient.send() should not be null", message);
51          assertTrue("Message payload should be a Map", message.getPayload() instanceof Map);
52          Map<?, ?> result = (Map<?, ?>) message.getPayload();
53          assertEquals("barValue", result.get("bar"));
54          assertEquals("fooValue", result.get("foo"));
55      }
56  
57      @Test
58      public void testInvalidParamType() throws Exception
59      {
60          MuleClient client = new MuleClient(muleContext);
61          MuleMessage message = client.send("vm://invalid", null, null);
62          assertNotNull("return message from MuleClient.send() should not be null", message);
63          assertNotNull(message.getExceptionPayload());
64          assertTrue(message.getExceptionPayload().getRootException() instanceof IllegalArgumentException);
65      }
66  }