View Javadoc

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