1   /*
2    * $Id: VMAttachmentsTestCase.java 11728 2008-05-13 07:31:11Z dirk.olmes $
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.providers.vm.functional;
12  
13  import org.mule.extras.client.MuleClient;
14  import org.mule.impl.MuleMessage;
15  import org.mule.tck.FunctionalTestCase;
16  import org.mule.umo.UMOMessage;
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-attachments-test.xml";
29      }
30  
31      public void testAttachments() throws Exception
32      {
33          MuleMessage msg = new MuleMessage("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          MuleClient client = new MuleClient();
38          UMOMessage reply = client.send("vm-in", msg);
39  
40          assertNotNull(reply);
41          if (reply.getExceptionPayload() != null)
42          {
43              fail(reply.getExceptionPayload().getException().getCause().toString());
44          }
45  
46          assertEquals(1, reply.getAttachmentNames().size());
47          assertNotNull(reply.getAttachment("mule"));
48          assertTrue(reply.getAttachment("mule").getContentType().startsWith("image/gif"));
49      }
50  
51  }