Return-Path: Delivered-To: apmail-tomcat-dev-archive@www.apache.org Received: (qmail 16214 invoked from network); 14 Jun 2008 15:56:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 14 Jun 2008 15:56:48 -0000 Received: (qmail 89790 invoked by uid 500); 14 Jun 2008 15:56:46 -0000 Delivered-To: apmail-tomcat-dev-archive@tomcat.apache.org Received: (qmail 89755 invoked by uid 500); 14 Jun 2008 15:56:46 -0000 Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Developers List" Delivered-To: mailing list dev@tomcat.apache.org Received: (qmail 89744 invoked by uid 500); 14 Jun 2008 15:56:46 -0000 Delivered-To: apmail-jakarta-tomcat-dev@jakarta.apache.org Received: (qmail 89741 invoked by uid 99); 14 Jun 2008 15:56:46 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 14 Jun 2008 08:56:46 -0700 X-ASF-Spam-Status: No, hits=-1998.5 required=10.0 tests=ALL_TRUSTED,WEIRD_PORT X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 14 Jun 2008 15:55:56 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id C521D2388A03; Sat, 14 Jun 2008 08:55:44 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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 Date: Sat, 14 Jun 2008 15:55:44 -0000 To: tomcat-dev@jakarta.apache.org From: costin@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080614155544.C521D2388A03@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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