View Javadoc

1   /*
2    * $Id: VMAttachmentsTestCase.java 19368 2010-09-05 05:19:34Z mike.schilling $
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.transport.vm.functional;
12  
13  import org.mule.DefaultMuleMessage;
14  import org.mule.api.MuleMessage;
15  import org.mule.module.client.MuleClient;
16  import org.mule.tck.FunctionalTestCase;
17  
18  import java.io.File;
19  
20  import javax.activation.DataHandler;
21  import javax.activation.FileDataSource;
22  
23  public class VMAttachmentsTestCase extends FunctionalTestCase
24  {
25  
26      protected String getConfigResources()
27      {
28          return "vm/vm-attachments-test.xml";
29      }
30  
31      public void testAttachments() throws Exception
32      {
33          DefaultMuleMessage msg = new DefaultMuleMessage("Mmm... attachments!", muleContext);
34          FileDataSource ds = new FileDataSource(new File("transports/vm/src/test/resources/"
35                                                          + getConfigResources()).getAbsoluteFile());
36          msg.addOutboundAttachment("test-attachment", new DataHandler(ds));
37  
38          MuleClient client = new MuleClient(muleContext);
39          MuleMessage reply = client.send("vm-in", msg);
40  
41          assertNotNull(reply);
42          if (reply.getExceptionPayload() != null)
43          {
44              fail(reply.getExceptionPayload().getException().getCause().toString());
45          }
46  
47          //TODO MULE-5000 attachments should be on the inbound
48          assertEquals(1, reply.getInboundAttachmentNames().size());
49          assertNotNull(reply.getInboundAttachment("mule"));
50          assertTrue(reply.getInboundAttachment("mule").getContentType().startsWith("image/gif"));
51      }
52  }