1   /*
2    * $Id: VMAttachmentsTestCase.java 10789 2008-02-12 20:04:43Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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!");
34          FileDataSource ds = new FileDataSource(new File("transports/vm/src/test/resources/"
35                                                          + getConfigResources()).getAbsoluteFile());
36          msg.addAttachment("test-attachment", new DataHandler(ds));
37  
38          MuleClient client = new MuleClient();
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          assertEquals(1, reply.getAttachmentNames().size());
48          assertNotNull(reply.getAttachment("mule"));
49          assertTrue(reply.getAttachment("mule").getContentType().startsWith("image/gif"));
50      }
51  }