1   /*
2    * $Id: HttpContinueFunctionalTestCase.java 7963 2007-08-21 08:53:15Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.providers.http.functional;
12  
13  import org.mule.extras.client.MuleClient;
14  import org.mule.providers.http.HttpConnector;
15  import org.mule.tck.FunctionalTestCase;
16  import org.mule.umo.UMOMessage;
17  
18  import java.util.HashMap;
19  import java.util.Map;
20  
21  import org.apache.commons.httpclient.HttpVersion;
22  import org.apache.commons.httpclient.params.HttpClientParams;
23  import org.apache.commons.lang.time.StopWatch;
24  
25  public class HttpContinueFunctionalTestCase extends FunctionalTestCase
26  {
27  
28      public static final String TEST_MESSAGE = "Foo Bar";
29  
30      protected String getConfigResources()
31      {
32          return "http-functional-test.xml";
33      }
34  
35      /**
36       * HttpClient has default 3 seconds wait for Expect-Continue calls.
37       */
38      public static final int DEFAULT_HTTP_CLIENT_CONTINUE_WAIT = 3000;
39  
40      protected StopWatch stopWatch;
41  
42      public void testSendWithContinue() throws Exception
43      {
44          MuleClient client = new MuleClient();
45          Map props = new HashMap();
46          //Need to use Http1.1 for Expect: Continue
47          HttpClientParams params = new HttpClientParams();
48          params.setVersion(HttpVersion.HTTP_1_1);
49          params.setBooleanParameter(HttpClientParams.USE_EXPECT_CONTINUE, true);
50          props.put(HttpConnector.HTTP_PARAMS_PROPERTY, params);
51          stopWatch = new StopWatch();
52          stopWatch.start();
53          UMOMessage result = client.send("clientEndpoint", TEST_MESSAGE, props);
54          stopWatch.stop();
55  
56          assertNotNull(result);
57          assertEquals(TEST_MESSAGE + " Received", result.getPayloadAsString());
58  
59          if (stopWatch.getTime() > DEFAULT_HTTP_CLIENT_CONTINUE_WAIT)
60          {
61              fail("Server did not handle Expect=100-continue header properly,");
62          }
63      }
64  }