1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.vm.functional;
12
13 import org.mule.api.MessagingException;
14 import org.mule.api.MuleEventContext;
15 import org.mule.api.MuleMessage;
16 import org.mule.api.lifecycle.Callable;
17 import org.mule.api.transport.PropertyScope;
18 import org.mule.module.client.MuleClient;
19 import org.mule.tck.FunctionalTestCase;
20
21 import java.util.HashMap;
22 import java.util.Map;
23
24 public class EndpointContentTypeTestCase extends FunctionalTestCase
25 {
26 @Override
27 protected String getConfigResources()
28 {
29 return "org/mule/test/config/content-type-setting-endpoint-configs.xml";
30 }
31
32 public void testContentTypes() throws Exception
33 {
34 MuleMessage response;
35 Map<String, Object> messageProperties = new HashMap<String, Object>();
36 messageProperties.put("content-type", "text/xml");
37 MuleClient client = new MuleClient(muleContext);
38 response = client.send("vm://in1?connector=vm-in1", "<OK/>", messageProperties);
39 assertNotNull(response);
40 assertNotNull("Invalid mime type was not rejected", response.getExceptionPayload());
41 assertTrue(response.getExceptionPayload().getException() instanceof MessagingException);
42 messageProperties.put("content-type", "text/plain");
43 EchoComponent.setExpectedContentType("text/plain");
44 response = client.send("vm://in1?connector=vm-in1", "OK", messageProperties);
45 assertNotNull(response);
46 assertEquals("OK", response.getPayload());
47
48 messageProperties.remove("content-type");
49 EchoComponent.setExpectedContentType("text/plain");
50 response = client.send("vm://in1?connector=vm-in1", "OK", messageProperties);
51 assertNotNull(response);
52 assertEquals("OK", response.getPayload());
53
54 messageProperties.put("content-type", "text/plain");
55 EchoComponent.setExpectedContentType("text/xml");
56 response = client.send("vm://in2?connector=vm-in2", "OK", messageProperties);
57 assertNotNull(response);
58 assertEquals("OK", response.getPayload());
59 }
60
61 public static class EchoComponent implements Callable
62 {
63 static String expectedContentType;
64
65 public Object onCall(MuleEventContext eventContext) throws Exception
66 {
67 MuleMessage message = eventContext.getMessage();
68 assertEquals(expectedContentType, message.getProperty("content-type", PropertyScope.INBOUND));
69 return message;
70 }
71
72 public static void setExpectedContentType(String expectedContentType)
73 {
74 EchoComponent.expectedContentType = expectedContentType;
75 }
76 }
77 }