[logback-dev] svn commit: r1901 - in logback/trunk: logback-access/src/test/java/ch/qos/logback/access/db logback-classic/src/test/java/ch/qos/logback/classic/db

noreply.ceki at qos.ch noreply.ceki at qos.ch
Wed Oct 29 14:56:20 CET 2008


Author: ceki
Date: Wed Oct 29 14:56:19 2008
New Revision: 1901

Added:
   logback/trunk/logback-access/src/test/java/ch/qos/logback/access/db/DBAppenderTestFixture.java
      - copied, changed from r1874, /logback/trunk/logback-access/src/test/java/ch/qos/logback/access/db/DBAppenderTestInfrastructure.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderTestFixture.java
      - copied, changed from r1899, /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderTestBase.java
Removed:
   logback/trunk/logback-access/src/test/java/ch/qos/logback/access/db/DBAppenderTestInfrastructure.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderTestBase.java
Modified:
   logback/trunk/logback-access/src/test/java/ch/qos/logback/access/db/DBAppenderTest.java
   logback/trunk/logback-access/src/test/java/ch/qos/logback/access/db/PackageTest.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderTest.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/PackageTest.java

Log:
placing DBAppender fixture in a separate class. DBAppenderTest no longer extends the fixture.
This should make the code a somewhat clearer


Modified: logback/trunk/logback-access/src/test/java/ch/qos/logback/access/db/DBAppenderTest.java
==============================================================================
--- logback/trunk/logback-access/src/test/java/ch/qos/logback/access/db/DBAppenderTest.java	(original)
+++ logback/trunk/logback-access/src/test/java/ch/qos/logback/access/db/DBAppenderTest.java	Wed Oct 29 14:56:19 2008
@@ -1,29 +1,49 @@
 package ch.qos.logback.access.db;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
 import ch.qos.logback.access.dummy.DummyRequest;
 import ch.qos.logback.access.dummy.DummyResponse;
 import ch.qos.logback.access.dummy.DummyServerAdapter;
-import ch.qos.logback.access.spi.AccessEvent;
 import ch.qos.logback.access.spi.AccessContext;
+import ch.qos.logback.access.spi.AccessEvent;
 import ch.qos.logback.core.db.DriverManagerConnectionSource;
 import ch.qos.logback.core.util.StatusPrinter;
 
-public class DBAppenderTest extends DBAppenderTestInfrastructure {
+public class DBAppenderTest  {
 
   AccessContext context;
   DBAppender appender;
   DriverManagerConnectionSource connectionSource;
 
-  public DBAppenderTest(String name) {
-    super(name);
+  static DBAppenderTestFixture DB_APPENDER_TEST_FIXTURE;
+  
+  @BeforeClass
+  static public void fixtureSetUp() throws SQLException {
+    DB_APPENDER_TEST_FIXTURE = new DBAppenderTestFixture();
+    DB_APPENDER_TEST_FIXTURE.setUp();
+  } 
+  
+  @AfterClass
+  static public  void fixtureTearDown()  throws SQLException {
+    DB_APPENDER_TEST_FIXTURE.tearDown();
   }
-
+  
+  @Before
   public void setUp() throws SQLException {
-    super.setUp();
     context = new AccessContext();
     context.setName("default");
     appender = new DBAppender();
@@ -31,10 +51,10 @@
     appender.setContext(context);
     connectionSource = new DriverManagerConnectionSource();
     connectionSource.setContext(context);
-    connectionSource.setDriverClass(DRIVER_CLASS);
-    connectionSource.setUrl(url);
-    connectionSource.setUser(user);
-    connectionSource.setPassword(password);
+    connectionSource.setDriverClass(DBAppenderTestFixture.DRIVER_CLASS);
+    connectionSource.setUrl(DB_APPENDER_TEST_FIXTURE.url);
+    connectionSource.setUser(DB_APPENDER_TEST_FIXTURE.user);
+    connectionSource.setPassword(DB_APPENDER_TEST_FIXTURE.password);
     connectionSource.start();
     appender.setConnectionSource(connectionSource);
   }
@@ -44,13 +64,14 @@
     appender.start();
   }
 
+  @After
   public void tearDown() throws SQLException {
-    super.tearDown();
     context = null;
     appender = null;
     connectionSource = null;
   }
 
+  @Test
   public void testAppendAccessEvent() throws SQLException {
     setInsertHeadersAndStart(false);
 
@@ -80,6 +101,7 @@
   }
   
   
+  @Test
   public void testCheckNoHeadersAreInserted() throws Exception {
     setInsertHeadersAndStart(false);
     
@@ -97,6 +119,7 @@
     stmt.close();
   }
 
+  @Test
   public void testAppendHeaders() throws SQLException {   
     setInsertHeadersAndStart(true);
     
@@ -131,15 +154,17 @@
     stmt.close();
   }
 
+  @Test
   public void testAppendMultipleEvents() throws SQLException {
+    String uri = "testAppendMultipleEvents";
     for (int i = 0; i < 10; i++) {
-      AccessEvent event = createAccessEvent();
+      AccessEvent event = createAccessEvent(uri);
       appender.append(event);
     }
 
     Statement stmt = connectionSource.getConnection().createStatement();
     ResultSet rs = null;
-    rs = stmt.executeQuery("SELECT * FROM access_event");
+    rs = stmt.executeQuery("SELECT * FROM access_event where requestURI='"+uri+"'");
     int count = 0;
     while (rs.next()) {
       count++;
@@ -151,7 +176,12 @@
   }
 
   private AccessEvent createAccessEvent() {
+     return createAccessEvent(""); 
+  }
+  
+  private AccessEvent createAccessEvent(String uri) {
     DummyRequest request = new DummyRequest();
+    request.setRequestUri(uri);
     DummyResponse response = new DummyResponse();
     DummyServerAdapter adapter = new DummyServerAdapter(request, response);
 

Copied: logback/trunk/logback-access/src/test/java/ch/qos/logback/access/db/DBAppenderTestFixture.java (from r1874, /logback/trunk/logback-access/src/test/java/ch/qos/logback/access/db/DBAppenderTestInfrastructure.java)
==============================================================================
--- /logback/trunk/logback-access/src/test/java/ch/qos/logback/access/db/DBAppenderTestInfrastructure.java	(original)
+++ logback/trunk/logback-access/src/test/java/ch/qos/logback/access/db/DBAppenderTestFixture.java	Wed Oct 29 14:56:19 2008
@@ -5,11 +5,9 @@
 import java.sql.SQLException;
 import java.sql.Statement;
 
-import junit.framework.TestCase;
-
 import org.hsqldb.Server;
 
-public abstract class DBAppenderTestInfrastructure extends TestCase {
+public class DBAppenderTestFixture  {
 
   public static final String DRIVER_CLASS = "org.hsqldb.jdbcDriver";
   String serverProps;
@@ -19,11 +17,8 @@
   Server server;
   boolean isNetwork = true;
 
-  public DBAppenderTestInfrastructure(String name) {
-    super(name);
-  }
 
-  protected void setUp() throws SQLException {
+  void setUp() throws SQLException {
     if (isNetwork) {
       if (url == null) {
         url = "jdbc:hsqldb:hsql://localhost/test";
@@ -55,7 +50,7 @@
     createTables();
   }
 
-  protected void tearDown() throws SQLException {
+  void tearDown() throws SQLException {
     dropTables();
     if (isNetwork) {
       server.stop();
@@ -67,7 +62,7 @@
     return DriverManager.getConnection(url, user, password);
   }
 
-  void createTables() throws SQLException {
+  private void createTables() throws SQLException {
     Connection conn = newConnection();
     StringBuffer buf = new StringBuffer();
     buf.append("CREATE TABLE access_event (");
@@ -94,7 +89,7 @@
     query(conn, buf.toString());
   }
 
-  void dropTables() throws SQLException {
+  private  void dropTables() throws SQLException {
     Connection conn = newConnection();
     
     StringBuffer buf = new StringBuffer();
@@ -106,7 +101,7 @@
     query(conn, buf.toString());
   }
 
-  void query(Connection conn, String expression) throws SQLException {
+  private  void query(Connection conn, String expression) throws SQLException {
     Statement st = null;
     st = conn.createStatement();
 

Modified: logback/trunk/logback-access/src/test/java/ch/qos/logback/access/db/PackageTest.java
==============================================================================
--- logback/trunk/logback-access/src/test/java/ch/qos/logback/access/db/PackageTest.java	(original)
+++ logback/trunk/logback-access/src/test/java/ch/qos/logback/access/db/PackageTest.java	Wed Oct 29 14:56:19 2008
@@ -15,7 +15,7 @@
 
   public static Test suite() {
     TestSuite suite = new TestSuite();
-    suite.addTestSuite(DBAppenderTest.class);
+    suite.addTest(new JUnit4TestAdapter(DBAppenderTest.class));
     suite.addTest(new JUnit4TestAdapter(DBAppenderIntegrationTest.class));
     return suite;
   }

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderTest.java	Wed Oct 29 14:56:19 2008
@@ -1,10 +1,18 @@
 package ch.qos.logback.classic.db;
 
+import static org.junit.Assert.*;
+
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.Map;
 
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
 import ch.qos.logback.classic.Level;
 import ch.qos.logback.classic.Logger;
 import ch.qos.logback.classic.LoggerContext;
@@ -12,19 +20,28 @@
 import ch.qos.logback.classic.spi.LoggingEvent;
 import ch.qos.logback.core.db.DriverManagerConnectionSource;
 
-public class DBAppenderTest extends DBAppenderTestBase {
+public class DBAppenderTest  {
 
   LoggerContext lc;
   Logger logger;
   DBAppender appender;
   DriverManagerConnectionSource connectionSource;
 
-  public DBAppenderTest(String name) {
-    super(name);
+  static DBAppenderTestFixture DB_APPENDER_TEST_FIXTURE;
+  
+  @BeforeClass
+  public  static  void fixtureSetUp() throws SQLException {
+    DB_APPENDER_TEST_FIXTURE = new DBAppenderTestFixture();
+    DB_APPENDER_TEST_FIXTURE.setUp();
   }
-
+  
+  @AfterClass
+  public static void fixtureTearDown() throws SQLException {
+    DB_APPENDER_TEST_FIXTURE.tearDown();
+  }
+  
+  @Before
   public void setUp() throws SQLException {
-    super.setUp();
     lc = new LoggerContext();
     lc.setName("default");
     logger = lc.getLogger("root");
@@ -33,23 +50,24 @@
     appender.setContext(lc);
     connectionSource = new DriverManagerConnectionSource();
     connectionSource.setContext(lc);
-    connectionSource.setDriverClass(HSQLDB_DRIVER_CLASS);
-    connectionSource.setUrl(url);
-    connectionSource.setUser(user);
-    connectionSource.setPassword(password);
+    connectionSource.setDriverClass(DBAppenderTestFixture.HSQLDB_DRIVER_CLASS);
+    connectionSource.setUrl(DB_APPENDER_TEST_FIXTURE.url);
+    connectionSource.setUser(DB_APPENDER_TEST_FIXTURE.user);
+    connectionSource.setPassword(DB_APPENDER_TEST_FIXTURE.password);
     connectionSource.start();
     appender.setConnectionSource(connectionSource);
     appender.start();
   }
   
+  @After
   public void tearDown() throws SQLException {
-    super.tearDown();
     logger = null;
     lc = null;
     appender = null;
     connectionSource = null;
   }
 
+  @Test
   public void testAppendLoggingEvent() throws SQLException {
     LoggingEvent event = createLoggingEvent();
 

Copied: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderTestFixture.java (from r1899, /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderTestBase.java)
==============================================================================
--- /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderTestBase.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderTestFixture.java	Wed Oct 29 14:56:19 2008
@@ -1,18 +1,18 @@
 package ch.qos.logback.classic.db;
 
+import static org.junit.Assert.assertNotNull;
+
 import java.io.PrintWriter;
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.Properties;
 
-import junit.framework.TestCase;
-
 import org.hsqldb.Server;
 import org.hsqldb.ServerConstants;
 import org.hsqldb.jdbcDriver;
 
-public abstract class DBAppenderTestBase extends TestCase {
+public class DBAppenderTestFixture  {
 
   public static final String HSQLDB_DRIVER_CLASS = "org.hsqldb.jdbcDriver";
   // String serverProps;
@@ -24,8 +24,7 @@
   // boolean isNetwork = true;
   HsqlMode mode = HsqlMode.MEM;
 
-  public DBAppenderTestBase(String name) {
-    super(name);
+  public DBAppenderTestFixture() {
   }
 
   public void setUp() throws SQLException {
@@ -92,7 +91,7 @@
     // return DriverManager.getConnection(url, user, password);
   }
 
-  void createTables() throws SQLException {
+  private void createTables() throws SQLException {
     Connection conn = newConnection();
     assertNotNull(conn);
     StringBuffer buf = new StringBuffer();
@@ -129,7 +128,7 @@
     query(conn, buf.toString());
   }
 
-  void dropTables() throws SQLException {
+  private  void dropTables() throws SQLException {
     Connection conn = newConnection();
     StringBuffer buf = new StringBuffer();
     buf.append("DROP TABLE logging_event_exception IF EXISTS;");
@@ -144,7 +143,7 @@
     query(conn, buf.toString());
   }
 
-  void query(Connection conn, String expression) throws SQLException {
+  private  void query(Connection conn, String expression) throws SQLException {
 
     Statement st = null;
     st = conn.createStatement();

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/PackageTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/PackageTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/PackageTest.java	Wed Oct 29 14:56:19 2008
@@ -15,7 +15,7 @@
 
   public static Test suite() {
     TestSuite suite = new TestSuite();
-    suite.addTestSuite(DBAppenderTest.class);
+    suite.addTest(new JUnit4TestAdapter(DBAppenderTest.class));
     return suite;
   }
 }
\ No newline at end of file


More information about the logback-dev mailing list