logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nickwilli...@apache.org
Subject svn commit: r1482797 - in /logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc: AbstractJdbcAppenderTest.java JdbcH2AppenderTest.java JdbcHyperSqlAppenderTest.java
Date Wed, 15 May 2013 12:53:00 GMT
Author: nickwilliams
Date: Wed May 15 12:52:59 2013
New Revision: 1482797

URL: http://svn.apache.org/r1482797
Log:
In JDBC Appender tests, moving constructors to top, fixing typos, removing unnecessary whitespace,
removing troubleshooting "System.out" calls that were accidentally left in.

Modified:
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/AbstractJdbcAppenderTest.java
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcH2AppenderTest.java
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcHyperSqlAppenderTest.java

Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/AbstractJdbcAppenderTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/AbstractJdbcAppenderTest.java?rev=1482797&r1=1482796&r2=1482797&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/AbstractJdbcAppenderTest.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/AbstractJdbcAppenderTest.java
Wed May 15 12:52:59 2013
@@ -16,15 +16,6 @@
  */
 package org.apache.logging.log4j.core.appender.db.jdbc;
 
-import static org.easymock.EasyMock.createStrictMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
 import java.io.ByteArrayOutputStream;
 import java.io.PrintWriter;
 import java.sql.Connection;
@@ -32,7 +23,6 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.Map;
-
 import javax.naming.InitialContext;
 import javax.sql.DataSource;
 
@@ -48,14 +38,15 @@ import org.junit.After;
 import org.junit.Test;
 import org.mockejb.jndi.MockContextFactory;
 
-public abstract class AbstractJdbcAppenderTest {
-
-    private final String dbType;
+import static org.easymock.EasyMock.*;
+import static org.junit.Assert.*;
 
+public abstract class AbstractJdbcAppenderTest {
+    private final String databaseType;
     private Connection connection;
 
-    public AbstractJdbcAppenderTest(final String dbType) {
-        this.dbType = dbType;
+    public AbstractJdbcAppenderTest(final String databaseType) {
+        this.databaseType = databaseType;
     }
 
     protected abstract Connection newConnection() throws SQLException;
@@ -64,7 +55,7 @@ public abstract class AbstractJdbcAppend
         this.connection = this.newConnection();
         final Statement statement = this.connection.createStatement();
         try {
-            statement.executeUpdate(toCreateTableSqlString(tableName));
+            statement.executeUpdate(this.toCreateTableSqlString(tableName));
         } finally {
             statement.close();
         }
@@ -77,15 +68,6 @@ public abstract class AbstractJdbcAppend
         StatusLogger.getLogger().reset();
     }
 
-    protected void setUpTable(final String tableName) throws SQLException {
-        final Statement statement = this.connection.createStatement();
-        try {
-            statement.executeUpdate(toCreateTableSqlString(tableName));
-        } finally {
-            statement.close();
-        }
-    }
-
     @After
     public void tearDown() throws SQLException {
         final LoggerContext context = (LoggerContext) LogManager.getContext(false);
@@ -119,7 +101,6 @@ public abstract class AbstractJdbcAppend
 
     @Test
     public void testDataSourceConfig() throws Exception {
-        System.out.println("Before creating mock data source.");
         final DataSource dataSource = createStrictMock(DataSource.class);
 
         expect(dataSource.getConnection()).andAnswer(new IAnswer<Connection>() {
@@ -130,24 +111,19 @@ public abstract class AbstractJdbcAppend
         }).atLeastOnce();
         replay(dataSource);
 
-        System.out.println("Before creating mock context.");
         MockContextFactory.setAsInitial();
 
-        System.out.println("Before instantiating context.");
         final InitialContext context = new InitialContext();
         context.createSubcontext("java:");
         context.createSubcontext("java:/comp");
         context.createSubcontext("java:/comp/env");
         context.createSubcontext("java:/comp/env/jdbc");
 
-        System.out.println("Before binding data source.");
         context.bind("java:/comp/env/jdbc/TestDataSourceAppender", dataSource);
 
         try {
-            System.out.println("Before setting up.");
             this.setUp("dsLogEntry", "log4j2-data-source.xml");
 
-            System.out.println("After setting up.");
             final Error exception = new Error("Final error massage is fatal!");
             final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
             final PrintWriter writer = new PrintWriter(outputStream);
@@ -187,7 +163,7 @@ public abstract class AbstractJdbcAppend
 
     @Test
     public void testDriverManagerConfig() throws SQLException {
-        this.setUp("dmLogEntry", "log4j2-" + this.dbType + "-driver-manager.xml");
+        this.setUp("dmLogEntry", "log4j2-" + this.databaseType + "-driver-manager.xml");
 
         final RuntimeException exception = new RuntimeException("Hello, world!");
         final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
@@ -235,7 +211,7 @@ public abstract class AbstractJdbcAppend
 
     @Test
     public void testFactoryMethodConfig() throws SQLException {
-        this.setUp("fmLogEntry", "log4j2-" + this.dbType + "-factory-method.xml");
+        this.setUp("fmLogEntry", "log4j2-" + this.databaseType + "-factory-method.xml");
 
         final SQLException exception = new SQLException("Some other error message!");
         final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
@@ -286,5 +262,4 @@ public abstract class AbstractJdbcAppend
                 + "id INTEGER IDENTITY, eventDate DATETIME, literalColumn VARCHAR(255), level
VARCHAR(10), "
                 + "logger VARCHAR(255), message VARCHAR(1024), exception VARCHAR(1048576)"
+ " )";
     }
-
 }

Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcH2AppenderTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcH2AppenderTest.java?rev=1482797&r1=1482796&r2=1482797&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcH2AppenderTest.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcH2AppenderTest.java
Wed May 15 12:52:59 2013
@@ -24,25 +24,23 @@ import java.sql.SQLException;
  * Tests the JDBC appender with the H2 database in memory.
  */
 public class JdbcH2AppenderTest extends AbstractJdbcAppenderTest {
-
     private static final String PASSWORD = "";
     private static final String USER_ID = "sa";
 
+    public JdbcH2AppenderTest() {
+        super("h2");
+    }
+
     /**
-     * Referred from log4j2-factory-method.xml.
+     * Referred from log4j2-h2-factory-method.xml.
      */
     @SuppressWarnings("unused")
     public static Connection getConfigConnection() throws SQLException {
         return DriverManager.getConnection("jdbc:h2:mem:Log4j", USER_ID, PASSWORD);
     }
 
-    public JdbcH2AppenderTest() {
-        super("h2");
-    }
-
     @Override
     protected Connection newConnection() throws SQLException {
         return DriverManager.getConnection("jdbc:h2:mem:Log4j", USER_ID, PASSWORD);
     }
-
 }

Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcHyperSqlAppenderTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcHyperSqlAppenderTest.java?rev=1482797&r1=1482796&r2=1482797&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcHyperSqlAppenderTest.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcHyperSqlAppenderTest.java
Wed May 15 12:52:59 2013
@@ -24,22 +24,23 @@ import java.sql.SQLException;
  * Tests the JDBC appender with the HyperSQL database (a.k.a. HSQLDB) in memory.
  */
 public class JdbcHyperSqlAppenderTest extends AbstractJdbcAppenderTest {
+    private static final String PASSWORD = "";
+    private static final String USER_ID = "sa";
+
+    public JdbcHyperSqlAppenderTest() {
+        super("hsqldb");
+    }
 
     /**
-     * Referred from log4j2-factory-method.xml.
+     * Referred from log4j2-hsqldb-factory-method.xml.
      */
     @SuppressWarnings("unused")
     public static Connection getConfigConnection() throws SQLException {
-        return DriverManager.getConnection("jdbc:hsqldb:mem:Log4j;ifexists=true", "sa", "");
-    }
-
-    public JdbcHyperSqlAppenderTest() {
-        super("hsqldb");
+        return DriverManager.getConnection("jdbc:hsqldb:mem:Log4j;ifexists=true", USER_ID,
PASSWORD);
     }
 
     @Override
     protected Connection newConnection() throws SQLException {
-        return DriverManager.getConnection("jdbc:hsqldb:mem:Log4j", "sa", "");
+        return DriverManager.getConnection("jdbc:hsqldb:mem:Log4j", USER_ID, PASSWORD);
     }
-
 }



Mime
View raw message