Author: costin
Date: Tue Mar 25 21:10:10 2008
New Revision: 641135
URL: http://svn.apache.org/viewvc?rev=641135&view=rev
Log:
2 simple tests/examples of starting/embedding tomcat-lite
Added:
tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/lite/
tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/lite/TomcatLiteNoConnectorTest.java
(with props)
tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/lite/TomcatLiteTest.java
(with props)
Added:
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=641135&view=auto
==============================================================================
---
tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/lite/TomcatLiteNoConnectorTest.java
(added)
+++
tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/lite/TomcatLiteNoConnectorTest.java
Tue Mar 25 21:10:10 2008
@@ -0,0 +1,68 @@
+/*
+ */
+package org.apache.tomcat.lite;
+
+
+
+import junit.framework.TestCase;
+
+import org.apache.tomcat.servlets.addon.ConfigurableServletContext;
+import org.apache.tomcat.util.buf.ByteChunk;
+
+public class TomcatLiteNoConnectorTest extends TestCase {
+
+ TomcatLite lite = TomcatLite.getServletImpl();
+
+ void initServer() throws Exception {
+ ConfigurableServletContext ctx =
+ (ConfigurableServletContext) lite.addServletContext(null, null,
"/test1");
+
+ ctx.addServlet("test", new SimpleServlet());
+ ctx.addMapping("/1stTest", "test");
+
+ lite.init();
+ lite.start();
+ }
+
+ public void stopServer() {
+ lite.stop();
+ }
+
+ public void setUp() throws Exception {
+ initServer();
+ }
+
+ public void tearDown() throws Exception {
+ stopServer();
+ }
+
+ public void testSimpleRequest() throws Exception {
+ ByteChunk out = new ByteChunk();
+ ServletRequestImpl req =
+ lite.createMessage("/test1/1stTest", out);
+
+ // more changes can be made to the req.
+
+ ServletResponseImpl res = lite.service(req);
+
+ assertEquals("Hello world", out.toString());
+ // Headers are still in the response
+ assertEquals(res.getHeader("Foo"), "Bar");
+ assertEquals(res.getStatus(), 200);
+ }
+
+ public void testPostRequest() throws Exception {
+ ByteChunk out = new ByteChunk();
+ ServletRequestImpl req =
+ lite.createMessage("/test1/1stTest", out);
+ req.setMethod("POST");
+
+ ServletResponseImpl res = lite.service(req);
+
+ assertEquals("Hello post world", out.toString());
+ // Headers are still in the response
+ assertEquals(res.getHeader("Foo"), "Post");
+ assertEquals(res.getStatus(), 200);
+ }
+
+}
Propchange:
tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/lite/TomcatLiteNoConnectorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
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=641135&view=auto
==============================================================================
--- tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/lite/TomcatLiteTest.java
(added)
+++ tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/lite/TomcatLiteTest.java
Tue Mar 25 21:10:10 2008
@@ -0,0 +1,66 @@
+/*
+ */
+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 junit.framework.TestCase;
+
+import org.apache.tomcat.servlets.addon.ConfigurableServletContext;
+
+public class TomcatLiteTest extends TestCase {
+
+ TomcatLite lite = TomcatLite.getServletImpl();
+
+ 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
+ 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();
+ }
+
+ 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);
+ }
+
+}
Propchange:
tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/lite/TomcatLiteTest.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]