View Javadoc

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