Added:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/LiveHttpThreadedTest.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/LiveHttpThreadedTest.java?rev=884421&view=auto
==============================================================================
---
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/LiveHttpThreadedTest.java
(added)
+++
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/LiveHttpThreadedTest.java
Thu Nov 26 06:55:49 2009
@@ -0,0 +1,116 @@
+/*
+ * 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.load;
+
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.apache.tomcat.lite.TestMain;
+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.http.HttpChannel.HttpService;
+import org.apache.tomcat.lite.http.HttpChannel.RequestCompleted;
+
+public class LiveHttpThreadedTest extends TestCase {
+ HttpConnector staticMain = TestMain.getTestServer();
+
+
+ int tCount = 1;
+ Thread[] threads = new Thread[tCount];
+ int[] ok = new int[tCount];
+ private int rCount = 100;
+
+ public void xtestSimpleRequest() throws Exception {
+ long t0 = System.currentTimeMillis();
+ for (int i = 0; i < tCount; i++) {
+ final int j = i;
+ threads[i] = new Thread(new Runnable() {
+ public void run() {
+ makeRequests(j, true);
+ }
+ });
+ threads[i].start();
+ }
+
+ int res = 0;
+ for (int i = 0; i < tCount; i++) {
+ threads[i].join();
+ res += ok[i];
+ }
+ long t1 = System.currentTimeMillis();
+ System.err.println("Time: " + (t1 - t0) + " " + res);
+ }
+
+ public void testSimpleRequestNB() throws Exception {
+ long t0 = System.currentTimeMillis();
+ for (int i = 0; i < tCount; i++) {
+ final int j = i;
+ threads[i] = new Thread(new Runnable() {
+ public void run() {
+ makeRequests(j, false);
+ }
+ });
+ threads[i].start();
+ }
+
+ int res = 0;
+ for (int i = 0; i < tCount; i++) {
+ threads[i].join();
+ res += ok[i];
+ }
+ long t1 = System.currentTimeMillis();
+ System.err.println("TimeNB: " + (t1 - t0) + " " + res);
+ }
+
+ void makeRequests(int t, boolean b) {
+ for (int i = 0; i < rCount ; i++) {
+ try {
+ //System.err.println("MakeReq " + t + " " + i);
+ makeRequest(t, b);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ static RequestCompleted reqCallback = new RequestCompleted() {
+ @Override
+ public void handle(HttpChannel data, Object extraData)
+ throws IOException {
+ //dumpHead(cstate);
+ //System.err.println("DATA\n" + cstate.output.toString() + "\n----");
+ //assertTrue(cstate.bodyRecvBuffer.toString().indexOf("AAA") >= 0);
+
+ data.release();
+ }
+
+ };
+
+ void makeRequest(int i, boolean block) throws Exception {
+ HttpChannel cstate = DefaultHttpConnector.get().get("localhost", 8802);
+
+ cstate.getRequest().requestURI().set("/hello");
+ cstate.setCompletedCallback(reqCallback);
+
+ // Send the request, wait response
+ cstate.sendRequest();
+ }
+
+}
Propchange:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/LiveHttpThreadedTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/MicroTest.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/MicroTest.java?rev=884421&view=auto
==============================================================================
---
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/MicroTest.java
(added)
+++
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/MicroTest.java
Thu Nov 26 06:55:49 2009
@@ -0,0 +1,49 @@
+/*
+ */
+package org.apache.tomcat.lite.load;
+
+import org.apache.tomcat.lite.http.BaseMapper;
+import org.apache.tomcat.lite.http.MappingData;
+import org.apache.tomcat.lite.io.CBuffer;
+
+import junit.framework.TestCase;
+
+public class MicroTest extends TestCase {
+
+ public void testMapper() throws Exception {
+ BaseMapper mapper = new BaseMapper();
+
+ MappingData mappingData = new MappingData();
+ CBuffer host = CBuffer.newInstance();
+ host.set("test1.com");
+
+ CBuffer uri = CBuffer.newInstance();
+ uri.set("/foo/bar/blah/bobou/foo");
+
+ String[] welcomes = new String[2];
+ welcomes[0] = "index.html";
+ welcomes[1] = "foo.html";
+
+ for (int i = 0; i < 100; i++) {
+ String hostN = "test" + i + ".com";
+ mapper.addContext(hostN, "", "context0", new String[0], null,
null);
+ mapper.addContext(hostN, "/foo", "context1", new String[0], null,
null);
+ mapper.addContext(hostN, "/foo/bar", "context2", welcomes, null,
null);
+ mapper.addContext(hostN, "/foo/bar/bla", "context3", new
String[0], null, null);
+
+ mapper.addWrapper(hostN, "/foo/bar", "/fo/*", "wrapper0");
+ }
+ int N = 10000;
+ for (int i = 0; i < N; i++) {
+ mappingData.recycle();
+ mapper.map(host, uri, mappingData);
+ }
+
+ long time = System.currentTimeMillis();
+ for (int i = 0; i < N; i++) {
+ mappingData.recycle();
+ mapper.map(host, uri, mappingData);
+ }
+ System.out.println("Elapsed:" + (System.currentTimeMillis() - time));
+ }
+}
Propchange:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/MicroTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/proxy/LiveProxyHttp1Test.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/proxy/LiveProxyHttp1Test.java?rev=884421&view=auto
==============================================================================
---
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/proxy/LiveProxyHttp1Test.java
(added)
+++
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/proxy/LiveProxyHttp1Test.java
Thu Nov 26 06:55:49 2009
@@ -0,0 +1,33 @@
+/*
+ * 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.proxy;
+
+
+import java.io.IOException;
+
+import org.apache.tomcat.lite.http.LiveHttp1Test;
+
+
+public class LiveProxyHttp1Test extends LiveHttp1Test {
+ public void setUp() throws IOException {
+ // All tests in super, but with client pointing to
+ // the proxy server, which in turn hits the real server.
+ clientPort = 8903;
+ super.setUp();
+ }
+
+}
Propchange:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/proxy/LiveProxyHttp1Test.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/proxy/ProxyTest.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/proxy/ProxyTest.java?rev=884421&view=auto
==============================================================================
---
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/proxy/ProxyTest.java
(added)
+++
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/proxy/ProxyTest.java
Thu Nov 26 06:55:49 2009
@@ -0,0 +1,120 @@
+/*
+n * 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.proxy;
+
+import java.io.IOException;
+
+import org.apache.tomcat.lite.TestMain;
+
+import junit.framework.TestCase;
+
+
+public class ProxyTest extends TestCase {
+
+ String resStr;
+
+ public void setUp() throws Exception {
+ TestMain.getTestServer();
+ }
+
+ public void tearDown() throws IOException {
+ }
+
+ public void xtestRequestSlowChunked() throws Exception {
+ resStr =
+ TestMain.get("http://localhost:8903/sleep/1c").toString();
+ assertEquals("sleep 1csleep 1c", resStr);
+ }
+
+ public void testSingleRequest() throws Exception {
+ String resStr =
+ TestMain.get("http://localhost:8903/hello").toString();
+ assertEquals("Hello world", resStr);
+ }
+
+
+ public void test2Requests() throws Exception {
+ String resStr =
+ TestMain.get("http://localhost:8903/hello").toString();
+ assertEquals("Hello world", resStr);
+ resStr =
+ TestMain.get("http://localhost:8903/hello?a=b").toString();
+ assertEquals("Hello world", resStr);
+ }
+
+ public void testRequestSimple() throws Exception {
+ resStr =
+ TestMain.get("http://localhost:8903/hello").toString();
+ assertEquals("Hello world", resStr);
+ resStr =
+ TestMain.get("http://localhost:8903/hello").toString();
+ assertEquals("Hello world", resStr);
+ resStr =
+ TestMain.get("http://localhost:8903/hello").toString();
+ assertEquals(resStr, "Hello world");
+
+ }
+
+ public void testExtAdapter() throws Exception {
+ String res =
+ TestMain.get("http://www.apache.org/").toString();
+ assertTrue(res.indexOf("Apache") > 0);
+
+ Thread.currentThread().sleep(100);
+ // second time - are we reusing ?
+ res =
+ TestMain.get("http://www.apache.org/").toString();
+
+ assertTrue(res.indexOf("Apache") > 0);
+
+ }
+
+ public void testStaticAdapter() throws Exception {
+
+ assertEquals("Hello world",
+ TestMain.get("http://localhost:8802/hello").toString());
+ assertEquals("Hello world2",
+ TestMain.get("http://localhost:8802/2nd").toString());
+
+ }
+
+ public void testRequestParams() throws Exception {
+ // qry string
+ String resStr =
+ TestMain.get("http://localhost:8903/echo/foo?q=a&b")
+ .toString();
+ assertTrue(resStr, resStr.indexOf("foo?q=a&b") > 0);
+ }
+
+
+ public void testRequestChunked() throws Exception {
+ // Chunked encoding
+ String resStr =
+ TestMain.get("http://localhost:8903/chunked/test")
+ .toString();
+ assertEquals(8, resStr.length());
+ assertTrue(resStr.indexOf("AAA") >= 0);
+ }
+
+
+ public void testRequestSlow() throws Exception {
+ // Slow
+ String resStr =
+ TestMain.get("http://localhost:8903/sleep/1").toString();
+ assertEquals("sleep 1sleep 1", resStr.toString());
+ }
+}
Propchange:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/proxy/ProxyTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/proxy/SmallProxyTest.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/proxy/SmallProxyTest.java?rev=884421&view=auto
==============================================================================
---
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/proxy/SmallProxyTest.java
(added)
+++
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/proxy/SmallProxyTest.java
Thu Nov 26 06:55:49 2009
@@ -0,0 +1,106 @@
+/*
+ */
+package org.apache.tomcat.lite.proxy;
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.apache.tomcat.lite.http.HttpChannel;
+import org.apache.tomcat.lite.http.HttpConnector;
+import org.apache.tomcat.lite.io.MemoryIOConnector;
+import org.apache.tomcat.lite.io.MemoryIOConnector.MemoryIOChannel;
+
+public class SmallProxyTest extends TestCase {
+
+ MemoryIOConnector memoryServerConnector =
+ new MemoryIOConnector();
+
+ MemoryIOConnector memoryClientConnector =
+ new MemoryIOConnector().withServer(memoryServerConnector);
+
+
+ HttpConnector httpPool = 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) {
+ @Override
+ public HttpChannel get(CharSequence target) throws IOException {
+ lastClient = new HttpChannel();
+ lastClient.setConnector(this);
+ return lastClient;
+ }
+ public HttpChannel get(String host, int port) throws IOException {
+ lastClient = new HttpChannel();
+ lastClient.setConnector(this);
+ return lastClient;
+ }
+ public HttpChannel getServer() {
+ throw new RuntimeException();
+ }
+ };
+
+ HttpChannel lastServer;
+ HttpChannel lastClient;
+
+ boolean hasBody = false;
+ boolean bodyDone = false;
+ boolean bodySentDone = false;
+ boolean headersDone = false;
+ boolean allDone = false;
+
+
+ //MemoryIOChannel clientNet = new MemoryIOChannel();
+
+ MemoryIOConnector.MemoryIOChannel net = new MemoryIOChannel();
+ HttpChannel http;
+
+ public void setUp() throws IOException {
+ http = httpPool.getServer();
+ }
+
+ /**
+ * More complicated test..
+ * @throws IOException
+ */
+ public void testProxy() throws IOException {
+ http.setHttpService(new HttpProxyService()
+ .withSelector(memoryClientConnector)
+ .withHttpClient(httpClient));
+
+ http.getNet().getIn().append("GET http://www.cyberluca.com/
HTTP/1.0\n" +
+ "Connection: Close\n\n");
+ http.getNet().getIn().close();
+
+ // lastClient.rawSendBuffers has the request sent by proxy
+ lastClient.getNet().getIn()
+ .append("HTTP/1.0 200 OK\n\nHi\n");
+ lastClient.getNet().getIn()
+ .append("world\n");
+
+ // TODO: check what the proxy sent
+ // lastClient.getOut();
+
+ // will also trigger 'release' - both sides are closed.
+ lastClient.getNet().getIn().close();
+
+ // wait response...
+ // http.sendBody.close();
+ String res = net.out.toString();
+ assertTrue(res.indexOf("Hi\nworld\n") > 0);
+ assertTrue(res.indexOf("HTTP/1.0 200 OK") == 0);
+ assertTrue(res.indexOf("tomcatproxy") > 0);
+
+ }
+}
Propchange:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/proxy/SmallProxyTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/AnnotationTest.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/AnnotationTest.java?rev=884421&view=auto
==============================================================================
---
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/AnnotationTest.java
(added)
+++
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/AnnotationTest.java
Thu Nov 26 06:55:49 2009
@@ -0,0 +1,54 @@
+/*
+ */
+package org.apache.tomcat.lite.servlet;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.apache.tomcat.servlets.config.ServletContextConfig;
+import org.apache.tomcat.servlets.config.deploy.AnnotationsProcessor;
+
+public class AnnotationTest extends TestCase {
+
+ // TODO: fix the build file to find the target dir
+ // you can run this manually until this happens
+ String eclipseBase = "test-webapp/WEB-INF/classes";
+
+ public void testScanClasses() throws IOException {
+ ServletContextConfig cfg = new ServletContextConfig();
+ AnnotationsProcessor scanner = new AnnotationsProcessor(cfg);
+// scanner.processDir(eclipseBase);
+//
+// dump(cfg);
+
+ }
+
+ public void testScanClass() throws IOException {
+ ServletContextConfig cfg = new ServletContextConfig();
+ AnnotationsProcessor scanner = new AnnotationsProcessor(cfg);
+
+ String path = eclipseBase +
"/org/apache/tomcat/lite/Annotated2Servlet.class";
+// scanner.processClass(new FileInputStream(path), eclipseBase, path);
+//
+// dump(cfg);
+
+ }
+
+ private void dump(ServletContextConfig cfg) {
+// ObjectMapper jackson = new ObjectMapper();
+// try {
+// jackson.configure(SerializationConfig.Feature.INDENT_OUTPUT,
true);
+//
jackson.configure(SerializationConfig.Feature.WRITE_NULL_PROPERTIES,
+// false);
+//
+// ByteArrayOutputStream out = new ByteArrayOutputStream();
+// jackson.writeValue(out, cfg);
+// System.err.println(out.toString());
+// } catch (Throwable t) {
+// t.printStackTrace();
+// }
+ }
+
+}
Propchange:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/AnnotationTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/JspWatchdogTests.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/JspWatchdogTests.java?rev=884421&view=auto
==============================================================================
---
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/JspWatchdogTests.java
(added)
+++
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/JspWatchdogTests.java
Thu Nov 26 06:55:49 2009
@@ -0,0 +1,57 @@
+/*
+ * 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.servlet;
+
+
+import org.apache.tomcat.lite.servlet.TomcatLite;
+
+import junit.framework.Test;
+
+public class JspWatchdogTests extends TomcatLiteWatchdog {
+
+ public JspWatchdogTests() {
+ super();
+ testMatch =
+ //"precompileNegativeTest";
+ null;
+ // Test we know are failing - need to fix at some point.
+ exclude = new String[] {
+ "negativeDuplicateExtendsFatalTranslationErrorTest",
+ "negativeDuplicateErrorPageFatalTranslationErrorTest",
+ "negativeDuplicateInfoFatalTranslationErrorTest",
+ "negativeDuplicateLanguageFatalTranslationErrorTest",
+ "negativeDuplicateSessionFatalTranslationErrorTest",
+ "positiveIncludeCtxRelativeHtmlTest",
+ "precompileNegativeTest"
+ };
+ file = getWatchdogdir() + "/src/conf/jsp-gtest.xml";
+ goldenDir =
+ getWatchdogdir() + "/src/clients/org/apache/jcheck/jsp/client/";
+ targetMatch = "jsp-test";
+
+ }
+
+ protected void addConnector(TomcatLite lite) {
+ lite.setPort(8019);
+ }
+
+ public static Test suite() {
+ return new JspWatchdogTests().getSuite(8019);
+ }
+
+}
+
Propchange:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/JspWatchdogTests.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/LiteTestHelper.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/LiteTestHelper.java?rev=884421&view=auto
==============================================================================
---
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/LiteTestHelper.java
(added)
+++
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/LiteTestHelper.java
Thu Nov 26 06:55:49 2009
@@ -0,0 +1,117 @@
+/*
+ */
+package org.apache.tomcat.lite.servlet;
+
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.tomcat.lite.io.BBuffer;
+import org.apache.tomcat.lite.servlet.ServletContextImpl;
+import org.apache.tomcat.lite.servlet.TomcatLite;
+
+public class LiteTestHelper {
+ static TomcatLite lite;
+
+ public static ServletContextImpl addContext(TomcatLite lite) throws
ServletException {
+ ServletContextImpl ctx =
+ (ServletContextImpl) lite.addServletContext(null, null, "/test1");
+
+
+ ctx.add("testException", new HttpServlet() {
+ public void doGet(HttpServletRequest req, HttpServletResponse
res)
+ throws IOException {
+ throw new NullPointerException();
+ }
+ });
+ ctx.addMapping("/testException", "testException");
+
+
+ ctx.add("test", new HttpServlet() {
+ public void doGet(HttpServletRequest req, HttpServletResponse
res) throws IOException {
+ res.addHeader("Foo", "Bar");
+ res.getWriter().write("Hello world");
+ }
+ });
+
+ ctx.addMapping("/1stTest", "test");
+
+
+ return ctx;
+ }
+
+ public static void startLite() throws IOException, ServletException {
+ if (lite == null) {
+ lite = new TomcatLite();
+
+ LiteTestHelper.addContext(lite);
+ lite.start();
+
+ lite.startConnector();
+ }
+ }
+
+ public static void initServletsAndRun(TomcatLite lite, int port) throws
ServletException, IOException {
+ addContext(lite);
+ lite.init();
+ lite.start();
+
+
+ if (port > 0) {
+ // This should be added after all local initialization to avoid
+ // the server from responding.
+ // Alternatively, you can load this early but set it to return
+ // 'unavailable' if load balancers depend on this.
+ addConnector(lite, port, true);
+
+ // 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 static void addConnector(TomcatLite lite,
+ int port, boolean daemon) {
+ lite.setPort(port);
+ }
+
+ /**
+ * Get url using URLConnection.
+ */
+ public static BBuffer getUrl(String path) throws IOException {
+
+ BBuffer out = BBuffer.allocate(4096);
+
+ URL url = new URL(path);
+ URLConnection connection = url.openConnection();
+ connection.setReadTimeout(5000);
+ connection.connect();
+ InputStream is = connection.getInputStream();
+ out.readAll(is);
+ return out;
+ }
+
+// static class ByteChunkOutputBuffer implements OutputBuffer {
+//
+// protected ByteChunk output = null;
+//
+// public ByteChunkOutputBuffer(ByteChunk output) {
+// this.output = output;
+// }
+//
+// public int doWrite(ByteChunk chunk, Response response)
+// throws IOException {
+// output.append(chunk);
+// return chunk.getLength();
+// }
+// }
+
+
+}
Propchange:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/LiteTestHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/PropertiesSpiTest.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/PropertiesSpiTest.java?rev=884421&view=auto
==============================================================================
---
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/PropertiesSpiTest.java
(added)
+++
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/PropertiesSpiTest.java
Thu Nov 26 06:55:49 2009
@@ -0,0 +1,54 @@
+/*
+ */
+package org.apache.tomcat.lite.servlet;
+
+import java.io.IOException;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.apache.tomcat.integration.simple.SimpleObjectManager;
+
+
+public class PropertiesSpiTest extends TestCase {
+
+ SimpleObjectManager spi;
+
+ public void setUp() {
+ spi = new SimpleObjectManager();
+
+ spi.getProperties().put("obj1.name", "foo");
+ spi.getProperties().put("obj1.(class)", BoundObj.class.getName());
+
+ }
+
+ public void testArgs() throws IOException {
+ spi = new SimpleObjectManager(new String[] {
+ "-a=1", "-b", "2"});
+ Properties res = spi.getProperties();
+
+ assertEquals("1", res.get("a"));
+ assertEquals("2", res.get("b"));
+
+
+ }
+
+ public static class BoundObj {
+ String name;
+
+ public void setName(String n) {
+ this.name = n;
+ }
+ }
+
+ public void testBind() throws Exception {
+ BoundObj bo = new BoundObj();
+ spi.bind("obj1", bo);
+ assertEquals(bo.name, "foo");
+ }
+
+ public void testCreate() throws Exception {
+ BoundObj bo = (BoundObj) spi.get("obj1");
+ assertEquals(bo.name, "foo");
+ }
+}
Propchange:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/PropertiesSpiTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/ServletTests.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/ServletTests.java?rev=884421&view=auto
==============================================================================
---
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/ServletTests.java
(added)
+++
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/ServletTests.java
Thu Nov 26 06:55:49 2009
@@ -0,0 +1,29 @@
+/*
+ */
+package org.apache.tomcat.lite.servlet;
+
+import org.apache.tomcat.lite.servlet.TomcatLite;
+
+import junit.framework.Test;
+
+public class ServletTests extends TomcatLiteWatchdog {
+
+ public ServletTests() {
+ super();
+ exclude = new String[] {
+ "ServletToJSPErrorPageTest",
+ "ServletToJSPError502PageTest",
+ };
+ }
+
+ protected void addConnector(TomcatLite connector) {
+ connector.setPort(7074);
+ }
+
+ /**
+ * Magic JUnit method
+ */
+ public static Test suite() {
+ return new ServletTests().getSuite(7074);
+ }
+}
Propchange:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/ServletTests.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/TomcatLiteNoConnectorTest.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/TomcatLiteNoConnectorTest.java?rev=884421&view=auto
==============================================================================
---
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/TomcatLiteNoConnectorTest.java
(added)
+++
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/TomcatLiteNoConnectorTest.java
Thu Nov 26 06:55:49 2009
@@ -0,0 +1,116 @@
+/*
+ * 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.servlet;
+
+
+
+import junit.framework.TestCase;
+
+import org.apache.tomcat.lite.http.HttpChannel;
+import org.apache.tomcat.lite.http.HttpConnector;
+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.io.MemoryIOConnector;
+import org.apache.tomcat.lite.io.MemoryIOConnector.MemoryIOChannel;
+import org.apache.tomcat.lite.servlet.TomcatLite;
+
+/**
+ * Example of testing servlets without using sockets.
+ *
+ * @author Costin Manolache
+ */
+public class TomcatLiteNoConnectorTest extends TestCase {
+
+ TomcatLite lite;
+ MemoryIOConnector net;
+ HttpConnector con;
+
+ public void setUp() throws Exception {
+ net = new MemoryIOConnector();
+ con = new HttpConnector(net);
+
+ lite = new TomcatLite();
+ lite.setHttpConnector(con);
+
+ // Load all servlets we need to test
+ LiteTestHelper.initServletsAndRun(lite, 0);
+ }
+
+ public void tearDown() throws Exception {
+ lite.stop();
+ }
+
+
+ public void testSimpleRequest() throws Exception {
+ MemoryIOConnector.MemoryIOChannel ch = new MemoryIOChannel();
+
+ HttpChannel httpCh = con.getServer();
+ httpCh.withBuffers(ch);
+
+ HttpRequest req = httpCh.getRequest();
+ req.setURI("/test1/1stTest");
+
+ HttpResponse res = httpCh.getResponse();
+
+ lite.getHttpConnector().getDispatcher().service(req, res, true);
+ // req/res will be recycled
+
+ // parse out to a response
+ BBuffer out = ch.out;
+ MemoryIOChannel clientCh = new MemoryIOChannel();
+ clientCh.getIn().append(out);
+
+ HttpChannel client = con.get("localhost", 80);
+ client.withBuffers(clientCh);
+ clientCh.handleReceived(clientCh);
+
+
+ HttpResponse cres = client.getResponse();
+ assertEquals(res.getStatus(), 200);
+
+ BBuffer resBody = BBuffer.allocate(200);
+ cres.getBody().readAll(resBody);
+ assertEquals("Hello world", resBody.toString());
+ assertEquals(cres.getHeader("Foo"), "Bar");
+ assertEquals(cres.getStatus(), 200);
+ }
+
+//
+// public void testPostRequest() throws Exception {
+// ByteChunk out = new ByteChunk();
+// ServletRequestImpl req =
+// LiteTestHelper.createMessage(lite, "/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);
+// }
+//
+// public void testException() throws IOException, Exception {
+// ByteChunk out = new ByteChunk();
+// ServletRequestImpl req =
+// LiteTestHelper.createMessage(lite, "/test1/testException", out);
+// ServletResponseImpl res = lite.service(req);
+// assertEquals(res.getStatus(), 500);
+// }
+
+}
Propchange:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/TomcatLiteNoConnectorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/TomcatLiteSimpleTest.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/TomcatLiteSimpleTest.java?rev=884421&view=auto
==============================================================================
---
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/TomcatLiteSimpleTest.java
(added)
+++
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/TomcatLiteSimpleTest.java
Thu Nov 26 06:55:49 2009
@@ -0,0 +1,52 @@
+/*
+ * 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.servlet;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+
+import junit.framework.TestCase;
+
+import org.apache.tomcat.lite.io.IOBuffer;
+
+/**
+ * TODO: convert to new API
+ *
+ */
+public class TomcatLiteSimpleTest extends TestCase {
+
+ protected TomcatLite lite = new TomcatLite();
+
+ public void setUp() throws Exception {
+ LiteTestHelper.addContext(lite);
+
+ lite.init();
+
+ lite.setPort(8884);
+ lite.start();
+ lite.startConnector();
+ }
+
+ public void testSimpleRequest() throws Exception {
+ URL url = new URL("http://localhost:8884/test1/1stTest");
+ URLConnection connection = url.openConnection();
+ InputStream is = connection.getInputStream();
+ String res = new IOBuffer().append(is).readAll(null).toString();
+ assertEquals("Hello world", res);
+ }
+}
Propchange:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/TomcatLiteSimpleTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/TomcatLiteWatchdog.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/TomcatLiteWatchdog.java?rev=884421&view=auto
==============================================================================
---
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/TomcatLiteWatchdog.java
(added)
+++
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/TomcatLiteWatchdog.java
Thu Nov 26 06:55:49 2009
@@ -0,0 +1,94 @@
+/*
+ * 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.servlet;
+
+import java.io.File;
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+
+import junit.framework.TestResult;
+
+import org.apache.tomcat.lite.servlet.TomcatLite;
+import org.apache.tomcat.test.watchdog.WatchdogClient;
+
+
+public abstract class TomcatLiteWatchdog extends WatchdogClient {
+
+ public TomcatLiteWatchdog() {
+ goldenDir = getWatchdogdir() +
"/src/clients/org/apache/jcheck/servlet/client/";
+ testMatch =
+ //"HttpServletResponseWrapperSetStatusMsgTest";
+ //"ServletContextAttributeAddedEventTest";
+ null;
+ // ex: "ServletToJSP";
+ file = getWatchdogdir() + "/src/conf/servlet-gtest.xml";
+ targetMatch = "gtestservlet-test";
+ }
+
+ protected void beforeSuite() {
+ // required for the tests
+ System.setProperty("org.apache.coyote.USE_CUSTOM_STATUS_MSG_IN_HEADER",
+ "true");
+
+ try {
+ initServerWithWatchdog(getWatchdogdir());
+ } catch (ServletException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ protected abstract void addConnector(TomcatLite liteServer);
+
+ TomcatLite tomcatForWatchdog;
+
+ public void initServerWithWatchdog(String wdDir) throws ServletException,
+ IOException {
+ File f = new File(wdDir + "/build/webapps");
+
+ tomcatForWatchdog = new TomcatLite();
+
+ addConnector(tomcatForWatchdog);
+// tomcatForWatchdog.getHttpConnector().setDebug(true);
+// tomcatForWatchdog.getHttpConnector().setDebugHttp(true);
+
+ tomcatForWatchdog.addServletContext(null, "webapps/ROOT",
"/").loadConfig();
+
+ for (String s : new String[] {
+ "servlet-compat",
+ "servlet-tests",
+ "jsp-tests"} ) {
+ tomcatForWatchdog.addServletContext(null, f.getCanonicalPath() + "/"
+ s,
+ "/" + s).loadConfig();
+ }
+
+ tomcatForWatchdog.init();
+ tomcatForWatchdog.start();
+
+ tomcatForWatchdog.startConnector();
+ }
+
+
+
+ protected void afterSuite(TestResult res) {
+ // no need to stop it - using daemon threads.
+ }
+}
Propchange:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/servlet/TomcatLiteWatchdog.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/test.properties
URL:
http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/test.properties?rev=884421&view=auto
==============================================================================
---
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/test.properties
(added)
+++
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/test.properties
Thu Nov 26 06:55:49 2009
@@ -0,0 +1,63 @@
+RUN=Log,JMXProxy,Socks,TomcatLite
+
+Log.(class)=org.apache.tomcat.lite.service.LogConfig
+Log.debug=org.apache.tomcat.lite.http.HttpConnector
+Log.debug=Proxy
+
+JMXProxy.(class)=org.apache.tomcat.lite.service.JMXProxy
+JMXProxy.port=8003
+
+Socks.(class)=org.apache.tomcat.lite.proxy.SocksServer
+Socks.port=2080
+Socks.idleTimeout=0
+
+#HttpConnector-TestServer.debug=true
+#HttpConnector-TestServer.debugHttp=true
+xHttpConnector-TestServer.clientKeepAlive=true
+xHttpConnector-TestServer.serverKeepAlive=true
+xHttpConnector-TestServer.maxHttpPoolSize=0
+
+#HttpConnector.debug=true
+#HttpConnector.debugHttp=true
+xHttpConnector.clientKeepAlive=true
+xHttpConnector.serverKeepAlive=true
+xHttpConnector.maxHttpPoolSize=0
+
+#HttpConnector-Proxy.debug=true
+#HttpConnector-Proxy.debugHttp=true
+xHttpConnector-Proxy.clientKeepAlive=true
+xHttpConnector-Proxy.serverKeepAlive=true
+xHttpConnector-Proxy.maxHttpPoolSize=0
+
+
+#IOConnector.debug=true
+
+# Tomcat-lite config
+# include:
+# config=org/apache/tomcat/lite/config.properties
+TomcatLite.(class)=org.apache.tomcat.lite.servlet.TomcatLite
+#
TomcatLite.deployListener=org.apache.tomcat.servlets.config.deploy.WebXmlContextListener
+
+# Tomcat-lite plugins
+org.apache.tomcat.lite.WebappServletMapper.(class)=org.apache.tomcat.lite.WebappServletMapper
+org.apache.tomcat.lite.WebappFilterMapper.(class)=org.apache.tomcat.lite.WebappFilterMapper
+org.apache.tomcat.servlets.session.UserSessionManager.(class)=org.apache.tomcat.servlets.session.SimpleSessionManager
+org.apache.tomcat.servlets.jsp.UserTemplateClassMapper.(class)=org.apache.tomcat.servlets.jsp.JasperCompilerTemplateClassMapper
+org.apache.tomcat.servlets.file.Filesystem.(class)=org.apache.tomcat.file.LocalFilesystem
+default-servlet.(class)=org.apache.tomcat.servlets.file.WebdavServlet
+jspwildcard-servlet.(class)=org.apache.tomcat.servlets.jsp.WildcardTemplateServlet
+filetemplate-servlet.(class)=org.apache.tomcat.servlets.jsp.JspFileTemplateServlet
+
+org.apache.tomcat.lite.Connector.(class)=org.apache.tomcat.lite.AsyncConnector
+org.apache.tomcat.lite.Connector.port=8800
+
+
+
+TomcatLite.context.1=/examples:./webapps/examples
+TomcatLite.context.2=/:./webapps/ROOT
+TomcatLite.context.3=/lite:./modules/tomcat-lite/test-webapp
+// No base dir
+TomcatLite.context.4=/dynamic:
+
+
+JMXProxyServlet.(class)=org.apache.tomcat.integration.jmx.JMXProxyServlet
Propchange:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/test.properties
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogClient.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogClient.java?rev=884421&r1=884420&r2=884421&view=diff
==============================================================================
---
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogClient.java
(original)
+++
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogClient.java
Thu Nov 26 06:55:49 2009
@@ -16,6 +16,7 @@
*/
package org.apache.tomcat.test.watchdog;
+import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
@@ -26,15 +27,13 @@
import junit.framework.TestResult;
import junit.framework.TestSuite;
-import org.apache.tomcat.util.DomUtil;
+import org.apache.tomcat.servlets.config.deploy.DomUtil;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
public class WatchdogClient {
-
- protected String base = "../watchdog";
protected String goldenDir;
protected String testMatch;
@@ -51,11 +50,13 @@
Properties props = new Properties();
protected void beforeSuite() {
-
}
protected void afterSuite(TestResult res) {
-
+ }
+
+ public Test getSuite() {
+ return getSuite(8080);
}
/**
@@ -66,11 +67,11 @@
* @param testMatch Prefix of tests to be run
* @return
*/
- public Test getSuite() {
+ public Test getSuite(int port) {
TestSuite tests = new WatchdogTests();
tests.setName(this.getClass().getSimpleName());
- props.setProperty("port", "8080");
+ props.setProperty("port", Integer.toString(port));
props.setProperty("host", "localhost");
props.setProperty("wgdir",
goldenDir);
@@ -112,22 +113,16 @@
}
}
testName = testName + ";" + this.getClass().getName();
- WatchdogTest test = new WatchdogTest(watchE, props, testName);
+ WatchdogTestCase test = new WatchdogTestCase(watchE, props,
testName);
tests.addTest(test);
}
-
- // if (targetSuite.countTestCases() > 0) {
- // tests.addTest(targetSuite);
- // }
}
} catch (IOException e) {
- e.printStackTrace();
+ e.printStackTrace();
} catch (SAXException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
} catch (ParserConfigurationException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
}
return tests;
@@ -135,6 +130,22 @@
// --------- Inner classes -------------
+ protected String getWatchdogdir() {
+ String path = System.getProperty("watchdog.home");
+ if (path != null) {
+ return path;
+ }
+ path = "..";
+ for (int i = 0; i < 10; i++) {
+ File f = new File(path + "/watchdog");
+ if (f.exists()) {
+ return f.getAbsolutePath();
+ }
+ path = path + "/..";
+ }
+ return null;
+ }
+
public class WatchdogTests extends TestSuite {
public void run(TestResult res) {
beforeSuite();
@@ -142,5 +153,5 @@
afterSuite(res);
}
}
-
+
}
Modified:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogHttpClient.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogHttpClient.java?rev=884421&r1=884420&r2=884421&view=diff
==============================================================================
---
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogHttpClient.java
(original)
+++
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogHttpClient.java
Thu Nov 26 06:55:49 2009
@@ -37,7 +37,7 @@
static int debug = 0;
- public static void dispatch(GTest client) throws Exception {
+ public static void dispatch(WatchdogTestImpl client) throws Exception {
HashMap requestHeaders = client.requestHeaders;
String host = client.host;
int port = client.port;
@@ -45,7 +45,14 @@
String request = client.request;
// XXX headers are ignored
- Socket socket = new Socket( host, port );
+ Socket socket;
+ try {
+ socket = new Socket( host, port );
+ } catch (IOException ex) {
+ System.out.println( " Socket Exception: " + ex );
+ return;
+ }
+ //socket.setSoTimeout(10000);
//socket obtained, rebuild the request.
rebuildRequest(client, client.request, socket);
@@ -57,7 +64,7 @@
OutputStream out = new BufferedOutputStream(
socket.getOutputStream() );
- StringBuilder reqbuf = new StringBuilder( 128 );
+ StringBuffer reqbuf = new StringBuffer( 128 );
// set the Host header
client.setHeaderDetails( "Host:" + host + ":" + port, requestHeaders,
true );
@@ -92,7 +99,7 @@
Iterator iter = requestHeaders.keySet().iterator();
while ( iter.hasNext() ) {
- StringBuilder tmpBuf = new StringBuilder(32);
+ StringBuffer tmpBuf = new StringBuffer(32);
String headerKey = ( String ) iter.next();
ArrayList values = (ArrayList) requestHeaders.get(
headerKey );
String[] value = (String[]) values.toArray( new
String[ values.size() ] );
@@ -168,7 +175,6 @@
} catch ( SocketException ex ) {
System.out.println( " Socket Exception: " + ex );
- ex.printStackTrace();
} finally {
if ( debug > 0 ) {
System.out.println( " closing socket" );
@@ -187,7 +193,7 @@
* @return a <code>byte[]</code> representation of the response
*/
private static byte[] readBody( InputStream input ) {
- StringBuilder sb = new StringBuilder( 255 );
+ StringBuffer sb = new StringBuffer( 255 );
while ( true ) {
try {
int ch = input.read();
@@ -222,7 +228,7 @@
*/
private static String read( InputStream input ) throws IOException {
// Read the next line from the input stream
- StringBuilder sb = new StringBuilder();
+ StringBuffer sb = new StringBuffer();
while ( true ) {
try {
@@ -265,7 +271,7 @@
*
* @exception IOException if an input/output error occurs
*/
- private static HashMap parseHeaders( GTest client, InputStream is ) throws
IOException {
+ private static HashMap parseHeaders( WatchdogTestImpl client, InputStream
is ) throws IOException {
HashMap headers = new HashMap();
client.cookieVector = new Vector();
@@ -307,7 +313,7 @@
*
* @exception Exception if an error occurs
*/
- private static void rebuildRequest(GTest client, String req, Socket
socket) throws Exception {
+ private static void rebuildRequest(WatchdogTestImpl client, String req,
Socket socket) throws Exception {
client.request = client.replaceMarkers(req, socket );
String addressString = client.request.substring(
client.request.indexOf( "/" ), client.request.indexOf( "HTTP" ) ).trim();
Added:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogTestCase.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogTestCase.java?rev=884421&view=auto
==============================================================================
---
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogTestCase.java
(added)
+++
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogTestCase.java
Thu Nov 26 06:55:49 2009
@@ -0,0 +1,117 @@
+/*
+ */
+package org.apache.tomcat.test.watchdog;
+
+import java.util.Properties;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.Test;
+import junit.framework.TestResult;
+import junit.framework.TestSuite;
+
+import org.apache.tomcat.integration.DynamicObject;
+import org.apache.tomcat.integration.simple.AntProperties;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+public class WatchdogTestCase implements Test {
+ String testName;
+
+ Element watchE;
+
+ private Properties props;
+
+ private WatchdogTestCase delegate;
+ private WatchdogClient wc;
+
+ public WatchdogTestCase(String s) throws Throwable {
+ String[] comp = s.split(";");
+ if (comp.length < 2) {
+ return;
+ }
+ Class c = Class.forName(comp[1]);
+ wc = (WatchdogClient) c.newInstance();
+ TestSuite suite = (TestSuite) wc.getSuite();
+ // need to encode the base, file, etc in the test name
+
+ System.err.println(s);
+
+ for (int i = 0; i < suite.testCount(); i++) {
+ WatchdogTestCase t = (WatchdogTestCase) suite.testAt(i);
+ if (s.equals(t.getName())) {
+ delegate = t;
+ return;
+ }
+ }
+ }
+
+ public WatchdogTestCase(Element watchE, Properties props, String testName)
{
+ this.testName = testName;
+ this.watchE = watchE;
+ this.props = props;
+ }
+
+ public int countTestCases() {
+ return 1;
+ }
+
+ public String getName() {
+ return testName;
+ }
+
+ public void testDummy() {
+ }
+
+ public void run(TestResult res) {
+ if (delegate != null) {
+ // Single method run
+ wc.beforeSuite();
+ delegate.run(res);
+ wc.afterSuite(res);
+ return;
+ }
+ if (watchE == null) {
+ res.endTest(this);
+ return;
+ }
+ WatchdogTestImpl test = new WatchdogTestImpl();
+ NamedNodeMap attrs = watchE.getAttributes();
+
+ for (int i = 0; i < attrs.getLength(); i++) {
+ Node n = attrs.item(i);
+ String name = n.getNodeName();
+ String value = n.getNodeValue();
+ value = AntProperties.replaceProperties(value, props, null);
+ try {
+ new DynamicObject(test.getClass()).setProperty(test,
+ name, value);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ try {
+ res.startTest(this);
+ new DynamicObject(test.getClass()).invoke(test, "execute");
+ } catch (Throwable e) {
+ res.addError(this, e);
+ // res.stop();
+ }
+
+ if (test.passCount == 1) {
+ res.endTest(this);
+ return;
+ } else {
+ if (test.lastError == null) {
+ res.addFailure(this, new AssertionFailedError(test.request
+ + " " + test.description + "\n" + test.resultOut));
+ } else {
+ res.addError(this, test.lastError);
+ }
+ }
+ res.endTest(this);
+ }
+
+}
Propchange:
tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]