hammant     2002/12/21 15:18:14

  Modified:    altrmi   build.xml
               altrmi/src/java/org/apache/excalibur/altrmi/server
                        AttributeHelper.java
               altrmi/src/test/org/apache/excalibur/altrmi/test
                        AbstractHelloTestCase.java
               altrmi/src/test/org/apache/excalibur/altrmi/test/http
                        CustomHttpServletTestCase.java
  Added:       altrmi/src/test/org/apache/excalibur/altrmi/test
                        AbstractAltrmiTestCase.java
               altrmi/src/test/org/apache/excalibur/altrmi/test/http
                        JettyServletTestCase.java TestLogSink.java
                        TestServlet.java
  Log:
  Add a Jetty servlet testcase
  
  Revision  Changes    Path
  1.54      +6 -1      jakarta-avalon-excalibur/altrmi/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/altrmi/build.xml,v
  retrieving revision 1.53
  retrieving revision 1.54
  diff -u -r1.53 -r1.54
  --- build.xml 21 Dec 2002 20:32:36 -0000      1.53
  +++ build.xml 21 Dec 2002 23:18:13 -0000      1.54
  @@ -264,9 +264,14 @@
               <formatter type="plain" usefile="false"/>  <!-- text reports for 
humans     -->
               <batchtest todir="${build.tests}">
                   <fileset dir="${build.testclasses}">
  +
  +
  +
  +
   <!--
  +                    <include name="**/test/**/JettyServletTestCase.class"/>
                       <include 
name="**/test/**/CustomHttpServletTestCase.class"/>
  -                    -->
  +-->
                       <include name="**/test/**/*TestCase.class"/>
                       <exclude name="**/Abstract*"/>
                       <exclude name="**/JSXObjectStreamTestCase.class"/>
  
  
  
  1.3       +0 -1      
jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/AttributeHelper.java
  
  Index: AttributeHelper.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/altrmi/src/java/org/apache/excalibur/altrmi/server/AttributeHelper.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AttributeHelper.java      21 Dec 2002 20:32:37 -0000      1.2
  +++ AttributeHelper.java      21 Dec 2002 23:18:14 -0000      1.3
  @@ -16,7 +16,6 @@
   
       protected boolean isMethodAsync(Method method)
       {
  -        System.out.println("method " + method.toString());
           Attribute attr = Attributes.getAttribute(method, "altrmi:method");
           return (attr == null ? false : attr.getValue().equals("async"));
       }
  
  
  
  1.8       +1 -24     
jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/AbstractHelloTestCase.java
  
  Index: AbstractHelloTestCase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/AbstractHelloTestCase.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- AbstractHelloTestCase.java        26 Aug 2002 13:59:51 -0000      1.7
  +++ AbstractHelloTestCase.java        21 Dec 2002 23:18:14 -0000      1.8
  @@ -7,42 +7,19 @@
    */
   package org.apache.excalibur.altrmi.test;
   
  -import org.apache.excalibur.altrmi.server.impl.AbstractServer;
  -import org.apache.excalibur.altrmi.client.AltrmiFactory;
  -
   import java.beans.PropertyVetoException;
   import java.io.IOException;
   
  -import junit.framework.TestCase;
  -
   /**
    * Extended by classes that name the transport.
    * @author Paul Hammant
    */
  -public abstract class AbstractHelloTestCase extends TestCase
  +public abstract class AbstractHelloTestCase extends AbstractAltrmiTestCase
   {
   
  -    protected AbstractServer server;
  -    protected TestInterfaceImpl testServer;
  -    protected TestInterface testClient;
  -    protected AltrmiFactory altrmiFactory;
  -    protected boolean testForBug4499841 = true;
  -
       public AbstractHelloTestCase(String name)
       {
           super(name);
  -    }
  -
  -    public void testHelloCall() throws Exception
  -    {
  -        // lookup worked ?
  -        assertNotNull(testClient);
  -
  -        // Invoke a method over AltRMI.
  -        testClient.hello("Hello!?");
  -
  -        // test the server has logged the message.
  -        assertEquals("Hello!?", ((TestInterfaceImpl) 
testServer).getStoredState("void:hello(String)"));
       }
   
       public void testHello2Call() throws Exception
  
  
  
  1.1                  
jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/AbstractAltrmiTestCase.java
  
  Index: AbstractAltrmiTestCase.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;
  
  import org.apache.excalibur.altrmi.server.impl.AbstractServer;
  import org.apache.excalibur.altrmi.client.AltrmiFactory;
  
  import java.beans.PropertyVetoException;
  import java.io.IOException;
  
  import junit.framework.TestCase;
  
  /**
   * Extended by classes that name the transport.
   * @author Paul Hammant
   */
  public abstract class AbstractAltrmiTestCase extends TestCase
  {
  
      protected AbstractServer server;
      protected TestInterfaceImpl testServer;
      protected TestInterface testClient;
      protected AltrmiFactory altrmiFactory;
      protected boolean testForBug4499841 = true;
  
      public AbstractAltrmiTestCase(String name)
      {
          super(name);
      }
  
      public void testHelloCall() throws Exception
      {
          // lookup worked ?
          assertNotNull(testClient);
  
          // Invoke a method over AltRMI.
          testClient.hello("Hello!?");
  
          // test the server has logged the message.
          assertEquals("Hello!?", ((TestInterfaceImpl) 
testServer).getStoredState("void:hello(String)"));
      }
  
  
  }
  
  
  
  1.4       +9 -3      
jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/http/CustomHttpServletTestCase.java
  
  Index: CustomHttpServletTestCase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/http/CustomHttpServletTestCase.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- CustomHttpServletTestCase.java    21 Dec 2002 19:34:44 -0000      1.3
  +++ CustomHttpServletTestCase.java    21 Dec 2002 23:18:14 -0000      1.4
  @@ -16,22 +16,25 @@
   import org.apache.excalibur.altrmi.test.TestInterface2;
   import org.apache.excalibur.altrmi.test.TestInterface3;
   import org.apache.excalibur.altrmi.test.TestInterfaceImpl;
  +import org.apache.excalibur.altrmi.test.AbstractAltrmiTestCase;
   import org.mortbay.http.HttpContext;
   import org.mortbay.http.HttpServer;
   import org.mortbay.http.SocketListener;
   import org.mortbay.jetty.servlet.ServletHandler;
  +import org.mortbay.util.Log;
   
   
   /**
  - * Test Custom Stream over sockets.
  + * Test Custom Stream over HTTP
    * @author Paul Hammant
    */
  -public class CustomHttpServletTestCase extends AbstractHelloTestCase
  +public class CustomHttpServletTestCase extends AbstractAltrmiTestCase
   {
       private static final int HTTP_PORT = 8181;
       HttpServer m_httpServer;
       SocketListener m_listener;
       HttpContext m_context;
  +    TestLogSink m_testLogSink;
   
       public CustomHttpServletTestCase(String name)
       {
  @@ -55,6 +58,10 @@
           m_listener.setPort(HTTP_PORT);
           m_httpServer.addListener(m_listener);
   
  +        m_testLogSink = new TestLogSink();
  +
  +        Log.instance().add(m_testLogSink);
  +
           // Create a context
   
           m_context = new HttpContext();
  @@ -94,7 +101,6 @@
           // threads, AltRMI being a client/server thing
           Thread.yield();
       }
  -
   
       protected void tearDown() throws Exception
       {
  
  
  
  1.1                  
jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/http/JettyServletTestCase.java
  
  Index: JettyServletTestCase.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 junit.framework.TestCase;
  import org.apache.excalibur.altrmi.server.impl.http.CustomHttpServlet;
  import org.apache.commons.httpclient.HttpClient;
  import org.apache.commons.httpclient.methods.GetMethod;
  import org.mortbay.http.HttpContext;
  import org.mortbay.http.HttpServer;
  import org.mortbay.http.SocketListener;
  import org.mortbay.jetty.servlet.ServletHandler;
  import org.mortbay.util.Log;
  
  /**
   * Test Jetty servlet in conjunction with HTTPClient
   * @author Paul Hammant
   */
  public class JettyServletTestCase extends TestCase
  {
      private static final int HTTP_PORT = 8181;
      HttpServer m_httpServer;
      SocketListener m_listener;
      HttpContext m_context;
      TestLogSink m_testLogSink;
  
      public JettyServletTestCase(String name)
      {
          super(name);
      }
  
      protected void setUp() throws Exception
      {
          super.setUp();
  
          CustomHttpServlet customHttpServlet = new CustomHttpServlet();
          KludgeServlet.setRealServlet(customHttpServlet);
  
          // 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);
  
          m_testLogSink = new TestLogSink();
  
          Log.instance().add(m_testLogSink);
  
          // Create a context
  
          m_context = new HttpContext();
          m_context.setContextPath("/mystuff/*");
          m_httpServer.addContext(m_context);
  
          // Create a servlet container
          ServletHandler servlets = new ServletHandler();
  
          // Map a servlet onto the container
          servlets.addServlet("Dump", "/Dump/*", 
"org.apache.excalibur.altrmi.test.http.TestServlet");
  
          m_context.addHandler(servlets);
  
          // Start the http server
          m_httpServer.start();
  
      }
  
      public void testHttpClientGet() throws Exception {
          HttpClient client = new HttpClient();
          client.getHostConfiguration().setHost("localhost", HTTP_PORT, "http");
          // we shouldn't have to wait if a connection is available
          client.setHttpConnectionFactoryTimeout( 10 * 1000 );
  
          GetMethod getMethod = new GetMethod("/mystuff/Dump");
          client.executeMethod(getMethod);
          assertEquals("Hello",new String(getMethod.getResponseBody()));
      }
  
      public void testHttpClientGet2() throws Exception {
          // make sure the get is reentrant
          testHttpClientGet();
      }
  
  
  
      protected void tearDown() throws Exception
      {
          m_httpServer.removeContext(m_context);
          m_listener.stop();
          m_httpServer.removeListener(m_listener);
          m_httpServer.stop();
          super.tearDown();
      }
  
  
  }
  
  
  
  1.1                  
jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/http/TestLogSink.java
  
  Index: TestLogSink.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.util.LogSink;
  import org.mortbay.util.Frame;
  
  public class TestLogSink implements LogSink {
  
      private String m_options;
  
      public void setOptions(String s)
      {
          m_options = s;
  
      }
  
      public String getOptions()
      {
          return m_options;
      }
  
      public void log(String s, Object o, Frame frame, long l)
      {
          System.out.println("Jetty: " + s + ", " + o + ", " + l );
      }
  
      public void log(String s)
      {
          System.out.println("Jetty: " + s);
      }
  
      public void start() throws Exception
      {
      }
  
      public void stop() throws InterruptedException
      {
      }
  
      public boolean isStarted()
      {
          return true;
      }
  }
  
  
  
  1.1                  
jakarta-avalon-excalibur/altrmi/src/test/org/apache/excalibur/altrmi/test/http/TestServlet.java
  
  Index: TestServlet.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 javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpServlet;
  import java.io.IOException;
  import java.io.PrintWriter;
  
  public class TestServlet extends HttpServlet
  {
  
      protected void doGet(HttpServletRequest httpServletRequest, 
HttpServletResponse httpServletResponse) throws ServletException, IOException
      {
          httpServletResponse.setContentType("text/plain");
          final PrintWriter outputWriter = httpServletResponse.getWriter();
          outputWriter.print("Hello");
      }
  
  }
  
  
  

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

Reply via email to