1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.servlet.jetty.functional;
12
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertNotNull;
15
16 import org.mule.api.MuleMessage;
17 import org.mule.module.client.MuleClient;
18 import org.mule.transport.http.HttpConnector;
19 import org.mule.transport.http.HttpConstants;
20 import org.mule.transport.http.functional.HttpFunctionalTestCase;
21
22 import java.util.Arrays;
23 import java.util.Collection;
24 import java.util.HashMap;
25 import java.util.Map;
26
27 import org.junit.Test;
28 import org.junit.runners.Parameterized.Parameters;
29
30 public class JettyHttpEncodingFunctionalTestCase extends HttpFunctionalTestCase
31 {
32 protected static String TEST_MESSAGE = "Test Http Request (R�dgr�d), 57 = \u06f7\u06f5 in Arabic";
33
34 public JettyHttpEncodingFunctionalTestCase(ConfigVariant variant, String configResources)
35 {
36 super(variant, configResources);
37 }
38
39 @Parameters
40 public static Collection<Object[]> parameters()
41 {
42 return Arrays.asList(new Object[][]{
43 {ConfigVariant.SERVICE, "jetty-http-encoding-test-service.xml"},
44 {ConfigVariant.FLOW, "jetty-http-encoding-test-flow.xml"}
45 });
46 }
47
48 @Test
49 public void testSendWithProperResponseContentType() throws Exception
50 {
51 MuleClient client = new MuleClient(muleContext);
52 Map<String, String> messageProperties = new HashMap<String, String>();
53 messageProperties.put(HttpConstants.HEADER_CONTENT_TYPE, getSendEncoding());
54 MuleMessage reply = client.send("clientEndpoint", TEST_MESSAGE, messageProperties);
55 assertNotNull(reply);
56 assertEquals("200", reply.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY));
57 assertEquals("text/baz;charset=UTF-16BE", reply.getInboundProperty(HttpConstants.HEADER_CONTENT_TYPE));
58 assertEquals("UTF-16BE", reply.getEncoding());
59 assertEquals(TEST_MESSAGE + " Received", reply.getPayloadAsString());
60 }
61
62
63
64
65 @Test
66 public void testSendWithInvalidResponseContentType() throws Exception
67 {
68 MuleClient client = new MuleClient(muleContext);
69 Map<String, String> messageProperties = new HashMap<String, String>();
70 messageProperties.put(HttpConstants.HEADER_CONTENT_TYPE, getSendEncoding());
71 MuleMessage reply = client.send("clientEndpoint2", TEST_MESSAGE, messageProperties);
72 assertNotNull(reply);
73 assertEquals("200", reply.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY));
74 assertEquals("text/plain;charset=UTF-8", reply.getInboundProperty(HttpConstants.HEADER_CONTENT_TYPE));
75 assertEquals("UTF-8", reply.getEncoding());
76 }
77
78 protected String getSendEncoding()
79 {
80 return "text/plain;charset=UTF-8";
81 }
82 }