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