hammant     2002/12/19 15:08:58

  Added:       altrmi/src/test/org/apache/excalibur/altrmi/test/http
                        JettyTestCase.java
  Log:
  Test Jetty on its own.
  
  Revision  Changes    Path
  1.1                  
jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/http/JettyTestCase.java
  
  Index: JettyTestCase.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.excalibur.altrmi.test.http;
  
  import org.mortbay.http.HttpContext;
  import org.mortbay.http.HttpServer;
  import org.mortbay.http.SocketListener;
  import org.mortbay.http.handler.ResourceHandler;
  import junit.framework.TestCase;
  
  import java.net.URL;
  import java.net.URLConnection;
  
  
  /**
   * Test Jetty itself.
   * @author Paul Hammant
   */
  public class JettyTestCase extends TestCase
  {
      private static final int HTTP_PORT = 8181;
      HttpServer m_httpServer;
      SocketListener m_listener;
      HttpContext m_context;
  
      public JettyTestCase(String name)
      {
          super(name);
      }
  
      protected void setUp() throws Exception
      {
          super.setUp();
  
          // Create the server
  
          m_httpServer = new HttpServer();
  
          // Create a port listener
  
          m_listener = new SocketListener();
          m_listener.setPort(HTTP_PORT);
          m_httpServer.addListener(m_listener);
  
          // Create a context
  
          m_context = new HttpContext();
          m_context.setContextPath("/test/*");
          m_context.setResourceBase("..");
          m_context.addHandler(new ResourceHandler());
          m_httpServer.addContext(m_context);
  
          // Start the http server
          m_httpServer.start();
  
      }
  
      public void testBlah() throws Exception {
          URL url = new URL("http","localhost", HTTP_PORT,"/test/hi.txt");
          URLConnection connection = url.openConnection();
          String contentType = connection.getContentType();
          assertEquals("text/plain", contentType);
      }
  
      public void testBlah2() throws Exception {
          testBlah();
      }
  
      public void testBlah3() throws Exception {
          testBlah();
      }
  
      protected void tearDown() throws Exception
      {
          System.gc();
          Thread.yield();
          Thread.yield();
          m_httpServer.removeContext(m_context);
          m_listener.stop();
          m_httpServer.removeListener(m_listener);
          m_httpServer.stop();
          Thread.yield();
          m_listener = null;
          m_httpServer = null;
          super.tearDown();
      }
  }
  
  
  

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

Reply via email to