View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.vm.functional;
8   
9   import org.mule.DefaultMuleMessage;
10  import org.mule.api.MuleMessage;
11  import org.mule.module.client.MuleClient;
12  import org.mule.tck.junit4.FunctionalTestCase;
13  
14  import java.io.File;
15  
16  import javax.activation.DataHandler;
17  import javax.activation.FileDataSource;
18  
19  import org.junit.Test;
20  
21  import static org.junit.Assert.assertEquals;
22  import static org.junit.Assert.assertNotNull;
23  import static org.junit.Assert.assertTrue;
24  import static org.junit.Assert.fail;
25  
26  public class VMAttachmentsTestCase extends FunctionalTestCase
27  {
28  
29      @Override
30      protected String getConfigResources()
31      {
32          return "vm/vm-attachments-test.xml";
33      }
34  
35      @Test
36      public void testAttachments() throws Exception
37      {
38          DefaultMuleMessage msg = new DefaultMuleMessage("Mmm... attachments!", muleContext);
39          FileDataSource ds = new FileDataSource(new File("transports/vm/src/test/resources/"
40                                                          + getConfigResources()).getAbsoluteFile());
41          msg.addOutboundAttachment("test-attachment", new DataHandler(ds));
42  
43          MuleClient client = new MuleClient(muleContext);
44          MuleMessage reply = client.send("vm-in", msg);
45  
46          assertNotNull(reply);
47          if (reply.getExceptionPayload() != null)
48          {
49              fail(reply.getExceptionPayload().getException().getCause().toString());
50          }
51  
52          //TODO MULE-5000 attachments should be on the inbound
53          assertEquals(1, reply.getInboundAttachmentNames().size());
54          assertNotNull(reply.getInboundAttachment("mule"));
55          assertTrue(reply.getInboundAttachment("mule").getContentType().startsWith("image/gif"));
56      }
57  }