View Javadoc

1   /*
2    * $Id: Http10FunctionalTestCase.java 22518 2011-07-22 07:00:22Z claude.mamo $
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 static org.junit.Assert.assertEquals;
14  import static org.junit.Assert.assertNotNull;
15  import static org.junit.Assert.assertNull;
16  
17  import org.mule.api.endpoint.InboundEndpoint;
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.HttpConstants;
22  
23  import java.util.Arrays;
24  import java.util.Collection;
25  
26  import org.apache.commons.httpclient.HttpClient;
27  import org.apache.commons.httpclient.HttpVersion;
28  import org.apache.commons.httpclient.methods.GetMethod;
29  import org.apache.commons.httpclient.params.HttpClientParams;
30  import org.junit.Rule;
31  import org.junit.Test;
32  import org.junit.runners.Parameterized.Parameters;
33  
34  /**
35   * Tests as per http://www.io.com/~maus/HttpKeepAlive.html
36   */
37  public class Http10FunctionalTestCase extends AbstractServiceAndFlowTestCase
38  {
39      @Rule
40      public DynamicPort dynamicPort = new DynamicPort("port1");
41  
42      @Parameters
43      public static Collection<Object[]> parameters()
44      {
45          return Arrays.asList(new Object[][]{
46              {ConfigVariant.SERVICE, "http-10-config-service.xml"},
47              {ConfigVariant.FLOW, "http-10-config-flow.xml"}
48          });
49      }      
50  
51      public Http10FunctionalTestCase(ConfigVariant variant, String configResources)
52      {
53          super(variant, configResources);    
54      }
55      
56      private HttpClient setupHttpClient()
57      {
58          HttpClientParams params = new HttpClientParams();
59          params.setVersion(HttpVersion.HTTP_1_0);
60          return new HttpClient(params);
61      }
62  
63      @Test
64      public void testHttp10EnforceNonChunking() throws Exception
65      {
66          HttpClient client = setupHttpClient();
67          MuleClient muleClient = new MuleClient(muleContext);
68          GetMethod request = new GetMethod(((InboundEndpoint) muleClient.getMuleContext().getRegistry().lookupObject("inStreaming")).getAddress());
69          client.executeMethod(request);
70          assertEquals("hello", request.getResponseBodyAsString());
71          
72          assertNull(request.getResponseHeader(HttpConstants.HEADER_TRANSFER_ENCODING));
73          assertNotNull(request.getResponseHeader(HttpConstants.HEADER_CONTENT_LENGTH));
74      }
75  }