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.api.transformer.TransformerException;
11  import org.mule.module.client.MuleClient;
12  import org.mule.tck.junit4.FunctionalTestCase;
13  import org.mule.util.IOUtils;
14  
15  import java.io.InputStream;
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.assertTrue;
22  
23  public class PayloadAnnotationTestCase extends FunctionalTestCase
24  {
25      public PayloadAnnotationTestCase()
26      {
27          setDisposeContextPerClass(true);
28      }
29  
30      @Override
31      protected String getConfigResources()
32      {
33          return "org/mule/test/annotations/payload-annotation.xml";
34      }
35  
36      @Test
37      public void testPayloadNoTransform() throws Exception
38      {
39          MuleClient client = new MuleClient(muleContext);
40          MuleMessage message = client.send("vm://payload1", "foo", null);
41          assertNotNull("return message from MuleClient.send() should not be null", message);
42          assertTrue("Message payload should be a String", message.getPayload() instanceof String);
43          assertEquals("foo", message.getPayload());
44      }
45  
46      @Test
47      public void testPayloadAutoTransform() throws Exception
48      {
49          MuleClient client = new MuleClient(muleContext);
50          MuleMessage message = client.send("vm://payload2", "foo", null);
51          assertNotNull("return message from MuleClient.send() should not be null", message);
52          assertTrue("Message payload should be a String", message.getPayload() instanceof InputStream);
53          assertEquals("foo", IOUtils.toString((InputStream)message.getPayload()));
54      }
55  
56      @Test
57      public void testPayloadFailedTransform() throws Exception
58      {
59          MuleClient client = new MuleClient(muleContext);
60          MuleMessage message = client.send("vm://payload3", null, null);
61          assertNotNull("return message from MuleClient.send() should not be null", message);
62          assertNotNull(message.getExceptionPayload());
63          assertTrue(message.getExceptionPayload().getRootException() instanceof TransformerException);
64      }
65  }