View Javadoc

1   /*
2    * $Id: VMAttachmentsTestCase.java 22449 2011-07-19 07:40:43Z justin.calleja $
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 static org.junit.Assert.assertEquals;
14  import static org.junit.Assert.assertNotNull;
15  import static org.junit.Assert.assertTrue;
16  import static org.junit.Assert.fail;
17  
18  import java.io.File;
19  import java.util.Arrays;
20  import java.util.Collection;
21  
22  import javax.activation.DataHandler;
23  import javax.activation.FileDataSource;
24  
25  import org.junit.Test;
26  import org.junit.runners.Parameterized.Parameters;
27  import org.mule.DefaultMuleMessage;
28  import org.mule.api.MuleMessage;
29  import org.mule.module.client.MuleClient;
30  import org.mule.tck.AbstractServiceAndFlowTestCase;
31  
32  public class VMAttachmentsTestCase extends AbstractServiceAndFlowTestCase
33  {
34  
35      public VMAttachmentsTestCase(ConfigVariant variant, String configResources)
36      {
37          super(variant, configResources);
38      }
39     
40      @Parameters
41      public static Collection<Object[]> parameters()
42      {
43          return Arrays.asList(new Object[][]{
44              {ConfigVariant.SERVICE, "vm/vm-attachments-test-service.xml"},
45              {ConfigVariant.FLOW, "vm/vm-attachments-test-flow.xml"}
46          });
47      }
48  
49      @Test
50      public void testAttachments() throws Exception
51      {
52          DefaultMuleMessage msg = new DefaultMuleMessage("Mmm... attachments!", muleContext);
53          FileDataSource ds = new FileDataSource(new File("transports/vm/src/test/resources/"
54                                                          + getConfigResources()).getAbsoluteFile());
55          msg.addOutboundAttachment("test-attachment", new DataHandler(ds));
56  
57          MuleClient client = new MuleClient(muleContext);
58          MuleMessage reply = client.send("vm-in", msg);
59  
60          assertNotNull(reply);
61          if (reply.getExceptionPayload() != null)
62          {
63              fail(reply.getExceptionPayload().getException().getCause().toString());
64          }
65  
66          //TODO MULE-5000 attachments should be on the inbound
67          assertEquals(1, reply.getInboundAttachmentNames().size());
68          assertNotNull(reply.getInboundAttachment("mule"));
69          assertTrue(reply.getInboundAttachment("mule").getContentType().startsWith("image/gif"));
70      }
71  }