incubator-deft-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmee...@apache.org
Subject svn commit: r1159923 - in /incubator/deft/sandbox/src: main/java/org/apache/deft/configuration/ main/java/org/apache/deft/web/ test/java/org/apache/deft/configuration/ test/java/org/apache/deft/web/
Date Sat, 20 Aug 2011 23:15:10 GMT
Author: jmeehan
Date: Sat Aug 20 23:15:10 2011
New Revision: 1159923

URL: http://svn.apache.org/viewvc?rev=1159923&view=rev
Log:
DEFT-182 - DeftSystemTest in place again.

Added:
    incubator/deft/sandbox/src/test/java/org/apache/deft/web/DeftSystemTestHandlers.java   (with props)
Modified:
    incubator/deft/sandbox/src/main/java/org/apache/deft/configuration/AnnotationsScanner.java
    incubator/deft/sandbox/src/main/java/org/apache/deft/web/HttpServer.java
    incubator/deft/sandbox/src/test/java/org/apache/deft/configuration/AnnotationsScannerTest.java
    incubator/deft/sandbox/src/test/java/org/apache/deft/web/DeftSystemTest.java
    incubator/deft/sandbox/src/test/java/org/apache/deft/web/HttpServerTest.java

Modified: incubator/deft/sandbox/src/main/java/org/apache/deft/configuration/AnnotationsScanner.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/main/java/org/apache/deft/configuration/AnnotationsScanner.java?rev=1159923&r1=1159922&r2=1159923&view=diff
==============================================================================
--- incubator/deft/sandbox/src/main/java/org/apache/deft/configuration/AnnotationsScanner.java (original)
+++ incubator/deft/sandbox/src/main/java/org/apache/deft/configuration/AnnotationsScanner.java Sat Aug 20 23:15:10 2011
@@ -34,6 +34,8 @@ import org.apache.deft.web.handler.Reque
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Strings;
+
 /**
  * Provides functionality to retrieve known <code>Annotation</code> types and
  * associated values.
@@ -59,6 +61,11 @@ public class AnnotationsScanner {
      */
     public Map<String, RequestHandler> findHandlers(String handlerPackage) {
 
+        if (Strings.isNullOrEmpty(handlerPackage)) {
+            logger.warn("No RequestHandler package defined");
+            return pathHandlers;
+        }
+
         List<Class<?>> classes = findClasses(handlerPackage);
         for (Class<?> clazz : classes) {
             if (clazz.isAnnotationPresent(Path.class)) {

Modified: incubator/deft/sandbox/src/main/java/org/apache/deft/web/HttpServer.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/main/java/org/apache/deft/web/HttpServer.java?rev=1159923&r1=1159922&r2=1159923&view=diff
==============================================================================
--- incubator/deft/sandbox/src/main/java/org/apache/deft/web/HttpServer.java (original)
+++ incubator/deft/sandbox/src/main/java/org/apache/deft/web/HttpServer.java Sat Aug 20 23:15:10 2011
@@ -35,7 +35,6 @@ import org.apache.deft.web.http.HttpProt
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Strings;
 import com.google.common.collect.Lists;
 
 public class HttpServer {
@@ -52,10 +51,6 @@ public class HttpServer {
 
     public HttpServer(Configuration configuration) {
 
-        if (Strings.isNullOrEmpty(configuration.getHandlerPackage())) {
-            logger.warn("No RequestHandler found under package [" + configuration.getHandlerPackage() + "]");
-        }
-
         application = createApplication(configuration.getHandlerPackage());
         application.setStaticContentDir(configuration.getStaticDirectory());
         application.setConfiguration(configuration);

Modified: incubator/deft/sandbox/src/test/java/org/apache/deft/configuration/AnnotationsScannerTest.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/test/java/org/apache/deft/configuration/AnnotationsScannerTest.java?rev=1159923&r1=1159922&r2=1159923&view=diff
==============================================================================
--- incubator/deft/sandbox/src/test/java/org/apache/deft/configuration/AnnotationsScannerTest.java (original)
+++ incubator/deft/sandbox/src/test/java/org/apache/deft/configuration/AnnotationsScannerTest.java Sat Aug 20 23:15:10 2011
@@ -48,4 +48,13 @@ public class AnnotationsScannerTest {
 
         assertEquals(0, handlers.size());
     }
+
+    @Test
+    public void testFindHandlersForEmptyPath() {
+
+        AnnotationsScanner scanner = new AnnotationsScanner();
+        Map<String, RequestHandler> handlers = scanner.findHandlers(null);
+
+        assertEquals(0, handlers.size());
+    }
 }

Modified: incubator/deft/sandbox/src/test/java/org/apache/deft/web/DeftSystemTest.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/test/java/org/apache/deft/web/DeftSystemTest.java?rev=1159923&r1=1159922&r2=1159923&view=diff
==============================================================================
--- incubator/deft/sandbox/src/test/java/org/apache/deft/web/DeftSystemTest.java (original)
+++ incubator/deft/sandbox/src/test/java/org/apache/deft/web/DeftSystemTest.java Sat Aug 20 23:15:10 2011
@@ -19,12 +19,12 @@
  */
 package org.apache.deft.web;
 
+import static org.apache.deft.web.DeftSystemTestHandlers.expectedPayload;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 import java.io.BufferedReader;
-import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -43,16 +43,31 @@ import java.util.concurrent.ExecutorServ
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 
-import org.apache.deft.annotation.Asynchronous;
-import org.apache.deft.annotation.Authenticated;
 import org.apache.deft.configuration.Configuration;
-import org.apache.deft.example.keyvalue.KeyValueStore;
-import org.apache.deft.example.keyvalue.KeyValueStoreClient;
 import org.apache.deft.io.IOLoop;
 import org.apache.deft.io.timeout.Timeout;
+import org.apache.deft.web.DeftSystemTestHandlers.AsyncThrowingHttpExceptionRequestHandler;
+import org.apache.deft.web.DeftSystemTestHandlers.AuthenticatedRequestHandler;
+import org.apache.deft.web.DeftSystemTestHandlers.CapturingRequestRequestHandler;
+import org.apache.deft.web.DeftSystemTestHandlers.ChunkedRequestHandler;
+import org.apache.deft.web.DeftSystemTestHandlers.DeleteRequestHandler;
+import org.apache.deft.web.DeftSystemTestHandlers.EchoingPostBodyRequestHandler;
+import org.apache.deft.web.DeftSystemTestHandlers.ExampleRequestHandler;
+import org.apache.deft.web.DeftSystemTestHandlers.KeyValueStoreExampleRequestHandler;
+import org.apache.deft.web.DeftSystemTestHandlers.MovedPermanentlyRequestHandler;
+import org.apache.deft.web.DeftSystemTestHandlers.NoBodyRequestHandler;
+import org.apache.deft.web.DeftSystemTestHandlers.PostRequestHandler;
+import org.apache.deft.web.DeftSystemTestHandlers.PutRequestHandler;
+import org.apache.deft.web.DeftSystemTestHandlers.QueryParamsRequestHandler;
+import org.apache.deft.web.DeftSystemTestHandlers.ThrowingHttpExceptionRequestHandler;
+import org.apache.deft.web.DeftSystemTestHandlers.UserDefinedStaticContentHandler;
+import org.apache.deft.web.DeftSystemTestHandlers.WFFFWFFFRequestHandler;
+import org.apache.deft.web.DeftSystemTestHandlers.WFWFRequestHandler;
+import org.apache.deft.web.DeftSystemTestHandlers.WRequestHandler;
+import org.apache.deft.web.DeftSystemTestHandlers.WWFWRequestHandler;
+import org.apache.deft.web.DeftSystemTestHandlers.WWRequestHandler;
+import org.apache.deft.web.DeftSystemTestHandlers._450KBResponseEntityRequestHandler;
 import org.apache.deft.web.handler.RequestHandler;
-import org.apache.deft.web.http.HttpException;
-import org.apache.deft.web.http.HttpRequest;
 import org.apache.deft.web.http.client.AsynchronousHttpClient;
 import org.apache.deft.web.http.protocol.HttpStatus;
 import org.apache.http.Header;
@@ -72,254 +87,23 @@ import org.apache.http.params.HttpParams
 import org.apache.http.params.HttpProtocolParams;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
-import org.junit.Ignore;
 import org.junit.Test;
 
 import com.ning.http.client.AsyncCompletionHandler;
 import com.ning.http.client.AsyncHttpClient;
 import com.ning.http.client.Response;
 
-@Ignore
+/**
+ * General tests of server operation.
+ */
 public class DeftSystemTest {
 
     private static final int PORT = 8081;
 
-    public static final String expectedPayload = "hello test";
-
-    private static class ExampleRequestHandler extends RequestHandler {
-        @Override
-        public void get(org.apache.deft.web.http.HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
-            response.write(expectedPayload);
-        }
-    }
-
-    private static class WRequestHandler extends RequestHandler {
-        @Override
-        public void get(org.apache.deft.web.http.HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
-            response.write("1");
-        }
-    }
-
-    private static class WWRequestHandler extends RequestHandler {
-        @Override
-        public void get(org.apache.deft.web.http.HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
-            response.write("1");
-            response.write("2");
-        }
-    }
-
-    private static class WWFWRequestHandler extends RequestHandler {
-        @Override
-        public void get(org.apache.deft.web.http.HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
-            response.write("1");
-            response.write("2");
-            response.flush();
-            response.write("3");
-        }
-    }
-
-    private static class WFWFRequestHandler extends RequestHandler {
-        @Override
-        public void get(org.apache.deft.web.http.HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
-            response.write("1");
-            response.flush();
-            response.write("2");
-            response.flush();
-        }
-    }
-
-    private static class WFFFWFFFRequestHandler extends RequestHandler {
-        @Override
-        public void get(org.apache.deft.web.http.HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
-            response.write("1");
-            response.flush();
-            response.flush();
-            response.flush();
-            response.write("2");
-            response.flush();
-            response.flush();
-            response.flush();
-        }
-    }
-
-    private static class DeleteRequestHandler extends RequestHandler {
-        @Override
-        public void delete(org.apache.deft.web.http.HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
-            response.write("del");
-            response.flush();
-            response.write("ete");
-            response.flush();
-        }
-    }
-
-    private static class PostRequestHandler extends RequestHandler {
-        @Override
-        public void post(org.apache.deft.web.http.HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
-            response.write("po");
-            response.flush();
-            response.write("st");
-            response.flush();
-        }
-    }
-
-    private static class PutRequestHandler extends RequestHandler {
-        @Override
-        public void put(org.apache.deft.web.http.HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
-            response.write("p");
-            response.flush();
-            response.write("ut");
-            response.flush();
-        }
-    }
-
-    private static class CapturingRequestRequestHandler extends RequestHandler {
-        @Override
-        public void get(org.apache.deft.web.http.HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
-            response.write(request.getRequestedPath());
-        }
-    }
-
-    private static class ThrowingHttpExceptionRequestHandler extends RequestHandler {
-        @Override
-        public void get(org.apache.deft.web.http.HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
-            throw new HttpException(HttpStatus.SERVER_ERROR_INTERNAL_SERVER_ERROR, "exception message");
-        }
-    }
-
-    private static class AsyncThrowingHttpExceptionRequestHandler extends RequestHandler {
-        @Asynchronous
-        @Override
-        public void get(org.apache.deft.web.http.HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
-            throw new HttpException(HttpStatus.SERVER_ERROR_INTERNAL_SERVER_ERROR, "exception message");
-        }
-    }
-
-    public static class NoBodyRequestHandler extends RequestHandler {
-        @Override
-        public void get(HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
-            response.setStatus(HttpStatus.SUCCESS_ACCEPTED);
-        }
-    }
-
-    public static class MovedPermanentlyRequestHandler extends RequestHandler {
-        @Override
-        public void get(HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
-            response.setStatus(HttpStatus.REDIRECTION_MOVED_PERMANENTLY);
-            response.setHeader("Location", "/");
-        }
-    }
-
-    public static class UserDefinedStaticContentHandler extends RequestHandler {
-        @Override
-        public void get(HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
-            response.write(new File("src/test/resources/test.txt"));
-        }
-    }
-
-    public static class KeyValueStoreExampleRequestHandler extends RequestHandler {
-
-        private final KeyValueStoreClient client = new KeyValueStoreClient(KeyValueStore.HOST, KeyValueStore.PORT);
-
-        public KeyValueStoreExampleRequestHandler() {
-            new KeyValueStore().start();
-            client.connect();
-        }
-
-        @Override
-        @Asynchronous
-        public void get(HttpRequest request, final org.apache.deft.web.http.HttpResponse response) {
-            client.get("deft", new AsyncResult<byte[]>() {
-                @Override
-                public void onFailure(Throwable caught) { /* ignore */
-                }
-
-                @Override
-                public void onSuccess(byte[] result) {
-                    response.write(new String(result)).finish();
-                }
-            });
-        }
-
-    }
-
-    public static class _450KBResponseEntityRequestHandler extends RequestHandler {
-        public static String entity;
-
-        static {
-            int iterations = 450 * 1024;
-            StringBuilder sb = new StringBuilder();
-            for (int i = 1; i <= iterations; i++) {
-                sb.append("a");
-            }
-            entity = sb.toString();
-        }
-
-        @Override
-        public void get(HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
-            response.write(entity);
-        }
-    }
-
-    public static class EchoingPostBodyRequestHandler extends RequestHandler {
-        @Override
-        public void post(HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
-            response.write(request.getBody());
-        }
-    }
-
-    public static class AuthenticatedRequestHandler extends RequestHandler {
-        @Override
-        @Authenticated
-        public void get(HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
-            response.write(request.getHeader("user"));
-        }
-
-        @Override
-        public String getCurrentUser(HttpRequest request) {
-            return request.getHeader("user");
-        }
-    }
-
-    private static class QueryParamsRequestHandler extends RequestHandler {
-        @Override
-        public void get(HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
-            response.write(request.getParameter("key1") + " " + request.getParameter("key2"));
-        }
-    }
-
-    private static class ChunkedRequestHandler extends RequestHandler {
-        @Override
-        public void get(HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
-            response.setHeader("Transfer-Encoding", "chunked");
-            sleep(300);
-
-            response.write("1\r\n");
-            response.write("a\r\n").flush();
-            sleep(300);
-
-            response.write("5\r\n");
-            response.write("roger\r\n").flush();
-            sleep(300);
-
-            response.write("2\r\n");
-            response.write("ab\r\n").flush();
-            sleep(300);
-
-            response.write("0\r\n");
-            response.write("\r\n");
-        }
-
-        private static void sleep(long ms) {
-            try {
-                Thread.sleep(ms);
-            } catch (InterruptedException ignore) { /* nop */
-            }
-        }
-    }
-
     @BeforeClass
     public static void setup() {
-        Map<String, RequestHandler> reqHandlers = new HashMap<String, RequestHandler>();
+
+        final Map<String, RequestHandler> reqHandlers = new HashMap<String, RequestHandler>();
         reqHandlers.put("/", new ExampleRequestHandler());
         reqHandlers.put("/w", new WRequestHandler());
         reqHandlers.put("/ww", new WWRequestHandler());
@@ -342,18 +126,21 @@ public class DeftSystemTest {
         reqHandlers.put("/query_params", new QueryParamsRequestHandler());
         reqHandlers.put("/chunked", new ChunkedRequestHandler());
 
-        final Application application = new Application(reqHandlers);
-        application.setStaticContentDir("src/test/resources");
-
-        // start deft instance from a new thread because the start invocation is
-        // blocking
-        // (invoking thread will be I/O loop thread)
+        /*
+         * Start server instance from a new thread because the start invocation
+         * is blocking (invoking thread will be I/O loop thread).
+         */
         new Thread(new Runnable() {
             @Override
             public void run() {
-                HttpServer server = new HttpServer(new Configuration()) {
+
+                Configuration configuration = new Configuration();
+                configuration.setCreateETags(true);
+                configuration.setStaticDirectory("src/test/resources");
+
+                HttpServer server = new HttpServer(configuration) {
                     protected Application createApplication(String packageName) {
-                        return application;
+                        return new Application(reqHandlers);
                     }
                 };
                 server.listen(PORT);
@@ -364,6 +151,7 @@ public class DeftSystemTest {
 
     @AfterClass
     public static void tearDown() throws InterruptedException {
+
         IOLoop.INSTANCE.addCallback(new AsyncCallback() {
             @Override
             public void onCallback() {
@@ -378,32 +166,6 @@ public class DeftSystemTest {
         doSimpleGetRequest();
     }
 
-    private void doSimpleGetRequest() throws ClientProtocolException, IOException {
-        List<Header> headers = new LinkedList<Header>();
-        headers.add(new BasicHeader("Connection", "Close"));
-        HttpParams params = new BasicHttpParams();
-        params.setParameter("http.default-headers", headers);
-
-        HttpClient httpclient = new DefaultHttpClient(params);
-        HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/");
-        HttpResponse response = httpclient.execute(httpget);
-        List<String> expectedHeaders = Arrays.asList(new String[] { "Server", "Date", "Content-Length", "Etag",
-                "Connection" });
-
-        assertEquals(200, response.getStatusLine().getStatusCode());
-        assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
-        assertEquals("OK", response.getStatusLine().getReasonPhrase());
-
-        assertEquals(expectedHeaders.size(), response.getAllHeaders().length);
-
-        for (String header : expectedHeaders) {
-            assertTrue(response.getFirstHeader(header) != null);
-        }
-
-        assertEquals(expectedPayload, convertStreamToString(response.getEntity().getContent()).trim());
-        assertEquals(expectedPayload.length() + "", response.getFirstHeader("Content-Length").getValue());
-    }
-
     /**
      * Test a RH that does a single write
      * 
@@ -412,8 +174,10 @@ public class DeftSystemTest {
      */
     @Test
     public void wTest() throws ClientProtocolException, IOException {
+
         List<Header> headers = new LinkedList<Header>();
         headers.add(new BasicHeader("Connection", "Close"));
+
         HttpParams params = new BasicHttpParams();
         params.setParameter("http.default-headers", headers);
 
@@ -422,9 +186,10 @@ public class DeftSystemTest {
         HttpResponse response = httpclient.execute(httpget);
 
         assertNotNull(response);
-        assertEquals(200, response.getStatusLine().getStatusCode());
+        assertEquals(HttpStatus.SUCCESS_OK.code(), response.getStatusLine().getStatusCode());
         assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
         assertEquals("OK", response.getStatusLine().getReasonPhrase());
+
         String payLoad = convertStreamToString(response.getEntity().getContent()).trim();
         assertEquals("1", payLoad);
         assertEquals(5, response.getAllHeaders().length);
@@ -433,8 +198,10 @@ public class DeftSystemTest {
 
     @Test
     public void wwTest() throws ClientProtocolException, IOException {
+
         List<Header> headers = new LinkedList<Header>();
         headers.add(new BasicHeader("Connection", "Close"));
+
         HttpParams params = new BasicHttpParams();
         params.setParameter("http.default-headers", headers);
 
@@ -443,9 +210,10 @@ public class DeftSystemTest {
         HttpResponse response = httpclient.execute(httpget);
 
         assertNotNull(response);
-        assertEquals(200, response.getStatusLine().getStatusCode());
+        assertEquals(HttpStatus.SUCCESS_OK.code(), response.getStatusLine().getStatusCode());
         assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
         assertEquals("OK", response.getStatusLine().getReasonPhrase());
+
         String payLoad = convertStreamToString(response.getEntity().getContent()).trim();
         assertEquals("12", payLoad);
         assertEquals(5, response.getAllHeaders().length);
@@ -454,8 +222,10 @@ public class DeftSystemTest {
 
     @Test
     public void wwfwTest() throws ClientProtocolException, IOException {
+
         List<Header> headers = new LinkedList<Header>();
         headers.add(new BasicHeader("Connection", "Close"));
+
         HttpParams params = new BasicHttpParams();
         params.setParameter("http.default-headers", headers);
 
@@ -464,9 +234,10 @@ public class DeftSystemTest {
         HttpResponse response = httpclient.execute(httpget);
 
         assertNotNull(response);
-        assertEquals(200, response.getStatusLine().getStatusCode());
+        assertEquals(HttpStatus.SUCCESS_OK.code(), response.getStatusLine().getStatusCode());
         assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
         assertEquals("OK", response.getStatusLine().getReasonPhrase());
+
         String payLoad = convertStreamToString(response.getEntity().getContent()).trim();
         assertEquals("123", payLoad);
         assertEquals(3, response.getAllHeaders().length);
@@ -474,8 +245,10 @@ public class DeftSystemTest {
 
     @Test
     public void wfwfTest() throws ClientProtocolException, IOException {
+
         List<Header> headers = new LinkedList<Header>();
         headers.add(new BasicHeader("Connection", "Close"));
+
         HttpParams params = new BasicHttpParams();
         params.setParameter("http.default-headers", headers);
 
@@ -484,9 +257,10 @@ public class DeftSystemTest {
         HttpResponse response = httpclient.execute(httpget);
 
         assertNotNull(response);
-        assertEquals(200, response.getStatusLine().getStatusCode());
+        assertEquals(HttpStatus.SUCCESS_OK.code(), response.getStatusLine().getStatusCode());
         assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
         assertEquals("OK", response.getStatusLine().getReasonPhrase());
+
         String payLoad = convertStreamToString(response.getEntity().getContent()).trim();
         assertEquals("12", payLoad);
         assertEquals(3, response.getAllHeaders().length);
@@ -494,8 +268,10 @@ public class DeftSystemTest {
 
     @Test
     public void wfffwfffTest() throws ClientProtocolException, IOException {
+
         List<Header> headers = new LinkedList<Header>();
         headers.add(new BasicHeader("Connection", "Close"));
+
         HttpParams params = new BasicHttpParams();
         params.setParameter("http.default-headers", headers);
 
@@ -504,9 +280,10 @@ public class DeftSystemTest {
         HttpResponse response = httpclient.execute(httpget);
 
         assertNotNull(response);
-        assertEquals(200, response.getStatusLine().getStatusCode());
+        assertEquals(HttpStatus.SUCCESS_OK.code(), response.getStatusLine().getStatusCode());
         assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
         assertEquals("OK", response.getStatusLine().getReasonPhrase());
+
         String payLoad = convertStreamToString(response.getEntity().getContent()).trim();
         assertEquals("12", payLoad);
         assertEquals(3, response.getAllHeaders().length);
@@ -514,8 +291,10 @@ public class DeftSystemTest {
 
     @Test
     public void deleteTest() throws ClientProtocolException, IOException {
+
         List<Header> headers = new LinkedList<Header>();
         headers.add(new BasicHeader("Connection", "Close"));
+
         HttpParams params = new BasicHttpParams();
         params.setParameter("http.default-headers", headers);
 
@@ -524,17 +303,20 @@ public class DeftSystemTest {
         HttpResponse response = httpclient.execute(httpdelete);
 
         assertNotNull(response);
-        assertEquals(200, response.getStatusLine().getStatusCode());
+        assertEquals(HttpStatus.SUCCESS_OK.code(), response.getStatusLine().getStatusCode());
         assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
         assertEquals("OK", response.getStatusLine().getReasonPhrase());
+
         String payLoad = convertStreamToString(response.getEntity().getContent()).trim();
         assertEquals("delete", payLoad);
     }
 
     @Test
     public void PostTest() throws ClientProtocolException, IOException {
+
         List<Header> headers = new LinkedList<Header>();
         headers.add(new BasicHeader("Connection", "Close"));
+
         HttpParams params = new BasicHttpParams();
         params.setParameter("http.default-headers", headers);
 
@@ -543,17 +325,20 @@ public class DeftSystemTest {
         HttpResponse response = httpclient.execute(httppost);
 
         assertNotNull(response);
-        assertEquals(200, response.getStatusLine().getStatusCode());
+        assertEquals(HttpStatus.SUCCESS_OK.code(), response.getStatusLine().getStatusCode());
         assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
         assertEquals("OK", response.getStatusLine().getReasonPhrase());
+
         String payLoad = convertStreamToString(response.getEntity().getContent()).trim();
         assertEquals("post", payLoad);
     }
 
     @Test
     public void putTest() throws ClientProtocolException, IOException {
+
         List<Header> headers = new LinkedList<Header>();
         headers.add(new BasicHeader("Connection", "Close"));
+
         HttpParams params = new BasicHttpParams();
         params.setParameter("http.default-headers", headers);
 
@@ -562,17 +347,20 @@ public class DeftSystemTest {
         HttpResponse response = httpclient.execute(httpput);
 
         assertNotNull(response);
-        assertEquals(200, response.getStatusLine().getStatusCode());
+        assertEquals(HttpStatus.SUCCESS_OK.code(), response.getStatusLine().getStatusCode());
         assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
         assertEquals("OK", response.getStatusLine().getReasonPhrase());
+
         String payLoad = convertStreamToString(response.getEntity().getContent()).trim();
         assertEquals("put", payLoad);
     }
 
     @Test
     public void capturingTest() throws ClientProtocolException, IOException {
+
         List<Header> headers = new LinkedList<Header>();
         headers.add(new BasicHeader("Connection", "Close"));
+
         HttpParams params = new BasicHttpParams();
         params.setParameter("http.default-headers", headers);
 
@@ -581,17 +369,20 @@ public class DeftSystemTest {
         HttpResponse response = httpclient.execute(httpget);
 
         assertNotNull(response);
-        assertEquals(200, response.getStatusLine().getStatusCode());
+        assertEquals(HttpStatus.SUCCESS_OK.code(), response.getStatusLine().getStatusCode());
         assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
         assertEquals("OK", response.getStatusLine().getReasonPhrase());
+
         String payLoad = convertStreamToString(response.getEntity().getContent()).trim();
         assertEquals("/capturing/1911", payLoad);
     }
 
     @Test
     public void erroneousCapturingTest() throws ClientProtocolException, IOException {
+
         List<Header> headers = new LinkedList<Header>();
         headers.add(new BasicHeader("Connection", "Close"));
+
         HttpParams params = new BasicHttpParams();
         params.setParameter("http.default-headers", headers);
 
@@ -600,15 +391,17 @@ public class DeftSystemTest {
         HttpResponse response = httpclient.execute(httpget);
 
         assertNotNull(response);
-        assertEquals(404, response.getStatusLine().getStatusCode());
+        assertEquals(HttpStatus.CLIENT_ERROR_NOT_FOUND.code(), response.getStatusLine().getStatusCode());
         assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
         assertEquals("Not Found", response.getStatusLine().getReasonPhrase());
+
         String payLoad = convertStreamToString(response.getEntity().getContent()).trim();
         assertEquals("Requested URL: /capturing/r1911 was not found", payLoad);
     }
 
     @Test
     public void simpleConcurrentGetRequestTest() {
+
         int nThreads = 8;
         int nRequests = 2048;
         final CountDownLatch latch = new CountDownLatch(nRequests);
@@ -641,6 +434,7 @@ public class DeftSystemTest {
 
     @Test
     public void keepAliveRequestTest() throws ClientProtocolException, IOException {
+
         List<Header> headers = new LinkedList<Header>();
         headers.add(new BasicHeader("Connection", "Keep-Alive"));
         HttpParams params = new BasicHttpParams();
@@ -654,20 +448,23 @@ public class DeftSystemTest {
     }
 
     private void doKeepAliveRequestTest(DefaultHttpClient httpclient) throws IOException, ClientProtocolException {
+
         HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/");
         HttpResponse response = httpclient.execute(httpget);
 
         assertNotNull(response);
-        assertEquals(200, response.getStatusLine().getStatusCode());
+        assertEquals(HttpStatus.SUCCESS_OK.code(), response.getStatusLine().getStatusCode());
         assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
         assertEquals("OK", response.getStatusLine().getReasonPhrase());
         assertEquals(5, response.getAllHeaders().length);
+
         String payLoad = convertStreamToString(response.getEntity().getContent()).trim();
         assertEquals(expectedPayload, payLoad);
     }
 
     @Test
     public void HTTP_1_0_noConnectionHeaderTest() throws ClientProtocolException, IOException {
+
         HttpParams params = new BasicHttpParams();
         HttpProtocolParams.setVersion(params, new ProtocolVersion("HTTP", 1, 0));
         DefaultHttpClient httpclient = new DefaultHttpClient();
@@ -675,67 +472,75 @@ public class DeftSystemTest {
         HttpResponse response = httpclient.execute(httpget);
 
         assertNotNull(response);
-        assertEquals(200, response.getStatusLine().getStatusCode());
+        assertEquals(HttpStatus.SUCCESS_OK.code(), response.getStatusLine().getStatusCode());
         assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
         assertEquals("OK", response.getStatusLine().getReasonPhrase());
         assertEquals(5, response.getAllHeaders().length);
+
         String payLoad = convertStreamToString(response.getEntity().getContent()).trim();
         assertEquals(expectedPayload, payLoad);
     }
 
     @Test
     public void httpExceptionTest() throws ClientProtocolException, IOException {
+
         DefaultHttpClient httpclient = new DefaultHttpClient();
         HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/throw");
         HttpResponse response = httpclient.execute(httpget);
 
         assertNotNull(response);
-        assertEquals(500, response.getStatusLine().getStatusCode());
+        assertEquals(HttpStatus.SERVER_ERROR_INTERNAL_SERVER_ERROR.code(), response.getStatusLine().getStatusCode());
         assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
         assertEquals("Internal Server Error", response.getStatusLine().getReasonPhrase());
         assertEquals(5, response.getAllHeaders().length);
+
         String payLoad = convertStreamToString(response.getEntity().getContent()).trim();
         assertEquals("exception message", payLoad);
     }
 
     @Test
     public void asyncHttpExceptionTest() throws ClientProtocolException, IOException {
+
         DefaultHttpClient httpclient = new DefaultHttpClient();
         HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/async_throw");
         HttpResponse response = httpclient.execute(httpget);
 
         assertNotNull(response);
-        assertEquals(500, response.getStatusLine().getStatusCode());
+        assertEquals(HttpStatus.SERVER_ERROR_INTERNAL_SERVER_ERROR.code(), response.getStatusLine().getStatusCode());
         assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
         assertEquals("Internal Server Error", response.getStatusLine().getReasonPhrase());
         assertEquals(5, response.getAllHeaders().length);
+
         String payLoad = convertStreamToString(response.getEntity().getContent()).trim();
         assertEquals("exception message", payLoad);
     }
 
     @Test
     public void staticFileRequestTest() throws ClientProtocolException, IOException {
+
         DefaultHttpClient httpclient = new DefaultHttpClient();
         HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/src/test/resources/test.txt");
         HttpResponse response = httpclient.execute(httpget);
 
         assertNotNull(response);
-        assertEquals(200, response.getStatusLine().getStatusCode());
+        assertEquals(HttpStatus.SUCCESS_OK.code(), response.getStatusLine().getStatusCode());
         assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
         assertEquals("OK", response.getStatusLine().getReasonPhrase());
         assertEquals(7, response.getAllHeaders().length);
+
         String payLoad = convertStreamToString(response.getEntity().getContent()).trim();
         assertEquals("test.txt", payLoad);
     }
 
     @Test
     public void pictureStaticFileRequestTest() throws ClientProtocolException, IOException {
+
         DefaultHttpClient httpclient = new DefaultHttpClient();
         HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/src/test/resources/n792205362_2067.jpg");
         HttpResponse response = httpclient.execute(httpget);
 
         assertNotNull(response);
-        assertEquals(200, response.getStatusLine().getStatusCode());
+        assertEquals(HttpStatus.SUCCESS_OK.code(), response.getStatusLine().getStatusCode());
         assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
         assertEquals("OK", response.getStatusLine().getReasonPhrase());
         assertEquals(7, response.getAllHeaders().length);
@@ -746,12 +551,13 @@ public class DeftSystemTest {
 
     @Test
     public void pictureStaticLargeFileRequestTest() throws ClientProtocolException, IOException {
+
         DefaultHttpClient httpclient = new DefaultHttpClient();
         HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/src/test/resources/f4_impact_1_original.jpg");
         HttpResponse response = httpclient.execute(httpget);
 
         assertNotNull(response);
-        assertEquals(200, response.getStatusLine().getStatusCode());
+        assertEquals(HttpStatus.SUCCESS_OK.code(), response.getStatusLine().getStatusCode());
         assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
         assertEquals("OK", response.getStatusLine().getReasonPhrase());
         assertEquals(7, response.getAllHeaders().length);
@@ -766,12 +572,13 @@ public class DeftSystemTest {
 
     @Test
     public void noBodyRequest() throws ClientProtocolException, IOException {
+
         HttpClient httpclient = new DefaultHttpClient();
         HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/no_body");
         HttpResponse response = httpclient.execute(httpget);
         List<String> expectedHeaders = Arrays.asList(new String[] { "Server", "Date", "Content-Length", "Connection" });
 
-        assertEquals(200, response.getStatusLine().getStatusCode());
+        assertEquals(HttpStatus.SUCCESS_OK.code(), response.getStatusLine().getStatusCode());
         assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
         assertEquals("OK", response.getStatusLine().getReasonPhrase());
 
@@ -787,13 +594,14 @@ public class DeftSystemTest {
 
     @Test
     public void movedPermanentlyRequest() throws ClientProtocolException, IOException {
+
         HttpClient httpclient = new DefaultHttpClient();
         HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/moved_perm");
         HttpResponse response = httpclient.execute(httpget);
         List<String> expectedHeaders = Arrays.asList(new String[] { "Server", "Date", "Content-Length", "Connection",
                 "Etag" });
 
-        assertEquals(200, response.getStatusLine().getStatusCode());
+        assertEquals(HttpStatus.SUCCESS_OK.code(), response.getStatusLine().getStatusCode());
         assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
         assertEquals("OK", response.getStatusLine().getReasonPhrase());
 
@@ -809,6 +617,7 @@ public class DeftSystemTest {
 
     @Test
     public void sendGarbageTest() throws IOException {
+
         InetSocketAddress socketAddress = new InetSocketAddress(PORT);
         SocketChannel channel = SocketChannel.open(socketAddress);
         channel.write(ByteBuffer.wrap(new byte[] { 1, 1, 1, 1 } // garbage
@@ -818,13 +627,13 @@ public class DeftSystemTest {
 
     @Test
     public void userDefinedStaticContentHandlerTest() throws ClientProtocolException, IOException {
-        // /static_file_handler
+
         DefaultHttpClient httpclient = new DefaultHttpClient();
         HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/static_file_handler");
         HttpResponse response = httpclient.execute(httpget);
 
         assertNotNull(response);
-        assertEquals(200, response.getStatusLine().getStatusCode());
+        assertEquals(HttpStatus.SUCCESS_OK.code(), response.getStatusLine().getStatusCode());
         assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
         assertEquals("OK", response.getStatusLine().getReasonPhrase());
         assertEquals(4, response.getAllHeaders().length);
@@ -833,6 +642,7 @@ public class DeftSystemTest {
 
     @Test
     public void timeoutTest() throws InterruptedException {
+
         long now = System.currentTimeMillis();
         final CountDownLatch latch = new CountDownLatch(5);
         final AsyncCallback cb = new AsyncCallback() {
@@ -882,12 +692,13 @@ public class DeftSystemTest {
 
     @Test
     public void keyValueStoreClientTest() throws ClientProtocolException, IOException {
+
         DefaultHttpClient httpclient = new DefaultHttpClient();
         HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/keyvalue");
         HttpResponse response = httpclient.execute(httpget);
 
         assertNotNull(response);
-        assertEquals(200, response.getStatusLine().getStatusCode());
+        assertEquals(HttpStatus.SUCCESS_OK.code(), response.getStatusLine().getStatusCode());
         assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
         assertEquals("OK", response.getStatusLine().getReasonPhrase());
         assertEquals(5, response.getAllHeaders().length);
@@ -898,6 +709,7 @@ public class DeftSystemTest {
     // ning === http://github.com/ning/async-http-client
     @Test
     public void doSimpleAsyncRequestTestWithNing() throws IOException, InterruptedException {
+
         int iterations = 100;
         final CountDownLatch latch = new CountDownLatch(iterations);
         AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
@@ -914,7 +726,7 @@ public class DeftSystemTest {
                             {
                                 List<String> expectedHeaders = Arrays.asList(new String[] { "Server", "Date",
                                         "Content-Length", "Etag", "Connection" });
-                                assertEquals(200, response.getStatusCode());
+                                assertEquals(HttpStatus.SUCCESS_OK.code(), response.getStatusCode());
                                 assertEquals(expectedHeaders.size(), response.getHeaders().size());
                                 for (String header : expectedHeaders) {
                                     assertTrue(response.getHeader(header) != null);
@@ -982,12 +794,13 @@ public class DeftSystemTest {
 
     @Test
     public void _450KBEntityTest() throws ClientProtocolException, IOException {
+
         DefaultHttpClient httpclient = new DefaultHttpClient();
         HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/450kb_body");
         HttpResponse response = httpclient.execute(httpget);
 
         assertNotNull(response);
-        assertEquals(200, response.getStatusLine().getStatusCode());
+        assertEquals(HttpStatus.SUCCESS_OK.code(), response.getStatusLine().getStatusCode());
         assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
         assertEquals("OK", response.getStatusLine().getReasonPhrase());
         assertEquals(5, response.getAllHeaders().length);
@@ -1001,6 +814,7 @@ public class DeftSystemTest {
 
     @Test
     public void smallHttpPostBodyWithUnusualCharactersTest() throws ClientProtocolException, IOException {
+
         final String body = "Räger Schildmäijår";
 
         DefaultHttpClient httpclient = new DefaultHttpClient();
@@ -1011,7 +825,7 @@ public class DeftSystemTest {
         HttpResponse response = httpclient.execute(httppost);
 
         assertNotNull(response);
-        assertEquals(200, response.getStatusLine().getStatusCode());
+        assertEquals(HttpStatus.SUCCESS_OK.code(), response.getStatusLine().getStatusCode());
         assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
         assertEquals("OK", response.getStatusLine().getReasonPhrase());
         assertEquals(5, response.getAllHeaders().length);
@@ -1021,6 +835,7 @@ public class DeftSystemTest {
 
     @Test
     public void smallHttpPostBodyTest() throws ClientProtocolException, IOException, InterruptedException {
+
         final String body = "Roger Schildmeijer";
         final CountDownLatch latch = new CountDownLatch(1);
         AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
@@ -1030,7 +845,7 @@ public class DeftSystemTest {
                     @Override
                     public Response onCompleted(Response response) throws Exception {
                         assertNotNull(response);
-                        assertEquals(200, response.getStatusCode());
+                        assertEquals(HttpStatus.SUCCESS_OK.code(), response.getStatusCode());
                         assertEquals("OK", response.getStatusText());
                         assertEquals(5, response.getHeaders().size());
                         String payLoad = response.getResponseBody();
@@ -1050,6 +865,7 @@ public class DeftSystemTest {
 
     @Test
     public void largeHttpPostBodyTest() throws ClientProtocolException, IOException, InterruptedException {
+
         String body = "Roger Schildmeijer: 0\n";
         for (int i = 1; i <= 1000; i++) {
             body += "Roger Schildmeijer: " + i + "\n";
@@ -1063,7 +879,7 @@ public class DeftSystemTest {
                     @Override
                     public Response onCompleted(Response response) throws Exception {
                         assertNotNull(response);
-                        assertEquals(200, response.getStatusCode());
+                        assertEquals(HttpStatus.SUCCESS_OK.code(), response.getStatusCode());
                         assertEquals("OK", response.getStatusText());
                         assertEquals(5, response.getHeaders().size());
                         String payLoad = response.getResponseBody();
@@ -1083,13 +899,14 @@ public class DeftSystemTest {
 
     @Test
     public void authenticatedRequestHandlerTest() throws ClientProtocolException, IOException {
+
         DefaultHttpClient httpclient = new DefaultHttpClient();
         HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/authenticated");
         httpget.setHeader("user", "Roger Schildmeijer");
         HttpResponse response = httpclient.execute(httpget);
 
         assertNotNull(response);
-        assertEquals(200, response.getStatusLine().getStatusCode());
+        assertEquals(HttpStatus.SUCCESS_OK.code(), response.getStatusLine().getStatusCode());
         assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
         assertEquals("OK", response.getStatusLine().getReasonPhrase());
         assertEquals(5, response.getAllHeaders().length);
@@ -1099,13 +916,14 @@ public class DeftSystemTest {
 
     @Test
     public void notAuthenticatedRequestHandlerTest() throws ClientProtocolException, IOException {
+
         DefaultHttpClient httpclient = new DefaultHttpClient();
         HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/authenticated");
         httpget.setHeader("wrong_header", "Roger Schildmeijer");
         HttpResponse response = httpclient.execute(httpget);
 
         assertNotNull(response);
-        assertEquals(403, response.getStatusLine().getStatusCode());
+        assertEquals(HttpStatus.CLIENT_ERROR_FORBIDDEN.code(), response.getStatusLine().getStatusCode());
         assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
         assertEquals("Forbidden", response.getStatusLine().getReasonPhrase());
         assertEquals(5, response.getAllHeaders().length);
@@ -1115,13 +933,14 @@ public class DeftSystemTest {
 
     @Test
     public void queryParamsTest() throws ClientProtocolException, IOException {
+
         HttpClient httpclient = new DefaultHttpClient();
         HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/query_params?key1=value1&key2=value2");
         HttpResponse response = httpclient.execute(httpget);
         List<String> expectedHeaders = Arrays.asList(new String[] { "Server", "Date", "Content-Length", "Etag",
                 "Connection" });
 
-        assertEquals(200, response.getStatusLine().getStatusCode());
+        assertEquals(HttpStatus.SUCCESS_OK.code(), response.getStatusLine().getStatusCode());
         assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
         assertEquals("OK", response.getStatusLine().getReasonPhrase());
 
@@ -1138,7 +957,11 @@ public class DeftSystemTest {
 
     @Test
     public void multipleStartStopCombinations() throws InterruptedException {
-        final HttpServer server = new HttpServer(new Configuration());
+
+        Configuration configuration = new Configuration();
+        configuration.setHandlerPackage(DeftSystemTest.class.getPackage().getName());
+
+        final HttpServer server = new HttpServer(configuration);
 
         final int n = 10;
         final CountDownLatch latch = new CountDownLatch(n);
@@ -1161,6 +984,7 @@ public class DeftSystemTest {
 
     @Test
     public void connectToUnresolvableAddressUsingAsynchronousHttpClient() throws InterruptedException {
+
         final String unresolvableAddress = "http://ttasfdqwertyuiop.se./start";
         final CountDownLatch latch = new CountDownLatch(1);
         final AsynchronousHttpClient client = new AsynchronousHttpClient();
@@ -1190,6 +1014,7 @@ public class DeftSystemTest {
 
     @Test
     public void connectToUnconnectableAddressUsingAsynchronousHttpClient() throws InterruptedException {
+
         final String unconnectableAddress = "http://localhost:8039/start";
         final CountDownLatch latch = new CountDownLatch(1);
         final AsynchronousHttpClient client = new AsynchronousHttpClient();
@@ -1219,6 +1044,7 @@ public class DeftSystemTest {
 
     @Test
     public void multipleAsynchronousHttpClientTest() throws InterruptedException {
+
         for (int i = 0; i < 100; i++) {
             final CountDownLatch latch = new CountDownLatch(1);
             final String url = "http://localhost:" + PORT + "/";
@@ -1251,6 +1077,7 @@ public class DeftSystemTest {
 
     @Test
     public void AsynchronousHttpClientConnectionFailedTest() throws InterruptedException {
+
         final CountDownLatch latch = new CountDownLatch(1);
         final String url = "http://localhost:" + (PORT + 1) + "/";
         final AsynchronousHttpClient http = new AsynchronousHttpClient();
@@ -1277,6 +1104,7 @@ public class DeftSystemTest {
 
     @Test
     public void AsynchronousHttpClientRedirectTest() throws InterruptedException {
+
         final CountDownLatch latch = new CountDownLatch(1);
         // final String url = "http://localhost:" + (PORT) + "/moved_perm";
         final String url = "http://localhost:" + PORT + "/moved_perm";
@@ -1305,6 +1133,7 @@ public class DeftSystemTest {
 
     @Test
     public void asynchronousHttpClientTransferEncodingChunkedTest() throws InterruptedException {
+
         final CountDownLatch latch = new CountDownLatch(1);
         final String url = "http://localhost:" + PORT + "/chunked";
         final AsynchronousHttpClient http = new AsynchronousHttpClient();
@@ -1330,7 +1159,36 @@ public class DeftSystemTest {
         assertEquals(0, latch.getCount());
     }
 
+    private void doSimpleGetRequest() throws ClientProtocolException, IOException {
+
+        List<Header> headers = new LinkedList<Header>();
+        headers.add(new BasicHeader("Connection", "Close"));
+
+        HttpParams params = new BasicHttpParams();
+        params.setParameter("http.default-headers", headers);
+
+        HttpClient httpclient = new DefaultHttpClient(params);
+        HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/");
+        HttpResponse response = httpclient.execute(httpget);
+        List<String> expectedHeaders = Arrays.asList(new String[] { "Server", "Date", "Content-Length", "Etag",
+                "Connection" });
+
+        assertEquals(HttpStatus.SUCCESS_OK.code(), response.getStatusLine().getStatusCode());
+        assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
+        assertEquals("OK", response.getStatusLine().getReasonPhrase());
+
+        assertEquals(expectedHeaders.size(), response.getAllHeaders().length);
+
+        for (String header : expectedHeaders) {
+            assertTrue(response.getFirstHeader(header) != null);
+        }
+
+        assertEquals(expectedPayload, convertStreamToString(response.getEntity().getContent()).trim());
+        assertEquals(expectedPayload.length() + "", response.getFirstHeader("Content-Length").getValue());
+    }
+
     private String convertStreamToString(InputStream is) throws IOException {
+
         if (is != null) {
             StringBuilder sb = new StringBuilder();
             String line;
@@ -1343,10 +1201,10 @@ public class DeftSystemTest {
             } finally {
                 is.close();
             }
+
             return sb.toString();
-        } else {
-            return "";
         }
-    }
 
+        return "";
+    }
 }

Added: incubator/deft/sandbox/src/test/java/org/apache/deft/web/DeftSystemTestHandlers.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/test/java/org/apache/deft/web/DeftSystemTestHandlers.java?rev=1159923&view=auto
==============================================================================
--- incubator/deft/sandbox/src/test/java/org/apache/deft/web/DeftSystemTestHandlers.java (added)
+++ incubator/deft/sandbox/src/test/java/org/apache/deft/web/DeftSystemTestHandlers.java Sat Aug 20 23:15:10 2011
@@ -0,0 +1,271 @@
+/*
+ *  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.deft.web;
+
+import java.io.File;
+
+import org.apache.deft.annotation.Asynchronous;
+import org.apache.deft.annotation.Authenticated;
+import org.apache.deft.example.keyvalue.KeyValueStore;
+import org.apache.deft.example.keyvalue.KeyValueStoreClient;
+import org.apache.deft.web.handler.RequestHandler;
+import org.apache.deft.web.http.HttpException;
+import org.apache.deft.web.http.HttpRequest;
+import org.apache.deft.web.http.protocol.HttpStatus;
+
+/**
+ * A collection of <code>RequestHandler</code>s used by
+ * <code>DeftSystemTest</code>.
+ */
+public class DeftSystemTestHandlers {
+
+    public static final String expectedPayload = "hello test";
+
+    public static class ExampleRequestHandler extends RequestHandler {
+        @Override
+        public void get(org.apache.deft.web.http.HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
+            response.write(expectedPayload);
+        }
+    }
+
+    public static class WRequestHandler extends RequestHandler {
+        @Override
+        public void get(org.apache.deft.web.http.HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
+            response.write("1");
+        }
+    }
+
+    public static class WWRequestHandler extends RequestHandler {
+        @Override
+        public void get(org.apache.deft.web.http.HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
+            response.write("1");
+            response.write("2");
+        }
+    }
+
+    public static class WWFWRequestHandler extends RequestHandler {
+        @Override
+        public void get(org.apache.deft.web.http.HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
+            response.write("1");
+            response.write("2");
+            response.flush();
+            response.write("3");
+        }
+    }
+
+    public static class WFWFRequestHandler extends RequestHandler {
+        @Override
+        public void get(org.apache.deft.web.http.HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
+            response.write("1");
+            response.flush();
+            response.write("2");
+            response.flush();
+        }
+    }
+
+    public static class WFFFWFFFRequestHandler extends RequestHandler {
+        @Override
+        public void get(org.apache.deft.web.http.HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
+            response.write("1");
+            response.flush();
+            response.flush();
+            response.flush();
+            response.write("2");
+            response.flush();
+            response.flush();
+            response.flush();
+        }
+    }
+
+    public static class DeleteRequestHandler extends RequestHandler {
+        @Override
+        public void delete(org.apache.deft.web.http.HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
+            response.write("del");
+            response.flush();
+            response.write("ete");
+            response.flush();
+        }
+    }
+
+    public static class PostRequestHandler extends RequestHandler {
+        @Override
+        public void post(org.apache.deft.web.http.HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
+            response.write("po");
+            response.flush();
+            response.write("st");
+            response.flush();
+        }
+    }
+
+    public static class PutRequestHandler extends RequestHandler {
+        @Override
+        public void put(org.apache.deft.web.http.HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
+            response.write("p");
+            response.flush();
+            response.write("ut");
+            response.flush();
+        }
+    }
+
+    public static class CapturingRequestRequestHandler extends RequestHandler {
+        @Override
+        public void get(org.apache.deft.web.http.HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
+            response.write(request.getRequestedPath());
+        }
+    }
+
+    public static class ThrowingHttpExceptionRequestHandler extends RequestHandler {
+        @Override
+        public void get(org.apache.deft.web.http.HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
+            throw new HttpException(HttpStatus.SERVER_ERROR_INTERNAL_SERVER_ERROR, "exception message");
+        }
+    }
+
+    public static class AsyncThrowingHttpExceptionRequestHandler extends RequestHandler {
+        @Asynchronous
+        @Override
+        public void get(org.apache.deft.web.http.HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
+            throw new HttpException(HttpStatus.SERVER_ERROR_INTERNAL_SERVER_ERROR, "exception message");
+        }
+    }
+
+    public static class NoBodyRequestHandler extends RequestHandler {
+        @Override
+        public void get(HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
+            response.setStatus(HttpStatus.SUCCESS_OK);
+        }
+    }
+
+    public static class MovedPermanentlyRequestHandler extends RequestHandler {
+        @Override
+        public void get(HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
+            response.setStatus(HttpStatus.REDIRECTION_MOVED_PERMANENTLY);
+            response.setHeader("Location", "/");
+        }
+    }
+
+    public static class UserDefinedStaticContentHandler extends RequestHandler {
+        @Override
+        public void get(HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
+            response.write(new File("src/test/resources/test.txt"));
+        }
+    }
+
+    public static class KeyValueStoreExampleRequestHandler extends RequestHandler {
+
+        public final KeyValueStoreClient client = new KeyValueStoreClient(KeyValueStore.HOST, KeyValueStore.PORT);
+
+        public KeyValueStoreExampleRequestHandler() {
+            new KeyValueStore().start();
+            client.connect();
+        }
+
+        @Override
+        @Asynchronous
+        public void get(HttpRequest request, final org.apache.deft.web.http.HttpResponse response) {
+            client.get("deft", new AsyncResult<byte[]>() {
+                @Override
+                public void onFailure(Throwable caught) { /* ignore */
+                }
+
+                @Override
+                public void onSuccess(byte[] result) {
+                    response.write(new String(result)).finish();
+                }
+            });
+        }
+
+    }
+
+    public static class _450KBResponseEntityRequestHandler extends RequestHandler {
+        public static String entity;
+
+        static {
+            int iterations = 450 * 1024;
+            StringBuilder sb = new StringBuilder();
+            for (int i = 1; i <= iterations; i++) {
+                sb.append("a");
+            }
+            entity = sb.toString();
+        }
+
+        @Override
+        public void get(HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
+            response.write(entity);
+        }
+    }
+
+    public static class EchoingPostBodyRequestHandler extends RequestHandler {
+        @Override
+        public void post(HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
+            response.write(request.getBody());
+        }
+    }
+
+    public static class AuthenticatedRequestHandler extends RequestHandler {
+        @Override
+        @Authenticated
+        public void get(HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
+            response.write(request.getHeader("user"));
+        }
+
+        @Override
+        public String getCurrentUser(HttpRequest request) {
+            return request.getHeader("user");
+        }
+    }
+
+    public static class QueryParamsRequestHandler extends RequestHandler {
+        @Override
+        public void get(HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
+            response.write(request.getParameter("key1") + " " + request.getParameter("key2"));
+        }
+    }
+
+    public static class ChunkedRequestHandler extends RequestHandler {
+        @Override
+        public void get(HttpRequest request, org.apache.deft.web.http.HttpResponse response) {
+            response.setHeader("Transfer-Encoding", "chunked");
+            sleep(300);
+
+            response.write("1\r\n");
+            response.write("a\r\n").flush();
+            sleep(300);
+
+            response.write("5\r\n");
+            response.write("roger\r\n").flush();
+            sleep(300);
+
+            response.write("2\r\n");
+            response.write("ab\r\n").flush();
+            sleep(300);
+
+            response.write("0\r\n");
+            response.write("\r\n");
+        }
+
+        public static void sleep(long ms) {
+            try {
+                Thread.sleep(ms);
+            } catch (InterruptedException ignore) { /* nop */
+            }
+        }
+    }
+}

Propchange: incubator/deft/sandbox/src/test/java/org/apache/deft/web/DeftSystemTestHandlers.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/deft/sandbox/src/test/java/org/apache/deft/web/HttpServerTest.java
URL: http://svn.apache.org/viewvc/incubator/deft/sandbox/src/test/java/org/apache/deft/web/HttpServerTest.java?rev=1159923&r1=1159922&r2=1159923&view=diff
==============================================================================
--- incubator/deft/sandbox/src/test/java/org/apache/deft/web/HttpServerTest.java (original)
+++ incubator/deft/sandbox/src/test/java/org/apache/deft/web/HttpServerTest.java Sat Aug 20 23:15:10 2011
@@ -30,8 +30,6 @@ import com.google.common.collect.Maps;
  */
 public class HttpServerTest {
 
-    private final Application application = new Application(Maps.<String, RequestHandler> newHashMap());
-
     @Test(expected = IllegalArgumentException.class)
     public void testPortInRange_low() {
         int port = 0;
@@ -48,7 +46,7 @@ public class HttpServerTest {
 
     @Test
     public void testPortInRange_ok() {
-        int port = 34;
+        int port = 8084;
         HttpServer server = createServer();
         server.listen(port);
     }
@@ -58,7 +56,7 @@ public class HttpServerTest {
         HttpServer server = new HttpServer(new Configuration()) {
             @Override
             protected Application createApplication(String packageName) {
-                return application;
+                return new Application(Maps.<String, RequestHandler> newHashMap());
             }
         };
 



Mime
View raw message