You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ac...@apache.org on 2006/09/29 10:50:00 UTC

svn commit: r451170 - in /incubator/activemq/trunk/activemq-optional/src/test: java/org/apache/activemq/util/JmsLogAppenderTest.java resources/jndi.properties resources/org/apache/activemq/util/test-log4j.properties

Author: aco
Date: Fri Sep 29 01:49:59 2006
New Revision: 451170

URL: http://svn.apache.org/viewvc?view=rev&rev=451170
Log:
Added test case for JmsLogAppender
For: https://issues.apache.org/activemq/browse/AMQ-935

Added:
    incubator/activemq/trunk/activemq-optional/src/test/resources/jndi.properties   (with props)
Modified:
    incubator/activemq/trunk/activemq-optional/src/test/java/org/apache/activemq/util/JmsLogAppenderTest.java
    incubator/activemq/trunk/activemq-optional/src/test/resources/org/apache/activemq/util/test-log4j.properties

Modified: incubator/activemq/trunk/activemq-optional/src/test/java/org/apache/activemq/util/JmsLogAppenderTest.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-optional/src/test/java/org/apache/activemq/util/JmsLogAppenderTest.java?view=diff&rev=451170&r1=451169&r2=451170
==============================================================================
--- incubator/activemq/trunk/activemq-optional/src/test/java/org/apache/activemq/util/JmsLogAppenderTest.java (original)
+++ incubator/activemq/trunk/activemq-optional/src/test/java/org/apache/activemq/util/JmsLogAppenderTest.java Fri Sep 29 01:49:59 2006
@@ -24,23 +24,89 @@
 
 import org.apache.log4j.Logger;
 import org.apache.log4j.PropertyConfigurator;
+import org.apache.log4j.Level;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.command.ActiveMQTopic;
+
+import javax.jms.JMSException;
+import javax.jms.Connection;
+import javax.jms.MessageConsumer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
 
-/**
- * @version $Revision$
- */
 public class JmsLogAppenderTest extends TestCase {
+    protected BrokerService broker;
 
+    public void testLoggingWithJMS() throws IOException, JMSException {
+        // Setup the consumers
+        MessageConsumer info, debug, warn;
+        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost");
+        Connection conn = factory.createConnection();
+        conn.start();
+
+        warn  = conn.createSession(false, Session.AUTO_ACKNOWLEDGE).createConsumer(new ActiveMQTopic("log4j.MAIN.WARN"));
+        info  = conn.createSession(false, Session.AUTO_ACKNOWLEDGE).createConsumer(new ActiveMQTopic("log4j.MAIN.INFO"));
+        debug = conn.createSession(false, Session.AUTO_ACKNOWLEDGE).createConsumer(new ActiveMQTopic("log4j.MAIN.DEBUG"));
+
+        // lets try configure log4j
+        Properties properties = new Properties();
+        properties.load(getClass().getResourceAsStream("test-log4j.properties"));
+        PropertyConfigurator.configure(properties);
+
+        Logger warnLog, infoLog, debugLog;
+
+        warnLog = Logger.getLogger("MAIN.WARN");
+        warnLog.setLevel(Level.WARN);
+        warnLog.warn("Warn Message");
+        warnLog.info("Info Message");
+        warnLog.debug("Debug Message");
+
+        infoLog = Logger.getLogger("MAIN.INFO");
+        infoLog.setLevel(Level.INFO);
+        infoLog.warn("Warn Message");
+        infoLog.info("Info Message");
+        infoLog.debug("Debug Message");
+
+        debugLog = Logger.getLogger("MAIN.DEBUG");
+        debugLog.setLevel(Level.DEBUG);
+        debugLog.warn("Warn Message");
+        debugLog.info("Info Message");
+        debugLog.debug("Debug Message");
+
+        TextMessage msg;
+
+        // Test warn level
+        msg = (TextMessage)warn.receive(1000);
+        assertNotNull(msg);
+        assertEquals("Warn Message", msg.getText());
+
+        msg = (TextMessage)warn.receive(1000);
+        assertNull(msg); // We should not receive anymore message because our level is warning only
+
+        // Test info level
+        msg = (TextMessage)info.receive(1000);
+        assertNotNull(msg);
+        assertEquals("Warn Message", msg.getText());
+
+        msg = (TextMessage)info.receive(1000);
+        assertNotNull(msg);
+        assertEquals("Info Message", msg.getText());
+
+        msg = (TextMessage)info.receive(1000);
+        assertNull(msg); // We should not receive the debug message
+
+        // Test debug level
+        msg = (TextMessage)debug.receive(1000);
+        assertNotNull(msg);
+        assertEquals("Warn Message", msg.getText());
+
+        msg = (TextMessage)debug.receive(1000);
+        assertNotNull(msg);
+        assertEquals("Info Message", msg.getText());
 
-    public void testLoggingWithJMS() throws IOException {
-
-         // lets try configure log4j
-         Properties properties = new Properties();
-         properties.load(getClass().getResourceAsStream("test-log4j.properties"));
-         PropertyConfigurator.configure(properties);
-
-         Logger.getLogger("FOO.BAR").info("Hello");
-         Logger.getLogger("FOO.BAR.WHATNOT").debug("A debug message");
-         Logger.getLogger("FOO.BAR.WHATNOT.ANOTHER").warn("Some warnings");
-
+        msg = (TextMessage)debug.receive(1000);
+        assertNotNull(msg);
     }
+
 }

Added: incubator/activemq/trunk/activemq-optional/src/test/resources/jndi.properties
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-optional/src/test/resources/jndi.properties?view=auto&rev=451170
==============================================================================
--- incubator/activemq/trunk/activemq-optional/src/test/resources/jndi.properties (added)
+++ incubator/activemq/trunk/activemq-optional/src/test/resources/jndi.properties Fri Sep 29 01:49:59 2006
@@ -0,0 +1,25 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+# START SNIPPET: jndi
+
+java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory
+
+# use the following property to configure the default connector
+java.naming.provider.url = vm://localhost
+
+# END SNIPPET: jndi

Propchange: incubator/activemq/trunk/activemq-optional/src/test/resources/jndi.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/activemq/trunk/activemq-optional/src/test/resources/jndi.properties
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: incubator/activemq/trunk/activemq-optional/src/test/resources/jndi.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/activemq/trunk/activemq-optional/src/test/resources/org/apache/activemq/util/test-log4j.properties
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-optional/src/test/resources/org/apache/activemq/util/test-log4j.properties?view=diff&rev=451170&r1=451169&r2=451170
==============================================================================
--- incubator/activemq/trunk/activemq-optional/src/test/resources/org/apache/activemq/util/test-log4j.properties (original)
+++ incubator/activemq/trunk/activemq-optional/src/test/resources/org/apache/activemq/util/test-log4j.properties Fri Sep 29 01:49:59 2006
@@ -1,3 +1,5 @@
-log4j.rootLogger=info, jms
+# Make level to fatal so it would not affect the test case
+log4j.rootLogger=fatal, jms
 
-log4j.appender.jms=org.apache.activemq.util.JmsLogAppender
+log4j.appender.jms=org.apache.activemq.util.JndiJmsLogAppender
+log4j.appender.jms.jndiName=ConnectionFactory