Author: dallen6
Date: 2009-03-16 08:24:23 -0400 (Mon, 16 Mar 2009)
New Revision: 2037
Added:
extensions/trunk/logging/src/test/
extensions/trunk/logging/src/test/java/
extensions/trunk/logging/src/test/java/org/
extensions/trunk/logging/src/test/java/org/jboss/
extensions/trunk/logging/src/test/java/org/jboss/webbeans/
extensions/trunk/logging/src/test/java/org/jboss/webbeans/test/
extensions/trunk/logging/src/test/java/org/jboss/webbeans/test/log/
extensions/trunk/logging/src/test/java/org/jboss/webbeans/test/log/LoggingTest.java
extensions/trunk/logging/src/test/java/org/jboss/webbeans/test/log/TestAppender.java
extensions/trunk/logging/src/test/resources/
extensions/trunk/logging/src/test/resources/log4j.xml
Log:
Added some unit tests for logging.
Added:
extensions/trunk/logging/src/test/java/org/jboss/webbeans/test/log/LoggingTest.java
===================================================================
--- extensions/trunk/logging/src/test/java/org/jboss/webbeans/test/log/LoggingTest.java
(rev 0)
+++
extensions/trunk/logging/src/test/java/org/jboss/webbeans/test/log/LoggingTest.java 2009-03-16
12:24:23 UTC (rev 2037)
@@ -0,0 +1,59 @@
+package org.jboss.webbeans.test.log;
+
+import org.jboss.webbeans.log.Log;
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
+import org.testng.annotations.Test;
+
+/**
+ * Simple tests to verify proper operation of the logging system.
+ *
+ * @author David Allen
+ *
+ */
+public class LoggingTest
+{
+ private static final String TEST_MSG = "Test Message";
+
+ @Test
+ public void testLogProvider()
+ {
+ LogProvider logProvider = Logging.getLogProvider(LoggingTest.class);
+ assert logProvider != null;
+ }
+
+ @Test
+ public void testLogBasedOnClassObject()
+ {
+ Log log = Logging.getLog(LoggingTest.class);
+ assert log != null : "No Log object returned";
+
+ log.info(TEST_MSG);
+ assert TestAppender.getLastEvent() != null : "There was no last event in
Log4j";
+ assert
TestAppender.getLastEvent().getLoggerName().equals("org.jboss.webbeans.test.log.LoggingTest");
+ assert TestAppender.getLastEvent().getRenderedMessage().equals(TEST_MSG) :
"Last event has incorrect message";
+ }
+
+ @Test
+ public void testLogBasedOnStringObject()
+ {
+ Log log = Logging.getLog("MyLogger");
+ assert log != null;
+
+ log.info(TEST_MSG);
+ assert TestAppender.getLastEvent() != null : "There was no last event in
Log4j";
+ assert TestAppender.getLastEvent().getLoggerName().equals("MyLogger");
+ assert TestAppender.getLastEvent().getRenderedMessage().equals(TEST_MSG) :
"Last event has incorrect message";
+ }
+
+ @Test
+ public void testLogMessageFormatting()
+ {
+ Log log = Logging.getLog(LoggingTest.class);
+ assert log != null : "No Log object returned";
+
+ log.info("Message with {0} parameters starting with {1} and including
{2}", 3, "param1", "param2");
+ assert TestAppender.getLastEvent() != null : "There was no last event in
Log4j";
+ assert TestAppender.getLastEvent().getRenderedMessage().equals("Message with 3
parameters starting with param1 and including param2");
+ }
+}
Property changes on:
extensions/trunk/logging/src/test/java/org/jboss/webbeans/test/log/LoggingTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
extensions/trunk/logging/src/test/java/org/jboss/webbeans/test/log/TestAppender.java
===================================================================
--- extensions/trunk/logging/src/test/java/org/jboss/webbeans/test/log/TestAppender.java
(rev 0)
+++
extensions/trunk/logging/src/test/java/org/jboss/webbeans/test/log/TestAppender.java 2009-03-16
12:24:23 UTC (rev 2037)
@@ -0,0 +1,21 @@
+package org.jboss.webbeans.test.log;
+
+import org.apache.log4j.spi.LoggingEvent;
+import org.apache.log4j.varia.NullAppender;
+
+public class TestAppender extends NullAppender
+{
+ private static LoggingEvent lastEvent;
+
+ @Override
+ public void doAppend(LoggingEvent event)
+ {
+ lastEvent = event;
+ }
+
+ public static LoggingEvent getLastEvent()
+ {
+ return lastEvent;
+ }
+
+}
Property changes on:
extensions/trunk/logging/src/test/java/org/jboss/webbeans/test/log/TestAppender.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: extensions/trunk/logging/src/test/resources/log4j.xml
===================================================================
--- extensions/trunk/logging/src/test/resources/log4j.xml (rev 0)
+++ extensions/trunk/logging/src/test/resources/log4j.xml 2009-03-16 12:24:23 UTC (rev
2037)
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE
log4j:configuration SYSTEM "log4j.dtd">
+
+<log4j:configuration
xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="false">
+
+ <appender name="CONSOLE"
class="org.jboss.webbeans.test.log.TestAppender">
+ <layout class="org.apache.log4j.PatternLayout">
+ <!-- The default pattern: Date Priority [Category] Message\n -->
+ <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p
[%c{2}] %m%n"/>
+ </layout>
+ </appender>
+
+ <category name="org.jboss.webbeans.test">
+ <priority value="INFO"/>
+ </category>
+
+ <root>
+ <priority value="INFO"/>
+ <appender-ref ref="CONSOLE"/>
+ </root>
+
+</log4j:configuration>
Property changes on: extensions/trunk/logging/src/test/resources/log4j.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain