You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2018/01/29 20:03:27 UTC
[3/4] logging-log4j2 git commit: [LOG4J2-2233] Move JDBC code to a
new module log4j-jdbc.
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b5d4655d/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/AbstractJdbcAppenderFactoryMethodTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/AbstractJdbcAppenderFactoryMethodTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/AbstractJdbcAppenderFactoryMethodTest.java
deleted file mode 100644
index 72f7f39..0000000
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/AbstractJdbcAppenderFactoryMethodTest.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.core.appender.db.jdbc;
-
-import java.io.ByteArrayOutputStream;
-import java.io.PrintWriter;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.ThreadContext;
-import org.apache.logging.log4j.junit.JdbcRule;
-import org.apache.logging.log4j.junit.LoggerContextRule;
-import org.apache.logging.log4j.util.Strings;
-import org.h2.util.IOUtils;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.RuleChain;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Abstract unit test for JdbcAppender using a {@link FactoryMethodConnectionSource} configuration.
- */
-public abstract class AbstractJdbcAppenderFactoryMethodTest {
-
- @Rule
- public final RuleChain rules;
- private final JdbcRule jdbcRule;
-
- protected AbstractJdbcAppenderFactoryMethodTest(final JdbcRule jdbcRule, final String databaseType) {
- this.rules = RuleChain.emptyRuleChain().around(jdbcRule).around(new LoggerContextRule(
- "org/apache/logging/log4j/core/appender/db/jdbc/log4j2-" + databaseType + "-factory-method.xml"));
- this.jdbcRule = jdbcRule;
- }
-
- @Test
- public void testFactoryMethodConfig() throws Exception {
- try (final Connection connection = jdbcRule.getConnectionSource().getConnection()) {
- final SQLException exception = new SQLException("Some other error message!");
- final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- try (final PrintWriter writer = new PrintWriter(outputStream)) {
- exception.printStackTrace(writer);
- }
- final String stackTrace = outputStream.toString();
-
- final long millis = System.currentTimeMillis();
-
- ThreadContext.put("some_int", "42");
- final Logger logger = LogManager.getLogger(this.getClass().getName() + ".testFactoryMethodConfig");
- logger.debug("Factory logged message 01.");
- logger.error("Error from factory 02.", exception);
-
- try (final Statement statement = connection.createStatement();
- final ResultSet resultSet = statement.executeQuery("SELECT * FROM fmLogEntry ORDER BY id")) {
-
- assertTrue("There should be at least one row.", resultSet.next());
-
- long date = resultSet.getTimestamp("eventDate").getTime();
- long anotherDate = resultSet.getTimestamp("anotherDate").getTime();
- assertEquals(date, anotherDate);
- assertTrue("The date should be later than pre-logging (1).", date >= millis);
- assertTrue("The date should be earlier than now (1).", date <= System.currentTimeMillis());
- assertEquals("The literal column is not correct (1).", "Some Other Literal Value",
- resultSet.getString("literalColumn"));
- assertEquals("The level column is not correct (1).", "DEBUG", resultSet.getNString("level"));
- assertEquals("The logger column is not correct (1).", logger.getName(), resultSet.getNString("logger"));
- assertEquals("The message column is not correct (1).", "Factory logged message 01.",
- resultSet.getString("message"));
- assertEquals("The exception column is not correct (1).", Strings.EMPTY,
- IOUtils.readStringAndClose(resultSet.getNClob("exception").getCharacterStream(), -1));
-
- assertTrue("There should be two rows.", resultSet.next());
-
- date = resultSet.getTimestamp("eventDate").getTime();
- anotherDate = resultSet.getTimestamp("anotherDate").getTime();
- assertEquals(date, anotherDate);
- assertTrue("The date should be later than pre-logging (2).", date >= millis);
- assertTrue("The date should be earlier than now (2).", date <= System.currentTimeMillis());
- assertEquals("The literal column is not correct (2).", "Some Other Literal Value",
- resultSet.getString("literalColumn"));
- assertEquals("The level column is not correct (2).", "ERROR", resultSet.getNString("level"));
- assertEquals("The logger column is not correct (2).", logger.getName(), resultSet.getNString("logger"));
- assertEquals("The message column is not correct (2).", "Error from factory 02.",
- resultSet.getString("message"));
- assertEquals("The exception column is not correct (2).", stackTrace,
- IOUtils.readStringAndClose(resultSet.getNClob("exception").getCharacterStream(), -1));
-
- assertFalse("There should not be three rows.", resultSet.next());
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b5d4655d/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/ColumnConfigTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/ColumnConfigTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/ColumnConfigTest.java
deleted file mode 100644
index 9d36cb7..0000000
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/ColumnConfigTest.java
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.core.appender.db.jdbc;
-
-import org.apache.logging.log4j.util.Strings;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-public class ColumnConfigTest {
-
- @Test
- public void testNullNameNoConfig() {
- final ColumnConfig config = ColumnConfig.newBuilder().setPattern("%l").build();
-
- assertNull("The result should be null.", config);
- }
-
- @Test
- public void testPatternAndLiteralNoConfig() {
- final ColumnConfig config = ColumnConfig.newBuilder()
- .setName("col")
- .setPattern("%l")
- .setLiteral("literal")
- .build();
-
- assertNull("The result should be null.", config);
- }
-
- @Test
- public void testPatternAndDateNoConfig() {
- final ColumnConfig config = ColumnConfig.newBuilder()
- .setName("col")
- .setPattern("%l")
- .setEventTimestamp(true)
- .build();
-
- assertNull("The result should be null.", config);
- }
-
- @Test
- public void testLiteralAndDateNoConfig() {
- final ColumnConfig config = ColumnConfig.newBuilder()
- .setName("col")
- .setLiteral("literal")
- .setEventTimestamp(true)
- .build();
-
- assertNull("The result should be null.", config);
- }
-
- @Test
- public void testNoSettingNoConfig01() {
- final ColumnConfig config = ColumnConfig.newBuilder().setName("col").build();
-
- assertNull("The result should be null.", config);
- }
-
- @Test
- public void testNoSettingNoConfig02() {
- final ColumnConfig config = ColumnConfig.newBuilder()
- .setName("col")
- .setEventTimestamp(false)
- .build();
-
- assertNull("The result should be null.", config);
- }
-
- @Test
- public void testNoSettingNoConfig03() {
- final ColumnConfig config = ColumnConfig.newBuilder()
- .setName("col")
- .setPattern(Strings.EMPTY)
- .setLiteral(Strings.EMPTY)
- .setEventTimestamp(false)
- .build();
-
- assertNull("The result should be null.", config);
- }
-
- @Test
- public void testDateColumn01() {
- final ColumnConfig config = ColumnConfig.newBuilder()
- .setName("col")
- .setEventTimestamp(true)
- .build();
-
- assertNotNull("The result should not be null.", config);
- assertEquals("The column name is not correct.", "col", config.getColumnName());
- assertNull("The pattern should be null.", config.getLayout());
- assertNull("The literal value should be null.", config.getLiteralValue());
- assertTrue("The timestamp flag should be true.", config.isEventTimestamp());
- assertFalse("The unicode flag should be false.", config.isUnicode());
- assertFalse("The clob flag should be false.", config.isClob());
- }
-
- @Test
- public void testDateColumn02() {
- final ColumnConfig config = ColumnConfig.newBuilder()
- .setName("col2")
- .setEventTimestamp(true)
- .setUnicode(true)
- .setClob(true)
- .build();
-
- assertNotNull("The result should not be null.", config);
- assertEquals("The column name is not correct.", "col2", config.getColumnName());
- assertNull("The pattern should be null.", config.getLayout());
- assertNull("The literal value should be null.", config.getLiteralValue());
- assertTrue("The timestamp flag should be true.", config.isEventTimestamp());
- assertFalse("The unicode flag should be false.", config.isUnicode());
- assertFalse("The clob flag should be false.", config.isClob());
- }
-
- @Test
- public void testPatternColumn01() {
- final ColumnConfig config = ColumnConfig.newBuilder()
- .setName("col")
- .setPattern("%l")
- .build();
-
- assertNotNull("The result should not be null.", config);
- assertEquals("The column name is not correct.", "col", config.getColumnName());
- assertNotNull("The pattern should not be null.", config.getLayout());
- assertEquals("The pattern is not correct.", "%l", config.getLayout().toString());
- assertNull("The literal value should be null.", config.getLiteralValue());
- assertFalse("The timestamp flag should be false.", config.isEventTimestamp());
- assertTrue("The unicode flag should be true.", config.isUnicode());
- assertFalse("The clob flag should be false.", config.isClob());
- }
-
- @Test
- public void testPatternColumn02() {
- final ColumnConfig config = ColumnConfig.newBuilder()
- .setName("col2")
- .setPattern("%X{id} %level")
- .setLiteral(Strings.EMPTY)
- .setEventTimestamp(false)
- .setUnicode(false)
- .setClob(true)
- .build();
-
- assertNotNull("The result should not be null.", config);
- assertEquals("The column name is not correct.", "col2", config.getColumnName());
- assertNotNull("The pattern should not be null.", config.getLayout());
- assertEquals("The pattern is not correct.", "%X{id} %level", config.getLayout().toString());
- assertNull("The literal value should be null.", config.getLiteralValue());
- assertFalse("The timestamp flag should be false.", config.isEventTimestamp());
- assertFalse("The unicode flag should be false.", config.isUnicode());
- assertTrue("The clob flag should be true.", config.isClob());
- }
-
- @Test
- public void testPatternColumn03() {
- final ColumnConfig config = ColumnConfig.newBuilder()
- .setName("col3")
- .setPattern("%X{id} %level")
- .setLiteral(Strings.EMPTY)
- .setEventTimestamp(false)
- .setUnicode(true)
- .setClob(false)
- .build();
-
- assertNotNull("The result should not be null.", config);
- assertEquals("The column name is not correct.", "col3", config.getColumnName());
- assertNotNull("The pattern should not be null.", config.getLayout());
- assertEquals("The pattern is not correct.", "%X{id} %level", config.getLayout().toString());
- assertNull("The literal value should be null.", config.getLiteralValue());
- assertFalse("The timestamp flag should be false.", config.isEventTimestamp());
- assertTrue("The unicode flag should be true.", config.isUnicode());
- assertFalse("The clob flag should be false.", config.isClob());
- }
-
- @Test
- public void testLiteralColumn01() {
- final ColumnConfig config = ColumnConfig.newBuilder()
- .setName("col")
- .setLiteral("literalValue01")
- .build();
-
- assertNotNull("The result should not be null.", config);
- assertEquals("The column name is not correct.", "col", config.getColumnName());
- assertNull("The pattern should be null.", config.getLayout());
- assertNotNull("The literal value should be null.", config.getLiteralValue());
- assertEquals("The literal value is not correct.", "literalValue01", config.getLiteralValue());
- assertFalse("The timestamp flag should be false.", config.isEventTimestamp());
- assertFalse("The unicode flag should be false.", config.isUnicode());
- assertFalse("The clob flag should be false.", config.isClob());
- }
-
- @Test
- public void testLiteralColumn02() {
- final ColumnConfig config = ColumnConfig.newBuilder()
- .setName("col2")
- .setLiteral("USER1.MY_SEQUENCE.NEXT")
- .setUnicode(true)
- .setClob(true)
- .build();
-
- assertNotNull("The result should not be null.", config);
- assertEquals("The column name is not correct.", "col2", config.getColumnName());
- assertNull("The pattern should be null.", config.getLayout());
- assertNotNull("The literal value should be null.", config.getLiteralValue());
- assertEquals("The literal value is not correct.", "USER1.MY_SEQUENCE.NEXT", config.getLiteralValue());
- assertFalse("The timestamp flag should be false.", config.isEventTimestamp());
- assertFalse("The unicode flag should be false.", config.isUnicode());
- assertFalse("The clob flag should be false.", config.isClob());
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b5d4655d/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/DataSourceConnectionSourceTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/DataSourceConnectionSourceTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/DataSourceConnectionSourceTest.java
deleted file mode 100644
index a49404a..0000000
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/DataSourceConnectionSourceTest.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.core.appender.db.jdbc;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-
-import javax.sql.DataSource;
-
-import org.apache.logging.log4j.junit.JndiRule;
-import org.apache.logging.log4j.junit.LoggerContextRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.RuleChain;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-@RunWith(Parameterized.class)
-public class DataSourceConnectionSourceTest {
-
- @Parameterized.Parameters(name = "{0}")
- public static Object[][] data() {
- return new Object[][]{
- {"java:/comp/env/jdbc/Logging01"},
- {"java:/comp/env/jdbc/Logging02"}
- };
- }
-
- private static final String CONFIG = "log4j-fatalOnly.xml";
-
- @Rule
- public final RuleChain rules;
- private final DataSource dataSource = mock(DataSource.class);
- private final String jndiURL;
-
- public DataSourceConnectionSourceTest(final String jndiURL) {
- this.rules = RuleChain.outerRule(new JndiRule(jndiURL, dataSource))
- .around(new LoggerContextRule(CONFIG));
- this.jndiURL = jndiURL;
- }
-
- @Test
- public void testNullJndiName() {
- final DataSourceConnectionSource source = DataSourceConnectionSource.createConnectionSource(null);
-
- assertNull("The connection source should be null.", source);
- }
-
- @Test
- public void testEmptyJndiName() {
- final DataSourceConnectionSource source = DataSourceConnectionSource.createConnectionSource("");
-
- assertNull("The connection source should be null.", source);
- }
-
- @Test
- public void testNoDataSource() {
- final DataSourceConnectionSource source = DataSourceConnectionSource.createConnectionSource(jndiURL + "123");
-
- assertNull("The connection source should be null.", source);
- }
-
- @Test
- public void testDataSource() throws SQLException {
- try (final Connection connection1 = mock(Connection.class);
- final Connection connection2 = mock(Connection.class)) {
-
- given(dataSource.getConnection()).willReturn(connection1, connection2);
-
- DataSourceConnectionSource source = DataSourceConnectionSource.createConnectionSource(jndiURL);
-
- assertNotNull("The connection source should not be null.", source);
- 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(jndiURL.substring(0, jndiURL.length() - 1));
-
- assertNull("The connection source should be null now.", source);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b5d4655d/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/DriverManagerConnectionSourceTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/DriverManagerConnectionSourceTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/DriverManagerConnectionSourceTest.java
deleted file mode 100644
index 5a4835a..0000000
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/DriverManagerConnectionSourceTest.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.core.appender.db.jdbc;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-
-import org.apache.logging.log4j.core.config.Property;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class DriverManagerConnectionSourceTest {
-
- @Test
- public void testH2Properties() throws SQLException {
- Property[] properties = new Property[] {
- // @formatter:off
- Property.createProperty("username", JdbcH2TestHelper.USER_NAME),
- Property.createProperty("password", JdbcH2TestHelper.PASSWORD),
- // @formatter:on
- };
- // @formatter:off
- DriverManagerConnectionSource source = DriverManagerConnectionSource.newBuilder()
- .setConnectionString(JdbcH2TestHelper.CONNECTION_STRING)
- .setProperties(properties)
- .build();
- // @formatter:on
- try (Connection conn = source.getConnection()) {
- Assert.assertFalse(conn.isClosed());
- }
- }
-
- @Test
- public void testH2UserAndPassword() throws SQLException {
- // @formatter:off
- DriverManagerConnectionSource source = DriverManagerConnectionSource.newBuilder()
- .setConnectionString(JdbcH2TestHelper.CONNECTION_STRING)
- .setUserName(JdbcH2TestHelper.USER_NAME.toCharArray())
- .setPassword(JdbcH2TestHelper.PASSWORD.toCharArray())
- .build();
- // @formatter:on
- try (Connection conn = source.getConnection()) {
- Assert.assertFalse(conn.isClosed());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b5d4655d/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/FactoryMethodConnectionSourceTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/FactoryMethodConnectionSourceTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/FactoryMethodConnectionSourceTest.java
deleted file mode 100644
index 28b6d87..0000000
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/FactoryMethodConnectionSourceTest.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.core.appender.db.jdbc;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-import javax.sql.DataSource;
-
-import org.apache.logging.log4j.junit.LoggerContextRule;
-import org.junit.After;
-import org.junit.ClassRule;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
-
-public class FactoryMethodConnectionSourceTest {
- private static ThreadLocal<Object> holder = new ThreadLocal<>();
- private static final String CONFIG = "log4j-fatalOnly.xml";
-
- @ClassRule
- public static LoggerContextRule ctx = new LoggerContextRule(CONFIG);
-
- @After
- public void tearDown() {
- holder.remove();
- }
-
- @Test
- public void testNoClassName() {
- final FactoryMethodConnectionSource source =
- FactoryMethodConnectionSource.createConnectionSource(null, "method");
-
- assertNull("The connection source should be null.", source);
- }
-
- @Test
- public void testNoMethodName() {
- final FactoryMethodConnectionSource source =
- FactoryMethodConnectionSource.createConnectionSource("someClass", null);
-
- assertNull("The connection source should be null.", source);
- }
-
- @Test
- public void testBadClassName() {
- final FactoryMethodConnectionSource source =
- FactoryMethodConnectionSource.createConnectionSource("org.apache.BadClass", "factoryMethod");
-
- assertNull("The connection source should be null.", source);
- }
-
- @Test
- public void testBadMethodName() {
- final FactoryMethodConnectionSource source =
- FactoryMethodConnectionSource.createConnectionSource(this.getClass().getName(), "factoryMethod");
-
- assertNull("The connection source should be null.", source);
- }
-
- @Test
- public void testBadReturnType() {
- final FactoryMethodConnectionSource source = FactoryMethodConnectionSource.createConnectionSource(
- BadReturnTypeFactory.class.getName(), "factoryMethod01"
- );
-
- assertNull("The connection source should be null.", source);
- }
-
- @Test
- public void testDataSourceReturnType() throws SQLException {
- final DataSource dataSource = mock(DataSource.class);
- try (final Connection connection1 = mock(Connection.class);
- final Connection connection2 = mock(Connection.class)) {
-
- given(dataSource.getConnection()).willReturn(connection1, connection2);
-
- holder.set(dataSource);
-
- final FactoryMethodConnectionSource source = FactoryMethodConnectionSource
- .createConnectionSource(DataSourceFactory.class.getName(), "factoryMethod02");
-
- assertNotNull("The connection source should not be null.", source);
- assertEquals("The toString value is not correct.", "factory{ public static javax.sql.DataSource["
- + dataSource + "] " + DataSourceFactory.class.getName() + ".factoryMethod02() }",
- source.toString());
- assertSame("The connection is not correct (1).", connection1, source.getConnection());
- assertSame("The connection is not correct (2).", connection2, source.getConnection());
- }
- }
-
- @Test
- public void testConnectionReturnType() throws SQLException {
- try (final Connection connection = mock(Connection.class)) {
-
- holder.set(connection);
-
- final FactoryMethodConnectionSource source = FactoryMethodConnectionSource
- .createConnectionSource(ConnectionFactory.class.getName(), "anotherMethod03");
-
- assertNotNull("The connection source should not be null.", source);
- assertEquals("The toString value is not correct.", "factory{ public static java.sql.Connection "
- + ConnectionFactory.class.getName() + ".anotherMethod03() }", source.toString());
- assertSame("The connection is not correct (1).", connection, source.getConnection());
- assertSame("The connection is not correct (2).", connection, source.getConnection());
- }
- }
-
- @SuppressWarnings("unused")
- protected static final class BadReturnTypeFactory {
- public static String factoryMethod01() {
- return "hello";
- }
- }
-
- @SuppressWarnings("unused")
- protected static final class DataSourceFactory {
- public static DataSource factoryMethod02() {
- return (DataSource) holder.get();
- }
- }
-
- @SuppressWarnings("unused")
- protected static final class ConnectionFactory {
- public static Connection anotherMethod03() {
- return (Connection) holder.get();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b5d4655d/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcAppenderH2DataSourceTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcAppenderH2DataSourceTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcAppenderH2DataSourceTest.java
deleted file mode 100644
index acd14ca..0000000
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcAppenderH2DataSourceTest.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.core.appender.db.jdbc;
-
-import org.apache.logging.log4j.junit.JdbcRule;
-
-/**
- *
- */
-public class JdbcAppenderH2DataSourceTest extends AbstractJdbcAppenderDataSourceTest {
- public JdbcAppenderH2DataSourceTest() {
- super(new JdbcRule(JdbcH2TestHelper.TEST_CONFIGURATION_SOURCE,
- "CREATE TABLE dsLogEntry ("
- + "id INTEGER IDENTITY, eventDate DATETIME, literalColumn VARCHAR(255), level NVARCHAR(10), "
- + "logger NVARCHAR(255), message VARCHAR(1024), exception NCLOB, anotherDate TIMESTAMP" + ")",
- "DROP TABLE dsLogEntry"));
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b5d4655d/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcAppenderH2FactoryMethodTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcAppenderH2FactoryMethodTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcAppenderH2FactoryMethodTest.java
deleted file mode 100644
index c79b6ba..0000000
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcAppenderH2FactoryMethodTest.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.core.appender.db.jdbc;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-
-import org.apache.logging.log4j.junit.JdbcRule;
-
-/**
- *
- */
-public class JdbcAppenderH2FactoryMethodTest extends AbstractJdbcAppenderFactoryMethodTest {
- public JdbcAppenderH2FactoryMethodTest() {
- super(new JdbcRule(JdbcH2TestHelper.TEST_CONFIGURATION_SOURCE,
- "CREATE TABLE fmLogEntry ("
- + "id INTEGER IDENTITY, eventDate DATETIME, literalColumn VARCHAR(255), level NVARCHAR(10), "
- + "logger NVARCHAR(255), message VARCHAR(1024), exception NCLOB, anotherDate TIMESTAMP" + ")",
- "DROP TABLE fmLogEntry"), "h2");
- }
-
- public static Connection getConnection() throws SQLException {
- return JdbcH2TestHelper.getConnection();
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b5d4655d/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcAppenderHsqldbDataSourceTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcAppenderHsqldbDataSourceTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcAppenderHsqldbDataSourceTest.java
deleted file mode 100644
index 79560ff..0000000
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcAppenderHsqldbDataSourceTest.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.core.appender.db.jdbc;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-
-import org.apache.logging.log4j.junit.JdbcRule;
-
-/**
- *
- */
-public class JdbcAppenderHsqldbDataSourceTest extends AbstractJdbcAppenderDataSourceTest {
- public JdbcAppenderHsqldbDataSourceTest() {
- super(new JdbcRule(
- new AbstractConnectionSource() {
- @Override
- public Connection getConnection() throws SQLException {
- return DriverManager.getConnection("jdbc:hsqldb:mem:Log4j", "sa", "");
- }
- },
- "CREATE TABLE dsLogEntry (" +
- "id INTEGER IDENTITY, eventDate DATETIME, literalColumn VARCHAR(255), level VARCHAR(10), " +
- "logger VARCHAR(255), message VARCHAR(1024), exception CLOB, anotherDate TIMESTAMP" +
- ")",
- "DROP TABLE dsLogEntry"
- ));
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b5d4655d/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcAppenderHsqldbFactoryMethodTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcAppenderHsqldbFactoryMethodTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcAppenderHsqldbFactoryMethodTest.java
deleted file mode 100644
index 0d76ac1..0000000
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcAppenderHsqldbFactoryMethodTest.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.core.appender.db.jdbc;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-
-import org.apache.logging.log4j.junit.JdbcRule;
-
-/**
- *
- */
-public class JdbcAppenderHsqldbFactoryMethodTest extends AbstractJdbcAppenderFactoryMethodTest {
- public JdbcAppenderHsqldbFactoryMethodTest() {
- super(new JdbcRule(
- new AbstractConnectionSource() {
- @Override
- public Connection getConnection() throws SQLException {
- return JdbcAppenderHsqldbFactoryMethodTest.getConnection();
- }
- },
- "CREATE TABLE fmLogEntry (" +
- "id INTEGER IDENTITY, eventDate DATETIME, literalColumn VARCHAR(255), level VARCHAR(10), " +
- "logger VARCHAR(255), message VARCHAR(1024), exception CLOB, anotherDate TIMESTAMP" +
- ")",
- "DROP TABLE fmLogEntry"
- ),
- "hsqldb"
- );
- }
-
- public static Connection getConnection() throws SQLException {
- return DriverManager.getConnection("jdbc:hsqldb:mem:Log4j", "sa", "");
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b5d4655d/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcAppenderMapMessageDataSourceTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcAppenderMapMessageDataSourceTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcAppenderMapMessageDataSourceTest.java
deleted file mode 100644
index c186537..0000000
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcAppenderMapMessageDataSourceTest.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.core.appender.db.jdbc;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
-
-import java.io.ByteArrayOutputStream;
-import java.io.PrintWriter;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-
-import javax.sql.DataSource;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.util.Throwables;
-import org.apache.logging.log4j.junit.JdbcRule;
-import org.apache.logging.log4j.junit.JndiRule;
-import org.apache.logging.log4j.junit.LoggerContextRule;
-import org.apache.logging.log4j.message.MapMessage;
-import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.RuleChain;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-
-/**
- * Unit tests {@link MapMessage}s for JdbcAppender using a {@link DataSource} configuration.
- */
-public class JdbcAppenderMapMessageDataSourceTest {
-
- @Rule
- public final RuleChain rules;
- private final JdbcRule jdbcRule;
-
- public JdbcAppenderMapMessageDataSourceTest() {
- this(new JdbcRule(JdbcH2TestHelper.TEST_CONFIGURATION_SOURCE,
- // @formatter:off
- "CREATE TABLE dsLogEntry (Id INTEGER IDENTITY, ColumnA VARCHAR(255), ColumnB VARCHAR(255))",
- "DROP TABLE dsLogEntry"));
- // @formatter:on
- }
-
- protected JdbcAppenderMapMessageDataSourceTest(final JdbcRule jdbcRule) {
- // @formatter:off
- this.rules = RuleChain.emptyRuleChain()
- .around(new JndiRule("java:/comp/env/jdbc/TestDataSourceAppender", createMockDataSource()))
- .around(jdbcRule)
- .around(new LoggerContextRule("org/apache/logging/log4j/core/appender/db/jdbc/log4j2-data-source-map-message.xml"));
- // @formatter:on
- this.jdbcRule = jdbcRule;
- }
-
- private DataSource createMockDataSource() {
- try {
- final DataSource dataSource = mock(DataSource.class);
- given(dataSource.getConnection()).willAnswer(new Answer<Connection>() {
- @Override
- public Connection answer(final InvocationOnMock invocation) throws Throwable {
- return jdbcRule.getConnectionSource().getConnection();
- }
- });
- return dataSource;
- } catch (final SQLException e) {
- Throwables.rethrow(e);
- throw new InternalError("unreachable");
- }
- }
-
- @Test
- public void testDataSourceConfig() throws Exception {
- try (final Connection connection = jdbcRule.getConnectionSource().getConnection()) {
- final Error exception = new Error("Final error massage is fatal!");
- final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- final PrintWriter writer = new PrintWriter(outputStream);
- exception.printStackTrace(writer);
- writer.close();
-
- final Logger logger = LogManager.getLogger(this.getClass().getName() + ".testDataSourceConfig");
- MapMessage mapMessage = new MapMessage();
- mapMessage.with("Id", 1);
- mapMessage.with("ColumnA", "ValueA");
- mapMessage.with("ColumnB", "ValueB");
- logger.info(mapMessage);
-
- try (final Statement statement = connection.createStatement();
- final ResultSet resultSet = statement
- .executeQuery("SELECT Id, ColumnA, ColumnB FROM dsLogEntry ORDER BY Id")) {
-
- assertTrue("There should be at least one row.", resultSet.next());
-
- Assert.assertEquals(1, resultSet.getInt("Id"));
-
- assertFalse("There should not be two rows.", resultSet.next());
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b5d4655d/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcH2TestHelper.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcH2TestHelper.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcH2TestHelper.java
deleted file mode 100644
index 7152f11..0000000
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcH2TestHelper.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.core.appender.db.jdbc;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-
-public class JdbcH2TestHelper {
-
- public static final String CONNECTION_STRING = "jdbc:h2:mem:Log4j";
- public static final String USER_NAME = "sa";
- public static final String PASSWORD = "";
-
- public static ConnectionSource TEST_CONFIGURATION_SOURCE = new AbstractConnectionSource() {
- @Override
- public Connection getConnection() throws SQLException {
- return JdbcH2TestHelper.getConnection();
- }
- };
-
- public static Connection getConnection() throws SQLException {
- return DriverManager.getConnection(CONNECTION_STRING, USER_NAME, PASSWORD);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b5d4655d/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/convert/DateTypeConverterTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/convert/DateTypeConverterTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/convert/DateTypeConverterTest.java
deleted file mode 100644
index 1c83d8d..0000000
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/convert/DateTypeConverterTest.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.core.config.plugins.convert;
-
-import java.sql.Time;
-import java.sql.Timestamp;
-import java.util.Date;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-import static org.junit.Assert.assertEquals;
-
-/**
- *
- */
-@RunWith(Parameterized.class)
-public class DateTypeConverterTest {
-
- private final Class<? extends Date> dateClass;
- private final long timestamp;
- private final Object expected;
-
- @Parameterized.Parameters
- public static Object[][] data() {
- final long millis = System.currentTimeMillis();
- return new Object[][]{
- {Date.class, millis, new Date(millis)},
- {java.sql.Date.class, millis, new java.sql.Date(millis)},
- {Time.class, millis, new Time(millis)},
- {Timestamp.class, millis, new Timestamp(millis)}
- };
- }
-
- public DateTypeConverterTest(final Class<? extends Date> dateClass, final long timestamp, final Object expected) {
- this.dateClass = dateClass;
- this.timestamp = timestamp;
- this.expected = expected;
- }
-
- @Test
- public void testFromMillis() throws Exception {
- assertEquals(expected, DateTypeConverter.fromMillis(timestamp, dateClass));
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b5d4655d/log4j-core/src/test/java/org/apache/logging/log4j/junit/JdbcRule.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/junit/JdbcRule.java b/log4j-core/src/test/java/org/apache/logging/log4j/junit/JdbcRule.java
deleted file mode 100644
index 9354a5e..0000000
--- a/log4j-core/src/test/java/org/apache/logging/log4j/junit/JdbcRule.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.junit;
-
-import java.sql.Connection;
-import java.sql.Statement;
-
-import org.apache.logging.log4j.core.appender.db.jdbc.ConnectionSource;
-import org.junit.rules.TestRule;
-import org.junit.runner.Description;
-
-/**
- * JUnit rule to set up a database. This will create a table using the configure creation statement on startup, run its
- * wrapped test(s), then execute a drop table statement on shutdown, and finally will attempt execute a {@code SHUTDOWN}
- * command afterward (e.g., for H2, HSQLDB). When used in integration tests, this rule should be the outer rule in a
- * chain with {@link LoggerContextRule}.
- *
- * @since 2.8
- */
-public class JdbcRule implements TestRule {
-
- private final ConnectionSource connectionSource;
- private final String createTableStatement;
- private final String dropTableStatement;
-
- /**
- * Creates a JdbcRule using a {@link ConnectionSource} and a table creation statement.
- *
- * @param connectionSource a source for obtaining a Connection
- * @param createTableStatement a SQL DDL statement to set up a table for use in a JUnit test
- * @param dropTableStatement a SQL DDL statement to drop the created table
- */
- public JdbcRule(final ConnectionSource connectionSource, final String createTableStatement,
- final String dropTableStatement) {
- this.dropTableStatement = dropTableStatement;
- this.connectionSource = connectionSource;
- this.createTableStatement = createTableStatement;
- }
-
- public ConnectionSource getConnectionSource() {
- return connectionSource;
- }
-
- @Override
- public org.junit.runners.model.Statement apply(final org.junit.runners.model.Statement base,
- final Description description) {
- return new org.junit.runners.model.Statement() {
- @Override
- public void evaluate() throws Throwable {
- try (final Connection connection = connectionSource.getConnection()) {
- try (final Statement statement = connection.createStatement()) {
- statement.executeUpdate(createTableStatement);
- }
- base.evaluate();
- try (final Statement statement = connection.createStatement()) {
- statement.executeUpdate(dropTableStatement);
- statement.execute("SHUTDOWN");
- }
- }
- }
- };
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b5d4655d/log4j-core/src/test/resources/log4j-fatalOnly.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-fatalOnly.xml b/log4j-core/src/test/resources/log4j-fatalOnly.xml
deleted file mode 100644
index e90a469..0000000
--- a/log4j-core/src/test/resources/log4j-fatalOnly.xml
+++ /dev/null
@@ -1,34 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
--->
-<Configuration status="OFF" name="Log4jTest">
-
- <Appenders>
- <Console name="STDOUT">
- <PatternLayout pattern="%m%n"/>
- </Console>
- </Appenders>
-
- <Loggers>
-
- <Root level="fatal">
- <AppenderRef ref="STDOUT"/>
- </Root>
- </Loggers>
-
-</Configuration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b5d4655d/log4j-core/src/test/resources/org/apache/logging/log4j/core/appender/db/jdbc/log4j2-data-source-map-message.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/org/apache/logging/log4j/core/appender/db/jdbc/log4j2-data-source-map-message.xml b/log4j-core/src/test/resources/org/apache/logging/log4j/core/appender/db/jdbc/log4j2-data-source-map-message.xml
deleted file mode 100644
index a50bbf6..0000000
--- a/log4j-core/src/test/resources/org/apache/logging/log4j/core/appender/db/jdbc/log4j2-data-source-map-message.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<Configuration status="ERROR">
-
- <Appenders>
- <Console name="STDOUT">
- <PatternLayout pattern="%C{1.} %m %level MDC%X%n"/>
- </Console>
- <Jdbc name="databaseAppender" tableName="dsLogEntry" ignoreExceptions="false">
- <DataSource jndiName="java:/comp/env/jdbc/TestDataSourceAppender" />
- <ColumnMapping name="Id" />
- <ColumnMapping name="ColumnA" />
- <ColumnMapping name="ColumnB" />
- <MessageLayout />
- </Jdbc>
- </Appenders>
-
- <Loggers>
- <Logger name="org.apache.logging.log4j.core.appender.db" level="debug" additivity="false">
- <AppenderRef ref="databaseAppender" />
- </Logger>
-
- <Root level="fatal">
- <AppenderRef ref="STDOUT"/>
- </Root>
- </Loggers>
-
-</Configuration>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b5d4655d/log4j-core/src/test/resources/org/apache/logging/log4j/core/appender/db/jdbc/log4j2-data-source.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/org/apache/logging/log4j/core/appender/db/jdbc/log4j2-data-source.xml b/log4j-core/src/test/resources/org/apache/logging/log4j/core/appender/db/jdbc/log4j2-data-source.xml
deleted file mode 100644
index 4e6ca91..0000000
--- a/log4j-core/src/test/resources/org/apache/logging/log4j/core/appender/db/jdbc/log4j2-data-source.xml
+++ /dev/null
@@ -1,45 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<Configuration status="OFF">
-
- <Appenders>
- <Console name="STDOUT">
- <PatternLayout pattern="%C{1.} %m %level MDC%X%n"/>
- </Console>
- <Jdbc name="databaseAppender" tableName="dsLogEntry" ignoreExceptions="false">
- <DataSource jndiName="java:/comp/env/jdbc/TestDataSourceAppender" />
- <Column name="eventDate" isEventTimestamp="true" />
- <Column name="literalColumn" literal="'Literal Value of Data Source'" />
- <Column name="level" pattern="%level" />
- <Column name="logger" pattern="%logger" />
- <Column name="message" pattern="%message" isUnicode="false" />
- <Column name="exception" pattern="%ex{full}" isClob="true" />
- </Jdbc>
- </Appenders>
-
- <Loggers>
- <Logger name="org.apache.logging.log4j.core.appender.db" level="debug" additivity="false">
- <AppenderRef ref="databaseAppender" />
- </Logger>
-
- <Root level="fatal">
- <AppenderRef ref="STDOUT"/>
- </Root>
- </Loggers>
-
-</Configuration>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b5d4655d/log4j-core/src/test/resources/org/apache/logging/log4j/core/appender/db/jdbc/log4j2-h2-factory-method.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/org/apache/logging/log4j/core/appender/db/jdbc/log4j2-h2-factory-method.xml b/log4j-core/src/test/resources/org/apache/logging/log4j/core/appender/db/jdbc/log4j2-h2-factory-method.xml
deleted file mode 100644
index b7ef940..0000000
--- a/log4j-core/src/test/resources/org/apache/logging/log4j/core/appender/db/jdbc/log4j2-h2-factory-method.xml
+++ /dev/null
@@ -1,47 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<Configuration status="OFF">
-
- <Appenders>
- <Console name="STDOUT">
- <PatternLayout pattern="%C{1.} %m %level MDC%X%n"/>
- </Console>
- <Jdbc name="databaseAppender" tableName="fmLogEntry" ignoreExceptions="false">
- <ConnectionFactory class="org.apache.logging.log4j.core.appender.db.jdbc.JdbcAppenderH2FactoryMethodTest"
- method="getConnection" />
- <Column name="eventDate" isEventTimestamp="true" />
- <Column name="literalColumn" literal="'Some Other Literal Value'" />
- <Column name="level" pattern="%level" />
- <Column name="logger" pattern="%logger" />
- <Column name="message" pattern="%message" isUnicode="false" />
- <Column name="exception" pattern="%ex{full}" isClob="true" />
- <ColumnMapping name="anotherDate" type="java.sql.Timestamp"/>
- </Jdbc>
- </Appenders>
-
- <Loggers>
- <Logger name="org.apache.logging.log4j.core.appender.db" level="debug" additivity="false">
- <AppenderRef ref="databaseAppender" />
- </Logger>
-
- <Root level="fatal">
- <AppenderRef ref="STDOUT"/>
- </Root>
- </Loggers>
-
-</Configuration>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b5d4655d/log4j-core/src/test/resources/org/apache/logging/log4j/core/appender/db/jdbc/log4j2-hsqldb-factory-method.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/org/apache/logging/log4j/core/appender/db/jdbc/log4j2-hsqldb-factory-method.xml b/log4j-core/src/test/resources/org/apache/logging/log4j/core/appender/db/jdbc/log4j2-hsqldb-factory-method.xml
deleted file mode 100644
index be92697..0000000
--- a/log4j-core/src/test/resources/org/apache/logging/log4j/core/appender/db/jdbc/log4j2-hsqldb-factory-method.xml
+++ /dev/null
@@ -1,47 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<Configuration status="OFF">
-
- <Appenders>
- <Console name="STDOUT">
- <PatternLayout pattern="%C{1.} %m %level MDC%X%n"/>
- </Console>
- <Jdbc name="databaseAppender" tableName="fmLogEntry" ignoreExceptions="false">
- <ConnectionFactory class="org.apache.logging.log4j.core.appender.db.jdbc.JdbcAppenderHsqldbFactoryMethodTest"
- method="getConnection" />
- <Column name="eventDate" isEventTimestamp="true" />
- <Column name="literalColumn" literal="'Some Other Literal Value'" />
- <Column name="level" pattern="%level" />
- <Column name="logger" pattern="%logger" />
- <Column name="message" pattern="%message" isUnicode="false" />
- <Column name="exception" pattern="%ex{full}" isClob="true" />
- <ColumnMapping name="anotherDate" type="java.sql.Timestamp"/>
- </Jdbc>
- </Appenders>
-
- <Loggers>
- <Logger name="org.apache.logging.log4j.core.appender.db" level="debug" additivity="false">
- <AppenderRef ref="databaseAppender" />
- </Logger>
-
- <Root level="fatal">
- <AppenderRef ref="STDOUT"/>
- </Root>
- </Loggers>
-
-</Configuration>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b5d4655d/log4j-distribution/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-distribution/pom.xml b/log4j-distribution/pom.xml
index 98217a1..275d379 100644
--- a/log4j-distribution/pom.xml
+++ b/log4j-distribution/pom.xml
@@ -124,6 +124,24 @@
<version>${project.version}</version>
<classifier>javadoc</classifier>
</dependency>
+ <!-- log4j-jdbc -->
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-jdbc</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-jdbc</artifactId>
+ <version>${project.version}</version>
+ <classifier>sources</classifier>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-jdbc</artifactId>
+ <version>${project.version}</version>
+ <classifier>javadoc</classifier>
+ </dependency>
<!-- log4j-jdbc-dbcp2 -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b5d4655d/log4j-jdbc-dbcp2/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-jdbc-dbcp2/pom.xml b/log4j-jdbc-dbcp2/pom.xml
index 3155019..900ac8e 100644
--- a/log4j-jdbc-dbcp2/pom.xml
+++ b/log4j-jdbc-dbcp2/pom.xml
@@ -34,6 +34,11 @@
<artifactId>log4j-core</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-jdbc</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.2.0</version>
@@ -54,6 +59,12 @@
<type>test-jar</type>
</dependency>
<dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-jdbc</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ </dependency>
+ <dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b5d4655d/log4j-jdbc-dbcp2/src/main/java/org/apache/logging/log4j/dbcp2/appender/PoolingDriverConnectionSource.java
----------------------------------------------------------------------
diff --git a/log4j-jdbc-dbcp2/src/main/java/org/apache/logging/log4j/dbcp2/appender/PoolingDriverConnectionSource.java b/log4j-jdbc-dbcp2/src/main/java/org/apache/logging/log4j/dbcp2/appender/PoolingDriverConnectionSource.java
index 6734e17..9357434 100644
--- a/log4j-jdbc-dbcp2/src/main/java/org/apache/logging/log4j/dbcp2/appender/PoolingDriverConnectionSource.java
+++ b/log4j-jdbc-dbcp2/src/main/java/org/apache/logging/log4j/dbcp2/appender/PoolingDriverConnectionSource.java
@@ -28,11 +28,11 @@ import org.apache.commons.dbcp2.PoolingDriver;
import org.apache.commons.pool2.ObjectPool;
import org.apache.commons.pool2.impl.GenericObjectPool;
import org.apache.logging.log4j.core.Core;
-import org.apache.logging.log4j.core.appender.db.jdbc.AbstractDriverManagerConnectionSource;
-import org.apache.logging.log4j.core.appender.db.jdbc.ConnectionSource;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
+import org.apache.logging.log4j.jdbc.appender.AbstractDriverManagerConnectionSource;
+import org.apache.logging.log4j.jdbc.appender.ConnectionSource;
/**
* A {@link ConnectionSource} that uses a JDBC connection string, a user name, and a password to call
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b5d4655d/log4j-jdbc-dbcp2/src/test/java/org/apache/logging/log4j/db/jdbc/appender/PoolingDriverConnectionSourceTest.java
----------------------------------------------------------------------
diff --git a/log4j-jdbc-dbcp2/src/test/java/org/apache/logging/log4j/db/jdbc/appender/PoolingDriverConnectionSourceTest.java b/log4j-jdbc-dbcp2/src/test/java/org/apache/logging/log4j/db/jdbc/appender/PoolingDriverConnectionSourceTest.java
deleted file mode 100644
index 56740f6..0000000
--- a/log4j-jdbc-dbcp2/src/test/java/org/apache/logging/log4j/db/jdbc/appender/PoolingDriverConnectionSourceTest.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-package org.apache.logging.log4j.db.jdbc.appender;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-
-import org.apache.logging.log4j.core.appender.db.jdbc.JdbcH2TestHelper;
-import org.apache.logging.log4j.core.config.Property;
-import org.apache.logging.log4j.dbcp2.appender.PoolingDriverConnectionSource;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class PoolingDriverConnectionSourceTest {
-
- @Test
- public void testH2Properties() throws SQLException {
- final Property[] properties = new Property[] {
- // @formatter:off
- Property.createProperty("username", JdbcH2TestHelper.USER_NAME),
- Property.createProperty("password", JdbcH2TestHelper.PASSWORD),
- // @formatter:on
- };
- // @formatter:off
- final PoolingDriverConnectionSource source = (PoolingDriverConnectionSource) PoolingDriverConnectionSource.newPoolingDriverConnectionSourceBuilder()
- .setConnectionString(JdbcH2TestHelper.CONNECTION_STRING)
- .setProperties(properties)
- .build();
- // @formatter:on
- try (Connection conn = source.getConnection()) {
- Assert.assertFalse(conn.isClosed());
- }
- }
-
- @Test
- public void testH2PropertiesAndPoolName() throws SQLException {
- final Property[] properties = new Property[] {
- // @formatter:off
- Property.createProperty("username", JdbcH2TestHelper.USER_NAME),
- Property.createProperty("password", JdbcH2TestHelper.PASSWORD),
- // @formatter:on
- };
- // @formatter:off
- final PoolingDriverConnectionSource source = PoolingDriverConnectionSource.newPoolingDriverConnectionSourceBuilder()
- .setConnectionString(JdbcH2TestHelper.CONNECTION_STRING)
- .setProperties(properties)
- .setPoolName("MyPoolName")
- .build();
- // @formatter:on
- try (Connection conn = source.getConnection()) {
- Assert.assertFalse(conn.isClosed());
- }
- }
-
- @Test
- public void testH2UserAndPassword() throws SQLException {
- // @formatter:off
- final PoolingDriverConnectionSource source = PoolingDriverConnectionSource.newPoolingDriverConnectionSourceBuilder()
- .setConnectionString(JdbcH2TestHelper.CONNECTION_STRING)
- .setUserName(JdbcH2TestHelper.USER_NAME.toCharArray())
- .setPassword(JdbcH2TestHelper.PASSWORD.toCharArray())
- .build();
- // @formatter:on
- try (Connection conn = source.getConnection()) {
- Assert.assertFalse(conn.isClosed());
- }
- }
-
- @Test
- public void testH2UserPasswordAndPoolName() throws SQLException {
- // @formatter:off
- final PoolingDriverConnectionSource source = PoolingDriverConnectionSource.newPoolingDriverConnectionSourceBuilder()
- .setConnectionString(JdbcH2TestHelper.CONNECTION_STRING)
- .setUserName(JdbcH2TestHelper.USER_NAME.toCharArray())
- .setPassword(JdbcH2TestHelper.PASSWORD.toCharArray())
- .setPoolName("MyPoolName")
- .build();
- // @formatter:on
- try (Connection conn = source.getConnection()) {
- Assert.assertFalse(conn.isClosed());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b5d4655d/log4j-jdbc-dbcp2/src/test/java/org/apache/logging/log4j/dbcp2/appender/PoolingDriverConnectionSourceTest.java
----------------------------------------------------------------------
diff --git a/log4j-jdbc-dbcp2/src/test/java/org/apache/logging/log4j/dbcp2/appender/PoolingDriverConnectionSourceTest.java b/log4j-jdbc-dbcp2/src/test/java/org/apache/logging/log4j/dbcp2/appender/PoolingDriverConnectionSourceTest.java
new file mode 100644
index 0000000..d415d43
--- /dev/null
+++ b/log4j-jdbc-dbcp2/src/test/java/org/apache/logging/log4j/dbcp2/appender/PoolingDriverConnectionSourceTest.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+
+package org.apache.logging.log4j.dbcp2.appender;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import org.apache.logging.log4j.core.config.Property;
+import org.apache.logging.log4j.jdbc.appender.JdbcH2TestHelper;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class PoolingDriverConnectionSourceTest {
+
+ @Test
+ public void testH2Properties() throws SQLException {
+ final Property[] properties = new Property[] {
+ // @formatter:off
+ Property.createProperty("username", JdbcH2TestHelper.USER_NAME),
+ Property.createProperty("password", JdbcH2TestHelper.PASSWORD),
+ // @formatter:on
+ };
+ // @formatter:off
+ final PoolingDriverConnectionSource source = PoolingDriverConnectionSource.newPoolingDriverConnectionSourceBuilder()
+ .setConnectionString(JdbcH2TestHelper.CONNECTION_STRING)
+ .setProperties(properties)
+ .build();
+ // @formatter:on
+ try (Connection conn = source.getConnection()) {
+ Assert.assertFalse(conn.isClosed());
+ }
+ }
+
+ @Test
+ public void testH2PropertiesAndPoolName() throws SQLException {
+ final Property[] properties = new Property[] {
+ // @formatter:off
+ Property.createProperty("username", JdbcH2TestHelper.USER_NAME),
+ Property.createProperty("password", JdbcH2TestHelper.PASSWORD),
+ // @formatter:on
+ };
+ // @formatter:off
+ final PoolingDriverConnectionSource source = PoolingDriverConnectionSource.newPoolingDriverConnectionSourceBuilder()
+ .setConnectionString(JdbcH2TestHelper.CONNECTION_STRING)
+ .setProperties(properties)
+ .setPoolName("MyPoolName")
+ .build();
+ // @formatter:on
+ try (Connection conn = source.getConnection()) {
+ Assert.assertFalse(conn.isClosed());
+ }
+ }
+
+ @Test
+ public void testH2UserAndPassword() throws SQLException {
+ // @formatter:off
+ final PoolingDriverConnectionSource source = PoolingDriverConnectionSource.newPoolingDriverConnectionSourceBuilder()
+ .setConnectionString(JdbcH2TestHelper.CONNECTION_STRING)
+ .setUserName(JdbcH2TestHelper.USER_NAME.toCharArray())
+ .setPassword(JdbcH2TestHelper.PASSWORD.toCharArray())
+ .build();
+ // @formatter:on
+ try (Connection conn = source.getConnection()) {
+ Assert.assertFalse(conn.isClosed());
+ }
+ }
+
+ @Test
+ public void testH2UserPasswordAndPoolName() throws SQLException {
+ // @formatter:off
+ final PoolingDriverConnectionSource source = PoolingDriverConnectionSource.newPoolingDriverConnectionSourceBuilder()
+ .setConnectionString(JdbcH2TestHelper.CONNECTION_STRING)
+ .setUserName(JdbcH2TestHelper.USER_NAME.toCharArray())
+ .setPassword(JdbcH2TestHelper.PASSWORD.toCharArray())
+ .setPoolName("MyPoolName")
+ .build();
+ // @formatter:on
+ try (Connection conn = source.getConnection()) {
+ Assert.assertFalse(conn.isClosed());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b5d4655d/log4j-jdbc/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-jdbc/pom.xml b/log4j-jdbc/pom.xml
new file mode 100644
index 0000000..9cc622e
--- /dev/null
+++ b/log4j-jdbc/pom.xml
@@ -0,0 +1,210 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- ~ Licensed to the Apache Software Foundation (ASF) under one or more ~ contributor license agreements. See the NOTICE
+ file distributed with ~ this work for additional information regarding copyright ownership. ~ The ASF licenses this file
+ to You under the Apache License, Version 2.0 ~ (the "License"); you may not use this file except in compliance with ~ the
+ License. You may obtain a copy of the License at ~ ~ http://www.apache.org/licenses/LICENSE-2.0 ~ ~ Unless required by applicable
+ law or agreed to in writing, software ~ distributed under the License is distributed on an "AS IS" BASIS, ~ WITHOUT WARRANTIES
+ OR CONDITIONS OF ANY KIND, either express or implied. ~ See the License for the specific language governing permissions and
+ ~ limitations under the License. -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>2.10.1-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>log4j-jdbc</artifactId>
+ <name>Apache Log4j JDBC</name>
+ <description>
+ Apache Log4j Java Database Connectivity (JDBC).
+ </description>
+ <properties>
+ <log4jParentDir>${basedir}/..</log4jParentDir>
+ <docLabel>Log4j JDBC Documentation</docLabel>
+ <projectDir>/log4j-jdbc</projectDir>
+ <module.name>org.apache.logging.log4j.jdbc</module.name>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ </dependency>
+ <!-- Test Dependencies -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api</artifactId>
+ <type>test-jar</type>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ <type>test-jar</type>
+ </dependency>
+ <!-- Mocking framework for use with JUnit -->
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <!-- Useful mock classes and utilities -->
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>default</id>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ <configuration>
+ <archive>
+ <manifestFile>${manifestfile}</manifestFile>
+ <manifestEntries>
+ <Specification-Title>${project.name}</Specification-Title>
+ <Specification-Version>${project.version}</Specification-Version>
+ <Specification-Vendor>${project.organization.name}</Specification-Vendor>
+ <Implementation-Title>${project.name}</Implementation-Title>
+ <Implementation-Version>${project.version}</Implementation-Version>
+ <Implementation-Vendor>${project.organization.name}</Implementation-Vendor>
+ <Implementation-Vendor-Id>org.apache</Implementation-Vendor-Id>
+ <X-Compile-Source-JDK>${maven.compiler.source}</X-Compile-Source-JDK>
+ <X-Compile-Target-JDK>${maven.compiler.target}</X-Compile-Target-JDK>
+ </manifestEntries>
+ </archive>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Fragment-Host>org.apache.logging.log4j.jdbc</Fragment-Host>
+ <Export-Package>*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-changes-plugin</artifactId>
+ <version>${changes.plugin.version}</version>
+ <reportSets>
+ <reportSet>
+ <reports>
+ <report>changes-report</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ <configuration>
+ <issueLinkTemplate>%URL%/show_bug.cgi?id=%ISSUE%</issueLinkTemplate>
+ <useJql>true</useJql>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <version>${checkstyle.plugin.version}</version>
+ <configuration>
+ <!--<propertiesLocation>${vfs.parent.dir}/checkstyle.properties</propertiesLocation> -->
+ <configLocation>${log4jParentDir}/checkstyle.xml</configLocation>
+ <suppressionsLocation>${log4jParentDir}/checkstyle-suppressions.xml</suppressionsLocation>
+ <enableRulesSummary>false</enableRulesSummary>
+ <propertyExpansion>basedir=${basedir}</propertyExpansion>
+ <propertyExpansion>licensedir=${log4jParentDir}/checkstyle-header.txt</propertyExpansion>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>${javadoc.plugin.version}</version>
+ <configuration>
+ <bottom><![CDATA[<p align="center">Copyright © {inceptionYear}-{currentYear} {organizationName}. All Rights Reserved.<br />
+ Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo,
+ and the Apache Log4j logo are trademarks of The Apache Software Foundation.</p>]]></bottom>
+ <!-- module link generation is completely broken in the javadoc plugin for a multi-module non-aggregating project -->
+ <detectOfflineLinks>false</detectOfflineLinks>
+ <linksource>true</linksource>
+ </configuration>
+ <reportSets>
+ <reportSet>
+ <id>non-aggregate</id>
+ <reports>
+ <report>javadoc</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <version>${findbugs.plugin.version}</version>
+ <configuration>
+ <fork>true</fork>
+ <jvmArgs>-Duser.language=en</jvmArgs>
+ <threshold>Normal</threshold>
+ <effort>Default</effort>
+ <excludeFilterFile>${log4jParentDir}/findbugs-exclude-filter.xml</excludeFilterFile>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jxr-plugin</artifactId>
+ <version>${jxr.plugin.version}</version>
+ <reportSets>
+ <reportSet>
+ <id>non-aggregate</id>
+ <reports>
+ <report>jxr</report>
+ </reports>
+ </reportSet>
+ <reportSet>
+ <id>aggregate</id>
+ <reports>
+ <report>aggregate</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-pmd-plugin</artifactId>
+ <version>${pmd.plugin.version}</version>
+ <configuration>
+ <targetJdk>${maven.compiler.target}</targetJdk>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
+</project>