1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.http.functional;
12
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertNotNull;
15 import static org.junit.Assert.fail;
16
17 import org.mule.api.MuleMessage;
18 import org.mule.module.client.MuleClient;
19 import org.mule.tck.AbstractServiceAndFlowTestCase;
20 import org.mule.tck.junit4.rule.DynamicPort;
21 import org.mule.transport.http.HttpConnector;
22
23 import java.util.Arrays;
24 import java.util.Collection;
25 import java.util.HashMap;
26 import java.util.Map;
27
28 import org.apache.commons.httpclient.HttpVersion;
29 import org.apache.commons.httpclient.params.HttpClientParams;
30 import org.apache.commons.lang.time.StopWatch;
31 import org.junit.Rule;
32 import org.junit.Test;
33 import org.junit.runners.Parameterized.Parameters;
34
35 public class HttpContinueFunctionalTestCase extends AbstractServiceAndFlowTestCase
36 {
37
38
39
40
41 private static final int DEFAULT_HTTP_CLIENT_CONTINUE_WAIT = 3000;
42
43 protected StopWatch stopWatch;
44
45 @Rule
46 public DynamicPort dynamicPort = new DynamicPort("port1");
47
48 public HttpContinueFunctionalTestCase(ConfigVariant variant, String configResources)
49 {
50 super(variant, configResources);
51 }
52
53 @Parameters
54 public static Collection<Object[]> parameters()
55 {
56 return Arrays.asList(new Object[][]{
57 {ConfigVariant.SERVICE, "http-functional-test-service.xml"},
58 {ConfigVariant.FLOW, "http-functional-test-flow.xml"}
59 });
60 }
61
62 @Test
63 public void testSendWithContinue() throws Exception
64 {
65 stopWatch = new StopWatch();
66 MuleClient client = new MuleClient(muleContext);
67
68
69 HttpClientParams params = new HttpClientParams();
70 params.setVersion(HttpVersion.HTTP_1_1);
71 params.setBooleanParameter(HttpClientParams.USE_EXPECT_CONTINUE, true);
72
73 Map<String, Object> props = new HashMap<String, Object>();
74 props.put(HttpConnector.HTTP_PARAMS_PROPERTY, params);
75
76 stopWatch.start();
77 MuleMessage result = client.send("clientEndpoint", TEST_MESSAGE, props);
78 stopWatch.stop();
79
80 assertNotNull(result);
81 assertEquals(TEST_MESSAGE + " Received", result.getPayloadAsString());
82
83 if (stopWatch.getTime() > DEFAULT_HTTP_CLIENT_CONTINUE_WAIT)
84 {
85 fail("Server did not handle Expect=100-continue header properly,");
86 }
87 }
88
89 }