[logback-dev] svn commit: r1612 - logback/trunk/logback-access/src/test/java/ch/qos/logback/access/jetty

noreply.ceki at qos.ch noreply.ceki at qos.ch
Fri Jan 25 18:13:41 CET 2008


Author: ceki
Date: Fri Jan 25 18:13:41 2008
New Revision: 1612

Added:
   logback/trunk/logback-access/src/test/java/ch/qos/logback/access/jetty/JettyFixture.java
      - copied, changed from r1608, /logback/trunk/logback-access/src/test/java/ch/qos/logback/access/jetty/JettyTestSetup.java
Removed:
   logback/trunk/logback-access/src/test/java/ch/qos/logback/access/jetty/JettyTestSetup.java
Modified:
   logback/trunk/logback-access/src/test/java/ch/qos/logback/access/jetty/JettyBasicTest.java
   logback/trunk/logback-access/src/test/java/ch/qos/logback/access/jetty/PackageTest.java

Log:
- ongoing work

Modified: logback/trunk/logback-access/src/test/java/ch/qos/logback/access/jetty/JettyBasicTest.java
==============================================================================
--- logback/trunk/logback-access/src/test/java/ch/qos/logback/access/jetty/JettyBasicTest.java	(original)
+++ logback/trunk/logback-access/src/test/java/ch/qos/logback/access/jetty/JettyBasicTest.java	Fri Jan 25 18:13:41 2008
@@ -1,41 +1,58 @@
 package ch.qos.logback.access.jetty;
 
+import static org.junit.Assert.assertEquals;
+
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
 import java.net.HttpURLConnection;
 import java.net.URL;
 
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
 import ch.qos.logback.access.spi.AccessEvent;
 import ch.qos.logback.access.spi.Util;
 import ch.qos.logback.core.read.ListAppender;
 
-public class JettyBasicTest extends TestCase {
+public class JettyBasicTest  {
 
   static RequestLogImpl requestLogImpl;
-
-  public static Test suite() {
-    TestSuite suite = new TestSuite();
-    suite.addTestSuite(JettyBasicTest.class);
+  static JettyFixture fixture;
+  
+  @BeforeClass
+  static public void startServer() throws Exception {
+    System.out.println("*** JettyBasicTest.startServer called");
     requestLogImpl = new RequestLogImpl();
-    return new JettyTestSetup(suite, requestLogImpl);
+    JettyFixture fixture = new JettyFixture(requestLogImpl);
+    fixture.start();
   }
-
+  
+  @AfterClass
+  static  public void stopServer() throws Exception {
+    System.out.println("*** JettyBasicTest.stopServer called");
+    if(fixture != null) {
+      fixture.stop();
+    }
+  }
+  
+  @Test
   public void testGetRequest() throws Exception {
-    URL url = new URL("http://localhost:"+ JettyTestSetup.PORT + "/");
+    URL url = new URL("http://localhost:"+ JettyFixture.PORT + "/");
     HttpURLConnection connection = (HttpURLConnection) url.openConnection();
     connection.setDoInput(true);
 
     String result = Util.readToString(connection.getInputStream());
 
-    assertEquals("hello world", result);
+    assertEquals("hello world", result); 
 
     ListAppender appender = (ListAppender) requestLogImpl.getAppender("list");
     appender.list.clear();
   }
 
+  @Test
   public void testEventGoesToAppenders() throws Exception {
-    URL url = new URL("http://localhost:"+ JettyTestSetup.PORT + "/");
+    URL url = new URL("http://localhost:"+ JettyFixture.PORT + "/");
     HttpURLConnection connection = (HttpURLConnection) url.openConnection();
     connection.setDoInput(true);
 
@@ -50,33 +67,37 @@
     appender.list.clear();
   }
 
-//  public void testPostContentConverter() throws Exception {
-//    //System.out.println("into test");
-//    URL url = new URL("http://localhost:8080/");
-//    String msg = "test message";
-//    
-//    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
-//    //this line is necessary to make the stream aware of when the message is over.
-//    connection.setFixedLengthStreamingMode(msg.getBytes().length);
-//    ((HttpURLConnection) connection).setRequestMethod("POST");
-//    connection.setDoOutput(true);
-//    connection.setDoInput(true);
-//    connection.setUseCaches(false);
-//    connection.setRequestProperty("Content-Type", "text/plain");
-//
-//   
-//    PrintWriter output = new PrintWriter(new OutputStreamWriter(connection
-//        .getOutputStream()));
-//    output.print(msg);
-//    output.flush();
-//    output.close();
-//
-//    // StatusPrinter.print(requestLogImpl.getStatusManager());
-//
-//    ListAppender listAppender = (ListAppender) requestLogImpl
-//        .getAppender("list");
-//    Thread.sleep(100);
-//    AccessEvent event = (AccessEvent) listAppender.list.get(0);
-//    assertEquals(msg, event.getPostContent());
-//  }
+  @Test
+  public void testPostContentConverter() throws Exception {
+    //System.out.println("into test");
+    URL url = new URL("http://localhost:"+ JettyFixture.PORT + "/");
+    String msg = "test message";
+    
+    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+    //this line is necessary to make the stream aware of when the message is over.
+    connection.setFixedLengthStreamingMode(msg.getBytes().length);
+    ((HttpURLConnection) connection).setRequestMethod("POST");
+    connection.setDoOutput(true);
+    connection.setDoInput(true);
+    connection.setUseCaches(false);
+    connection.setRequestProperty("Content-Type", "text/plain");
+
+   
+    PrintWriter output = new PrintWriter(new OutputStreamWriter(connection
+        .getOutputStream()));
+    output.print(msg);
+    output.flush();
+    output.close();
+
+    // StatusPrinter.print(requestLogImpl.getStatusManager());
+
+    ListAppender listAppender = (ListAppender) requestLogImpl
+        .getAppender("list");
+    Thread.sleep(100);
+    @SuppressWarnings("unused")
+    AccessEvent event = (AccessEvent) listAppender.list.get(0);
+    
+    // we should test the contents of the requests
+    // assertEquals(msg, event.getRequestContent());
+  }
 }

Copied: logback/trunk/logback-access/src/test/java/ch/qos/logback/access/jetty/JettyFixture.java (from r1608, /logback/trunk/logback-access/src/test/java/ch/qos/logback/access/jetty/JettyTestSetup.java)
==============================================================================
--- /logback/trunk/logback-access/src/test/java/ch/qos/logback/access/jetty/JettyTestSetup.java	(original)
+++ logback/trunk/logback-access/src/test/java/ch/qos/logback/access/jetty/JettyFixture.java	Fri Jan 25 18:13:41 2008
@@ -7,9 +7,6 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import junit.extensions.TestSetup;
-import junit.framework.Test;
-
 import org.mortbay.jetty.Connector;
 import org.mortbay.jetty.Handler;
 import org.mortbay.jetty.HttpConnection;
@@ -26,13 +23,12 @@
 import ch.qos.logback.core.ConsoleAppender;
 import ch.qos.logback.core.read.ListAppender;
 
-public class JettyTestSetup extends TestSetup {
+public class JettyFixture {
   RequestLogImpl requestLogImpl;
 
   public static final int PORT = 1234;
   
-  public JettyTestSetup(Test suite, RequestLogImpl impl) {
-    super(suite);
+  public JettyFixture(RequestLogImpl impl) {
     requestLogImpl = impl;
   }
 
@@ -43,9 +39,8 @@
   Server server;
   String url = "http://localhost:" + PORT + "/";
 
-  public void setUp() throws Exception {
+  public void start() throws Exception {
     // System.out.println("into setUp");
-    super.setUp();
 
     server = new Server();
     Connector connector = new SelectChannelConnector();
@@ -71,9 +66,8 @@
     Thread.yield();
   }
 
-  public void tearDown() throws Exception {
+  public void stop() throws Exception {
     // System.out.println("into tearDown");
-    super.tearDown();
     server.stop();
     Thread.sleep(1000);
     server = null;

Modified: logback/trunk/logback-access/src/test/java/ch/qos/logback/access/jetty/PackageTest.java
==============================================================================
--- logback/trunk/logback-access/src/test/java/ch/qos/logback/access/jetty/PackageTest.java	(original)
+++ logback/trunk/logback-access/src/test/java/ch/qos/logback/access/jetty/PackageTest.java	Fri Jan 25 18:13:41 2008
@@ -16,7 +16,7 @@
 
   public static Test suite() {
     TestSuite suite = new TestSuite();
-    suite.addTest(JettyBasicTest.suite());
+    suite.addTest(new JUnit4TestAdapter(JettyBasicTest.class));
     return suite;
   }
 }
\ No newline at end of file



More information about the logback-dev mailing list