Author: dallen6
Date: 2009-03-22 06:42:28 -0400 (Sun, 22 Mar 2009)
New Revision: 2129
Added:
extensions/trunk/logger/src/test/java/org/jboss/webbeans/test/log/Finch.java
extensions/trunk/logger/src/test/java/org/jboss/webbeans/test/log/TestAppender.java
extensions/trunk/logger/src/test/resources/log4j.xml
Modified:
extensions/trunk/logger/src/main/java/org/jboss/webbeans/annotation/Logger.java
extensions/trunk/logger/src/main/java/org/jboss/webbeans/producer/LoggerProducer.java
extensions/trunk/logger/src/test/java/org/jboss/webbeans/test/log/LoggerInjectionTest.java
Log:
Fixed outstanding bugs and finished the unit tests
Modified: extensions/trunk/logger/src/main/java/org/jboss/webbeans/annotation/Logger.java
===================================================================
---
extensions/trunk/logger/src/main/java/org/jboss/webbeans/annotation/Logger.java 2009-03-21
12:59:19 UTC (rev 2128)
+++
extensions/trunk/logger/src/main/java/org/jboss/webbeans/annotation/Logger.java 2009-03-22
10:42:28 UTC (rev 2129)
@@ -1,12 +1,16 @@
package org.jboss.webbeans.annotation;
import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
+import javax.annotation.NonBinding;
import javax.inject.BindingType;
/**
@@ -14,7 +18,7 @@
*
* @author Gavin King
*/
-@Target(FIELD)
+@Target({METHOD, FIELD, PARAMETER, TYPE})
@Retention(RUNTIME)
@Documented
@BindingType
@@ -23,5 +27,6 @@
/**
* @return the log category
*/
+ @NonBinding
String value() default "";
}
Modified:
extensions/trunk/logger/src/main/java/org/jboss/webbeans/producer/LoggerProducer.java
===================================================================
---
extensions/trunk/logger/src/main/java/org/jboss/webbeans/producer/LoggerProducer.java 2009-03-21
12:59:19 UTC (rev 2128)
+++
extensions/trunk/logger/src/main/java/org/jboss/webbeans/producer/LoggerProducer.java 2009-03-22
10:42:28 UTC (rev 2129)
@@ -17,9 +17,7 @@
package org.jboss.webbeans.producer;
-import javax.context.ApplicationScoped;
import javax.inject.Current;
-import javax.inject.DefinitionException;
import javax.inject.Produces;
import javax.inject.manager.InjectionPoint;
@@ -38,17 +36,13 @@
*/
public class LoggerProducer
{
- @Produces @ApplicationScoped
+ @Produces @Logger
public Log produceLog(@Current InjectionPoint injectionPoint)
{
Log log = null;
String category = null;
- if (injectionPoint.getType().equals(Log.class))
- {
- throw new DefinitionException("Cannot use @Logger on any type other than
org.jboss.webbeans.log.Log: " + injectionPoint);
- }
category = injectionPoint.getAnnotation(Logger.class).value();
- if (category == null)
+ if (category.isEmpty())
{
log = Logging.getLog((Class<?>)
injectionPoint.getMember().getDeclaringClass());
}
Added: extensions/trunk/logger/src/test/java/org/jboss/webbeans/test/log/Finch.java
===================================================================
--- extensions/trunk/logger/src/test/java/org/jboss/webbeans/test/log/Finch.java
(rev 0)
+++
extensions/trunk/logger/src/test/java/org/jboss/webbeans/test/log/Finch.java 2009-03-22
10:42:28 UTC (rev 2129)
@@ -0,0 +1,15 @@
+package org.jboss.webbeans.test.log;
+
+import org.jboss.webbeans.annotation.Logger;
+import org.jboss.webbeans.log.Log;
+
+public class Finch
+{
+ @Logger("Finch")
+ private Log log;
+
+ public void generateLogMessage()
+ {
+ log.info("A test message");
+ }
+}
Property changes on:
extensions/trunk/logger/src/test/java/org/jboss/webbeans/test/log/Finch.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
extensions/trunk/logger/src/test/java/org/jboss/webbeans/test/log/LoggerInjectionTest.java
===================================================================
---
extensions/trunk/logger/src/test/java/org/jboss/webbeans/test/log/LoggerInjectionTest.java 2009-03-21
12:59:19 UTC (rev 2128)
+++
extensions/trunk/logger/src/test/java/org/jboss/webbeans/test/log/LoggerInjectionTest.java 2009-03-22
10:42:28 UTC (rev 2129)
@@ -17,6 +17,8 @@
package org.jboss.webbeans.test.log;
+import javax.inject.ExecutionException;
+
import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.testharness.impl.packaging.Classes;
import org.jboss.webbeans.test.AbstractLogTest;
@@ -26,16 +28,26 @@
* All the tests related to the @Logger binding type and injection.
*
* @author David Allen
- *
*/
@Artifact
@Classes(packages = { "org.jboss.webbeans.producer",
"org.jboss.webbeans.test.log" })
public class LoggerInjectionTest extends AbstractLogTest
{
- @Test( groups = { "broken" } )
+ @Test
public void testBasicLogInjection()
{
Sparrow bird = getCurrentManager().getInstanceByType(Sparrow.class);
bird.generateLogMessage();
+ assert TestAppender.getLastEvent() != null;
+ assert
TestAppender.getLastEvent().getLoggerName().equals("org.jboss.webbeans.test.log.Sparrow");
}
+
+ @Test
+ public void testCategorySpecifiedLogger()
+ {
+ Finch bird = getCurrentManager().getInstanceByType(Finch.class);
+ bird.generateLogMessage();
+ assert TestAppender.getLastEvent() != null;
+ assert TestAppender.getLastEvent().getLoggerName().equals("Finch");
+ }
}
Added:
extensions/trunk/logger/src/test/java/org/jboss/webbeans/test/log/TestAppender.java
===================================================================
--- extensions/trunk/logger/src/test/java/org/jboss/webbeans/test/log/TestAppender.java
(rev 0)
+++
extensions/trunk/logger/src/test/java/org/jboss/webbeans/test/log/TestAppender.java 2009-03-22
10:42:28 UTC (rev 2129)
@@ -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/logger/src/test/java/org/jboss/webbeans/test/log/TestAppender.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: extensions/trunk/logger/src/test/resources/log4j.xml
===================================================================
--- extensions/trunk/logger/src/test/resources/log4j.xml (rev 0)
+++ extensions/trunk/logger/src/test/resources/log4j.xml 2009-03-22 10:42:28 UTC (rev
2129)
@@ -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/logger/src/test/resources/log4j.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain