1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.http.functional;
12
13 import org.mule.DefaultMuleMessage;
14 import org.mule.api.MuleEventContext;
15 import org.mule.api.MuleMessage;
16 import org.mule.api.client.LocalMuleClient;
17 import org.mule.api.config.MuleProperties;
18 import org.mule.tck.DynamicPortTestCase;
19 import org.mule.tck.functional.EventCallback;
20 import org.mule.tck.functional.FunctionalTestComponent;
21 import org.mule.util.IOUtils;
22 import org.mule.util.StringDataSource;
23
24 import javax.activation.DataHandler;
25
26 public class HttpAttachmentsFunctionalTestCase extends DynamicPortTestCase
27 {
28 protected String getConfigResources()
29 {
30 return "http-attachments-functional-test.xml";
31 }
32
33 public void testSendAttachment() throws Exception
34 {
35 FunctionalTestComponent ftc = getFunctionalTestComponent("testComponent");
36 assertNotNull(ftc);
37 ftc.setEventCallback(new EventCallback(){
38 public void eventReceived(MuleEventContext context, Object component) throws Exception
39 {
40 assertEquals("application/octet-stream; charset=ISO-8859-1", context.getMessage().getInboundProperty(MuleProperties.CONTENT_TYPE_PROPERTY));
41 assertEquals("We should have an attachment", 1, context.getMessage().getInboundAttachmentNames().size());
42 DataHandler dh = context.getMessage().getInboundAttachment("attach1");
43 assertNotNull("DataHandler with name 'attach1' should not be null", dh);
44 assertEquals("We should have an attachment with foo", "foo" , IOUtils.toString(dh.getInputStream()));
45 assertEquals("text/plain; charset=ISO-8859-1", dh.getContentType());
46 }
47 });
48
49 LocalMuleClient client = muleContext.getClient();
50 MuleMessage msg = new DefaultMuleMessage("test", muleContext);
51 msg.addOutboundAttachment("attach1", new DataHandler(new StringDataSource("foo", "attach1")));
52
53 MuleMessage result = client.send("endpoint1", msg);
54 assertEquals("We should have no attachments coming back", 0, result.getInboundAttachmentNames().size());
55 }
56
57 @Override
58 protected int getNumPortsToFind()
59 {
60 return 1;
61 }
62
63
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 }