View Javadoc

1   /*
2    * $Id: OutboundAttachmentsAnnotationTestCase.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.module.client.MuleClient;
14  import org.mule.tck.FunctionalTestCase;
15  
16  import java.util.Map;
17  
18  import javax.activation.DataHandler;
19  
20  public class OutboundAttachmentsAnnotationTestCase extends FunctionalTestCase
21  {
22      public OutboundAttachmentsAnnotationTestCase()
23      {
24          setDisposeManagerPerSuite(true);
25      }
26  
27      @Override
28      protected String getConfigResources()
29      {
30          return "org/mule/test/annotations/outbound-attachments-annotation.xml";
31      }
32  
33      public void testProcessAttachment() throws Exception
34      {
35          MuleClient client = new MuleClient(muleContext);
36          MuleMessage message = client.send("vm://attachment", null, null);
37          assertNotNull("return message from MuleClient.send() should not be null", message);
38          assertTrue("Message payload should be a Map", message.getPayload() instanceof Map);
39          Map<String, DataHandler> result = getMapPayload(message);
40          assertEquals("barValue", result.get("bar").getContent());
41      }
42  
43      public void testProcessAttachmentWithExistingOutAttachments() throws Exception
44      {
45          MuleClient client = new MuleClient(muleContext);
46          MuleMessage message = client.send("vm://attachment2", null, null);
47          assertNotNull("return message from MuleClient.send() should not be null", message);
48          assertTrue("Message payload should be a Map", message.getPayload() instanceof Map);
49          Map<String, DataHandler> result = getMapPayload(message);
50          assertEquals("barValue", result.get("bar").getContent());
51          assertEquals("fooValue", result.get("foo").getContent());
52      }
53  
54      public void testInvalidParamType() throws Exception
55      {
56          MuleClient client = new MuleClient(muleContext);
57          MuleMessage message = client.send("vm://invalid", null, null);
58          assertNotNull("return message from MuleClient.send() should not be null", message);
59          assertNotNull(message.getExceptionPayload());
60          assertTrue(message.getExceptionPayload().getRootException() instanceof IllegalArgumentException);
61      }
62      
63      @SuppressWarnings("unchecked")
64      private Map<String, DataHandler> getMapPayload(MuleMessage message)
65      {
66          return (Map<String, DataHandler>) message.getPayload();
67      }
68  }