logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mattsic...@apache.org
Subject svn commit: r1582179 - /logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/DataSourceConnectionSourceTest.java
Date Thu, 27 Mar 2014 04:20:44 GMT
Author: mattsicker
Date: Thu Mar 27 04:20:44 2014
New Revision: 1582179

URL: http://svn.apache.org/r1582179
Log:
De-duplicate redundant code.

Modified:
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/DataSourceConnectionSourceTest.java

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/DataSourceConnectionSourceTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/DataSourceConnectionSourceTest.java?rev=1582179&r1=1582178&r2=1582179&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/DataSourceConnectionSourceTest.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/DataSourceConnectionSourceTest.java
Thu Mar 27 04:20:44 2014
@@ -18,6 +18,8 @@ package org.apache.logging.log4j.core.ap
 
 import java.sql.Connection;
 import java.sql.SQLException;
+import java.util.Arrays;
+import java.util.Collection;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import javax.sql.DataSource;
@@ -25,14 +27,33 @@ import javax.sql.DataSource;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
 import org.mockejb.jndi.MockContextFactory;
 
 import static org.easymock.EasyMock.*;
 import static org.junit.Assert.*;
 
+@RunWith(Parameterized.class)
 public class DataSourceConnectionSourceTest {
+
+    @Parameterized.Parameters
+    public static Collection<Object[]> data() {
+        return Arrays.asList(
+                new Object[][]{
+                        {"java:/comp/env/jdbc/Logging01"},
+                        {"java:/comp/env/jdbc/Logging02"}
+                }
+        );
+    }
+
+    private final String jndiURL;
     private InitialContext context;
 
+    public DataSourceConnectionSourceTest(final String jndiURL) {
+        this.jndiURL = jndiURL;
+    }
+
     @Before
     public void setUp() throws NamingException {
         MockContextFactory.setAsInitial();
@@ -66,13 +87,13 @@ public class DataSourceConnectionSourceT
     @Test
     public void testNoDataSource() {
         final DataSourceConnectionSource source = DataSourceConnectionSource
-                .createConnectionSource("java:/comp/env/jdbc/Logging01");
+                .createConnectionSource(this.jndiURL);
 
         assertNull("The connection source should be null.", source);
     }
 
     @Test
-    public void testDataSource01() throws NamingException, SQLException {
+    public void testDataSource() throws NamingException, SQLException {
         final DataSource dataSource = createStrictMock(DataSource.class);
         final Connection connection1 = createStrictMock(Connection.class);
         final Connection connection2 = createStrictMock(Connection.class);
@@ -81,49 +102,22 @@ public class DataSourceConnectionSourceT
         expect(dataSource.getConnection()).andReturn(connection2);
         replay(dataSource, connection1, connection2);
 
-        this.context.bind("java:/comp/env/jdbc/Logging01", dataSource);
+        this.context.bind(this.jndiURL, dataSource);
 
         DataSourceConnectionSource source = DataSourceConnectionSource
-                .createConnectionSource("java:/comp/env/jdbc/Logging01");
+                .createConnectionSource(this.jndiURL);
 
         assertNotNull("The connection source should not be null.", source);
-        assertEquals("The toString value is not correct.", "dataSource{ name=java:/comp/env/jdbc/Logging01,
value="
+        assertEquals("The toString value is not correct.", "dataSource{ name=" + jndiURL
+ ", value="
                 + dataSource + " }", source.toString());
         assertSame("The connection is not correct (1).", connection1, source.getConnection());
         assertSame("The connection is not correct (2).", connection2, source.getConnection());
 
-        source = DataSourceConnectionSource.createConnectionSource("java:/comp/env/jdbc/Logging02");
+        source = DataSourceConnectionSource.createConnectionSource(jndiURL.substring(0, jndiURL.length()
- 1));
 
         assertNull("The connection source should be null now.", source);
 
         verify(dataSource, connection1, connection2);
     }
 
-    @Test
-    public void testDataSource02() throws NamingException, SQLException {
-        final DataSource dataSource = createStrictMock(DataSource.class);
-        final Connection connection1 = createStrictMock(Connection.class);
-        final Connection connection2 = createStrictMock(Connection.class);
-
-        expect(dataSource.getConnection()).andReturn(connection1);
-        expect(dataSource.getConnection()).andReturn(connection2);
-        replay(dataSource, connection1, connection2);
-
-        this.context.bind("java:/comp/env/jdbc/Logging02", dataSource);
-
-        DataSourceConnectionSource source = DataSourceConnectionSource
-                .createConnectionSource("java:/comp/env/jdbc/Logging02");
-
-        assertNotNull("The connection source should not be null.", source);
-        assertEquals("The toString value is not correct.", "dataSource{ name=java:/comp/env/jdbc/Logging02,
value="
-                + dataSource + " }", source.toString());
-        assertSame("The connection is not correct (1).", connection1, source.getConnection());
-        assertSame("The connection is not correct (2).", connection2, source.getConnection());
-
-        source = DataSourceConnectionSource.createConnectionSource("java:/comp/env/jdbc/Logging01");
-
-        assertNull("The connection source should be null now.", source);
-
-        verify(dataSource, connection1, connection2);
-    }
 }



Mime
View raw message