View Javadoc

1   /*
2    * $Id: Http10FunctionalTestCase.java 19817 2010-10-04 18:10:39Z dzapata $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.transport.http.functional;
12  
13  import org.mule.api.endpoint.InboundEndpoint;
14  import org.mule.module.client.MuleClient;
15  import org.mule.tck.DynamicPortTestCase;
16  import org.mule.tck.FunctionalTestCase;
17  import org.mule.transport.http.HttpConstants;
18  
19  import org.apache.commons.httpclient.HttpClient;
20  import org.apache.commons.httpclient.HttpVersion;
21  import org.apache.commons.httpclient.methods.GetMethod;
22  import org.apache.commons.httpclient.params.HttpClientParams;
23  
24  /**
25   * Tests as per http://www.io.com/~maus/HttpKeepAlive.html
26   */
27  public class Http10FunctionalTestCase extends DynamicPortTestCase
28  {
29      private HttpClient setupHttpClient()
30      {
31          HttpClientParams params = new HttpClientParams();
32          params.setVersion(HttpVersion.HTTP_1_0);
33          return new HttpClient(params);
34      }
35  
36      @Override
37      protected String getConfigResources()
38      {
39          return "http-10-config.xml";
40      }
41      
42      public void testHttp10EnforceNonChunking() throws Exception
43      {
44          HttpClient client = setupHttpClient();
45          MuleClient muleClient = new MuleClient(muleContext);
46          GetMethod request = new GetMethod(((InboundEndpoint) muleClient.getMuleContext().getRegistry().lookupObject("inStreaming")).getAddress());
47          client.executeMethod(request);
48          assertEquals("hello", request.getResponseBodyAsString());
49          
50          assertNull(request.getResponseHeader(HttpConstants.HEADER_TRANSFER_ENCODING));
51          assertNotNull(request.getResponseHeader(HttpConstants.HEADER_CONTENT_LENGTH));
52      }
53  
54      @Override
55      protected int getNumPortsToFind()
56      {
57          return 1;
58      }
59  }