I went and finally revisited a patch I proposed about a million years ago to enable testing of the JMSAppender class using ActiveMQ (Bug 38153).

See my patch below [1]. However when I run the tests locally I'm getting a compile error:

...
prepare:
[available] DEPRECATED - <available> used to override an existing property. [available] Build file should not reuse the same property name for different values.

build:
    [javac] Compiling 2 source files to /workspace/log4j/tests/classes
/workspace/log4j/tests/src/java/org/apache/log4j/jms/ JMSAppenderTest.java:19: package javax.jms does not exist
import javax.jms.Connection;

We appear to run the tests via an antrun call within Maven, is that right? Just curious of the rationale there, why we couldn't just make it a standard maven test phase. Maybe there's a complication I'm not aware of, it's just not something I've had to deal with before, so I'm a bit confused on how to proceed. Normally for testing under Maven I've just added dependencies under the test scope and been on my way.

help appreciated.

cheers,

Paul

[1] current patch


Property changes on: .
___________________________________________________________________
Modified: svn:ignore
   - goEnv*
dist
build.properties
target
surefire*
cobertura.ser
.classpath
.project
.settings
log4j.i*



   + goEnv*
dist
build.properties
target
surefire*
cobertura.ser
.classpath
.project
.settings
log4j.i*
activemq-data




Index: tests/src/java/org/apache/log4j/jms/JMSAppenderTest.java
===================================================================
--- tests/src/java/org/apache/log4j/jms/JMSAppenderTest.java (revision 0) +++ tests/src/java/org/apache/log4j/jms/JMSAppenderTest.java (revision 0)
@@ -0,0 +1,100 @@
+/*
+ * 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.log4j.jms;
+
+import javax.jms.Connection;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.Session;
+import javax.jms.Topic;
+
+import junit.framework.TestCase;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.jndi.ActiveMQInitialContextFactory;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.net.JMSAppender;
+
+public class JMSAppenderTest extends TestCase {
+
+    public void testJMSAppender() {
+ ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost");
+        Connection conn = null;
+        try {
+            conn = factory.createConnection();
+            conn.start();
+
+ Logger.getLogger("org.apache.activemq").setLevel(Level.OFF);
+            JMSAppender appender = new JMSAppender();
+ appender .setInitialContextFactoryName (ActiveMQInitialContextFactory.class.getName());
+            appender.setProviderURL("vm://localhost");
+ appender.setTopicConnectionFactoryBindingName("TopicConnectionFactory"); + appender.setTopicBindingName("dynamicTopics/ jmsappendertest");
+            appender.activateOptions();
+
+            Logger.getRootLogger().addAppender(appender);
+
+ Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            Topic topic = session.createTopic("jmsappendertest");
+            MessageConsumer consumer = session.createConsumer(topic);
+            TopicConsumer topicConsumer = new TopicConsumer(consumer);
+            Thread thread = new Thread(topicConsumer);
+
+
+            thread.start();
+
+            Logger.getRootLogger().info("Hello World");
+
+            thread.join();
+ assertTrue("Should have received a message", topicConsumer.receivedMessage);
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("Error during test");
+        } finally {
+            if (conn != null) {
+                try {
+                    conn.stop();
+                    conn.close();
+                } catch (Exception e) {
+                    e.printStackTrace();
+                    fail("Error on close/stop");
+                }
+            }
+        }
+
+    }
+
+    private static class TopicConsumer implements Runnable {
+        private boolean receivedMessage = false;
+
+        private MessageConsumer consumer;
+
+        private TopicConsumer(MessageConsumer consumer) {
+            this.consumer = consumer;
+        }
+
+        public void run() {
+            try {
+                Message message = consumer.receive(5000);
+                receivedMessage = (message != null);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+    }
+}
\ No newline at end of file
Index: tests/resources/jndi.properties
===================================================================
--- tests/resources/jndi.properties     (revision 0)
+++ tests/resources/jndi.properties     (revision 0)
@@ -0,0 +1,13 @@
+# Used by JMSAppenderTest
+#
+java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory
+
+# use the following property to configure the default connector
+java.naming.provider.url = vm://localhost
+
+connectionFactoryNames = ConnectionFactory, QueueConnectionFactory, TopicConnectionFactory
+
+
+# register some topics in JNDI using the form
+# topic.[jndiName] = [physicalName]
+topic.jmsappendertest = jmsappendertest
\ No newline at end of file
Index: src/changes/changes.xml
===================================================================
--- src/changes/changes.xml     (revision 686420)
+++ src/changes/changes.xml     (working copy)
@@ -59,6 +59,7 @@
<action action="fix" issue="40246">HierarchyDynamicMBean missing unregister MBean</action> <action action="fix" issue="45635">Support -Dm2_repo option on Maven build for non-default Maven repository location.</action> <action action="fix" issue="45636">2 tests for DateLayout are failing because of ill initialized DateFormat.</action> + <action action="add" issue="38513">Added test case for JMSAppender using ActiveMQ</action>
     </release>


Index: pom.xml
===================================================================
--- pom.xml     (revision 686420)
+++ pom.xml     (working copy)
@@ -443,6 +443,18 @@
       <version>1.0</version>
       <optional>true</optional>
     </dependency>
+    <dependency>
+       <groupId>org.apache.activemq</groupId>
+       <artifactId>activemq-core</artifactId>
+       <version>4.1.2</version>
+       <scope>test</scope>
+    </dependency>
+    <dependency>
+       <groupId>org.apache.derby</groupId>
+       <artifactId>derby</artifactId>
+       <version>10.4.1.3</version>
+       <scope>test</scope>
+    </dependency>
  </dependencies>
   <reporting>
     <excludeDefaults>true</excludeDefaults>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to