View Javadoc

1   /*
2    * $Id: OutboundHeadersAnnotationTestCase.java 22735 2011-08-25 16:02:35Z dfeist $
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.api.annotations.param;
12  
13  import static org.junit.Assert.assertEquals;
14  import static org.junit.Assert.assertNotNull;
15  import static org.junit.Assert.assertTrue;
16  
17  import org.mule.api.MuleMessage;
18  import org.mule.tck.AbstractServiceAndFlowTestCase;
19  import org.mule.util.ExceptionUtils;
20  
21  import java.util.Arrays;
22  import java.util.Collection;
23  import java.util.Map;
24  
25  import org.junit.Test;
26  import org.junit.runners.Parameterized.Parameters;
27  
28  public class OutboundHeadersAnnotationTestCase extends AbstractServiceAndFlowTestCase
29  {
30      @Parameters
31      public static Collection<Object[]> parameters()
32      {
33          return Arrays.asList(new Object[][]{
34              {ConfigVariant.SERVICE, "org/mule/test/annotations/outbound-headers-annotation-service.xml"},
35              {ConfigVariant.FLOW, "org/mule/test/annotations/outbound-headers-annotation-flow.xml"}});
36      }
37  
38      public OutboundHeadersAnnotationTestCase(ConfigVariant variant, String configResources)
39      {
40          super(variant, configResources);
41          setDisposeContextPerClass(true);
42      }
43  
44      @Test
45      public void testProcessHeader() throws Exception
46      {
47          MuleMessage message = muleContext.getClient().send("vm://header", null, null);
48          assertNotNull("return message from MuleClient.send() should not be null", message);
49          assertTrue("Message payload should be a Map", message.getPayload() instanceof Map);
50          Map<?, ?> result = (Map<?, ?>) message.getPayload();
51          assertEquals("barValue", result.get("bar"));
52      }
53  
54      @Test
55      public void testProcessHeaderWithExistingOutHeaders() throws Exception
56      {
57          MuleMessage message = muleContext.getClient().send("vm://header2", null, null);
58          assertNotNull("return message from MuleClient.send() should not be null", message);
59          assertTrue("Message payload should be a Map", message.getPayload() instanceof Map);
60          Map<?, ?> result = (Map<?, ?>) message.getPayload();
61          assertEquals("barValue", result.get("bar"));
62          assertEquals("fooValue", result.get("foo"));
63      }
64  
65      @Test
66      public void testInvalidParamType() throws Exception
67      {
68          MuleMessage message = muleContext.getClient().send("vm://invalid", null, null);
69          assertNotNull(message);
70          assertNotNull(message.getExceptionPayload());
71          assertEquals(IllegalArgumentException.class,
72              ExceptionUtils.getRootCause(message.getExceptionPayload().getException()).getClass());
73      }
74  }