logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1481028 [1/2] - in /logging/log4j/log4j2/trunk/core/src/test: java/org/apache/logging/log4j/core/appender/db/ java/org/apache/logging/log4j/core/appender/db/jdbc/ java/org/apache/logging/log4j/core/appender/db/jpa/ java/org/apache/logging/...
Date Fri, 10 May 2013 14:33:45 GMT
Author: ggregory
Date: Fri May 10 14:33:42 2013
New Revision: 1481028

URL: http://svn.apache.org/r1481028
Log:
[LOG4J2-229] New JDBC, JPA, and NoSQL database Appenders. Oops, forgot to add new files.

Added:
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/AbstractDatabaseAppenderTest.java   (with props)
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/AbstractDatabaseManagerTest.java   (with props)
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/ColumnConfigTest.java   (with props)
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/DataSourceConnectionSourceTest.java   (with props)
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/DriverManagerConnectionSourceTest.java   (with props)
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/FactoryMethodConnectionSourceTest.java   (with props)
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JDBCAppenderTest.java   (with props)
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/JPAAppenderTest.java   (with props)
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/TestEntity.java   (with props)
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/nosql/
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/nosql/NoSQLAppenderTest.java   (with props)
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/nosql/NoSQLDatabaseManagerTest.java   (with props)
    logging/log4j/log4j2/trunk/core/src/test/resources/META-INF/
    logging/log4j/log4j2/trunk/core/src/test/resources/META-INF/persistence.xml   (with props)
    logging/log4j/log4j2/trunk/core/src/test/resources/org/apache/logging/
    logging/log4j/log4j2/trunk/core/src/test/resources/org/apache/logging/log4j/
    logging/log4j/log4j2/trunk/core/src/test/resources/org/apache/logging/log4j/core/
    logging/log4j/log4j2/trunk/core/src/test/resources/org/apache/logging/log4j/core/appender/
    logging/log4j/log4j2/trunk/core/src/test/resources/org/apache/logging/log4j/core/appender/db/
    logging/log4j/log4j2/trunk/core/src/test/resources/org/apache/logging/log4j/core/appender/db/jdbc/
    logging/log4j/log4j2/trunk/core/src/test/resources/org/apache/logging/log4j/core/appender/db/jdbc/log4j2-driver-manager.xml   (with props)
    logging/log4j/log4j2/trunk/core/src/test/resources/org/apache/logging/log4j/core/appender/db/jdbc/log4j2-factory-method.xml   (with props)
    logging/log4j/log4j2/trunk/core/src/test/resources/org/apache/logging/log4j/core/appender/db/jpa/
    logging/log4j/log4j2/trunk/core/src/test/resources/org/apache/logging/log4j/core/appender/db/jpa/log4j2-jpa.xml   (with props)

Added: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/AbstractDatabaseAppenderTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/AbstractDatabaseAppenderTest.java?rev=1481028&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/AbstractDatabaseAppenderTest.java (added)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/AbstractDatabaseAppenderTest.java Fri May 10 14:33:42 2013
@@ -0,0 +1,162 @@
+/*
+ * 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;
+
+import static org.easymock.EasyMock.createMockBuilder;
+import static org.easymock.EasyMock.createStrictMock;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reset;
+import static org.easymock.EasyMock.same;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+
+import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.LogEvent;
+import org.junit.After;
+import org.junit.Test;
+
+public class AbstractDatabaseAppenderTest {
+    private static abstract class LocalAbstractDatabaseAppender extends
+            AbstractDatabaseAppender<LocalAbstractDatabaseManager> {
+        public LocalAbstractDatabaseAppender(final String name, final Filter filter, final boolean handleException,
+                final LocalAbstractDatabaseManager manager) {
+            super(name, filter, handleException, manager);
+        }
+    }
+
+    private static abstract class LocalAbstractDatabaseManager extends AbstractDatabaseManager {
+        public LocalAbstractDatabaseManager(final String name, final int bufferSize) {
+            super(name, bufferSize);
+        }
+    }
+
+    private LocalAbstractDatabaseAppender appender;
+
+    private LocalAbstractDatabaseManager manager;
+
+    public void setUp(final String name) {
+        this.manager = createMockBuilder(LocalAbstractDatabaseManager.class).withConstructor(String.class, int.class)
+                .withArgs(name, 0).addMockedMethod("release").createStrictMock();
+
+        this.appender = createMockBuilder(LocalAbstractDatabaseAppender.class)
+                .withConstructor(String.class, Filter.class, boolean.class, LocalAbstractDatabaseManager.class)
+                .withArgs(name, null, true, this.manager).createStrictMock();
+    }
+
+    @After
+    public void tearDown() {
+        verify(this.manager, this.appender);
+    }
+
+    @Test
+    public void testAppend() {
+        this.setUp("name");
+
+        final LogEvent event1 = createStrictMock(LogEvent.class);
+        final LogEvent event2 = createStrictMock(LogEvent.class);
+
+        this.manager.writeInternal(same(event1));
+        expectLastCall();
+        replay(this.manager, this.appender);
+
+        this.appender.append(event1);
+
+        verify(this.manager, this.appender);
+        reset(this.manager, this.appender);
+        this.manager.writeInternal(same(event2));
+        expectLastCall();
+        replay(this.manager, this.appender);
+
+        this.appender.append(event2);
+    }
+
+    @Test
+    public void testNameAndGetLayout01() {
+        this.setUp("testName01");
+
+        replay(this.manager, this.appender);
+
+        assertEquals("The name is not correct.", "testName01", this.appender.getName());
+        assertNull("The layout should always be null.", this.appender.getLayout());
+    }
+
+    @Test
+    public void testNameAndGetLayout02() {
+        this.setUp("anotherName02");
+
+        replay(this.manager, this.appender);
+
+        assertEquals("The name is not correct.", "anotherName02", this.appender.getName());
+        assertNull("The layout should always be null.", this.appender.getLayout());
+    }
+
+    @Test
+    public void testReplaceManager() {
+        this.setUp("name");
+
+        replay(this.manager, this.appender);
+
+        final LocalAbstractDatabaseManager manager = this.appender.getManager();
+
+        assertSame("The manager should be the same.", this.manager, manager);
+
+        verify(this.manager, this.appender);
+        reset(this.manager, this.appender);
+        this.manager.release();
+        expectLastCall();
+        final LocalAbstractDatabaseManager newManager = createMockBuilder(LocalAbstractDatabaseManager.class)
+                .withConstructor(String.class, int.class).withArgs("name", 0).addMockedMethod("release")
+                .createStrictMock();
+        newManager.connectInternal();
+        expectLastCall();
+        replay(this.manager, this.appender, newManager);
+
+        this.appender.replaceManager(newManager);
+
+        verify(this.manager, this.appender, newManager);
+        reset(this.manager, this.appender, newManager);
+        newManager.release();
+        expectLastCall();
+        replay(this.manager, this.appender, newManager);
+
+        this.appender.stop();
+
+        verify(newManager);
+    }
+
+    @Test
+    public void testStartAndStop() {
+        this.setUp("name");
+
+        this.manager.connectInternal();
+        expectLastCall();
+        replay(this.manager, this.appender);
+
+        this.appender.start();
+
+        verify(this.manager, this.appender);
+        reset(this.manager, this.appender);
+        this.manager.release();
+        expectLastCall();
+        replay(this.manager, this.appender);
+
+        this.appender.stop();
+    }
+}

Propchange: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/AbstractDatabaseAppenderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/AbstractDatabaseAppenderTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/AbstractDatabaseManagerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/AbstractDatabaseManagerTest.java?rev=1481028&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/AbstractDatabaseManagerTest.java (added)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/AbstractDatabaseManagerTest.java Fri May 10 14:33:42 2013
@@ -0,0 +1,253 @@
+/*
+ * 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;
+
+import static org.easymock.EasyMock.createMockBuilder;
+import static org.easymock.EasyMock.createStrictMock;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reset;
+import static org.easymock.EasyMock.same;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.logging.log4j.core.LogEvent;
+import org.junit.After;
+import org.junit.Test;
+
+public class AbstractDatabaseManagerTest {
+    private AbstractDatabaseManager manager;
+
+    public void setUp(final String name, final int buffer) {
+        this.manager = createMockBuilder(AbstractDatabaseManager.class).withConstructor(String.class, int.class)
+                .withArgs(name, buffer).addMockedMethod("release").createStrictMock();
+    }
+
+    @After
+    public void tearDown() {
+        verify(this.manager);
+    }
+
+    @Test
+    public void testBuffering01() {
+        this.setUp("name", 0);
+
+        final LogEvent event1 = createStrictMock(LogEvent.class);
+        final LogEvent event2 = createStrictMock(LogEvent.class);
+        final LogEvent event3 = createStrictMock(LogEvent.class);
+
+        this.manager.connectInternal();
+        expectLastCall();
+        this.manager.writeInternal(same(event1));
+        expectLastCall();
+        replay(this.manager);
+
+        this.manager.connect();
+
+        this.manager.write(event1);
+
+        verify(this.manager);
+        reset(this.manager);
+        this.manager.writeInternal(same(event2));
+        expectLastCall();
+        replay(this.manager);
+
+        this.manager.write(event2);
+
+        verify(this.manager);
+        reset(this.manager);
+        this.manager.writeInternal(same(event3));
+        expectLastCall();
+        replay(this.manager);
+
+        this.manager.write(event3);
+    }
+
+    @Test
+    public void testBuffering02() {
+        this.setUp("name", 4);
+
+        final LogEvent event1 = createStrictMock(LogEvent.class);
+        final LogEvent event2 = createStrictMock(LogEvent.class);
+        final LogEvent event3 = createStrictMock(LogEvent.class);
+        final LogEvent event4 = createStrictMock(LogEvent.class);
+
+        this.manager.connectInternal();
+        expectLastCall();
+        replay(this.manager);
+
+        this.manager.connect();
+
+        this.manager.write(event1);
+        this.manager.write(event2);
+        this.manager.write(event3);
+
+        verify(this.manager);
+        reset(this.manager);
+        this.manager.writeInternal(same(event1));
+        expectLastCall();
+        this.manager.writeInternal(same(event2));
+        expectLastCall();
+        this.manager.writeInternal(same(event3));
+        expectLastCall();
+        this.manager.writeInternal(same(event4));
+        expectLastCall();
+        replay(this.manager);
+
+        this.manager.write(event4);
+    }
+
+    @Test
+    public void testBuffering03() {
+        this.setUp("name", 10);
+
+        final LogEvent event1 = createStrictMock(LogEvent.class);
+        final LogEvent event2 = createStrictMock(LogEvent.class);
+        final LogEvent event3 = createStrictMock(LogEvent.class);
+
+        this.manager.connectInternal();
+        expectLastCall();
+        replay(this.manager);
+
+        this.manager.connect();
+
+        this.manager.write(event1);
+        this.manager.write(event2);
+        this.manager.write(event3);
+
+        verify(this.manager);
+        reset(this.manager);
+        this.manager.writeInternal(same(event1));
+        expectLastCall();
+        this.manager.writeInternal(same(event2));
+        expectLastCall();
+        this.manager.writeInternal(same(event3));
+        expectLastCall();
+        replay(this.manager);
+
+        this.manager.flush();
+    }
+
+    @Test
+    public void testBuffering04() {
+        this.setUp("name", 10);
+
+        final LogEvent event1 = createStrictMock(LogEvent.class);
+        final LogEvent event2 = createStrictMock(LogEvent.class);
+        final LogEvent event3 = createStrictMock(LogEvent.class);
+
+        this.manager.connectInternal();
+        expectLastCall();
+        replay(this.manager);
+
+        this.manager.connect();
+
+        this.manager.write(event1);
+        this.manager.write(event2);
+        this.manager.write(event3);
+
+        verify(this.manager);
+        reset(this.manager);
+        this.manager.writeInternal(same(event1));
+        expectLastCall();
+        this.manager.writeInternal(same(event2));
+        expectLastCall();
+        this.manager.writeInternal(same(event3));
+        expectLastCall();
+        this.manager.disconnectInternal();
+        expectLastCall();
+        replay(this.manager);
+
+        this.manager.disconnect();
+    }
+
+    @Test
+    public void testConnection01() {
+        this.setUp("testName01", 0);
+
+        replay(this.manager);
+
+        assertEquals("The name is not correct.", "testName01", this.manager.getName());
+        assertFalse("The manager should not be connected.", this.manager.isConnected());
+
+        verify(this.manager);
+        reset(this.manager);
+        this.manager.connectInternal();
+        expectLastCall();
+        replay(this.manager);
+
+        this.manager.connect();
+        assertTrue("The manager should be connected now.", this.manager.isConnected());
+
+        verify(this.manager);
+        reset(this.manager);
+        this.manager.disconnectInternal();
+        expectLastCall();
+        replay(this.manager);
+
+        this.manager.disconnect();
+        assertFalse("The manager should not be connected anymore.", this.manager.isConnected());
+    }
+
+    @Test
+    public void testConnection02() {
+        this.setUp("anotherName02", 0);
+
+        replay(this.manager);
+
+        assertEquals("The name is not correct.", "anotherName02", this.manager.getName());
+        assertFalse("The manager should not be connected.", this.manager.isConnected());
+
+        verify(this.manager);
+        reset(this.manager);
+        this.manager.connectInternal();
+        expectLastCall();
+        replay(this.manager);
+
+        this.manager.connect();
+        assertTrue("The manager should be connected now.", this.manager.isConnected());
+
+        verify(this.manager);
+        reset(this.manager);
+        this.manager.disconnectInternal();
+        expectLastCall();
+        replay(this.manager);
+
+        this.manager.releaseSub();
+        assertFalse("The manager should not be connected anymore.", this.manager.isConnected());
+    }
+
+    @Test
+    public void testToString01() {
+        this.setUp("someName01", 0);
+
+        replay(this.manager);
+
+        assertEquals("The string is not correct.", "someName01", this.manager.toString());
+    }
+
+    @Test
+    public void testToString02() {
+        this.setUp("bufferSize=12, anotherKey02=coolValue02", 12);
+
+        replay(this.manager);
+
+        assertEquals("The string is not correct.", "bufferSize=12, anotherKey02=coolValue02", this.manager.toString());
+    }
+}

Propchange: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/AbstractDatabaseManagerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/AbstractDatabaseManagerTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/ColumnConfigTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/ColumnConfigTest.java?rev=1481028&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/ColumnConfigTest.java (added)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/ColumnConfigTest.java Fri May 10 14:33:42 2013
@@ -0,0 +1,160 @@
+/*
+ * 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.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ColumnConfigTest {
+    @Before
+    public void setUp() {
+
+    }
+
+    @After
+    public void tearDown() {
+
+    }
+
+    @Test
+    public void testDateColumn01() {
+        final ColumnConfig config = ColumnConfig.createColumnConfig(null, "columnName01", null, null, "true");
+
+        assertNotNull("The result should not be null.", config);
+        assertEquals("The column name is not correct.", "columnName01", 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());
+    }
+
+    @Test
+    public void testDateColumn02() {
+        final ColumnConfig config = ColumnConfig.createColumnConfig(null, "anotherName02", null, null, "true");
+
+        assertNotNull("The result should not be null.", config);
+        assertEquals("The column name is not correct.", "anotherName02", 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());
+    }
+
+    @Test
+    public void testLiteralAndDateNoConfig() {
+        final ColumnConfig config = ColumnConfig.createColumnConfig(null, "columnName01", null, "literal", "true");
+
+        assertNull("The result should be null.", config);
+    }
+
+    @Test
+    public void testLiteralColumn01() {
+        final ColumnConfig config = ColumnConfig.createColumnConfig(null, "columnName01", null, "literalValue01", null);
+
+        assertNotNull("The result should not be null.", config);
+        assertEquals("The column name is not correct.", "columnName01", 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());
+    }
+
+    @Test
+    public void testLiteralColumn02() {
+        final ColumnConfig config = ColumnConfig.createColumnConfig(null, "anotherName02", null,
+                "USER1.MY_SEQUENCE.NEXT", null);
+
+        assertNotNull("The result should not be null.", config);
+        assertEquals("The column name is not correct.", "anotherName02", 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());
+    }
+
+    @Test
+    public void testNoSettingNoConfig01() {
+        final ColumnConfig config = ColumnConfig.createColumnConfig(null, "columnName01", null, null, null);
+
+        assertNull("The result should be null.", config);
+    }
+
+    @Test
+    public void testNoSettingNoConfig02() {
+        final ColumnConfig config = ColumnConfig.createColumnConfig(null, "columnName01", null, null, "false");
+
+        assertNull("The result should be null.", config);
+    }
+
+    @Test
+    public void testNoSettingNoConfig03() {
+        final ColumnConfig config = ColumnConfig.createColumnConfig(null, "columnName01", "", "", "");
+
+        assertNull("The result should be null.", config);
+    }
+
+    @Test
+    public void testNullNameNoConfig() {
+        final ColumnConfig config = ColumnConfig.createColumnConfig(null, null, "%l", null, null);
+
+        assertNull("The result should be null.", config);
+    }
+
+    @Test
+    public void testPatternAndDateNoConfig() {
+        final ColumnConfig config = ColumnConfig.createColumnConfig(null, "columnName01", "%l", null, "true");
+
+        assertNull("The result should be null.", config);
+    }
+
+    @Test
+    public void testPatternAndLiteralNoConfig() {
+        final ColumnConfig config = ColumnConfig.createColumnConfig(null, "columnName01", "%l", "literal", null);
+
+        assertNull("The result should be null.", config);
+    }
+
+    @Test
+    public void testPatternColumn01() {
+        final ColumnConfig config = ColumnConfig.createColumnConfig(null, "columnName01", "%l", null, null);
+
+        assertNotNull("The result should not be null.", config);
+        assertEquals("The column name is not correct.", "columnName01", 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());
+    }
+
+    @Test
+    public void testPatternColumn02() {
+        final ColumnConfig config = ColumnConfig
+                .createColumnConfig(null, "anotherName02", "%X{id} %level", "", "false");
+
+        assertNotNull("The result should not be null.", config);
+        assertEquals("The column name is not correct.", "anotherName02", 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());
+    }
+}

Propchange: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/ColumnConfigTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/ColumnConfigTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/DataSourceConnectionSourceTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/DataSourceConnectionSourceTest.java?rev=1481028&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/DataSourceConnectionSourceTest.java (added)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/DataSourceConnectionSourceTest.java Fri May 10 14:33:42 2013
@@ -0,0 +1,136 @@
+/*
+ * 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.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.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.sql.DataSource;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockejb.jndi.MockContextFactory;
+
+public class DataSourceConnectionSourceTest {
+    private InitialContext context;
+
+    @Before
+    public void setUp() throws NamingException {
+        MockContextFactory.setAsInitial();
+
+        this.context = new InitialContext();
+        this.context.createSubcontext("java:");
+        this.context.createSubcontext("java:/comp");
+        this.context.createSubcontext("java:/comp/env");
+        this.context.createSubcontext("java:/comp/env/jdbc");
+    }
+
+    @After
+    public void tearDown() {
+        MockContextFactory.revertSetAsInitial();
+    }
+
+    @Test
+    public void testDataSource01() 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/Logging01", dataSource);
+
+        DataSourceConnectionSource source = DataSourceConnectionSource
+                .createConnectionSource("java:/comp/env/jdbc/Logging01");
+
+        assertNotNull("The connection source should not be null.", source);
+        assertEquals("The toString value is not correct.", "dataSource{ name=java:/comp/env/jdbc/Logging01, 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");
+
+        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);
+    }
+
+    @Test
+    public void testNoDataSource() {
+        final DataSourceConnectionSource source = DataSourceConnectionSource
+                .createConnectionSource("java:/comp/env/jdbc/Logging01");
+
+        assertNull("The connection source should be null.", source);
+    }
+
+    @Test
+    public void testNoJndiName01() {
+        final DataSourceConnectionSource source = DataSourceConnectionSource.createConnectionSource(null);
+
+        assertNull("The connection source should be null.", source);
+    }
+
+    @Test
+    public void testNoJndiName02() {
+        final DataSourceConnectionSource source = DataSourceConnectionSource.createConnectionSource("");
+
+        assertNull("The connection source should be null.", source);
+    }
+}

Propchange: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/DataSourceConnectionSourceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/DataSourceConnectionSourceTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/DriverManagerConnectionSourceTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/DriverManagerConnectionSourceTest.java?rev=1481028&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/DriverManagerConnectionSourceTest.java (added)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/DriverManagerConnectionSourceTest.java Fri May 10 14:33:42 2013
@@ -0,0 +1,216 @@
+/*
+ * 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.easymock.EasyMock.capture;
+import static org.easymock.EasyMock.createStrictMock;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reset;
+import static org.easymock.EasyMock.verify;
+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 java.sql.Connection;
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.logging.log4j.core.helpers.NameUtil;
+import org.easymock.Capture;
+import org.easymock.CaptureType;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class DriverManagerConnectionSourceTest {
+    private Driver driver;
+
+    @Before
+    public void setUp() throws SQLException {
+        this.driver = createStrictMock(Driver.class);
+        replay(this.driver);
+        DriverManager.registerDriver(driver);
+        verify(this.driver);
+        reset(this.driver);
+    }
+
+    @After
+    public void tearDown() throws SQLException {
+        DriverManager.deregisterDriver(this.driver);
+        verify(this.driver);
+    }
+
+    @Test
+    public void testInvalidUrl() throws SQLException {
+        expect(this.driver.acceptsURL("log4j2:test:appender:jdbc:url://localhost:2737/database")).andReturn(false);
+        replay(this.driver);
+
+        final DriverManagerConnectionSource source = DriverManagerConnectionSource.createConnectionSource(
+                "log4j2:test:appender:jdbc:url://localhost:2737/database", "username01", "password01");
+
+        assertNull("The connection source should be null.", source);
+    }
+
+    @Test
+    public void testNoUrl01() {
+        replay(this.driver);
+
+        final DriverManagerConnectionSource source = DriverManagerConnectionSource.createConnectionSource(null,
+                "username01", "password01");
+
+        assertNull("The connection source should be null.", source);
+    }
+
+    @Test
+    public void testNoUrl02() {
+        replay(this.driver);
+
+        final DriverManagerConnectionSource source = DriverManagerConnectionSource.createConnectionSource("",
+                "username01", "password01");
+
+        assertNull("The connection source should be null.", source);
+    }
+
+    @Test
+    public void testValidUrlNoUsernamePassword01() throws SQLException {
+        final Connection connection1 = createStrictMock(Connection.class);
+        final Connection connection2 = createStrictMock(Connection.class);
+
+        final Capture<Properties> capture = new Capture<Properties>(CaptureType.ALL);
+
+        expect(this.driver.acceptsURL("log4j2:test:appender:jdbc:url://localhost:2737/anotherDb")).andReturn(true);
+        expect(this.driver.connect(eq("log4j2:test:appender:jdbc:url://localhost:2737/anotherDb"), capture(capture)))
+                .andReturn(connection1);
+        expect(this.driver.connect(eq("log4j2:test:appender:jdbc:url://localhost:2737/anotherDb"), capture(capture)))
+                .andReturn(connection2);
+        replay(this.driver, connection1, connection2);
+
+        final DriverManagerConnectionSource source = DriverManagerConnectionSource.createConnectionSource(
+                "log4j2:test:appender:jdbc:url://localhost:2737/anotherDb", null, null);
+
+        assertNotNull("The connection source should not be null.", source);
+        assertEquals("The toString value is not correct.",
+                "driverManager{ url=log4j2:test:appender:jdbc:url://localhost:2737/anotherDb, username=null, "
+                        + "passwordHash=" + NameUtil.md5(null + DriverManagerConnectionSource.class.getName()) + " }",
+                source.toString());
+        assertSame("The connection is not correct (1).", connection1, source.getConnection());
+        assertSame("The connection is not correct (2).", connection2, source.getConnection());
+
+        final List<Properties> captured = capture.getValues();
+        assertEquals("The number of captured properties is not correct.", 2, captured.size());
+
+        final Properties properties1 = captured.get(0);
+        assertNotNull("The properties object should not be null (1).", properties1);
+        assertNull("The username should be null (1).", properties1.getProperty("user"));
+        assertNull("The password should be null (1).", properties1.getProperty("password"));
+
+        final Properties properties2 = captured.get(1);
+        assertNotNull("The properties object should not be null (2).", properties2);
+        assertNull("The username should be null (2).", properties2.getProperty("user"));
+        assertNull("The password should be null (2).", properties2.getProperty("password"));
+
+        verify(connection1, connection2);
+    }
+
+    @Test
+    public void testValidUrlNoUsernamePassword02() throws SQLException {
+        final Connection connection1 = createStrictMock(Connection.class);
+        final Connection connection2 = createStrictMock(Connection.class);
+
+        final Capture<Properties> capture = new Capture<Properties>(CaptureType.ALL);
+
+        expect(this.driver.acceptsURL("log4j2:test:appender:jdbc:url://localhost:2737/finalDb")).andReturn(true);
+        expect(this.driver.connect(eq("log4j2:test:appender:jdbc:url://localhost:2737/finalDb"), capture(capture)))
+                .andReturn(connection1);
+        expect(this.driver.connect(eq("log4j2:test:appender:jdbc:url://localhost:2737/finalDb"), capture(capture)))
+                .andReturn(connection2);
+        replay(this.driver, connection1, connection2);
+
+        final DriverManagerConnectionSource source = DriverManagerConnectionSource.createConnectionSource(
+                "log4j2:test:appender:jdbc:url://localhost:2737/finalDb", "     ", "");
+
+        assertNotNull("The connection source should not be null.", source);
+        assertEquals("The toString value is not correct.",
+                "driverManager{ url=log4j2:test:appender:jdbc:url://localhost:2737/finalDb, username=null, "
+                        + "passwordHash=" + NameUtil.md5(null + DriverManagerConnectionSource.class.getName()) + " }",
+                source.toString());
+        assertSame("The connection is not correct (1).", connection1, source.getConnection());
+        assertSame("The connection is not correct (2).", connection2, source.getConnection());
+
+        final List<Properties> captured = capture.getValues();
+        assertEquals("The number of captured properties is not correct.", 2, captured.size());
+
+        final Properties properties1 = captured.get(0);
+        assertNotNull("The properties object should not be null (1).", properties1);
+        assertNull("The username should be null (1).", properties1.getProperty("user"));
+        assertNull("The password should be null (1).", properties1.getProperty("password"));
+
+        final Properties properties2 = captured.get(1);
+        assertNotNull("The properties object should not be null (2).", properties2);
+        assertNull("The username should be null (2).", properties2.getProperty("user"));
+        assertNull("The password should be null (2).", properties2.getProperty("password"));
+
+        verify(connection1, connection2);
+    }
+
+    @Test
+    public void testValidUrlUsernamePassword() throws SQLException {
+        final Connection connection1 = createStrictMock(Connection.class);
+        final Connection connection2 = createStrictMock(Connection.class);
+
+        final Capture<Properties> capture = new Capture<Properties>(CaptureType.ALL);
+
+        expect(this.driver.acceptsURL("log4j2:test:appender:jdbc:url://localhost:2737/database")).andReturn(true);
+        expect(this.driver.connect(eq("log4j2:test:appender:jdbc:url://localhost:2737/database"), capture(capture)))
+                .andReturn(connection1);
+        expect(this.driver.connect(eq("log4j2:test:appender:jdbc:url://localhost:2737/database"), capture(capture)))
+                .andReturn(connection2);
+        replay(this.driver, connection1, connection2);
+
+        final DriverManagerConnectionSource source = DriverManagerConnectionSource.createConnectionSource(
+                "log4j2:test:appender:jdbc:url://localhost:2737/database", "username01", "password01");
+
+        assertNotNull("The connection source should not be null.", source);
+        assertEquals("The toString value is not correct.",
+                "driverManager{ url=log4j2:test:appender:jdbc:url://localhost:2737/database, username=username01, "
+                        + "passwordHash=" + NameUtil.md5("password01" + DriverManagerConnectionSource.class.getName())
+                        + " }", source.toString());
+        assertSame("The connection is not correct (1).", connection1, source.getConnection());
+        assertSame("The connection is not correct (2).", connection2, source.getConnection());
+
+        final List<Properties> captured = capture.getValues();
+        assertEquals("The number of captured properties is not correct.", 2, captured.size());
+
+        final Properties properties1 = captured.get(0);
+        assertNotNull("The properties object should not be null (1).", properties1);
+        assertEquals("The username is not correct (1).", "username01", properties1.getProperty("user"));
+        assertEquals("The password is not correct (1).", "password01", properties1.getProperty("password"));
+
+        final Properties properties2 = captured.get(1);
+        assertNotNull("The properties object should not be null (2).", properties2);
+        assertEquals("The username is not correct (2).", "username01", properties2.getProperty("user"));
+        assertEquals("The password is not correct (2).", "password01", properties2.getProperty("password"));
+
+        verify(connection1, connection2);
+    }
+}

Propchange: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/DriverManagerConnectionSourceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/DriverManagerConnectionSourceTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/FactoryMethodConnectionSourceTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/FactoryMethodConnectionSourceTest.java?rev=1481028&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/FactoryMethodConnectionSourceTest.java (added)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/FactoryMethodConnectionSourceTest.java Fri May 10 14:33:42 2013
@@ -0,0 +1,161 @@
+/*
+ * 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.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.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import javax.sql.DataSource;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.Test;
+
+public class FactoryMethodConnectionSourceTest {
+    @SuppressWarnings("unused")
+    protected static final class BadReturnTypeFactory {
+        public static String factoryMethod01() {
+            return "hello";
+        }
+    }
+
+    @SuppressWarnings("unused")
+    protected static final class ConnectionFactory {
+        public static Connection anotherMethod03() {
+            return (Connection) holder.get();
+        }
+    }
+
+    @SuppressWarnings("unused")
+    protected static final class DataSourceFactory {
+        public static DataSource factoryMethod02() {
+            return (DataSource) holder.get();
+        }
+    }
+
+    private static ThreadLocal<Object> holder = new ThreadLocal<Object>();
+
+    @AfterClass
+    public static void tearDownClass() {
+        holder.remove();
+        holder = null;
+    }
+
+    @Before
+    public void setUp() {
+
+    }
+
+    @After
+    public void tearDown() {
+        holder.remove();
+    }
+
+    @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 testConnectionReturnType() throws SQLException {
+        final Connection connection = createStrictMock(Connection.class);
+
+        replay(connection);
+
+        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());
+
+        verify(connection);
+    }
+
+    @Test
+    public void testDataSourceReturnType() throws 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);
+
+        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());
+
+        verify(connection1, connection2);
+    }
+
+    @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);
+    }
+}

Propchange: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/FactoryMethodConnectionSourceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/FactoryMethodConnectionSourceTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JDBCAppenderTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JDBCAppenderTest.java?rev=1481028&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JDBCAppenderTest.java (added)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JDBCAppenderTest.java Fri May 10 14:33:42 2013
@@ -0,0 +1,195 @@
+/*
+ * 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.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;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Map;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.logging.log4j.core.config.DefaultConfiguration;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.junit.After;
+import org.junit.Test;
+
+public class JDBCAppenderTest {
+    @SuppressWarnings("unused")
+    public static Connection testFactoryMethodConfigMethod() throws SQLException {
+        return DriverManager.getConnection("jdbc:hsqldb:mem:Log4j;ifexists=true", "sa", "");
+    }
+
+    private Connection connection;
+
+    public void setUp(final String tableName, final String configFileName) throws SQLException {
+        this.connection = DriverManager.getConnection("jdbc:hsqldb:mem:Log4j", "sa", "");
+
+        final Statement statement = this.connection.createStatement();
+        statement.executeUpdate("CREATE TABLE " + tableName + " ( "
+                + "id INTEGER IDENTITY, eventDate DATETIME, literalColumn VARCHAR(255), level VARCHAR(10), "
+                + "logger VARCHAR(255), message VARCHAR(1024), exception VARCHAR(1048576)" + " )");
+        statement.close();
+
+        System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY,
+                "org/apache/logging/log4j/core/appender/db/jdbc/" + configFileName);
+        final LoggerContext context = (LoggerContext) LogManager.getContext(false);
+        if (context.getConfiguration() instanceof DefaultConfiguration) {
+            context.reconfigure();
+        }
+        StatusLogger.getLogger().reset();
+    }
+
+    @After
+    public void tearDown() throws SQLException {
+        final LoggerContext context = (LoggerContext) LogManager.getContext(false);
+        try {
+            final Map<String, Appender<?>> list = context.getConfiguration().getAppenders();
+            final Appender<?> appender = list.get("databaseAppender");
+            assertNotNull("The appender should not be null.", appender);
+            assertTrue("The appender should be a JDBCAppender.", appender instanceof JDBCAppender);
+            ((JDBCAppender) appender).getManager().release();
+        } finally {
+            System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
+            context.reconfigure();
+            StatusLogger.getLogger().reset();
+
+            Statement statement = null;
+            try {
+                statement = this.connection.createStatement();
+                statement.execute("SHUTDOWN");
+            } finally {
+                try {
+                    if (statement != null) {
+                        statement.close();
+                    }
+                } catch (final SQLException ignore) { /* */
+                }
+            }
+
+            this.connection.close();
+        }
+    }
+
+    @Test
+    public void testDriverManagerConfig() throws SQLException {
+        this.setUp("dmLogEntry", "log4j2-driver-manager.xml");
+
+        final RuntimeException exception = new RuntimeException("Hello, world!");
+        final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+        final PrintWriter writer = new PrintWriter(outputStream);
+        exception.printStackTrace(writer);
+        writer.close();
+        final String stackTrace = outputStream.toString();
+
+        final long millis = System.currentTimeMillis();
+
+        final Logger logger = LogManager.getLogger(this.getClass().getName() + ".testDriverManagerConfig");
+        logger.info("Test my message 01.");
+        logger.warn("This is another message 02.", exception);
+
+        final Statement statement = this.connection.createStatement();
+        final ResultSet resultSet = statement.executeQuery("SELECT * FROM dmLogEntry ORDER BY id");
+
+        assertTrue("There should be at least one row.", resultSet.next());
+
+        long date = resultSet.getTimestamp("eventDate").getTime();
+        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).", "Literal Value Test String",
+                resultSet.getString("literalColumn"));
+        assertEquals("The level column is not correct (1).", "INFO", resultSet.getString("level"));
+        assertEquals("The logger column is not correct (1).", logger.getName(), resultSet.getString("logger"));
+        assertEquals("The message column is not correct (1).", "Test my message 01.", resultSet.getString("message"));
+        assertEquals("The exception column is not correct (1).", "", resultSet.getString("exception"));
+
+        assertTrue("There should be two rows.", resultSet.next());
+
+        date = resultSet.getTimestamp("eventDate").getTime();
+        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).", "Literal Value Test String",
+                resultSet.getString("literalColumn"));
+        assertEquals("The level column is not correct (2).", "WARN", resultSet.getString("level"));
+        assertEquals("The logger column is not correct (2).", logger.getName(), resultSet.getString("logger"));
+        assertEquals("The message column is not correct (2).", "This is another message 02.",
+                resultSet.getString("message"));
+        assertEquals("The exception column is not correct (2).", stackTrace, resultSet.getString("exception"));
+
+        assertFalse("There should not be three rows.", resultSet.next());
+    }
+
+    @Test
+    public void testFactoryMethodConfig() throws SQLException {
+        this.setUp("fmLogEntry", "log4j2-factory-method.xml");
+
+        final SQLException exception = new SQLException("Some other error message!");
+        final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+        final PrintWriter writer = new PrintWriter(outputStream);
+        exception.printStackTrace(writer);
+        writer.close();
+        final String stackTrace = outputStream.toString();
+
+        final long millis = System.currentTimeMillis();
+
+        final Logger logger = LogManager.getLogger(this.getClass().getName() + ".testFactoryMethodConfig");
+        logger.debug("Factory logged message 01.");
+        logger.error("Error from factory 02.", exception);
+
+        final Statement statement = this.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();
+        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.getString("level"));
+        assertEquals("The logger column is not correct (1).", logger.getName(), resultSet.getString("logger"));
+        assertEquals("The message column is not correct (1).", "Factory logged message 01.",
+                resultSet.getString("message"));
+        assertEquals("The exception column is not correct (1).", "", resultSet.getString("exception"));
+
+        assertTrue("There should be two rows.", resultSet.next());
+
+        date = resultSet.getTimestamp("eventDate").getTime();
+        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.getString("level"));
+        assertEquals("The logger column is not correct (2).", logger.getName(), resultSet.getString("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, resultSet.getString("exception"));
+
+        assertFalse("There should not be three rows.", resultSet.next());
+    }
+}

Propchange: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JDBCAppenderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jdbc/JDBCAppenderTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/JPAAppenderTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/JPAAppenderTest.java?rev=1481028&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/JPAAppenderTest.java (added)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/JPAAppenderTest.java Fri May 10 14:33:42 2013
@@ -0,0 +1,225 @@
+/*
+ * 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.jpa;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintWriter;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Map;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.logging.log4j.core.config.DefaultConfiguration;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.junit.Test;
+
+public class JPAAppenderTest {
+    @SuppressWarnings("unused")
+    public static class BadConstructorEntity1 extends TestEntity {
+        private static final long serialVersionUID = 1L;
+
+        public BadConstructorEntity1(final LogEvent wrappedEvent) {
+            super(wrappedEvent);
+        }
+    }
+
+    @SuppressWarnings("unused")
+    public static class BadConstructorEntity2 extends TestEntity {
+        private static final long serialVersionUID = 1L;
+
+        public BadConstructorEntity2() {
+            super(null);
+        }
+
+        public BadConstructorEntity2(final LogEvent wrappedEvent, final String badParameter) {
+            super(wrappedEvent);
+        }
+    }
+
+    private Connection connection;
+
+    public void setUp(final String configFileName) throws SQLException {
+        this.connection = DriverManager.getConnection("jdbc:hsqldb:mem:Log4j", "sa", "");
+
+        final Statement statement = this.connection.createStatement();
+        statement.executeUpdate("CREATE TABLE jpaLogEntry ( "
+                + "id INTEGER IDENTITY, eventDate DATETIME, level VARCHAR(10), logger VARCHAR(255), "
+                + "message VARCHAR(1024), exception VARCHAR(1048576)" + " )");
+        statement.close();
+
+        System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY,
+                "org/apache/logging/log4j/core/appender/db/jpa/" + configFileName);
+        final LoggerContext context = (LoggerContext) LogManager.getContext(false);
+        if (context.getConfiguration() instanceof DefaultConfiguration) {
+            context.reconfigure();
+        }
+        StatusLogger.getLogger().reset();
+    }
+
+    public void tearDown() throws SQLException {
+        final LoggerContext context = (LoggerContext) LogManager.getContext(false);
+        try {
+            final Map<String, Appender<?>> list = context.getConfiguration().getAppenders();
+            final Appender<?> appender = list.get("databaseAppender");
+            assertNotNull("The appender should not be null.", appender);
+            assertTrue("The appender should be a JDBCAppender.", appender instanceof JPAAppender);
+            ((JPAAppender) appender).getManager().release();
+        } finally {
+            System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
+            context.reconfigure();
+            StatusLogger.getLogger().reset();
+
+            Statement statement = null;
+            try {
+                statement = this.connection.createStatement();
+                statement.execute("SHUTDOWN");
+            } finally {
+                try {
+                    if (statement != null) {
+                        statement.close();
+                    }
+                } catch (final SQLException ignore) { /* */
+                }
+            }
+
+            this.connection.close();
+        }
+    }
+
+    @Test
+    public void testBadConstructorEntity01() {
+        final JPAAppender appender = JPAAppender.createAppender("name", null, null, null,
+                BadConstructorEntity1.class.getName(), "jpaAppenderTestUnit");
+
+        assertNull("The appender should be null.", appender);
+    }
+
+    @Test
+    public void testBadConstructorEntity02() {
+        final JPAAppender appender = JPAAppender.createAppender("name", null, null, null,
+                BadConstructorEntity2.class.getName(), "jpaAppenderTestUnit");
+
+        assertNull("The appender should be null.", appender);
+    }
+
+    @Test
+    public void testBadEntityClassName() {
+        final JPAAppender appender = JPAAppender.createAppender("name", null, null, null, "com.foo.Bar",
+                "jpaAppenderTestUnit");
+
+        assertNull("The appender should be null.", appender);
+    }
+
+    @Test
+    public void testConfiguredAppender() throws SQLException {
+        try {
+            this.setUp("log4j2-jpa.xml");
+
+            final RuntimeException exception = new RuntimeException("Hello, world!");
+            final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+            final PrintWriter writer = new PrintWriter(outputStream);
+            exception.printStackTrace(writer);
+            writer.close();
+            final String stackTrace = outputStream.toString();
+
+            final long millis = System.currentTimeMillis();
+
+            final Logger logger1 = LogManager.getLogger(this.getClass().getName() + ".testConfiguredAppender");
+            final Logger logger2 = LogManager.getLogger(this.getClass().getName() + ".testConfiguredAppenderAgain");
+            logger1.info("Test my message 01.");
+            logger1.error("This is another message 02.", exception);
+            logger2.warn("A final warning has been issued.");
+
+            final Statement statement = this.connection.createStatement();
+            final ResultSet resultSet = statement.executeQuery("SELECT * FROM jpaLogEntry ORDER BY id");
+
+            assertTrue("There should be at least one row.", resultSet.next());
+
+            long date = resultSet.getTimestamp("eventDate").getTime();
+            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 level column is not correct (1).", "INFO", resultSet.getString("level"));
+            assertEquals("The logger column is not correct (1).", logger1.getName(), resultSet.getString("logger"));
+            assertEquals("The message column is not correct (1).", "Test my message 01.",
+                    resultSet.getString("message"));
+            assertNull("The exception column is not correct (1).", resultSet.getString("exception"));
+
+            assertTrue("There should be at least two rows.", resultSet.next());
+
+            date = resultSet.getTimestamp("eventDate").getTime();
+            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 level column is not correct (2).", "ERROR", resultSet.getString("level"));
+            assertEquals("The logger column is not correct (2).", logger1.getName(), resultSet.getString("logger"));
+            assertEquals("The message column is not correct (2).", "This is another message 02.",
+                    resultSet.getString("message"));
+            assertEquals("The exception column is not correct (2).", stackTrace, resultSet.getString("exception"));
+
+            assertTrue("There should be three rows.", resultSet.next());
+
+            date = resultSet.getTimestamp("eventDate").getTime();
+            assertTrue("The date should be later than pre-logging (3).", date >= millis);
+            assertTrue("The date should be earlier than now (3).", date <= System.currentTimeMillis());
+            assertEquals("The level column is not correct (3).", "WARN", resultSet.getString("level"));
+            assertEquals("The logger column is not correct (3).", logger2.getName(), resultSet.getString("logger"));
+            assertEquals("The message column is not correct (3).", "A final warning has been issued.",
+                    resultSet.getString("message"));
+            assertNull("The exception column is not correct (3).", resultSet.getString("exception"));
+
+            assertFalse("There should not be four rows.", resultSet.next());
+        } finally {
+            this.tearDown();
+        }
+    }
+
+    @Test
+    public void testNoEntityClassName() {
+        final JPAAppender appender = JPAAppender.createAppender("name", null, null, null, null, "jpaAppenderTestUnit");
+
+        assertNull("The appender should be null.", appender);
+    }
+
+    @Test
+    public void testNonLogEventEntity() {
+        final JPAAppender appender = JPAAppender.createAppender("name", null, null, null, Object.class.getName(),
+                "jpaAppenderTestUnit");
+
+        assertNull("The appender should be null.", appender);
+    }
+
+    @Test
+    public void testNoPersistenceUnitName() {
+        final JPAAppender appender = JPAAppender.createAppender("name", null, null, null, TestEntity.class.getName(),
+                null);
+
+        assertNull("The appender should be null.", appender);
+    }
+}

Propchange: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/JPAAppenderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/JPAAppenderTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/TestEntity.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/TestEntity.java?rev=1481028&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/TestEntity.java (added)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/TestEntity.java Fri May 10 14:33:42 2013
@@ -0,0 +1,175 @@
+/*
+ * 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.jpa;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintWriter;
+import java.util.Date;
+import java.util.Map;
+
+import javax.persistence.Basic;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.Marker;
+import org.apache.logging.log4j.ThreadContext;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.message.Message;
+
+@Entity
+@Table(name = "jpaLogEntry")
+@SuppressWarnings("unused")
+public class TestEntity extends LogEventWrapperEntity {
+    private static final long serialVersionUID = 1L;
+
+    private long id = 0L;
+
+    public TestEntity() {
+        super(null);
+    }
+
+    public TestEntity(final LogEvent wrappedEvent) {
+        super(wrappedEvent);
+    }
+
+    @Override
+    @Transient
+    public Map<String, String> getContextMap() {
+        return getWrappedEvent().getContextMap();
+    }
+
+    @Override
+    @Transient
+    public ThreadContext.ContextStack getContextStack() {
+        return getWrappedEvent().getContextStack();
+    }
+
+    @Temporal(TemporalType.TIMESTAMP)
+    @Column(name = "eventDate")
+    public Date getEventDate() {
+        return new Date(this.getMillis());
+    }
+
+    @Basic
+    @Column(name = "exception")
+    @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
+    public String getException() {
+        if (this.getThrown() != null) {
+            final ByteArrayOutputStream stream = new ByteArrayOutputStream();
+            final PrintWriter writer = new PrintWriter(stream);
+            this.getThrown().printStackTrace(writer);
+            writer.close();
+            return stream.toString();
+        }
+        return null;
+    }
+
+    @Override
+    @Transient
+    public String getFQCN() {
+        return getWrappedEvent().getFQCN();
+    }
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id")
+    public long getId() {
+        return this.id;
+    }
+
+    @Override
+    @Enumerated(EnumType.STRING)
+    @Column(name = "level")
+    public Level getLevel() {
+        return getWrappedEvent().getLevel();
+    }
+
+    @Override
+    @Basic
+    @Column(name = "logger")
+    public String getLoggerName() {
+        return getWrappedEvent().getLoggerName();
+    }
+
+    @Override
+    @Transient
+    public Marker getMarker() {
+        return getWrappedEvent().getMarker();
+    }
+
+    @Override
+    @Transient
+    public Message getMessage() {
+        return getWrappedEvent().getMessage();
+    }
+
+    @Basic
+    @Column(name = "message")
+    public String getMessageString() {
+        return this.getMessage().getFormattedMessage();
+    }
+
+    @Override
+    @Transient
+    public long getMillis() {
+        return getWrappedEvent().getMillis();
+    }
+
+    @Override
+    @Transient
+    public StackTraceElement getSource() {
+        return getWrappedEvent().getSource();
+    }
+
+    @Override
+    @Transient
+    public String getThreadName() {
+        return getWrappedEvent().getThreadName();
+    }
+
+    @Override
+    @Transient
+    public Throwable getThrown() {
+        return getWrappedEvent().getThrown();
+    }
+
+    public void setEventDate(final Date date) {
+        // this entity is write-only
+    }
+
+    public void setException(final String exception) {
+        // this entity is write-only
+    }
+
+    public void setId(final long id) {
+        this.id = id;
+    }
+
+    public void setMessageString(final String messageString) {
+        // this entity is write-only
+    }
+}

Propchange: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/TestEntity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/jpa/TestEntity.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/nosql/NoSQLAppenderTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/nosql/NoSQLAppenderTest.java?rev=1481028&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/nosql/NoSQLAppenderTest.java (added)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/nosql/NoSQLAppenderTest.java Fri May 10 14:33:42 2013
@@ -0,0 +1,85 @@
+/*
+ * 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.nosql;
+
+import static org.easymock.EasyMock.createStrictMock;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class NoSQLAppenderTest {
+    @Before
+    public void setUp() {
+
+    }
+
+    @After
+    public void tearDown() {
+
+    }
+
+    @Test
+    public void testNoProvider() {
+        final NoSQLAppender appender = NoSQLAppender.createAppender("myName01", null, null, null, null);
+
+        assertNull("The appender should be null.", appender);
+    }
+
+    @Test
+    public void testProvider() {
+        @SuppressWarnings("unchecked")
+        final NoSQLProvider<?> provider = createStrictMock(NoSQLProvider.class);
+
+        replay(provider);
+
+        final NoSQLAppender appender = NoSQLAppender.createAppender("myName01", null, null, null, provider);
+
+        assertNotNull("The appender should not be null.", appender);
+        assertEquals("The toString value is not correct.",
+                "myName01{ manager=noSqlManager{ description=myName01, bufferSize=0, provider=" + provider + " } }",
+                appender.toString());
+
+        appender.stop();
+
+        verify(provider);
+    }
+
+    @Test
+    public void testProviderBuffer() {
+        @SuppressWarnings("unchecked")
+        final NoSQLProvider<?> provider = createStrictMock(NoSQLProvider.class);
+
+        replay(provider);
+
+        final NoSQLAppender appender = NoSQLAppender.createAppender("anotherName02", null, null, "25", provider);
+
+        assertNotNull("The appender should not be null.", appender);
+        assertEquals("The toString value is not correct.",
+                "anotherName02{ manager=noSqlManager{ description=anotherName02, bufferSize=25, provider=" + provider
+                        + " } }", appender.toString());
+
+        appender.stop();
+
+        verify(provider);
+    }
+}

Propchange: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/nosql/NoSQLAppenderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/db/nosql/NoSQLAppenderTest.java
------------------------------------------------------------------------------
    svn:keywords = Id



Mime
View raw message