commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsde...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient SimpleHttpConection.java SimpleHttpMethod.java TestRequestHeaders.java TestMethodsNoHost.java TestNoHost.java TestResponseHeaders.java
Date Fri, 02 Aug 2002 11:38:12 GMT
jsdever     2002/08/02 04:38:12

  Modified:    httpclient/src/test/org/apache/commons/httpclient
                        TestMethodsNoHost.java TestNoHost.java
                        TestResponseHeaders.java
  Added:       httpclient/src/test/org/apache/commons/httpclient
                        SimpleHttpConection.java SimpleHttpMethod.java
                        TestRequestHeaders.java
  Log:
  Pull out two of the "Simple" classes used for testing.
  
  Revision  Changes    Path
  1.6       +10 -26    jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsNoHost.java
  
  Index: TestMethodsNoHost.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsNoHost.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TestMethodsNoHost.java	29 Jul 2002 23:40:01 -0000	1.5
  +++ TestMethodsNoHost.java	2 Aug 2002 11:38:12 -0000	1.6
  @@ -84,23 +84,7 @@
       static final NameValuePair PAIR1 = new NameValuePair(NAME1, VALUE1);
       static final NameValuePair PAIR2 = new NameValuePair(NAME2, VALUE2);
       
  -    /** Simple method for testing the HttpMethodBase.
  -     */
  -    class HttpSimpleMethod extends HttpMethodBase{
  -
  -       HttpSimpleMethod(){
  -	  super();
  -       }
  -
  -       HttpSimpleMethod(String path){
  -	  super(path);
  -       }
  -
  -       public String getName() {
  -	  return "Simple";
  -       }
  -
  -    }
  + 
   
       // ------------------------------------------------------------ Constructor
   
  @@ -237,7 +221,7 @@
       }
   
       public void testHttpMethodBasePaths() throws Exception {
  -        HttpMethod simple = new HttpSimpleMethod();
  +        HttpMethod simple = new SimpleHttpMethod();
   	String[] paths = {
   	   "/some/absolute/path",
   	   "../some/relative/path",
  @@ -252,7 +236,7 @@
       }
   
       public void testHttpMethodBaseDefaultPath() throws Exception {
  -        HttpMethod simple = new HttpSimpleMethod();
  +        HttpMethod simple = new SimpleHttpMethod();
   	assertEquals("/", simple.getPath());
   
   	simple.setPath("");
  @@ -263,13 +247,13 @@
       }
   
       public void testHttpMethodBasePathConstructor() throws Exception {
  -        HttpMethod simple = new HttpSimpleMethod(null);
  +        HttpMethod simple = new SimpleHttpMethod(null);
   	assertEquals("/", simple.getPath());
   
  -        simple = new HttpSimpleMethod("");
  +        simple = new SimpleHttpMethod("");
   	assertEquals("/", simple.getPath());
   
  -        simple = new HttpSimpleMethod("/some/path/");
  +        simple = new SimpleHttpMethod("/some/path/");
   	assertEquals("/some/path/", simple.getPath());
       }
   
  
  
  
  1.10      +5 -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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TestNoHost.java	19 Jul 2002 20:50:37 -0000	1.9
  +++ TestNoHost.java	2 Aug 2002 11:38:12 -0000	1.10
  @@ -96,6 +96,7 @@
           suite.addTest(TestMethodsNoHost.suite());
           suite.addTest(TestHttpState.suite());
           suite.addTest(TestResponseHeaders.suite());
  +        suite.addTest(TestRequestHeaders.suite());
           return suite;
       }
   
  
  
  
  1.2       +6 -30     jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestResponseHeaders.java
  
  Index: TestResponseHeaders.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestResponseHeaders.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestResponseHeaders.java	19 Jul 2002 20:50:37 -0000	1.1
  +++ TestResponseHeaders.java	2 Aug 2002 11:38:12 -0000	1.2
  @@ -6,7 +6,7 @@
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999 The Apache Software Foundation.  All rights
  + * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -97,31 +97,7 @@
           return new TestSuite(TestResponseHeaders.class);
       }
   
  -    // ------------------------------------------------------------ Inner Class
  -    /**
  -     * Hack HttpConnection to test the response header reading mechanism.
  -     */
  -    private class SimpleHttpConnection extends HttpConnection {
  -        BufferedReader headerReader = null;
  -        ByteArrayInputStream bodyInputStream = null;
  -        public SimpleHttpConnection(String headers, String body) {
  -            super(null, -1, "localhost", 80, false);
  -            this.headerReader = new BufferedReader(new StringReader(headers));
  -            bodyInputStream = new ByteArrayInputStream(body.getBytes());
  -        }
  -        public void open() throws IOException {
  -        }
  -        public void write(byte[] data) throws IOException, IllegalStateException, HttpRecoverableException
{
  -        }
  -        public void writeLine() throws IOException, IllegalStateException, HttpRecoverableException
{
  -        }
  -        public String readLine() throws IOException, IllegalStateException {
  -            return headerReader.readLine();
  -        }
  -        public InputStream getResponseInputStream(HttpMethod method) {
  -            return bodyInputStream;
  -        }
  -    }
  +
   
       /**
        * Simple extension of HttpMethodBase.
  
  
  
  1.1                  jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/SimpleHttpConection.java
  
  Index: SimpleHttpConection.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/SimpleHttpConection.java,v
1.1 2002/08/02 11:38:12 jsdever Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/02 11:38:12 $
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * 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.BufferedReader;
  import java.io.ByteArrayInputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.StringReader;
  
  /**
   * Hack HttpConnection to test the response header reading mechanism.
   */
  class SimpleHttpConnection extends HttpConnection {
  
  	BufferedReader headerReader = null;
  	ByteArrayInputStream bodyInputStream = null;
  
  	public SimpleHttpConnection(String headers, String body) {
  		super(null, -1, "localhost", 80, false);
  		this.headerReader = new BufferedReader(new StringReader(headers));
  		bodyInputStream = new ByteArrayInputStream(body.getBytes());
  	}
  	
  	public SimpleHttpConnection(String host, int port, boolean isSecure){
  		super(host, port, isSecure);
  	}
  
  	public void open() throws IOException {
  	}
  
  	public void write(byte[] data) 
      throws IOException, IllegalStateException, HttpRecoverableException {
  	}
  
  	public void writeLine() 
  	throws IOException, IllegalStateException, HttpRecoverableException {
  	}
  
  	public String readLine()
  	throws IOException, IllegalStateException {
  		return headerReader.readLine();
  	}
  
  	public InputStream getResponseInputStream(HttpMethod method) {
  		return bodyInputStream;
  	}
  
  }
  
  
  
  
  1.1                  jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/SimpleHttpMethod.java
  
  Index: SimpleHttpMethod.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/SimpleHttpMethod.java,v
1.1 2002/08/02 11:38:12 jsdever Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/02 11:38:12 $
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * 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;
  
  /** Simple method for testing the HttpMethodBase.
   */
  class SimpleHttpMethod extends HttpMethodBase{
  
  	SimpleHttpMethod(){
  		super();
  	}
  
  	SimpleHttpMethod(String path){
  		super(path);
  	}
  
  
  	public String getName() {
  		return "Simple";
  	}
  
  
  	public int execute(HttpState state, HttpConnection conn)
  	throws HttpException, IOException{
  		return super.execute(state, conn);
  	}
  
  	public void addRequestHeaders(HttpState state, HttpConnection conn)
  	throws HttpException, IOException{
  		super.addRequestHeaders(state, conn);
  	}
  }
  
  
  
  1.1                  jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestRequestHeaders.java
  
  Index: TestRequestHeaders.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestRequestHeaders.java,v
1.1 2002/08/02 11:38:12 jsdever Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/02 11:38:12 $
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * 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 junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import java.io.BufferedReader;
  import java.io.ByteArrayInputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.StringReader;
  
  /**
   * Tests for reading response headers.
   *
   * @author <a href="mailto:jsdever@apache.org">Jeff Dever</a>
   * @version $Id: TestRequestHeaders.java,v 1.1 2002/08/02 11:38:12 jsdever Exp $
   */
  public class TestRequestHeaders extends TestCase {
  
         HttpState state = null;
         SimpleHttpMethod method = null;
         HttpConnection conn = null;
  
      // ------------------------------------------------------------ Constructor
      public TestRequestHeaders(String testName) {
          super(testName);
      }
  
      // ------------------------------------------------------------------- Main
      public static void main(String args[]) {
          String[] testCaseName = {TestRequestHeaders.class.getName()};
          junit.textui.TestRunner.main(testCaseName);
      }
  
      // ------------------------------------------------------- TestCase Methods
      public static Test suite() {
          return new TestSuite(TestRequestHeaders.class);
      }
  
      public void setUp() {
         state = new HttpState();
         method = new SimpleHttpMethod("/some/absolute/path/");
         //assign conn in test case
      }
  
      public void tearDown() {
         state = null;
         method = null;
         conn = null;
      }
  
      public void testHostHeaderPortHTTP80() throws Exception {
         conn = new SimpleHttpConnection("some.host.name", 80, false);
         method.addRequestHeaders(state, conn);
         assertEquals("Host: some.host.name", method.getRequestHeader("Host").toString().trim());
      }
  
      public void testHostHeaderPortHTTP81() throws Exception {
         conn = new SimpleHttpConnection("some.host.name", 81, false);
         method.addRequestHeaders(state, conn);
         assertEquals("Host: some.host.name:81", method.getRequestHeader("Host").toString().trim());
      }
  
      public void testHostHeaderPortHTTPS443() throws Exception {
         conn = new SimpleHttpConnection("some.host.name", 443, true);
         method.addRequestHeaders(state, conn);
         assertEquals("Host: some.host.name", method.getRequestHeader("Host").toString().trim());
      }
  
  
      public void testHostHeaderPortHTTPS444() throws Exception {
         conn = new SimpleHttpConnection("some.host.name", 444, true);
         method.addRequestHeaders(state, conn);
         assertEquals("Host: some.host.name:444", method.getRequestHeader("Host").toString().trim());
      }
  
  }
  
  
  

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


Mime
View raw message