You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@apache.org on 2009/11/26 07:55:50 UTC

svn commit: r884421 [1/3] - in /tomcat/trunk/modules/tomcat-lite/test/org/apache: coyote/ coyote/lite/ coyote/servlet/ tomcat/lite/ tomcat/lite/http/ tomcat/lite/http/services/ tomcat/lite/io/ tomcat/lite/load/ tomcat/lite/proxy/ tomcat/lite/servlet/ t...

Author: costin
Date: Thu Nov 26 06:55:49 2009
New Revision: 884421

URL: http://svn.apache.org/viewvc?rev=884421&view=rev
Log:
Tests. Note that you need to have watchdog checked out and built (if it can still be built... - probably should checkin the binaries ).
There are a bunch of useful tests in watchdog - I'm not running watchdog, but turned it into JUnit test cases, we just
need the web apps and golden files from there.

At the moment there are about 12 failures (out of ~1000 tests - there are several dups because same tests are run against 
different targets )


Added:
    tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/
    tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/lite/
    tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/lite/TomcatLiteCoyoteTest.java   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/servlet/
    tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/servlet/LiteTestHelper.java
      - copied, changed from r883948, tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/LiteTestHelper.java
    tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/servlet/LiteWatchdogJspTests.java
      - copied, changed from r883948, tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/LiteWatchdogJspTests.java
    tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/servlet/LiteWatchdogServletTests.java
      - copied, changed from r883948, tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/LiteWatchdogServletTests.java
    tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/servlet/TomcatLiteSimpleTest.java
      - copied, changed from r883948, tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/TomcatLiteSimpleTest.java
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/TestMain.java   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/DispatcherTest.java   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpChannelInMemoryTest.java   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpChannelTest.java   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpsTest.java   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/LiveHttp1Test.java   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/MultiMapTest.java   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/services/
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/services/EchoCallback.java   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/services/SleepCallback.java   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/test.keystore   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/BBufferTest.java   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/CBufferTest.java   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/OneTest.java   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/SocksTest.java   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/UEncoderTest.java   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/test.properties   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/LiveHttp5Test.java   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/LiveHttpThreadedTest.java   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/MicroTest.java   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/proxy/
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/proxy/LiveProxyHttp1Test.java   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/proxy/ProxyTest.java   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/proxy/SmallProxyTest.java   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/AnnotationTest.java   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/JspWatchdogTests.java   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/LiteTestHelper.java   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/PropertiesSpiTest.java   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/ServletTests.java   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/TomcatLiteNoConnectorTest.java   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/TomcatLiteSimpleTest.java   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/TomcatLiteWatchdog.java   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/test.properties   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogTestCase.java   (with props)
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogTestImpl.java   (with props)
Removed:
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/HexDump.java
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/LiteTestHelper.java
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/LiteWatchdogJspTests.java
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/LiteWatchdogServletTests.java
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/TomcatLiteSimpleTest.java
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/GTest.java
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogTest.java
Modified:
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogClient.java
    tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogHttpClient.java

Added: tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/lite/TomcatLiteCoyoteTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/lite/TomcatLiteCoyoteTest.java?rev=884421&view=auto
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/lite/TomcatLiteCoyoteTest.java (added)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/lite/TomcatLiteCoyoteTest.java Thu Nov 26 06:55:49 2009
@@ -0,0 +1,74 @@
+/*
+ */
+package org.apache.coyote.lite;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+
+import junit.framework.TestCase;
+
+import org.apache.catalina.LifecycleException;
+import org.apache.catalina.connector.Connector;
+import org.apache.catalina.startup.Tomcat;
+import org.apache.coyote.lite.LiteProtocolHandler;
+import org.apache.tomcat.lite.http.DefaultHttpConnector;
+import org.apache.tomcat.lite.http.HttpChannel;
+import org.apache.tomcat.lite.http.HttpConnector;
+import org.apache.tomcat.lite.io.BBuffer;
+
+public class TomcatLiteCoyoteTest extends TestCase {
+
+    static Tomcat tomcat;
+    LiteProtocolHandler litePH; 
+    
+    public void setUp() {
+        if (tomcat == null) {
+            try {
+                tomcat = new Tomcat();
+                tomcat.setPort(8885);
+                tomcat.setBaseDir("output/build");
+                
+                tomcat.addWebapp("/examples", "examples");
+                tomcat.addWebapp("/", "ROOT");
+
+                
+                //tomcat.addServlet(ctx, "name", "class");
+                // ctx.addServletMapping("/foo/*", "name");
+                
+                litePH = setUp(tomcat);
+                
+                tomcat.start();
+            } catch (LifecycleException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            } catch (ServletException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+        }
+    }
+    
+    public static LiteProtocolHandler setUp(Tomcat tomcat) {
+        Connector connector = new Connector(LiteProtocolHandler.class.getName());
+        tomcat.getService().addConnector(connector);
+        connector.setPort(8885);
+        tomcat.setConnector(connector);
+        LiteProtocolHandler ph = 
+            (LiteProtocolHandler) connector.getProtocolHandler();
+        return ph;
+    }
+
+    
+    public void testSimple() throws IOException {
+        HttpConnector clientCon = DefaultHttpConnector.get();
+        HttpChannel ch = clientCon.get("localhost", 8885);
+        ch.getRequest().setRequestURI("/examples/servlets/servlet/HelloWorldExample");
+        ch.sendRequest();
+        BBuffer res = ch.readAll(null, 0);
+        
+        assertTrue(res.toString().indexOf("<title>Hello World!</title>") >= 0);
+    }
+    
+    
+}

Propchange: tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/lite/TomcatLiteCoyoteTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/servlet/LiteTestHelper.java (from r883948, tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/LiteTestHelper.java)
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/servlet/LiteTestHelper.java?p2=tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/servlet/LiteTestHelper.java&p1=tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/LiteTestHelper.java&r1=883948&r2=884421&rev=884421&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/LiteTestHelper.java (original)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/servlet/LiteTestHelper.java Thu Nov 26 06:55:49 2009
@@ -15,7 +15,7 @@
  *  limitations under the License.
  */
 
-package org.apache.tomcat.lite;
+package org.apache.coyote.servlet;
 
 import java.io.BufferedInputStream;
 import java.io.IOException;
@@ -30,7 +30,7 @@
 
 import org.apache.coyote.OutputBuffer;
 import org.apache.coyote.Response;
-import org.apache.tomcat.lite.coyote.CoyoteConnector;
+import org.apache.tomcat.lite.SimpleServlet;
 import org.apache.tomcat.util.buf.ByteChunk;
 
 public class LiteTestHelper {

Copied: tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/servlet/LiteWatchdogJspTests.java (from r883948, tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/LiteWatchdogJspTests.java)
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/servlet/LiteWatchdogJspTests.java?p2=tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/servlet/LiteWatchdogJspTests.java&p1=tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/LiteWatchdogJspTests.java&r1=883948&r2=884421&rev=884421&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/LiteWatchdogJspTests.java (original)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/servlet/LiteWatchdogJspTests.java Thu Nov 26 06:55:49 2009
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.tomcat.lite;
+package org.apache.coyote.servlet;
 
 
 import junit.framework.Test;
@@ -23,6 +23,7 @@
     
     public LiteWatchdogJspTests() {
         super();
+        port = 8017;
         testMatch = 
             //"precompileNegativeTest";
             null;
@@ -36,15 +37,15 @@
                 "positiveIncludeCtxRelativeHtmlTest",
                 "precompileNegativeTest"
             }; 
-        file = base + "/src/conf/jsp-gtest.xml";
+        file = getWatchdogdir() + "/src/conf/jsp-gtest.xml";
         goldenDir = 
-            base + "/src/clients/org/apache/jcheck/jsp/client/";
+            getWatchdogdir() + "/src/clients/org/apache/jcheck/jsp/client/";
         targetMatch = "jsp-test";
         
     }
     
     public static Test suite() {
-        return new LiteWatchdogJspTests().getSuite();
+        return new LiteWatchdogJspTests().getSuite(8017);
     }
     
 }

Copied: tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/servlet/LiteWatchdogServletTests.java (from r883948, tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/LiteWatchdogServletTests.java)
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/servlet/LiteWatchdogServletTests.java?p2=tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/servlet/LiteWatchdogServletTests.java&p1=tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/LiteWatchdogServletTests.java&r1=883948&r2=884421&rev=884421&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/LiteWatchdogServletTests.java (original)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/servlet/LiteWatchdogServletTests.java Thu Nov 26 06:55:49 2009
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.tomcat.lite;
+package org.apache.coyote.servlet;
 
 import java.io.File;
 import java.io.IOException;
@@ -31,13 +31,14 @@
   
   
   public LiteWatchdogServletTests() {
-      goldenDir = base + "/src/clients/org/apache/jcheck/servlet/client/";
+      port = 8115;      
+      goldenDir = getWatchdogdir() + "/src/clients/org/apache/jcheck/servlet/client/";
       testMatch = 
           //"HttpServletResponseWrapperSetStatusMsgTest";
           //"ServletContextAttributeAddedEventTest";
           null;
           // ex: "ServletToJSP";
-      file = base + "/src/conf/servlet-gtest.xml";
+      file = getWatchdogdir() + "/src/conf/servlet-gtest.xml";
       targetMatch = "gtestservlet-test";
   }
   
@@ -45,13 +46,9 @@
       // required for the tests
       System.setProperty("org.apache.coyote.USE_CUSTOM_STATUS_MSG_IN_HEADER",
               "true");
-      String path = System.getProperty("watchdog.home");
-      if (path != null) {
-          base = path;
-      }
       
       try {
-          initServerWithWatchdog(base);
+          initServerWithWatchdog(getWatchdogdir());
       } catch (ServletException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
@@ -61,8 +58,10 @@
       }
   }
   
+  int port = 8115;
+  
   protected void addConnector(TomcatLite liteServer) {
-      LiteTestHelper.addConnector(liteServer, 8080, true);      
+      LiteTestHelper.addConnector(liteServer, port, true);      
   }
   
   public void initServerWithWatchdog(String wdDir) throws ServletException, 
@@ -106,6 +105,6 @@
   public static Test suite() {
       // The individual targets are dups - and bad ones, 
       // RequestWrapper are missing part of the URL
-      return new LiteWatchdogServletTests().getSuite();
+      return new LiteWatchdogServletTests().getSuite(8115);
   }
 }

Copied: tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/servlet/TomcatLiteSimpleTest.java (from r883948, tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/TomcatLiteSimpleTest.java)
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/servlet/TomcatLiteSimpleTest.java?p2=tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/servlet/TomcatLiteSimpleTest.java&p1=tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/TomcatLiteSimpleTest.java&r1=883948&r2=884421&rev=884421&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/TomcatLiteSimpleTest.java (original)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/servlet/TomcatLiteSimpleTest.java Thu Nov 26 06:55:49 2009
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.tomcat.lite;
+package org.apache.coyote.servlet;
 
 import junit.framework.TestCase;
 
@@ -35,7 +35,7 @@
   public void testSimpleRequest() throws Exception {
     ByteChunk resb = 
         LiteTestHelper.getUrl("http://localhost:8804/test1/1stTest");
-    assertTrue(resb.length() > 0);
+    assertTrue(resb.getLength() > 0);
     assertEquals("Hello world", resb.toString());
   }
 

Added: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/TestMain.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/TestMain.java?rev=884421&view=auto
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/TestMain.java (added)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/TestMain.java Thu Nov 26 06:55:49 2009
@@ -0,0 +1,295 @@
+/*
+ */
+package org.apache.tomcat.lite;
+
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+
+import javax.net.ssl.SSLContext;
+
+import org.apache.tomcat.integration.simple.Main;
+import org.apache.tomcat.integration.simple.SimpleObjectManager;
+import org.apache.tomcat.lite.http.BaseMapper;
+import org.apache.tomcat.lite.http.DefaultHttpConnector;
+import org.apache.tomcat.lite.http.Dispatcher;
+import org.apache.tomcat.lite.http.HttpChannel;
+import org.apache.tomcat.lite.http.HttpConnector;
+import org.apache.tomcat.lite.http.BaseMapper.ContextMapping;
+import org.apache.tomcat.lite.http.HttpConnector.HttpChannelEvents;
+import org.apache.tomcat.lite.http.services.EchoCallback;
+import org.apache.tomcat.lite.http.services.SleepCallback;
+import org.apache.tomcat.lite.io.BBuffer;
+import org.apache.tomcat.lite.io.SocketConnector;
+import org.apache.tomcat.lite.io.SslConnector;
+import org.apache.tomcat.lite.proxy.HttpProxyService;
+import org.apache.tomcat.lite.proxy.StaticContentService;
+import org.apache.tomcat.lite.service.IOStatus;
+import org.apache.tomcat.util.buf.ByteChunk;
+
+/**
+ * Server with lost of test servlets.
+ * 
+ * Used in tests - one is running for the entire suite.
+ * 
+ * @author Costin Manolache
+ */
+public class TestMain {
+    static TestMain defaultServer;
+    
+    SimpleObjectManager om;
+
+    static SocketConnector serverCon = new SocketConnector();
+    
+    public static HttpConnector testClient = DefaultHttpConnector.get();
+    public static HttpConnector testServer = new HttpConnector(serverCon);
+    public static HttpConnector testProxy = new HttpConnector(serverCon);
+    
+    static Dispatcher mcb;
+    static HttpProxyService proxy;
+
+   
+    public static HttpConnector getTestServer() {
+        if (defaultServer == null) {
+            defaultServer = new TestMain();
+            defaultServer.run();
+        }
+        return defaultServer.testServer;
+    }
+
+
+    public static void initTestCallback(Dispatcher d) {
+        BaseMapper.ContextMapping mCtx = d.addContext(null, "", null, null, null, null);
+//      testServer.setDebugHttp(true);
+//      testServer.setDebug(true);
+        
+        d.addWrapper(mCtx, "/", new StaticContentService()
+            .setContentType("text/html")
+            .setData("<a href='/proc/cpool/client'>Client pool</a><br/>" +
+                    "<a href='/proc/cpool/server'>Server pool</a><br/>" +
+                    "<a href='/proc/cpool/proxy'>Proxy pool</a><br/>" +
+                    ""));
+
+        d.addWrapper(mCtx, "/hello", new StaticContentService().setData("Hello world"));
+        d.addWrapper(mCtx, "/2nd", new StaticContentService().setData("Hello world2"));
+        d.addWrapper(mCtx, "/echo/*", new EchoCallback());
+
+        d.addWrapper(mCtx, "/sleep/1", new SleepCallback().setData("sleep 1"));
+        d.addWrapper(mCtx, "/sleep/10", new SleepCallback().sleep(10000).setData(
+                "sleep 1"));
+
+        d.addWrapper(mCtx, "/chunked/*", new StaticContentService().setData("AAAA")
+                .chunked());
+        
+        d.addWrapper(mCtx, "/proc/cpool/client", new IOStatus(testClient.cpool));
+        d.addWrapper(mCtx, "/proc/cpool/proxy", new IOStatus(testProxy.cpool));
+        d.addWrapper(mCtx, "/proc/cpool/server", new IOStatus(testServer.cpool));
+    }
+
+    static boolean RELEASE = true;
+    /**
+     * Blocking get, returns when the body has been read.
+     */
+    public static BBuffer get(String url) throws IOException {
+
+        BBuffer out = BBuffer.allocate();
+
+        HttpChannel aclient = DefaultHttpConnector.get().get(url);
+        aclient.sendRequest();
+        aclient.readAll(out, 
+                //Long.MAX_VALUE);//
+                2000000);
+        if (RELEASE) {
+            aclient.release(); // return connection to pool
+        }
+        return out;
+    }
+
+    public void run() {
+        String cfgFile = "org/apache/tomcat/lite/test.properties";
+        try {
+            startAll(cfgFile, 8000);
+        } catch (Throwable t) {
+            t.printStackTrace();
+        }
+    } 
+    
+    protected void startAll(String cfgFile, int basePort) {
+        if (om == null) {
+            om = new SimpleObjectManager();
+        }
+
+        om.loadResource(cfgFile);
+
+        //        // Override the port - don't want on 8080, Watchdog may run in same 
+//        // process
+//        om.getProperties().put("org.apache.tomcat.lite.Connector.port", 
+//                Integer.toString(basePort + 800));
+        
+        // From Main:
+        String run = (String) om.getProperty("RUN");
+        String[] runNames = run == null ? new String[] {} : run.split(",");
+        
+        for (String name: runNames) {
+            Object main = om.get(name);
+            
+            if (main instanceof Runnable) {
+                ((Runnable) main).run();
+            }
+        }
+
+        om.bind("HttpConnector-TestServer", testServer);
+        om.bind("HttpConnector", testClient);
+        om.bind("HttpConnector-Proxy", testProxy);
+        
+        testServer.setOnCreate(new HttpChannelEvents() {
+            @Override
+            public void onCreate(HttpChannel data, HttpConnector extraData)
+                    throws IOException {
+                //data.trace("BIND");
+                om.bind("AsyncHttp-" + data.getId(), data);
+            }
+            @Override
+            public void onDestroy(HttpChannel data, HttpConnector extraData)
+                    throws IOException {
+                //data.trace("UNBIND");
+                om.unbind("AsyncHttp-" + data.getId());
+            }
+        });
+        
+//        ioConnector.setOnCreate(new IOConnector.ConnectedCallback() {
+//            AtomicInteger ser = new AtomicInteger();
+//            @Override
+//            public void handleConnected(IOChannel data)
+//                    throws IOException {
+//                data.setId("IOChannel-" + data.getTarget() + "-" + 
+//                        ser.incrementAndGet());
+//                om.bind(data.getId(), data);
+//            }
+//        });
+//        ioConnector.setOnClose(new IOConnector.ClosedCallback() {
+//            @Override
+//            public void handleClosed(IOChannel data)
+//                    throws IOException {
+//               System.err.println("UNBIND " + data.getId() + " " + data);
+//               om.unbind(data.getId());
+//            }
+//        });
+//        ioConnector.onNewWorker = new Callback<NioThread>() {
+//            @Override
+//            public void handle(NioThread data, Object extraData)
+//                    throws IOException {
+//                om.bind((String) extraData, data);
+//            }
+//        };
+        
+        int port = basePort + 903;
+        if (proxy == null) {
+            proxy = new HttpProxyService()
+                .withHttpClient(testClient);
+            testProxy.setPort(port);
+            testProxy.setDebugHttp(true);
+            testProxy.setDebug(true);
+
+            // dispatcher rejects 'http://'
+            testProxy.setHttpService(proxy);
+            try {
+                testProxy.start();
+            } catch (IOException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+            
+            port = basePort + 802;
+            initTestCallback(testServer.getDispatcher());
+            testServer.setPort(port);
+            try {
+                testServer.start();
+            } catch (IOException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+            
+            port = basePort + 443;
+            
+        }   
+        
+        Runtime.getRuntime().addShutdownHook(new Thread() {
+            public void run() {
+                System.err.println("Done");
+            }
+            public void start() {
+                System.err.println("Done1");
+            }
+        });
+
+        
+//        try {
+//            ServletContextImpl ctx = (ServletContextImpl) tomcat.addServletContext(null, null, "/jmx");
+//            // tomcat is already started, need to call init explicitely
+//            ((ServletContextImpl) ctx).loadConfig();
+//            
+//            Servlet servlet = new JMXProxyServlet();
+//            ServletRegistration.Dynamic jmxServlet = ctx.addServlet("jmx", 
+//                    servlet);
+//            jmxServlet.addMapping("/jmx");
+//            // TODO: init servlet 
+//            servlet.init(new ServletConfigImpl(ctx, null, null));
+//
+//            ctx.start();
+//            
+//        } catch (ServletException e) {
+//            // TODO Auto-generated catch block
+//            e.printStackTrace();
+//        }
+
+    }
+
+    static {
+        SslConnector.fixUrlConnection();
+    }
+    
+    public static ByteChunk getUrl(String path) throws IOException {
+        ByteChunk out = new ByteChunk();
+        getUrl(path, out, null);
+        return out;
+    }
+
+    public static int getUrl(String path, 
+                             ByteChunk out, 
+                             Map<String, List<String>> resHead) throws IOException {
+        URL url = new URL(path);
+        HttpURLConnection connection = 
+            (HttpURLConnection) url.openConnection();
+       // connection.setReadTimeout(100000);
+        connection.connect();
+        int rc = connection.getResponseCode();
+        if (resHead != null) {
+            Map<String, List<String>> head = connection.getHeaderFields();
+            resHead.putAll(head);
+        }
+        InputStream is = connection.getInputStream();
+        BufferedInputStream bis = new BufferedInputStream(is);
+        byte[] buf = new byte[2048];
+        int rd = 0;
+        while((rd = bis.read(buf)) > 0) {
+            out.append(buf, 0, rd);
+        }
+        return rc;
+    }
+    
+    
+    public static void main(String[] args) throws Exception, IOException {
+        TestMain testMain = new TestMain();
+        TestMain.defaultServer = testMain;
+        testMain.om = new SimpleObjectManager(args);
+        testMain.run();
+        Main.waitStop();
+    }
+
+    
+}

Propchange: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/TestMain.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/DispatcherTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/DispatcherTest.java?rev=884421&view=auto
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/DispatcherTest.java (added)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/DispatcherTest.java Thu Nov 26 06:55:49 2009
@@ -0,0 +1,46 @@
+/*
+ */
+package org.apache.tomcat.lite.http;
+
+import org.apache.tomcat.lite.io.CBuffer;
+
+import junit.framework.TestCase;
+
+public class DispatcherTest extends TestCase {
+
+    public void testMapper() throws Exception {
+        BaseMapper mapper = new BaseMapper();
+
+        String[] welcomes = new String[2];
+        welcomes[0] = "index.html";
+        welcomes[1] = "foo.html";
+
+        mapper.addContext("test1.com", "", "context0", new String[0], null, null);
+        mapper.addContext("test1.com", "/foo", "context1", new String[0], null, null);
+        mapper.addContext("test1.com", "/foo/bar", "context2", welcomes, null, null);
+        mapper.addContext("test1.com", "/foo/bar/bla", "context3", new String[0], null, null);
+
+        mapper.addWrapper("test1.com", "/foo/bar", "/fo/*", "wrapper0");
+        mapper.addWrapper("test1.com", "/foo/bar", "/", "wrapper1");
+        mapper.addWrapper("test1.com", "/foo/bar", "/blh", "wrapper2");
+        mapper.addWrapper("test1.com", "/foo/bar", "*.jsp", "wrapper3");
+        mapper.addWrapper("test1.com", "/foo/bar", "/blah/bou/*", "wrapper4");
+        mapper.addWrapper("test1.com", "/foo/bar", "/blah/bobou/*", "wrapper5");
+        mapper.addWrapper("test1.com", "/foo/bar", "*.htm", "wrapper6");
+
+        mapper.addContext("asdf.com", "", "context0", new String[0], null, null);
+
+        MappingData mappingData = new MappingData();
+        
+        CBuffer host = CBuffer.newInstance();
+        host.set("test1.com");
+        
+        CBuffer uri = CBuffer.newInstance();
+        uri.set("/foo/bar/blah/bobou/foo");
+
+        mapper.map(host, uri, mappingData);
+        
+        assertEquals("context2", mappingData.context.toString());
+        assertEquals("/foo/bar", mappingData.contextPath.toString());
+    }
+}

Propchange: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/DispatcherTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpChannelInMemoryTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpChannelInMemoryTest.java?rev=884421&view=auto
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpChannelInMemoryTest.java (added)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpChannelInMemoryTest.java Thu Nov 26 06:55:49 2009
@@ -0,0 +1,294 @@
+/*
+ */
+package org.apache.tomcat.lite.http;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.apache.tomcat.lite.http.HttpChannel.HttpService;
+import org.apache.tomcat.lite.http.HttpChannel.RequestCompleted;
+import org.apache.tomcat.lite.io.BBuffer;
+import org.apache.tomcat.lite.io.CBuffer;
+import org.apache.tomcat.lite.io.IOBuffer;
+import org.apache.tomcat.lite.io.IOChannel;
+import org.apache.tomcat.lite.io.IOConnector;
+import org.apache.tomcat.lite.io.MemoryIOConnector;
+import org.apache.tomcat.lite.io.MemoryIOConnector.MemoryIOChannel;
+
+public class HttpChannelInMemoryTest extends TestCase {
+    
+    MemoryIOConnector memoryServerConnector =  new MemoryIOConnector();
+    MemoryIOConnector memoryClientConnector = 
+        new MemoryIOConnector().withServer(memoryServerConnector);
+
+    
+    // Used for pipelined requests - after the first request is 
+    // processed, a new HttpChannel is used ( first may still be 
+    // in use )
+    HttpChannel lastServer;
+    
+    // The server channel will use this for I/O...
+    MemoryIOConnector.MemoryIOChannel net = new MemoryIOChannel();
+
+    HttpConnector serverConnector = new HttpConnector(memoryServerConnector) {
+        @Override
+        public HttpChannel get(CharSequence target) throws IOException {
+            throw new IOException();
+        }
+        public HttpChannel getServer() {
+            lastServer = new HttpChannel().serverMode(true);
+            lastServer.withBuffers(net);
+            lastServer.setConnector(this);
+            //lastServer.withIOConnector(memoryServerConnector);
+            return lastServer;
+        }
+    };
+
+    HttpConnector httpClient = new HttpConnector(memoryClientConnector);
+
+    boolean hasBody = false;
+    boolean bodyDone = false;
+    boolean bodySentDone = false;
+    boolean headersDone = false;
+    boolean allDone = false;
+    
+    
+    HttpChannel http = serverConnector.getServer();
+    
+    public void setUp() throws IOException {
+        serverConnector.setHttpService(null);
+    }
+    
+   
+    public void test2Req() throws IOException {
+        String req = "GET /index.html?q=b&c=d HTTP/1.1\r\n" +
+        "Host:  Foo.com \n" + 
+        "H2:Bar\r\n" + 
+        "H3: Foo \r\n" +
+        " Bar\r\n" +
+        "H4: Foo\n" +
+        "    Bar\n" +
+        "\r\n" + 
+        "HEAD /r2? HTTP/1.1\n" +
+        "Host: Foo.com\r\n" +
+        "H3: Foo \r\n" +
+        "       Bar\r\n" +
+        "H4: Foo\n" +
+        " Bar\n" +
+        "\r\n";
+        net.getIn().append(req);        
+        
+        assertTrue(http.getRequest().method().equals("GET"));
+        assertTrue(http.getRequest().protocol().equals("HTTP/1.1"));
+        assertEquals(http.getRequest().getMimeHeaders().size(), 4);
+        assertEquals(http.getRequest().getMimeHeaders().getHeader("Host").toString(),
+                "Foo.com");
+        assertEquals(http.getRequest().getMimeHeaders().getHeader("H2").toString(),
+                "Bar");
+        
+        http.getOut().append("Response1");
+        http.getOut().close();
+        http.startSending();
+        http.release(); 
+        
+        // now second response must be in. 
+        // the connector will create a new http channel
+        
+        http = lastServer;
+        
+        assertTrue(http.getRequest().method().equals("HEAD"));
+        assertTrue(http.getRequest().protocol().equals("HTTP/1.1"));
+        assertTrue(http.getRequest().getMimeHeaders().size() == 3);
+        assertTrue(http.getRequest().getMimeHeaders().getHeader("Host")
+                .equals("Foo.com"));
+    }
+
+    public void testMultiLineHead() throws IOException {
+        http.getNet().getIn().append("GET / HTTP/1.0\n" +
+                "Cookie: 1234\n" +
+                "  456 \n" +
+                "Connection:   Close\n\n");
+        http.getNet().getIn().close();
+        
+        MultiMap headers = http.getRequest().getMimeHeaders();
+        CBuffer cookie = headers.getHeader("Cookie");
+        CBuffer conn = headers.getHeader("Connection");
+        assertEquals(conn.toString(), "Close");
+        assertEquals(cookie.toString(), "1234 456");
+        
+        assertEquals(http.headRecvBuf.toString(), 
+                "GET / HTTP/1.0\n" +
+                "Cookie: 1234 456   \n" + // \n -> trailing space
+                "Connection:   Close\n\n");
+    }
+
+    public void testCloseSocket() throws IOException {
+        http.getNet().getIn().append("GET / HTTP/1.1\n"
+                + "Host: localhost\n"
+                + "\n");
+        assertTrue(http.keepAlive());
+
+        http.getNet().getIn().close();
+        assertFalse(http.keepAlive());
+    }
+    
+    public void test2ReqByte2Byte() throws IOException {
+        String req = "GET /index.html?q=b&c=d HTTP/1.1\r\n" +
+        "Host:  Foo.com \n" + 
+        "H2:Bar\r\n" + 
+        "H3: Foo \r\n" +
+        " Bar\r\n" +
+        "H4: Foo\n" +
+        "    Bar\n" +
+        "\r\n" + 
+        "HEAD /r2? HTTP/1.1\n" +
+        "Host: Foo1.com\n" +
+        "H3: Foo \r\n" +
+        "       Bar\r\n" +
+        "\r\n";
+        for (int i = 0; i < req.length(); i++) {
+            net.getIn().append(req.charAt(i));        
+        }
+        
+        assertTrue(http.getRequest().method().equals("GET"));
+        assertTrue(http.getRequest().protocol().equals("HTTP/1.1"));
+        assertTrue(http.getRequest().getMimeHeaders().size() == 4);
+        assertTrue(http.getRequest().getMimeHeaders().getHeader("Host")
+                .equals("Foo.com"));
+        
+        // send a response
+        http.sendBody.append("Response1");
+        http.getOut().close();
+        
+        http.startSending(); // This will trigger a pipelined request
+        
+        http.release(); // now second response must be in
+        
+        http = lastServer;
+        assertTrue(http.getRequest().method().equals("HEAD"));
+        assertTrue(http.getRequest().protocol().equals("HTTP/1.1"));
+        assertTrue(http.getRequest().getMimeHeaders().size() == 2);
+        assertTrue(http.getRequest().getMimeHeaders().getHeader("Host")
+                .equals("Foo1.com"));
+
+        // send a response - service method will be called
+        http.sendBody.append("Response2");
+        http.getOut().close();
+        http.release(); // now second response must be in
+        
+        
+    }
+    
+    public void testEndWithoutFlushCallbacks() throws IOException {
+        http.setCompletedCallback(new RequestCompleted() {
+            public void handle(HttpChannel data, Object extra)
+            throws IOException {
+                allDone = true;
+            }
+        });
+        http.getNet().getIn().append(POST);
+        http.getNet().getIn().close();
+        
+        http.sendBody.queue("Hi");
+        http.getOut().close();
+        http.startSending(); // will call handleEndSend
+
+        assertTrue(allDone);
+        
+    }
+
+    public void testCallbacks() throws IOException {
+        http.setCompletedCallback(new RequestCompleted() {
+            public void handle(HttpChannel data, Object extra)
+            throws IOException {
+                allDone = true;
+            }
+        });
+        http.setHttpService(new HttpService() {
+            public void service(HttpRequest httpReq, HttpResponse httpRes)
+            throws IOException {
+                headersDone = true;
+            }
+        });
+        http.setDataReceivedCallback(new IOConnector.DataReceivedCallback() {
+            @Override
+            public void handleReceived(IOChannel ch) throws IOException {
+                if (ch.getIn().isAppendClosed()) {
+                    bodyDone = true;
+                }
+            }
+        });
+        http.setDataFlushedCallback(new IOConnector.DataFlushedCallback() {
+            @Override
+            public void handleFlushed(IOChannel ch) throws IOException {
+                if (ch.getOut().isAppendClosed()) {
+                    bodySentDone = true;
+                }
+            }
+        });
+
+        // Inject the request
+        http.getNet().getIn().append(POST);
+        assertTrue(headersDone);
+        http.getNet().getIn().append("1234");
+        
+        http.getNet().getIn().close();
+        assertTrue(bodyDone);
+        
+        
+        http.sendBody.queue("Hi");
+        http.getOut().close();
+        http.startSending();
+        assertTrue(bodySentDone);
+
+        assertTrue(allDone);
+        
+    }
+    
+    public static String POST = "POST / HTTP/1.0\n" +
+        "Connection: Close\n" +
+        "Content-Length: 4\n\n" +
+        "1234"; 
+
+    public void testClose() throws IOException {
+        http.getNet().getIn().append(POST);
+        http.getNet().getIn().close();
+        
+        HttpBody receiveBody = http.receiveBody;
+        IOBuffer appData = receiveBody;
+        BBuffer res = BBuffer.allocate(1000);
+        appData.readAll(res);
+        
+        assertEquals(res.toString(), "1234");
+        assertFalse(http.keepAlive());
+        assertFalse(http.keepAlive());
+        
+        http.sendBody.queue(res);
+        http.getOut().close();
+        http.startSending();
+        
+        assertTrue(net.getOut().isAppendClosed());
+        assertTrue(net.out.toString().indexOf("\n1234") > 0);
+        
+    }
+    
+    public void testReadLine() throws Exception {
+        http.getNet().getIn().append("POST / HTTP/1.0\n" +
+        		"Content-Length: 28\n\n" +
+                "Line 1\n" +
+                "Line 2\r\n" +
+                "Line 3\r" +
+                "Line 4");
+        http.getNet().getIn().close();
+        
+        BufferedReader r = http.getRequest().getReader();
+        assertEquals("Line 1", r.readLine());
+        assertEquals("Line 2", r.readLine());
+        assertEquals("Line 3", r.readLine());
+        assertEquals("Line 4", r.readLine());
+        assertEquals(null, r.readLine());
+        
+    }
+}

Propchange: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpChannelInMemoryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpChannelTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpChannelTest.java?rev=884421&view=auto
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpChannelTest.java (added)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpChannelTest.java Thu Nov 26 06:55:49 2009
@@ -0,0 +1,130 @@
+/*
+ */
+package org.apache.tomcat.lite.http;
+
+import java.io.IOException;
+
+import org.apache.tomcat.lite.io.BBuffer;
+import org.apache.tomcat.lite.io.CBuffer;
+
+import junit.framework.TestCase;
+
+public class HttpChannelTest extends TestCase {
+
+    HttpChannel ch = new HttpChannel().serverMode(true);
+    HttpRequest req = ch.getRequest();
+    
+    
+    BBuffer head = BBuffer.allocate();
+    BBuffer line = BBuffer.wrapper();
+    BBuffer name = BBuffer.wrapper();
+    BBuffer value = BBuffer.wrapper();
+    
+    BBuffer statusB = BBuffer.wrapper();
+    BBuffer msgB = BBuffer.wrapper();
+    BBuffer methodB = BBuffer.wrapper();
+    BBuffer queryB = BBuffer.wrapper("");
+    BBuffer requestB = BBuffer.wrapper();
+    BBuffer protoB = BBuffer.wrapper();
+    
+    BBuffer l7 = BBuffer.wrapper("GET \n");
+    BBuffer l8 = BBuffer.wrapper("GET /\n");
+    BBuffer l9 = BBuffer.wrapper("GET /a?b\n");
+    BBuffer l10 = BBuffer.wrapper("GET /a?b HTTP/1.0\n");
+    BBuffer l11 = BBuffer.wrapper("GET /a?b HTTP/1.0\na:b");
+    BBuffer l12 = BBuffer.wrapper("GET /a?b HTTP/1.0\na:b\n");
+    
+    BBuffer f1 = BBuffer.wrapper("GET /a?b HTTP/1.0\na:b\n\n");
+    BBuffer f2 = BBuffer.wrapper("GET /a?b HTTP/1.0\na:b\r\n\r\n");
+    BBuffer f3 = BBuffer.wrapper("GET /a?b HTTP/1.0\na:b\r\r");
+    BBuffer f4 = BBuffer.wrapper("GET /a?b HTTP/1.0\na:b\r\n\r");
+
+    
+    public void reqTest(String lineS, String method, String req, 
+            String qry, String proto) throws IOException {
+        BBuffer line = BBuffer.wrapper(lineS);
+        queryB.recycle();
+        protoB.recycle();
+        requestB.recycle();
+        methodB.recycle();
+        ch.parseRequestLine(line, methodB, requestB, queryB, protoB);
+        assertEquals(proto, protoB.toString());
+        assertEquals(req, requestB.toString());
+        assertEquals(qry, queryB.toString());
+        assertEquals(method, methodB.toString());
+    }
+
+    public void testParams() throws IOException {
+        MultiMap params = processQry("a=b&c=d");
+        assertEquals("b", params.getString("a"));
+    }
+
+    private MultiMap processQry(String qry) throws IOException {
+        BBuffer head = BBuffer.wrapper("GET /a?" + qry + " HTTP/1.0\n" +
+        		"Host: a\n\n");
+        ch.parseMessage(head);
+        MultiMap params = req.getParameters();
+        return params;
+    }
+    
+    public void testParseReq() throws IOException {
+        reqTest("GET / HTTP/1.0", "GET", "/", "", "HTTP/1.0");
+        reqTest("GET", "GET", "", "", "");
+        reqTest("GET   / HTTP/1.0", "GET", "/", "", "HTTP/1.0");
+        reqTest("GET /     HTTP/1.0", "GET", "/", "", "HTTP/1.0");
+        reqTest("GET /?b HTTP/1.0", "GET", "/", "b", "HTTP/1.0");
+        reqTest("GET ?a HTTP/1.0", "GET", "", "a", "HTTP/1.0");
+        reqTest("GET a HTTP/1.0", "GET", "a", "", "HTTP/1.0");
+        reqTest("GET a? HTTP/1.0", "GET", "a", "", "HTTP/1.0");
+    }
+    
+    public void headTest(String headS, String expName, String expValue, 
+            String expLine, String expRest) throws IOException {
+        head = BBuffer.wrapper(headS);
+        head.readLine(line);
+        ch.parseHeader(head, line, name, value);
+        
+        assertEquals(expName, name.toString());
+        assertEquals(expValue, value.toString());
+
+        assertEquals(expLine, line.toString());
+        assertEquals(expRest, head.toString());
+    }
+    
+    public void testParseHeader() throws IOException {
+        headTest("a:b\n", "a", "b", "", "");
+        headTest("a :b\n", "a", "b", "", "");
+        headTest("a : b\n", "a", "b", "", "");
+        headTest("a :  b\n", "a", "b", "", "");
+        headTest("a :  b c \n", "a", "b c", "", "");
+        headTest("a :  b c\n", "a", "b c", "", "");
+        headTest("a :  b  c\n", "a", "b c", "", "");
+        headTest("a :  b  \n c\n", "a", "b c", "", "");
+        headTest("a :  b  \n  c\n", "a", "b c", "", "");
+        headTest("a :  b  \n  c\nd:", "a", "b c", "", "d:");
+       
+    }
+    
+    public void responseTest(String lineS, String proto, String status, 
+            String msg) throws IOException {
+        protoB.recycle();
+        statusB.recycle();
+        msgB.recycle();
+        BBuffer line = BBuffer.wrapper(lineS);
+        ch.parseResponseLine(line, 
+                protoB, statusB, msgB);
+        assertEquals(proto, protoB.toString());
+        assertEquals(status, statusB.toString());
+        assertEquals(msg, msgB.toString());
+    }
+    
+    public void testResponse() throws Exception {
+        responseTest("HTTP/1.1 200 OK", "HTTP/1.1", "200", "OK");
+        responseTest("HTTP/1.1  200 OK", "HTTP/1.1", "200", "OK");
+        responseTest("HTTP/1.1  200", "HTTP/1.1", "200", "");
+        responseTest("HTTP/1.1", "HTTP/1.1", "", "");
+    }
+    
+    
+
+}

Propchange: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpChannelTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpsTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpsTest.java?rev=884421&view=auto
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpsTest.java (added)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpsTest.java Thu Nov 26 06:55:49 2009
@@ -0,0 +1,200 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.lite.http;
+
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.tomcat.lite.TestMain;
+import org.apache.tomcat.lite.http.HttpChannel.HttpService;
+import org.apache.tomcat.lite.io.BBuffer;
+import org.apache.tomcat.lite.io.SslConnector;
+import org.apache.tomcat.util.buf.ByteChunk;
+
+public class HttpsTest extends TestCase {
+    
+    static int port = 8443;
+    HttpConnector con;
+    HttpConnector httpClient;
+    
+    public void setUp() {
+        Logger.getLogger("SSL").setLevel(Level.FINEST);
+    }
+
+    public void tearDown() {
+        if (con != null) {
+            con.stop();
+        }
+        if (httpClient != null) {
+            httpClient.stop();
+        }
+    }
+    
+    static HttpConnector initServer(int port) throws IOException {
+        SslConnector sslCon = new SslConnector()
+            .setKeysResource("org/apache/tomcat/lite/http/test.keystore", "changeit");
+        
+        HttpConnector con = new HttpConnector(sslCon);
+        con.setPort(port);
+
+        addService(con);
+        return con;
+    }
+    
+    private static void addService(HttpConnector con) throws IOException {
+        con.setMaxHttpPoolSize(0);
+//        con.setDebug(true);
+//        con.setDebugHttp(true);
+        
+        con.getDispatcher().setDefaultService(new HttpService() {
+            @Override
+            public void service(HttpRequest httpReq, HttpResponse httpRes)
+                    throws IOException {
+                httpRes.setHeader("Connection", "close");
+                httpRes.getBodyWriter().write("Hello");
+            }
+        });
+        con.start();
+    }
+
+    public void testSimpleClient() throws Exception {
+        SslConnector sslCon = new SslConnector();
+        httpClient = new HttpConnector(sslCon);
+//        httpClient.setDebug(true);
+//        httpClient.setDebugHttp(true);
+        httpClient.setMaxHttpPoolSize(0);
+        con = initServer(++port);
+        checkResponse(httpClient);
+    }
+    
+    
+    public void testSimpleServer() throws Exception {
+        con = initServer(++port);
+        ByteChunk res = TestMain.getUrl("https://localhost:" + port +
+            "/examples/servlets/servlet/HelloWorldExample");
+        assertTrue(res.toString().indexOf("Hello") >= 0);
+    }       
+
+    
+    private void checkResponse(HttpConnector httpClient) throws Exception {
+        HttpChannel ch = httpClient.get("localhost", port);
+        ch.getRequest().setRequestURI("/hello");
+        ch.getRequest().setProtocol("HTTP/1.0");
+        // problems with keep alive !!!
+        ch.sendRequest();
+        BBuffer res = ch.readAll(null, 1000000);
+        
+        assertTrue(res.toString().indexOf("Hello") >= 0);
+    }    
+    
+    public void testSimpleClient20() throws Exception {
+        SslConnector sslCon = new SslConnector();
+        httpClient = new HttpConnector(sslCon);
+//        httpClient.setDebug(true);
+//        httpClient.setDebugHttp(true);
+
+        con = initServer(++port);
+        for (int i = 0; i < 20; i++) {
+            checkResponse(httpClient);
+        }
+    }
+    
+    public void testSimpleRequestGoogle() throws Exception {
+        SslConnector sslCon = new SslConnector();
+        httpClient = new HttpConnector(sslCon);
+        HttpChannel client = httpClient.get("www.google.com", 443);
+        client.getRequest().setRequestURI("/accounts/ServiceLogin");
+        client.sendRequest();
+        
+        BBuffer res = BBuffer.allocate(10000);
+        client.readAll(res, 1000000);
+        assertTrue(res.toString().indexOf("<title>Google Accounts</title>") > 0);
+    }
+        
+
+    /** 
+     * Use byte[] for cert - avoids using the store file.
+     * This may be nice for:
+     * - tests without a file
+     * - frameworks managing configs - no need to deal with files 
+     * @throws Exception 
+     * 
+     */
+    public void testSeverWithKeys() throws Exception {
+        Base64 b64 = new Base64();
+
+        
+        byte[] keyBytes = b64.decode(PRIVATE_KEY);
+
+        SslConnector sslCon = new SslConnector()
+            .setKeys(CERTIFICATE, keyBytes);
+            
+        HttpConnector con = new HttpConnector(sslCon);
+        con.setPort(++port);
+        addService(con);
+        
+        ByteChunk res = TestMain.getUrl("https://localhost:" + port +
+            "/examples/servlets/servlet/HelloWorldExample");
+        assertTrue(res.toString().indexOf("Hello") >= 0);
+        
+    }
+    
+    
+    //byte[] encoded = 
+    //            SslConnector.getCertificateFromStore(
+    //                    "test/org/apache/tomcat/lite/http/test.keystore", 
+    //                "changeit");
+    //byte[] encoded = 
+    //            SslConnector.getPrivateKeyFromStore(
+    //        "test/org/apache/tomcat/lite/http/test.keystore", 
+    //        "changeit");
+    //        
+    //byte[] b64b = b64.encode(encoded);
+    //System.out.println(new String(b64b));
+    static String PRIVATE_KEY =
+        "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBALGOFqjC4Fefz0oOcfJeS8eLV8jY" +
+        "zA3sHUnTKmASfgfhG8prWUgSEq7O/849MrBysiKpIvTN8R+ykV4QCAxauGURDsNI2ZtAv23YX2Mb" +
+        "cfYfYqD0tgHEn355HKey0ICgmRuq3norlUWAH3hRv5qiQMc0UIhNrmdTs0jyvQ8E8AlZAgMBAAEC" +
+        "gYBybr8P2Tk5gBfbBOBPcpKocpgLLB6nQmvF7sC61nA/p8d/eBw8pNlBrMuVIkAPFHzWdee/mxMy" +
+        "eKXT18U4ISgBdIKLF9LwILhIgR8CwElLucmF2OdXqFe7baBIFI6OaqLvDgOwdHSIS6uZhAWOWIAZ" +
+        "38DhJbHMzPpfeBv1bAIhAQJBAPwhjzWqSWZjAfcED4htKa/ZSbdqMa1iYtveoHdXIcLuj4Ck1DKQ" +
+        "EFpzLnUe2gwul/TDcoW3ZVp85jn7jwnrNDECQQC0R5LgkGdGNMBih4kPU87tHFHUnggSMyIOBnCE" +
+        "XuQEN6i68VOwbdm2F7Rg1XGHD8IIJmVeiTSgLtS/mJRht6WpAkEAqs9VhQbTaTDkEOPIXiWOW1q6" +
+        "rS6dbxg7XzdowNDfx3706zM/qu2clpp3u9Ll5+DdA24xtNM1L+Nz2Y5KLm8Q0QJAQqpxEx/zQNAD" +
+        "EKyEL6nTTHV7gT+LRoeoIT2aYCji8vhOKgtR4l1M8/xiFKj5mXNnUjI4rDPaxR1sSQm4XUZXOQJB" +
+        "AJaCD0AhacU+KaOtk65tBJ7N2dKTbc5gs/CAz1uGgJtoD/jPjELMQwrxdp6AZP6+L6osqy6zDI3W" +
+        "zNHXS+wWAd0=";
+ 
+    static String CERTIFICATE = 
+        "-----BEGIN CERTIFICATE-----\n" + 
+        "MIICUzCCAbygAwIBAgIESviASzANBgkqhkiG9w0BAQUFADBuMRAwDgYDVQQGEwdVbmtub3duMRAw" + 
+        "DgYDVQQIEwdVbmtub3duMRAwDgYDVQQHEwdVbmtub3duMRAwDgYDVQQKEwdVbmtub3duMRAwDgYD" +
+        "VQQLEwdVbmtub3duMRIwEAYDVQQDEwlsb2NhbGhvc3QwHhcNMDkxMTA5MjA0OTE1WhcNMTAwMjA3" +
+        "MjA0OTE1WjBuMRAwDgYDVQQGEwdVbmtub3duMRAwDgYDVQQIEwdVbmtub3duMRAwDgYDVQQHEwdV" +
+        "bmtub3duMRAwDgYDVQQKEwdVbmtub3duMRAwDgYDVQQLEwdVbmtub3duMRIwEAYDVQQDEwlsb2Nh" +
+        "bGhvc3QwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALGOFqjC4Fefz0oOcfJeS8eLV8jYzA3s" +
+        "HUnTKmASfgfhG8prWUgSEq7O/849MrBysiKpIvTN8R+ykV4QCAxauGURDsNI2ZtAv23YX2MbcfYf" +
+        "YqD0tgHEn355HKey0ICgmRuq3norlUWAH3hRv5qiQMc0UIhNrmdTs0jyvQ8E8AlZAgMBAAEwDQYJ" +
+        "KoZIhvcNAQEFBQADgYEAPHUr1BDENlV28yIQvJOWKYbcNWLd6Cp8xCltSI897xhPpKQ5tDvs+l0g" +
+        "VfdBv5+jou0F5gbCkqgclBuUnUUWsU7r4HYBLVB8FiGSy9v5yuFJWyMMLJkWAfBgzxV1nHsCPhOn" +
+        "rspSB+i6bwag0i3ENXstD/Fg1lN/7l9dRpurneI=\n" +
+        "-----END CERTIFICATE-----\n\n";
+}

Propchange: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/LiveHttp1Test.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/LiveHttp1Test.java?rev=884421&view=auto
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/LiveHttp1Test.java (added)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/LiveHttp1Test.java Thu Nov 26 06:55:49 2009
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package org.apache.tomcat.lite.http;
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.apache.tomcat.lite.TestMain;
+import org.apache.tomcat.lite.io.BBuffer;
+import org.apache.tomcat.lite.io.CBuffer;
+import org.apache.tomcat.lite.io.SocketConnector;
+
+public class LiveHttp1Test extends TestCase {
+    // Proxy tests extend this class, run same tests via proxy on 8903 
+    protected int clientPort = 8802;
+
+    HttpChannel httpClient;
+
+    BBuffer bodyRecvBuffer = BBuffer.allocate(1024);
+
+    int to = 1000;
+
+    public void setUp() throws IOException {
+        // DefaultHttpConnector.get().setDebug(true);
+        // DefaultHttpConnector.get().setDebugHttp(true);
+        TestMain.getTestServer();
+
+        httpClient = DefaultHttpConnector.get().get("localhost", clientPort);
+
+        bodyRecvBuffer.recycle();
+    }
+
+    public void tearDown() throws Exception {
+        if (httpClient != null) {
+            httpClient.release(); // async
+            httpClient = null;
+        }
+    }
+
+    public void testSimpleRequest() throws Exception {
+        httpClient.getRequest().requestURI().set("/hello");
+
+        httpClient.sendRequest();
+        httpClient.readAll(bodyRecvBuffer, to);
+        assertEquals("Hello world", bodyRecvBuffer.toString());
+    }
+
+    public void testPoolGetRelease() throws Exception {
+        HttpConnector con = new HttpConnector(new SocketConnector());
+        con.setMaxHttpPoolSize(10);
+        HttpChannel httpCh = con.get("localhost", clientPort);
+        httpCh.release();
+
+        httpCh = con.get("localhost", clientPort);
+        httpCh.release();
+
+        httpCh = con.get("localhost", clientPort);
+        httpCh.release();
+
+    }
+
+    public void testSimpleChunkedRequest() throws Exception {
+        httpClient.getRequest().requestURI().set("/chunked/foo");
+        httpClient.sendRequest();
+        httpClient.readAll(bodyRecvBuffer, to);
+        assertTrue(bodyRecvBuffer.toString().indexOf("AAA") >= 0);
+    }
+
+    // Check waitResponseHead()
+    public void testRequestHead() throws Exception {
+        httpClient.getRequest().requestURI().set("/echo/foo");
+
+        // Send the request, wait response
+        httpClient.sendRequest();
+
+        httpClient.readAll(bodyRecvBuffer, to);
+        assertTrue(bodyRecvBuffer.toString().indexOf("GET /echo/foo") > 0);
+    }
+
+    public void test10() throws Exception {
+        for (int i = 0; i < 10; i++) {
+            testSimpleRequest();
+            tearDown();
+            setUp();
+
+            notFound();
+            tearDown();
+            setUp();
+
+            testSimpleRequest();
+            tearDown();
+            setUp();
+        }
+    }
+
+    public void notFound() throws Exception {
+        httpClient.getRequest().requestURI().set("/foo");
+        httpClient.sendRequest();
+        httpClient.readAll(bodyRecvBuffer, to);
+    }
+
+    // compression not implemented
+    public void testGzipRequest() throws Exception {
+        httpClient.getRequest().requestURI().set("/hello");
+        httpClient.getRequest().setHeader("accept-encoding",
+            "gzip");
+
+        // Send the request, wait response
+        httpClient.sendRequest();
+        // cstate.waitResponseHead(10000); // headers are received
+        // ByteChunk data = new ByteChunk(1024);
+        // acstate.serializeResponse(acstate.res, data);
+
+        // System.err.println(bodyRecvBuffer.toString());
+
+        httpClient.readAll(bodyRecvBuffer, to);
+        // Done
+    }
+
+    public void testWrongPort() throws Exception {
+        httpClient = DefaultHttpConnector.get().get("localhost", 18904);
+        httpClient.getRequest().requestURI().set("/hello");
+
+        httpClient.sendRequest();
+        
+        try {
+            httpClient.readAll(bodyRecvBuffer, to);
+        } catch (Throwable t) {
+            t.printStackTrace();
+            return;
+        }
+        fail("Error");
+    }
+}

Propchange: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/LiveHttp1Test.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/MultiMapTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/MultiMapTest.java?rev=884421&view=auto
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/MultiMapTest.java (added)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/MultiMapTest.java Thu Nov 26 06:55:49 2009
@@ -0,0 +1,54 @@
+/*
+ */
+package org.apache.tomcat.lite.http;
+
+import org.apache.tomcat.lite.http.MultiMap.Entry;
+
+import junit.framework.TestCase;
+
+public class MultiMapTest extends TestCase {
+
+    MultiMap map = new MultiMap();
+    MultiMap lmap = new MultiMap().insensitive();
+    
+    public void testAdd() {
+        map.add("foo", "bar");
+        assertEquals("bar", map.get("foo").toString());
+    }
+
+    public void testRemove() {
+        map.add("foo", "bar");
+        map.add("foo", "bar");
+        map.add("foo1", "bar");
+        assertEquals(3, map.count);
+        map.remove("foo");
+        assertEquals(1, map.count);
+    }
+
+    public void testRemove1() {
+        map.add("foo", "bar");
+        map.add("foo1", "bar");
+        map.add("foo", "bar");
+        assertEquals(3, map.count);
+        map.remove("foo");
+        assertEquals(1, map.count);
+        map.remove("foo1");
+        assertEquals(0, map.count);
+    }
+
+    public void testCase() {
+        lmap.add("foo", "bar1");
+        lmap.add("Foo", "bar2");
+        lmap.add("a", "bar3");
+        lmap.add("B", "bar4");
+        assertEquals(4, lmap.count);
+        assertEquals(3, lmap.map.size());
+        
+        assertEquals("bar3", lmap.getString("a"));
+        assertEquals("bar3", lmap.getString("A"));
+        assertEquals("bar1", lmap.getString("Foo"));
+        Entry entry = lmap.getEntry("FOO");
+        assertEquals(2, entry.values.size());
+    }
+
+}

Propchange: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/MultiMapTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/services/EchoCallback.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/services/EchoCallback.java?rev=884421&view=auto
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/services/EchoCallback.java (added)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/services/EchoCallback.java Thu Nov 26 06:55:49 2009
@@ -0,0 +1,60 @@
+/*  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.
+ */
+package org.apache.tomcat.lite.http.services;
+
+import java.io.IOException;
+import java.util.logging.Logger;
+
+import org.apache.tomcat.lite.http.HttpChannel;
+import org.apache.tomcat.lite.http.HttpRequest;
+import org.apache.tomcat.lite.http.HttpResponse;
+import org.apache.tomcat.lite.http.HttpChannel.HttpService;
+import org.apache.tomcat.lite.io.IOBuffer;
+
+/**
+ * Response is plain/text, copy of the received request
+ */
+public class EchoCallback implements HttpService {
+    Logger log = Logger.getLogger("coyote.static");
+    
+    String contentType = "text/plain";
+
+
+    public EchoCallback() {
+    }
+
+    @Override
+    public void service(HttpRequest req, HttpResponse res) throws IOException {
+        HttpChannel sproc = req.getHttpChannel();
+        res.setStatus(200);
+        res.setContentType(contentType);
+        
+        IOBuffer tmp = new IOBuffer(null);
+        req.serialize(tmp);
+        
+        sproc.getOut().append("REQ HEAD:\n");
+        sproc.getOut().append(tmp.readAll(null));
+        IOBuffer reqBuf = sproc.getOut();
+        
+        reqBuf.append("\nCONTENT_LENGTH:")
+            .append(Long.toString(req.getContentLength()))
+            .append("\n");
+//      
+//        sproc.release();
+    }
+
+    
+}
\ No newline at end of file

Propchange: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/services/EchoCallback.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/services/SleepCallback.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/services/SleepCallback.java?rev=884421&view=auto
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/services/SleepCallback.java (added)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/services/SleepCallback.java Thu Nov 26 06:55:49 2009
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package org.apache.tomcat.lite.http.services;
+
+import java.io.IOException;
+
+import org.apache.tomcat.lite.http.HttpRequest;
+import org.apache.tomcat.lite.http.HttpResponse;
+import org.apache.tomcat.lite.io.BBuffer;
+import org.apache.tomcat.lite.proxy.StaticContentService;
+
+/**
+ * Test adapters that sleeps, for load test and for encoding.
+ * REQUIRES THREAD POOL
+ */
+public class SleepCallback extends StaticContentService {
+  long t1;
+  long t2;
+  long t3;
+  long t4;
+  
+  public SleepCallback() {
+  }
+
+  public SleepCallback sleep(long t1, long t2, long t3,
+                            long t4) {
+    this.t1 = t1;
+    this.t2 = t2;
+    this.t3 = t3;
+    this.t4 = t4;
+    return this;
+  }
+    
+  public SleepCallback sleep(long t1) {
+    return sleep(t1, t1, t1, t1);
+  }
+
+  @Override
+  public void service(HttpRequest httpReq, HttpResponse res) throws IOException {
+      // TODO: blocking ! needs thread pool !
+    try {
+
+        Thread.currentThread().sleep(t1);
+        res.setStatus(200);
+        if (!chunked) {
+            res.setContentLength(mb.remaining() * 2);
+        }
+        res.setContentType(contentType);
+
+        res.sendHead();
+
+        Thread.currentThread().sleep(t2);
+
+        res.getBody().queue(BBuffer.wrapper(mb, 0, mb.remaining()));
+        res.flush();
+
+        //res.action(ActionCode.ACTION_CLIENT_FLUSH, res);
+
+        Thread.currentThread().sleep(t3);
+
+        res.getBody().queue(BBuffer.wrapper(mb, 0, mb.remaining()));
+        res.flush();
+
+        Thread.currentThread().sleep(t4);
+    } catch (InterruptedException e) {
+        // TODO Auto-generated catch block
+        e.printStackTrace();
+    }
+  }
+
+}
\ No newline at end of file

Propchange: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/services/SleepCallback.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/test.keystore
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/test.keystore?rev=884421&view=auto
==============================================================================
Binary file - no diff available.

Propchange: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/test.keystore
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/BBufferTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/BBufferTest.java?rev=884421&view=auto
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/BBufferTest.java (added)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/BBufferTest.java Thu Nov 26 06:55:49 2009
@@ -0,0 +1,159 @@
+/*
+ */
+package org.apache.tomcat.lite.io;
+
+import org.apache.tomcat.lite.io.BBuffer;
+
+import junit.framework.TestCase;
+
+public class BBufferTest extends TestCase {
+    BBuffer res = BBuffer.wrapper("");
+
+    BBuffer l1 = BBuffer.wrapper("");
+    BBuffer l1a = BBuffer.wrapper("a");
+
+    BBuffer l2 = BBuffer.wrapper("\r");
+    BBuffer l3 = BBuffer.wrapper("\n");
+    BBuffer l4 = BBuffer.wrapper("\r\n");
+    BBuffer l5 = BBuffer.wrapper("\r\na");
+    BBuffer l5_a = BBuffer.wrapper("\ra");
+    BBuffer l5_b = BBuffer.wrapper("\na");
+    BBuffer l6 = BBuffer.wrapper("a\n");
+    BBuffer l7 = BBuffer.wrapper("GET \n");
+    BBuffer l8 = BBuffer.wrapper("GET /\n");
+    BBuffer l9 = BBuffer.wrapper("GET /a?b\n");
+    BBuffer l10 = BBuffer.wrapper("GET /a?b HTTP/1.0\n");
+    BBuffer l11 = BBuffer.wrapper("GET /a?b HTTP/1.0\na:b");
+    BBuffer l12 = BBuffer.wrapper("GET /a?b HTTP/1.0\na:b\n");
+    
+    BBuffer f1 = BBuffer.wrapper("GET /a?b HTTP/1.0\na:b\n\n");
+    BBuffer f2 = BBuffer.wrapper("GET /a?b HTTP/1.0\na:b\r\n\r\n");
+    BBuffer f3 = BBuffer.wrapper("GET /a?b HTTP/1.0\na:b\r\r");
+    BBuffer f4 = BBuffer.wrapper("GET /a?b HTTP/1.0\na:b\r\n\r");
+
+    BBuffer s1 = BBuffer.wrapper(" \n");
+    BBuffer s2 = BBuffer.wrapper(" a");
+    BBuffer s3 = BBuffer.wrapper("  ");
+    BBuffer s4 = BBuffer.wrapper("   a");
+
+    BBuffer h1 = BBuffer.wrapper("a");
+    BBuffer h2 = BBuffer.wrapper("a?b");
+    BBuffer h3 = BBuffer.wrapper("a b");
+
+    public void hashTest(String s) {
+        assertEquals(s.hashCode(), BBuffer.wrapper(s).hashCode());
+    }
+    
+    public void testHash() {
+        hashTest("");
+        hashTest("a");
+        hashTest("123abc");
+        hashTest("123abc\0");
+        // Fails for UTF chars - only ascii hashTest("123abc\u12345;");
+    }
+    
+    public void testReadToSpace() {
+        assertEquals(3, l8.readToSpace(res));
+        assertEquals("GET", res.toString());
+        assertEquals(" /\n", l8.toString());        
+
+        assertEquals(0, l1.readToSpace(res));
+        assertEquals("", res.toString());
+        assertEquals("", l1.toString());        
+    }
+    
+    public void testReadToDelim() {
+        assertEquals(1, h1.readToDelimOrSpace((byte)'?', res));
+        assertEquals("a", res.toString());
+        assertEquals("", h1.toString());        
+        
+        assertEquals(1, h2.readToDelimOrSpace((byte)'?', res));
+        assertEquals("a", res.toString());
+        assertEquals("?b", h2.toString());        
+        
+        assertEquals(1, h3.readToDelimOrSpace((byte)'?', res));
+        assertEquals("a", res.toString());
+        assertEquals(" b", h3.toString());        
+    }
+    
+    public void testGet() {
+        assertEquals(0x20, s1.get(0));
+        assertEquals(0x0a, s1.get(1));
+        try {
+            s1.get(2);
+        } catch(ArrayIndexOutOfBoundsException ex) {
+            return;
+        }
+        fail("Exception");
+    }
+    
+    public void testSkipSpace() {
+        assertEquals(1, s1.skipSpace());
+        assertEquals("\n", s1.toString());        
+
+        assertEquals(1, s2.skipSpace());
+        assertEquals("a", s2.toString());        
+        
+        assertEquals(2, s3.skipSpace());
+        assertEquals("", s3.toString());        
+
+        assertEquals(3, s4.skipSpace());
+        assertEquals("a", s4.toString());        
+        
+        assertEquals(0, l1.skipSpace());
+        assertEquals("", l1.toString());        
+    }
+    
+    public void testLFLF() {
+        assertTrue(f1.hasLFLF());
+        assertTrue(f2.hasLFLF());
+        assertTrue(f3.hasLFLF());
+
+        assertFalse(f4.hasLFLF());
+        assertFalse(l1.hasLFLF());
+        assertFalse(l2.hasLFLF());
+        assertFalse(l3.hasLFLF());
+
+        assertFalse(l10.hasLFLF());
+        assertFalse(l11.hasLFLF());
+        assertFalse(l12.hasLFLF());
+    }
+        
+    public void testReadLine() {
+        assertEquals(-1, l1.readLine(res));
+        assertEquals("", res.toString());
+        assertEquals("", l1.toString());        
+        
+        assertEquals(-1, l1a.readLine(res));
+        assertEquals("", res.toString());
+        assertEquals("a", l1a.toString());        
+        
+        assertEquals(0, l2.readLine(res));
+        assertEquals("", l2.toString());        
+        assertEquals("", res.toString());
+        assertEquals(0, l3.readLine(res));
+        assertEquals("", l3.toString());        
+        assertEquals("", res.toString());
+        assertEquals(0, l4.readLine(res));
+        assertEquals("", res.toString());
+
+        assertEquals(0, l5.readLine(res));
+        assertEquals("", res.toString());
+        assertEquals("a", l5.toString());
+        assertEquals(0, l5_b.readLine(res));
+        assertEquals("", res.toString());
+        assertEquals("a", l5_b.toString());
+        assertEquals(0, l5_a.readLine(res));
+        assertEquals("", res.toString());
+        assertEquals("a", l5_a.toString());
+        
+        assertEquals(1, l6.readLine(res));
+        assertEquals("a", res.toString());
+
+        assertEquals(4, l7.readLine(res));
+        assertEquals("GET ", res.toString());
+        assertEquals(5, l8.readLine(res));
+        assertEquals("GET /", res.toString());
+
+    }
+}

Propchange: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/BBufferTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/CBufferTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/CBufferTest.java?rev=884421&view=auto
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/CBufferTest.java (added)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/CBufferTest.java Thu Nov 26 06:55:49 2009
@@ -0,0 +1,32 @@
+/*
+ */
+package org.apache.tomcat.lite.io;
+
+import junit.framework.TestCase;
+
+public class CBufferTest extends TestCase {
+
+    CBuffer ext = CBuffer.newInstance();
+    
+    public void extTest(String path, String exp) {
+        CBuffer.newInstance().append(path).getExtension(ext, '/', '.');
+        assertEquals(exp, ext.toString());
+    }
+    
+    public void testExt() {
+        extTest("foo.jsp", "jsp");
+        extTest("foo.j", "j");
+        extTest("/foo.j", "j");
+        extTest("//foo.j", "j");
+        extTest(".j", "j");
+        extTest(".", "");
+        extTest("/abc", "");
+        extTest("/abc.", "");
+        extTest("/abc/", "");
+        extTest("/abc/d", "");
+    }
+    
+    public void testLastIndexOf() {
+        
+    }
+}

Propchange: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/CBufferTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/OneTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/OneTest.java?rev=884421&view=auto
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/OneTest.java (added)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/OneTest.java Thu Nov 26 06:55:49 2009
@@ -0,0 +1,30 @@
+/*
+ */
+package org.apache.tomcat.lite.io;
+
+import java.io.IOException;
+
+import org.apache.tomcat.lite.TestMain;
+import org.apache.tomcat.lite.http.HttpChannel;
+import org.apache.tomcat.lite.io.MemoryIOConnector;
+import org.apache.tomcat.lite.io.MemoryIOConnector.MemoryIOChannel;
+
+import junit.framework.TestCase;
+
+public class OneTest extends TestCase {
+    MemoryIOConnector.MemoryIOChannel net = new MemoryIOChannel();
+    HttpChannel http = new HttpChannel()
+        .serverMode(true).withBuffers(net);
+ 
+    public void setUp() throws Exception {
+        TestMain.getTestServer();
+    }
+    
+    public void tearDown() throws IOException {
+    }
+
+
+    public void testOne() throws Exception {
+        
+    }
+}

Propchange: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/OneTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/SocksTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/SocksTest.java?rev=884421&view=auto
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/SocksTest.java (added)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/SocksTest.java Thu Nov 26 06:55:49 2009
@@ -0,0 +1,58 @@
+/*
+ */
+package org.apache.tomcat.lite.io;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.Proxy;
+import java.net.ProxySelector;
+import java.net.SocketAddress;
+import java.net.URI;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tomcat.lite.proxy.SocksServer;
+
+
+import junit.framework.TestCase;
+
+public class SocksTest extends TestCase {
+
+    public void setUp() { 
+//        SocksServer socks = new SocksServer();
+//        try {
+//            socks.initServer();
+//        } catch (IOException e1) {
+//            // TODO Auto-generated catch block
+//            e1.printStackTrace();
+//        }
+//        
+//        ProxySelector.setDefault(new ProxySelector() {
+//
+//            @Override
+//            public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
+//            }
+//
+//            @Override
+//            public List<Proxy> select(URI uri) {
+//                
+//                List<Proxy> res = new ArrayList<Proxy>();
+//                try {
+//                    res.add(new Proxy(Proxy.Type.SOCKS, 
+//                            new InetSocketAddress(InetAddress.getLocalHost(), 1080)));
+//                } catch (UnknownHostException e) {
+//                    // TODO Auto-generated catch block
+//                    e.printStackTrace();
+//                }
+//                return res;
+//            }
+//            
+//        });
+    }
+    
+    public void testSocks() {
+        
+    }
+}

Propchange: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/SocksTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/UEncoderTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/UEncoderTest.java?rev=884421&view=auto
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/UEncoderTest.java (added)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/UEncoderTest.java Thu Nov 26 06:55:49 2009
@@ -0,0 +1,45 @@
+/*
+ */
+package org.apache.tomcat.lite.io;
+
+import junit.framework.TestCase;
+
+
+public class UEncoderTest extends TestCase {
+    IOWriter enc=new IOWriter(null);
+    UrlEncoding dec = new UrlEncoding();
+    CBuffer cc = CBuffer.newInstance();
+    
+    /*
+     * 
+     * Test method for 'org.apache.tomcat.util.buf.UEncoder.encodeURL(String)'
+     * TODO: find the relevant rfc and apache tests and add more 
+     */
+    public void testEncodeURL() {
+
+        String eurl1=encodeURL("test");
+        assertEquals("test", eurl1);
+        
+        eurl1=encodeURL("/test");
+        assertEquals("/test", eurl1);
+
+        // safe ranges
+        eurl1=encodeURL("test$-_.");
+        assertEquals("test$-_.", eurl1);
+
+        eurl1=encodeURL("test$-_.!*'(),");
+        assertEquals("test$-_.!*'(),", eurl1);
+
+        eurl1=encodeURL("//test");
+        assertEquals("//test", eurl1);
+    }
+    
+    public String encodeURL(String uri) {
+        cc.recycle();
+        dec.urlEncode(uri, cc, enc);
+        return cc.toString();
+    }
+    
+    
+
+}

Propchange: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/UEncoderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/test.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/test.properties?rev=884421&view=auto
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/test.properties (added)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/test.properties Thu Nov 26 06:55:49 2009
@@ -0,0 +1,33 @@
+RUN=Log,JMXProxy,Socks
+
+Log.(class)=org.apache.tomcat.integration.simple.LogConfig
+Log.debug=org.apache.tomcat.async.AsyncHttpConnector
+Log.debug=Proxy
+
+JMXProxy.(class)=org.apache.tomcat.integration.simple.JMXProxy
+JMXProxy.port=8003
+
+Socks.(class)=org.apache.tomcat.async.callbacks.SocksServer
+Socks.port=2080
+Socks.idleTimeout=0
+
+HttpConnector-TestServer.debug=true
+#HttpConnector-TestServer.debugHttp=true
+HttpConnector-TestServer.clientKeepAlive=true
+HttpConnector-TestServer.serverKeepAlive=true
+HttpConnector-TestServer.maxHttpPoolSize=10
+
+HttpConnector.debug=true
+#HttpConnector.debugHttp=true
+HttpConnector.clientKeepAlive=true
+HttpConnector.serverKeepAlive=true
+HttpConnector.maxHttpPoolSize=10
+
+HttpConnector-Proxy.debug=true
+#HttpConnector-Proxy.debugHttp=true
+HttpConnector-Proxy.clientKeepAlive=true
+HttpConnector-Proxy.serverKeepAlive=true
+HttpConnector-Proxy.maxHttpPoolSize=10
+
+
+#IOConnector.debug=true

Propchange: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/io/test.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/LiveHttp5Test.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/LiveHttp5Test.java?rev=884421&view=auto
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/LiveHttp5Test.java (added)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/LiveHttp5Test.java Thu Nov 26 06:55:49 2009
@@ -0,0 +1,38 @@
+/*
+ */
+package org.apache.tomcat.lite.load;
+
+import org.apache.tomcat.lite.http.LiveHttp1Test;
+
+import junit.framework.TestSuite;
+
+public class LiveHttp5Test extends LiveHttp1Test {
+
+    /**
+     * Want to run the same tests few times.
+     */
+    public static TestSuite suite() {
+        TestSuite s = new TestSuite();
+        for (int i = 0; i < 5; i++) {
+            s.addTestSuite(LiveHttp1Test.class);
+        }
+        return s;
+    }
+    
+    public void test100() throws Exception {
+        for (int i = 0; i < 100; i++) {
+            testSimpleRequest();
+            tearDown(); 
+            setUp();
+            
+            notFound();
+            tearDown(); 
+            setUp();
+
+            testSimpleRequest();
+            tearDown(); 
+            setUp();
+        }
+    }
+
+}

Propchange: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/LiveHttp5Test.java
------------------------------------------------------------------------------
    svn:eol-style = native



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