1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.http.functional;
12
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertNotNull;
15
16 import org.mule.DefaultMuleMessage;
17 import org.mule.api.MuleEventContext;
18 import org.mule.api.MuleMessage;
19 import org.mule.api.client.LocalMuleClient;
20 import org.mule.api.config.MuleProperties;
21 import org.mule.tck.AbstractServiceAndFlowTestCase;
22 import org.mule.tck.functional.EventCallback;
23 import org.mule.tck.functional.FunctionalTestComponent;
24 import org.mule.tck.junit4.rule.DynamicPort;
25 import org.mule.util.IOUtils;
26 import org.mule.util.StringDataSource;
27
28 import java.util.Arrays;
29 import java.util.Collection;
30
31 import javax.activation.DataHandler;
32
33 import org.junit.Rule;
34 import org.junit.Test;
35 import org.junit.runners.Parameterized.Parameters;
36
37 public class HttpAttachmentsFunctionalTestCase extends AbstractServiceAndFlowTestCase
38 {
39
40 @Rule
41 public DynamicPort dynamicPort = new DynamicPort("port1");
42
43 public HttpAttachmentsFunctionalTestCase(ConfigVariant variant, String configResources)
44 {
45 super(variant, configResources);
46 }
47
48 @Parameters
49 public static Collection<Object[]> parameters()
50 {
51 return Arrays.asList(new Object[][]{
52 {ConfigVariant.SERVICE, "http-attachments-functional-test-service.xml"},
53 {ConfigVariant.FLOW, "http-attachments-functional-test-flow.xml"}
54 });
55 }
56
57 @Test
58 public void testSendAttachment() throws Exception
59 {
60 FunctionalTestComponent ftc = getFunctionalTestComponent("testComponent");
61 assertNotNull(ftc);
62 ftc.setEventCallback(new EventCallback(){
63 public void eventReceived(MuleEventContext context, Object component) throws Exception
64 {
65 assertEquals("application/octet-stream; charset=ISO-8859-1", context.getMessage().getInboundProperty(MuleProperties.CONTENT_TYPE_PROPERTY));
66 assertEquals("We should have an attachment", 1, context.getMessage().getInboundAttachmentNames().size());
67 DataHandler dh = context.getMessage().getInboundAttachment("attach1");
68 assertNotNull("DataHandler with name 'attach1' should not be null", dh);
69 assertEquals("We should have an attachment with foo", "foo" , IOUtils.toString(dh.getInputStream()));
70 assertEquals("text/plain; charset=ISO-8859-1", dh.getContentType());
71 }
72 });
73
74 LocalMuleClient client = muleContext.getClient();
75 MuleMessage msg = new DefaultMuleMessage("test", muleContext);
76 msg.addOutboundAttachment("attach1", new DataHandler(new StringDataSource("foo", "attach1")));
77
78 MuleMessage result = client.send("endpoint1", msg);
79 assertEquals("We should have no attachments coming back", 0, result.getInboundAttachmentNames().size());
80 }
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110 }