olegk       2004/02/25 14:33:59

  Modified:    httpclient/src/test/org/apache/commons/httpclient/server
                        SimpleHttpServerConnection.java
  Added:       httpclient/src/test/org/apache/commons/httpclient
                        HttpClientTestBase.java
  Log:
  * Base class for test cases using 
org.apache.commons.httpclient.server.SimpleHttpServer based framework
  * org.apache.commons.httpclient.server.auth package for authentication test cases
  
  Revision  Changes    Path
  1.1                  
jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/HttpClientTestBase.java
  
  Index: HttpClientTestBase.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/HttpClientTestBase.java,v
 1.1 2004/02/25 22:33:58 olegk Exp $
   * $Revision: 1.1 $
   * $Date: 2004/02/25 22:33:58 $
   * ====================================================================
   *
   *  Copyright 1999-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.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import org.apache.commons.httpclient.protocol.Protocol;
  import org.apache.commons.httpclient.server.RequestLine;
  import org.apache.commons.httpclient.server.ResponseWriter;
  import org.apache.commons.httpclient.server.SimpleHttpServer;
  import org.apache.commons.httpclient.server.SimpleHttpServerConnection;
  
  /**
   * Base class for test cases using 
   * [EMAIL PROTECTED] org.apache.commons.httpclient.server.SimpleHttpServer} based 
   * testing framework.
   *
   * @author Oleg Kalnichevski
   * 
   * @version $Id: HttpClientTestBase.java,v 1.1 2004/02/25 22:33:58 olegk Exp $
   */
  public class HttpClientTestBase extends TestCase {
  
      protected HttpClient client = null;
      protected SimpleHttpServer server = null;
  
      // ------------------------------------------------------------ Constructor
      public HttpClientTestBase(String testName) {
          super(testName);
      }
  
      // ------------------------------------------------------------------- Main
      public static void main(String args[]) {
          String[] testCaseName = { HttpClientTestBase.class.getName() };
          junit.textui.TestRunner.main(testCaseName);
      }
  
      // ------------------------------------------------------- TestCase Methods
  
      public static Test suite() {
          return new TestSuite(HttpClientTestBase.class);
      }
  
      // ------------------------------------------------- TestCase setup/shutdown
  
      public void setUp() throws IOException {
          // configure the server
          this.server = new SimpleHttpServer(); // use arbitrary port
  
          // configure the client
          this.client = new HttpClient();
          this.client.getHostConfiguration().setHost(
              this.server.getLocalAddress(), 
              this.server.getLocalPort(),
              Protocol.getProtocol("http"));
      
      }
  
      public void tearDown() throws IOException {
          this.client = null;
          this.server.destroy();
          this.server = null;
      }
      
      protected static void respondNotImplemented(SimpleHttpServerConnection conn) 
          throws IOException
      {
          RequestLine requestLine = conn.getRequestLine();
          ResponseWriter out = conn.getWriter();
          String content = requestLine.getMethod() + " method not supported";
          out.println("HTTP/1.1 501 Not implemented");
          out.println("Content-Type: text/plain");
          out.println("Content-Length: " + content.length());
          out.println("Connection: close");
          out.println();
          out.println(content);
          out.flush();
      }
  
      protected static void respondNotFound(SimpleHttpServerConnection conn) 
          throws IOException
      {
          RequestLine requestLine = conn.getRequestLine();
          ResponseWriter out = conn.getWriter();
          String content = requestLine.getUri() + " not found";
          out.println("HTTP/1.1 404 Not found");
          out.println("Content-Type: text/plain");
          out.println("Content-Length: " + content.length());
          out.println("Connection: close");
          out.println();
          out.println(content);
          out.flush();
      }
  }
  
  
  
  1.6       +16 -3     
jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/server/SimpleHttpServerConnection.java
  
  Index: SimpleHttpServerConnection.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/server/SimpleHttpServerConnection.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SimpleHttpServerConnection.java   22 Feb 2004 18:08:52 -0000      1.5
  +++ SimpleHttpServerConnection.java   25 Feb 2004 22:33:59 -0000      1.6
  @@ -175,6 +175,19 @@
           return copy;
       }
   
  +    public Header getHeader(final String name) {
  +        if (name == null) {
  +            throw new IllegalArgumentException("Header name may not be null");
  +        }
  +        for (int i = 0; i < this.headers.length; i++) {
  +            Header header = this.headers[i];
  +            if (name.equalsIgnoreCase(header.getName())) {
  +                return header;
  +            }
  +        }
  +        return null;
  +    }
  +
       public RequestLine getRequestLine() {
           return requestLine;
       }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to