View Javadoc

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