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

noreply.seb at qos.ch noreply.seb at qos.ch
Wed Nov 29 11:14:11 CET 2006


Author: seb
Date: Wed Nov 29 11:14:11 2006
New Revision: 1030

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/DBAppenderTestBase.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/DBAppenderTestBase.java

Log:
better test 

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 Nov 29 11:14:11 2006
@@ -10,6 +10,7 @@
 import ch.qos.logback.access.spi.AccessEvent;
 import ch.qos.logback.access.spi.BasicContext;
 import ch.qos.logback.core.db.DriverManagerConnectionSource;
+import ch.qos.logback.core.util.StatusPrinter;
 
 public class DBAppenderTest extends DBAppenderTestBase {
 
@@ -36,6 +37,10 @@
     connectionSource.setPassword(password);
     connectionSource.start();
     appender.setConnectionSource(connectionSource);
+  }
+  
+  private void setInsertHeadersAndStart(boolean insert) {
+    appender.setInsertHeaders(insert);
     appender.start();
   }
 
@@ -47,9 +52,11 @@
   }
 
   public void testAppendAccessEvent() throws SQLException {
+    setInsertHeadersAndStart(false);
+
     AccessEvent event = createAccessEvent();
     appender.append(event);
-
+    
     Statement stmt = connectionSource.getConnection().createStatement();
     ResultSet rs = null;
     rs = stmt.executeQuery("SELECT * FROM access_event");
@@ -71,16 +78,53 @@
     rs.close();
     stmt.close();
   }
+  
+  
+  public void testCheckNoHeadersAreInserted() throws Exception {
+    setInsertHeadersAndStart(false);
+    
+    AccessEvent event = createAccessEvent();
+    appender.append(event);
+    StatusPrinter.print(context.getStatusManager());
+    
+    //Check that no headers were inserted
+    Statement stmt = connectionSource.getConnection().createStatement();
+    ResultSet rs = null;
+    rs = stmt.executeQuery("SELECT * FROM access_event_header");
+    
+    assertFalse(rs.next());
+    rs.close();
+    stmt.close();
+  }
 
-  public void testAppendHeaders() throws SQLException {    
+  public void testAppendHeaders() throws SQLException {   
+    setInsertHeadersAndStart(true);
+    
     AccessEvent event = createAccessEvent();
     appender.append(event);
 
     Statement stmt = connectionSource.getConnection().createStatement();
     ResultSet rs = null;
-    rs = stmt.executeQuery("SELECT * FROM access_event_header where event_id = 0");
-    while (rs.next()) {
-      assertEquals(event.getRequestHeader(rs.getString(2)), rs.getString(3));
+    rs = stmt.executeQuery("SELECT * FROM access_event_header");
+    String key;
+    String value;
+    if (!rs.next()) {
+      fail("There should be results to this query");
+    } else {
+      key = rs.getString(2);
+      value = rs.getString(3);
+      assertNotNull(key);
+      assertNotNull(value);
+      assertEquals(event.getRequestHeader(key), value);
+      rs.next();
+      key = rs.getString(2);
+      value = rs.getString(3);
+      assertNotNull(key);
+      assertNotNull(value);
+      assertEquals(event.getRequestHeader(key), value);
+    }
+    if (rs.next()) {
+      fail("There should be no more rows available");
     }
 
     rs.close();

Modified: logback/trunk/logback-access/src/test/java/ch/qos/logback/access/db/DBAppenderTestBase.java
==============================================================================
--- logback/trunk/logback-access/src/test/java/ch/qos/logback/access/db/DBAppenderTestBase.java	(original)
+++ logback/trunk/logback-access/src/test/java/ch/qos/logback/access/db/DBAppenderTestBase.java	Wed Nov 29 11:14:11 2006
@@ -23,12 +23,6 @@
     super(name);
   }
 
-  public DBAppenderTestBase(String name, String url, boolean isNetwork) {
-    super(name);
-    this.isNetwork = isNetwork;
-    this.url = url;
-  }
-
   protected void setUp() throws SQLException {
     if (isNetwork) {
       if (url == null) {

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 Nov 29 11:14:11 2006
@@ -82,7 +82,6 @@
     LoggingEvent event = createLoggingEvent();
 
     appender.append(event);
-    //StatusPrinter.print(lc.getStatusManager());
     
     Statement stmt = connectionSource.getConnection().createStatement();
     ResultSet rs = null;
@@ -102,7 +101,6 @@
     lc.setProperty("testKey1", "testValue1");
     
     appender.append(event);
-    //StatusPrinter.print(lc.getStatusManager());
     
     Statement stmt = connectionSource.getConnection().createStatement();
     ResultSet rs = null;
@@ -123,7 +121,6 @@
       LoggingEvent event = createLoggingEvent();
       appender.append(event);
     }
-    //StatusPrinter.print(lc.getStatusManager());
     
     Statement stmt = connectionSource.getConnection().createStatement();
     ResultSet rs = null;

Modified: 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/DBAppenderTestBase.java	Wed Nov 29 11:14:11 2006
@@ -23,14 +23,6 @@
     super(name);
   }
 
-  public DBAppenderTestBase(String name, String url, boolean isNetwork) {
-
-    super(name);
-
-    this.isNetwork = isNetwork;
-    this.url = url;
-  }
-
   protected void setUp() throws SQLException {
 
     if (isNetwork) {



More information about the logback-dev mailing list