commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mbe...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient TestNoncompliant.java TestWebapp.java TestNoHost.java TestWebappNoncompliant.java
Date Sun, 14 Nov 2004 23:38:01 GMT
mbecke      2004/11/14 15:38:01

  Modified:    httpclient/src/test/org/apache/commons/httpclient
                        TestWebapp.java TestNoHost.java
  Added:       httpclient/src/test/org/apache/commons/httpclient
                        TestNoncompliant.java
  Removed:     httpclient/src/test/org/apache/commons/httpclient
                        TestWebappNoncompliant.java
  Log:
  Moved more test cases away from the webapp.
  
  Submitted by: Michael Becke
  
  Revision  Changes    Path
  1.14      +4 -5      jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebapp.java
  
  Index: TestWebapp.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebapp.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- TestWebapp.java	9 Nov 2004 04:25:05 -0000	1.13
  +++ TestWebapp.java	14 Nov 2004 23:38:00 -0000	1.14
  @@ -65,7 +65,6 @@
           suite.addTest(TestWebappParameters.suite());
           suite.addTest(TestWebappHeaders.suite());
           suite.addTest(TestWebappPostMethod.suite());
  -        suite.addTest(TestWebappNoncompliant.suite());
           suite.addTest(TestProxy.suite());
           return suite;
       }
  
  
  
  1.46      +6 -4      jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestNoHost.java
  
  Index: TestNoHost.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestNoHost.java,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- TestNoHost.java	7 Nov 2004 12:31:42 -0000	1.45
  +++ TestNoHost.java	14 Nov 2004 23:38:01 -0000	1.46
  @@ -96,6 +96,8 @@
           suite.addTest(TestPostMethod.suite());
           suite.addTest(TestPartsNoHost.suite());
           suite.addTest(TestMultipartPost.suite());
  +        
  +        suite.addTest(TestNoncompliant.suite());
           return suite;
       }
   
  
  
  
  1.1                  jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestNoncompliant.java
  
  Index: TestNoncompliant.java
  ===================================================================
  /*
   * ====================================================================
   *
   *  Copyright 2003-2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  package org.apache.commons.httpclient;
  
  import java.io.IOException;
  
  import junit.framework.*;
  import org.apache.commons.httpclient.methods.*;
  import org.apache.commons.httpclient.params.HttpMethodParams;
  import org.apache.commons.httpclient.server.HttpRequestHandler;
  import org.apache.commons.httpclient.server.ResponseWriter;
  import org.apache.commons.httpclient.server.SimpleHttpServerConnection;
  import org.apache.commons.httpclient.server.SimpleRequest;
  
  /**
   * Tests handling of non-compliant responses.
   * 
   * @author Oleg Kalnichevski
   * @author Jeff Dever
   */
  public class TestNoncompliant extends HttpClientTestBase {
  
      public TestNoncompliant(String s) throws IOException {
          super(s);
      }
  
      public static Test suite() {
          TestSuite suite = new TestSuite(TestNoncompliant.class);
          return suite;
      }
  
      /**
       * Tests if client is able able to recover gracefully when HTTP server or
       * proxy fails to send 100 status code when expected. The client should
       * resume sending the request body after a defined timeout without having
       * received "continue" code.
       */
      public void testNoncompliantPostMethodString() {
          this.server.setRequestHandler(new HttpRequestHandler() {
              public boolean processRequest(SimpleHttpServerConnection conn,
                      SimpleRequest request) throws IOException {
                  ResponseWriter out = conn.getWriter();
                  out.println("HTTP/1.1 200 OK");
                  out.println("Connection: close");
                  out.println("Content-Length: 0");
                  out.println();
                  out.flush();
                  return true;
              }
          });
  
          PostMethod method = new PostMethod("/");
          method.getParams().setBooleanParameter(
                  HttpMethodParams.USE_EXPECT_CONTINUE, true);
          method.setRequestEntity(new StringRequestEntity(
                  "This is data to be sent in the body of an HTTP POST."));
          try {
              client.executeMethod(method);
          } catch (Exception e) {
              e.printStackTrace();
              fail("Unexpected exception: " + e.toString());
          }
          assertEquals(200, method.getStatusCode());
      }
  
      /**
       * Tests that a response status line containing \r and \n is handled.
       */
      public void testNoncompliantStatusLine() {
          this.server.setRequestHandler(new HttpRequestHandler() {
              public boolean processRequest(SimpleHttpServerConnection conn,
                      SimpleRequest request) throws IOException {
                  ResponseWriter out = conn.getWriter();
                  out.println("HTTP/1.1 444 This status message contains\n"
                          + " a newline and a\r"
                          + " carrage return but that should be OK.");
                  out.println("Connection: close");
                  out.println("Content-Length: 0");
                  out.println();
                  out.flush();
                  return true;
              }
          });
          GetMethod method = new GetMethod("/");
          try {
              client.executeMethod(method);
          } catch (Exception e) {
              e.printStackTrace();
              fail("Unexpected exception: " + e.toString());
          }
          assertEquals(444, method.getStatusCode());
      }
  
      /**
       * Test if a response to HEAD method from non-compliant server that contains
       * an unexpected body content can be correctly redirected
       */
      public void testNoncompliantHeadWithResponseBody() throws Exception {
          final String body = "Test body";
          this.server.setRequestHandler(new HttpRequestHandler() {
              public boolean processRequest(SimpleHttpServerConnection conn,
                      SimpleRequest request) throws IOException {
                  ResponseWriter out = conn.getWriter();
                  out.println("HTTP/1.1 200 OK");
                  out.println("Connection: close");
                  out.println("Content-Length: " + body.length());
                  out.println();
                  out.print(body);
                  out.flush();
                  return true;
              }
          });
          HeadMethod method = new HeadMethod("/");
          method.getParams().setIntParameter(
                  HttpMethodParams.HEAD_BODY_CHECK_TIMEOUT, 50);
          client.executeMethod(method);
          assertEquals(200, method.getStatusCode());
          method.releaseConnection();
      }
  
      /**
       * Test if a response to HEAD method from non-compliant server causes an
       * HttpException to be thrown
       */
      public void testNoncompliantHeadStrictMode() throws Exception {
          final String body = "Test body";
          this.server.setRequestHandler(new HttpRequestHandler() {
              public boolean processRequest(SimpleHttpServerConnection conn,
                      SimpleRequest request) throws IOException {
                  ResponseWriter out = conn.getWriter();
                  out.println("HTTP/1.1 200 OK");
                  out.println("Connection: close");
                  out.println("Content-Length: " + body.length());
                  out.println();
                  out.print(body);
                  out.flush();
                  return true;
              }
          });
          client.getParams().setBooleanParameter(
                  HttpMethodParams.REJECT_HEAD_BODY, true);
          HeadMethod method = new NoncompliantHeadMethod("/");
          method.getParams().setIntParameter(
                  HttpMethodParams.HEAD_BODY_CHECK_TIMEOUT, 50);
          try {
              client.executeMethod(method);
              fail("HttpException should have been thrown");
          } catch (HttpException e) {
              // Expected
          }
          method.releaseConnection();
      }
  
  }
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message