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 2008/06/14 17:55:44 UTC

svn commit: r667822 - in /tomcat/sandbox/tomcat-lite/test/org/apache/tomcat: lite/TomcatLiteNoConnectorTest.java lite/TomcatLiteTest.java proxy/ proxy/ProxyTest.java util/http/ util/http/Http11ParserTest.java

Author: costin
Date: Sat Jun 14 08:55:44 2008
New Revision: 667822

URL: http://svn.apache.org/viewvc?rev=667822&view=rev
Log:
More tests.

Added:
    tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/proxy/
    tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/proxy/ProxyTest.java   (with props)
    tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/util/http/
    tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/util/http/Http11ParserTest.java   (with props)
Modified:
    tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/lite/TomcatLiteNoConnectorTest.java
    tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/lite/TomcatLiteTest.java

Modified: tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/lite/TomcatLiteNoConnectorTest.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/lite/TomcatLiteNoConnectorTest.java?rev=667822&r1=667821&r2=667822&view=diff
==============================================================================
--- tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/lite/TomcatLiteNoConnectorTest.java (original)
+++ tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/lite/TomcatLiteNoConnectorTest.java Sat Jun 14 08:55:44 2008
@@ -1,4 +1,18 @@
 /*
+ * 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;
 
@@ -17,7 +31,7 @@
 
 public class TomcatLiteNoConnectorTest extends TestCase {
 
-  TomcatLite lite = TomcatLite.getServletImpl();
+  TomcatLite lite = new TomcatLite();
   ConfigurableServletContext ctx; 
     
   

Modified: tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/lite/TomcatLiteTest.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/lite/TomcatLiteTest.java?rev=667822&r1=667821&r2=667822&view=diff
==============================================================================
--- tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/lite/TomcatLiteTest.java (original)
+++ tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/lite/TomcatLiteTest.java Sat Jun 14 08:55:44 2008
@@ -1,66 +1,70 @@
 /*
+ * 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;
 
-import java.io.BufferedInputStream;
 import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.net.URLConnection;
-
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+
+import javax.servlet.ServletException;
 
 import junit.framework.TestCase;
 
 import org.apache.tomcat.servlets.addon.ConfigurableServletContext;
+import org.apache.tomcat.test.CoyoteTestHelper;
+import org.apache.tomcat.util.buf.ByteChunk;
 
 public class TomcatLiteTest extends TestCase {
 
-  TomcatLite lite = TomcatLite.getServletImpl(); 
+  TomcatLite lite = new TomcatLite(); 
   
   void initServer() throws Exception {
-    ConfigurableServletContext ctx = 
-      (ConfigurableServletContext) lite.addServletContext(null, null, "/test1");
-    
-    ctx.addServlet("test", new SimpleServlet());
-    ctx.addMapping("/1stTest", "test");
-
-    // Ex: change the default 
+    TomcatLiteTest.initServlets(lite);
     lite.setPort(8804);
-    
-    lite.init();
-    lite.start(); 
-
     // At this point we can add contexts and inject requests, if we want to 
     // do it over HTTP need to start the connector as well.
     lite.startConnector(); 
   }
   
-  public void stopServer() {
-    lite.stop();
-  }
-  
   public void setUp() throws Exception {
     initServer();
   }
   
   public void tearDown() throws Exception {
-    stopServer();
+    lite.stop();
   }
   
   public void testSimpleRequest() throws Exception {
-    URL url = new URL("http://localhost:8804/test1/1stTest");
-    URLConnection connection = url.openConnection();
-    connection.connect();
-    InputStream is = connection.getInputStream();
-    BufferedInputStream bis = new BufferedInputStream(is);
-    byte[] buf = new byte[10240];
-    int rd = bis.read(buf);
-    assertTrue(rd > 0);
-    String res = new String(buf, 0, rd);
-    assertEquals("Hello world", res);
+    ByteChunk resb = 
+        CoyoteTestHelper.getUrl("http://localhost:8804/test1/1stTest");
+    assertTrue(resb.length() > 0);
+    assertEquals("Hello world", resb.toString());
+  }
+
+
+public static void initServlets(TomcatLite lite) throws ServletException, IOException {
+      ConfigurableServletContext ctx = 
+        (ConfigurableServletContext) lite.addServletContext(null, null, "/test1");
+      
+      ctx.addServlet("test", new SimpleServlet());
+      ctx.addMapping("/1stTest", "test");
+      
+      lite.init();
+      lite.start(); 
+
+      
   }
   
 }

Added: tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/proxy/ProxyTest.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/proxy/ProxyTest.java?rev=667822&view=auto
==============================================================================
--- tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/proxy/ProxyTest.java (added)
+++ tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/proxy/ProxyTest.java Sat Jun 14 08:55:44 2008
@@ -0,0 +1,87 @@
+/*
+ * 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.proxy;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+
+import junit.framework.TestCase;
+
+import org.apache.coyote.adapters.CoyoteServer;
+import org.apache.tomcat.test.CoyoteTestHelper;
+
+public class ProxyTest extends TestCase {
+
+  CoyoteServer staticMain;
+  CoyoteServer proxyMain;
+
+  String resStr;
+    
+  public void setUp() throws ServletException, IOException {
+      staticMain = CoyoteTestHelper.getTestServer(8902);
+      proxyMain = CoyoteTestHelper.getProxyServer(8901);
+  }
+  
+  public void tearDown() throws IOException {
+  }
+  
+  public void xtestRequestSlowChunked() throws Exception {
+      resStr = 
+          CoyoteTestHelper.getUrl("http://localhost:8901/sleep/1c").toString();
+      assertEquals("sleep 1csleep 1c", resStr);
+  }
+  
+  public void testRequestSimple() throws Exception {
+      System.err.println("PROXY 1");
+      resStr = 
+          CoyoteTestHelper.getUrl("http://localhost:8901/hello").toString();
+      System.err.println("PROXY 2");
+      resStr = 
+          CoyoteTestHelper.getUrl("http://localhost:8901/hello").toString();
+      System.err.println("PROXY 3");
+      resStr = 
+          CoyoteTestHelper.getUrl("http://localhost:8901/hello").toString();
+      assertEquals(resStr, "Hello world");
+
+  }
+  
+  public void testRequestSlow() throws Exception {
+      // Slow
+      resStr = 
+          CoyoteTestHelper.getUrl("http://localhost:8901/sleep/1").toString();
+      assertEquals("sleep 1sleep 1", resStr.toString());
+  }
+  
+  public void testRequestParams() throws Exception {
+      // qry string
+      resStr = 
+          CoyoteTestHelper.getUrl("http://localhost:8901/echo/foo?q=a&b")
+          .toString();
+      assertTrue(resStr, resStr.indexOf("foo?q=a&b") > 0);
+  }
+  
+  public void testRequestChunked() throws Exception {
+      // Chunked encoding
+      resStr = 
+          CoyoteTestHelper.getUrl("http://localhost:8901/chunked/test")
+          .toString();
+      assertEquals(8192, resStr.length());
+      assertTrue(resStr.indexOf("AAA") >= 0);
+  }
+
+}

Propchange: tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/proxy/ProxyTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/util/http/Http11ParserTest.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/util/http/Http11ParserTest.java?rev=667822&view=auto
==============================================================================
--- tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/util/http/Http11ParserTest.java (added)
+++ tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/util/http/Http11ParserTest.java Sat Jun 14 08:55:44 2008
@@ -0,0 +1,74 @@
+/*
+ * 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.util.http;
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.apache.coyote.Request;
+
+public class Http11ParserTest extends TestCase {
+
+    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" + 
+      "GET /r2? HTTP/1.1\n" +
+      "Host: Foo.com\n\n" +
+      "H2:        Bar     \r\n" + 
+      "H3: Foo \r\n" +
+      "       Bar\r\n" +
+      "H4: Foo\n" +
+      " Bar\n" +
+      "\r\n";
+
+    byte[] reqB = req.getBytes();
+     
+    public void testNextRequest() {
+    }
+
+    public void testParseRequestLine() throws IOException {
+        Http11Parser buf = new Http11Parser();
+        
+        //int remain = buf.getFreeSpace(reqB.length);
+        //System.arraycopy(reqB, 0, buf.buf, buf.pos, remain); 
+        
+        //boolean done = buf.parseRequestLine();
+        
+    }
+
+    public void testChunking() {
+        // Add it in small pieces ( of 1, 2, 4, then incr ).
+    }
+
+    // TODO: separate class
+    public void testSpeed() {
+        
+    }
+    
+    private void checkReq(Http11Parser p, Request buf) {
+        assertTrue(buf.method().equals("GET"));
+        assertTrue(buf.protocol().equals("HTTP/1.1"));
+        assertTrue(buf.getMimeHeaders().size() == 4);
+        assertTrue(buf.getMimeHeaders().getHeader("Host").equals("Foo.com"));
+    }
+}

Propchange: tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/util/http/Http11ParserTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



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