View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.http.functional;
8   
9   import org.mule.api.endpoint.InboundEndpoint;
10  import org.mule.module.client.MuleClient;
11  import org.mule.tck.junit4.FunctionalTestCase;
12  import org.mule.tck.junit4.rule.DynamicPort;
13  import org.mule.transport.http.HttpConstants;
14  
15  import org.apache.commons.httpclient.HttpClient;
16  import org.apache.commons.httpclient.HttpVersion;
17  import org.apache.commons.httpclient.methods.GetMethod;
18  import org.apache.commons.httpclient.params.HttpClientParams;
19  import org.junit.Rule;
20  import org.junit.Test;
21  
22  import static org.junit.Assert.assertEquals;
23  import static org.junit.Assert.assertNotNull;
24  import static org.junit.Assert.assertNull;
25  
26  /**
27   * Tests as per http://www.io.com/~maus/HttpKeepAlive.html
28   */
29  public class Http10FunctionalTestCase extends FunctionalTestCase
30  {
31  
32      @Rule
33      public DynamicPort dynamicPort = new DynamicPort("port1");
34  
35      @Override
36      protected String getConfigResources()
37      {
38          return "http-10-config.xml";
39      }
40  
41      private HttpClient setupHttpClient()
42      {
43          HttpClientParams params = new HttpClientParams();
44          params.setVersion(HttpVersion.HTTP_1_0);
45          return new HttpClient(params);
46      }
47  
48      @Test
49      public void testHttp10EnforceNonChunking() throws Exception
50      {
51          HttpClient client = setupHttpClient();
52          MuleClient muleClient = new MuleClient(muleContext);
53          GetMethod request = new GetMethod(((InboundEndpoint) muleClient.getMuleContext().getRegistry().lookupObject("inStreaming")).getAddress());
54          client.executeMethod(request);
55          assertEquals("hello", request.getResponseBodyAsString());
56          
57          assertNull(request.getResponseHeader(HttpConstants.HEADER_TRANSFER_ENCODING));
58          assertNotNull(request.getResponseHeader(HttpConstants.HEADER_CONTENT_LENGTH));
59      }
60  }