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