1
2
3
4
5
6
7
8
9
10
11 package org.mule.test.usecases.http;
12
13 import org.mule.DefaultMuleMessage;
14 import org.mule.api.MuleMessage;
15 import org.mule.module.client.MuleClient;
16 import org.mule.tck.FunctionalTestCase;
17 import org.mule.transport.NullPayload;
18 import org.mule.transport.http.HttpConnector;
19 import org.mule.transport.http.HttpConstants;
20
21 public class HttpResponseTestCase extends FunctionalTestCase
22 {
23 protected String getConfigResources()
24 {
25 return "org/mule/test/usecases/http/http-response.xml";
26 }
27
28 public void testNullPayloadUsingAsync() throws Exception
29 {
30 MuleClient client = new MuleClient(muleContext);
31 MuleMessage reply = client.send("http://localhost:8990", new DefaultMuleMessage("test", muleContext));
32
33
34 assertNotNull(reply.getPayload());
35 int status = reply.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, 0);
36 assertEquals(status, 200);
37 assertEquals(0, reply.getPayloadAsString().length());
38 }
39
40 public void testPayloadIsNotEmptyNoRemoteSynch() throws Exception
41 {
42 MuleClient client = new MuleClient(muleContext);
43 MuleMessage reply = client.send("http://localhost:8999", new DefaultMuleMessage("test", muleContext));
44 assertNotNull(reply.getPayload());
45 assertFalse(reply.getPayload() instanceof NullPayload);
46 assertEquals("test", reply.getPayloadAsString());
47 }
48
49 public void testPayloadIsNotEmptyWithRemoteSynch() throws Exception
50 {
51 MuleClient client = new MuleClient(muleContext);
52 MuleMessage reply = client.send("http://localhost:8989", new DefaultMuleMessage("test", muleContext));
53 assertNotNull(reply.getPayload());
54 assertFalse(reply.getPayload() instanceof NullPayload);
55 assertEquals("test", reply.getPayloadAsString());
56 }
57
58
59
60
61
62 public void testChunkingContentLength() throws Exception
63 {
64 MuleClient client = new MuleClient(muleContext);
65 MuleMessage reply = client.send("http://localhost:8988", new DefaultMuleMessage("test", muleContext));
66 assertNotNull(reply.getPayload());
67 assertFalse(reply.getPayload() instanceof NullPayload);
68 assertEquals("chunked", reply.getInboundProperty(HttpConstants.HEADER_TRANSFER_ENCODING));
69 assertNull(reply.getInboundProperty(HttpConstants.HEADER_CONTENT_LENGTH));
70 }
71
72 public void testNoChunkingContentLength() throws Exception
73 {
74 MuleClient client = new MuleClient(muleContext);
75 MuleMessage reply = client.send("http://localhost:8987", new DefaultMuleMessage("test", muleContext));
76 assertNotNull(reply.getPayload());
77 assertFalse(reply.getPayload() instanceof NullPayload);
78 assertNotSame("chunked", reply.getInboundProperty(HttpConstants.HEADER_TRANSFER_ENCODING));
79 assertNotNull(reply.getInboundProperty(HttpConstants.HEADER_CONTENT_LENGTH));
80 }
81
82 }