|
|
33cff6 |
From 4c962ce4c1356e94b66a5599a2c32c30eb3369e3 Mon Sep 17 00:00:00 2001
|
|
|
33cff6 |
From: Mikolaj Izdebski <mizdebsk@redhat.com>
|
|
|
33cff6 |
Date: Wed, 15 Dec 2021 17:26:22 +0100
|
|
|
33cff6 |
Subject: [PATCH 1/2] Add test case for JNDI disablement
|
|
|
33cff6 |
|
|
|
33cff6 |
---
|
|
|
33cff6 |
tests/build.xml | 14 +++++++-
|
|
|
33cff6 |
tests/input/JNDI0.properties | 3 ++
|
|
|
33cff6 |
tests/input/JNDI1.properties | 4 +++
|
|
|
33cff6 |
.../java/org/apache/log4j/JNDITestCase.java | 34 +++++++++++++++++++
|
|
|
33cff6 |
4 files changed, 54 insertions(+), 1 deletion(-)
|
|
|
33cff6 |
create mode 100644 tests/input/JNDI0.properties
|
|
|
33cff6 |
create mode 100644 tests/input/JNDI1.properties
|
|
|
33cff6 |
create mode 100644 tests/src/java/org/apache/log4j/JNDITestCase.java
|
|
|
33cff6 |
|
|
|
33cff6 |
diff --git a/tests/build.xml b/tests/build.xml
|
|
|
33cff6 |
index 74a7139d..7cac1424 100644
|
|
|
33cff6 |
--- a/tests/build.xml
|
|
|
33cff6 |
+++ b/tests/build.xml
|
|
|
33cff6 |
@@ -38,6 +38,8 @@
|
|
|
33cff6 |
<property name="activation.jar" location="lib/mail.jar"/>
|
|
|
33cff6 |
<property name="junit.version" value="3.8.1"/>
|
|
|
33cff6 |
<property name="junit.jar" location="lib/junit.jar"/>
|
|
|
33cff6 |
+
|
|
|
33cff6 |
+ value="lib/jms.jar"/>
|
|
|
33cff6 |
|
|
|
33cff6 |
|
|
|
33cff6 |
|
|
|
33cff6 |
@@ -71,6 +73,7 @@
|
|
|
33cff6 |
<pathelement location="${junit.jar}"/>
|
|
|
33cff6 |
<pathelement location="${javamail.jar}"/>
|
|
|
33cff6 |
<pathelement location="${activation.jar}"/>
|
|
|
33cff6 |
+ <pathelement location="${geronimo-jms.jar}"/>
|
|
|
33cff6 |
<pathelement path="${java.class.path}"/>
|
|
|
33cff6 |
</path>
|
|
|
33cff6 |
|
|
|
33cff6 |
@@ -158,7 +161,7 @@
|
|
|
33cff6 |
|
|
|
33cff6 |
|
|
|
33cff6 |
|
|
|
33cff6 |
- <target name="runAll" depends="regression, longUnit"/>
|
|
|
33cff6 |
+ <target name="runAll" depends="regression, longUnit, JNDI"/>
|
|
|
33cff6 |
|
|
|
33cff6 |
|
|
|
33cff6 |
|
|
|
33cff6 |
@@ -262,6 +265,15 @@
|
|
|
33cff6 |
</junit>
|
|
|
33cff6 |
</target>
|
|
|
33cff6 |
|
|
|
33cff6 |
+ <target name="JNDI" depends="build">
|
|
|
33cff6 |
+
|
|
|
33cff6 |
+ haltonfailure="${haltonfailure}" dir="${basedir}">
|
|
|
33cff6 |
+ <classpath refid="tests.classpath"/>
|
|
|
33cff6 |
+ <formatter type="plain" usefile="false"/>
|
|
|
33cff6 |
+ <test name="org.apache.log4j.JNDITestCase" />
|
|
|
33cff6 |
+ </junit>
|
|
|
33cff6 |
+ </target>
|
|
|
33cff6 |
+
|
|
|
33cff6 |
<target name="DefaultInit" depends="build">
|
|
|
33cff6 |
|
|
|
33cff6 |
<delete file="${basedir}/classes/log4j.xml"/>
|
|
|
33cff6 |
diff --git a/tests/input/JNDI0.properties b/tests/input/JNDI0.properties
|
|
|
33cff6 |
new file mode 100644
|
|
|
33cff6 |
index 00000000..1fd92627
|
|
|
33cff6 |
--- /dev/null
|
|
|
33cff6 |
+++ b/tests/input/JNDI0.properties
|
|
|
33cff6 |
@@ -0,0 +1,3 @@
|
|
|
33cff6 |
+log4j.rootLogger=DEBUG, testAppender
|
|
|
33cff6 |
+log4j.appender.testAppender=org.apache.log4j.net.JMSAppender
|
|
|
33cff6 |
+log4j.appender.testAppender.TopicConnectionFactoryBindingName=foo
|
|
|
33cff6 |
diff --git a/tests/input/JNDI1.properties b/tests/input/JNDI1.properties
|
|
|
33cff6 |
new file mode 100644
|
|
|
33cff6 |
index 00000000..28202fed
|
|
|
33cff6 |
--- /dev/null
|
|
|
33cff6 |
+++ b/tests/input/JNDI1.properties
|
|
|
33cff6 |
@@ -0,0 +1,4 @@
|
|
|
33cff6 |
+log4j.rootLogger=DEBUG, testAppender
|
|
|
33cff6 |
+log4j.appender.testAppender=org.apache.log4j.net.JMSAppender
|
|
|
33cff6 |
+log4j.appender.testAppender.TopicConnectionFactoryBindingName=foo
|
|
|
33cff6 |
+log4j.appender.testAppender.Enabled=true
|
|
|
33cff6 |
diff --git a/tests/src/java/org/apache/log4j/JNDITestCase.java b/tests/src/java/org/apache/log4j/JNDITestCase.java
|
|
|
33cff6 |
new file mode 100644
|
|
|
33cff6 |
index 00000000..6ef8ec90
|
|
|
33cff6 |
--- /dev/null
|
|
|
33cff6 |
+++ b/tests/src/java/org/apache/log4j/JNDITestCase.java
|
|
|
33cff6 |
@@ -0,0 +1,34 @@
|
|
|
33cff6 |
+package org.apache.log4j;
|
|
|
33cff6 |
+
|
|
|
33cff6 |
+import junit.framework.TestCase;
|
|
|
33cff6 |
+
|
|
|
33cff6 |
+/**
|
|
|
33cff6 |
+ * Test for JNDI disablement.
|
|
|
33cff6 |
+ *
|
|
|
33cff6 |
+ * @author Mikolaj Izdebski
|
|
|
33cff6 |
+ */
|
|
|
33cff6 |
+public class JNDITestCase extends TestCase {
|
|
|
33cff6 |
+
|
|
|
33cff6 |
+ public JNDITestCase(String name) {
|
|
|
33cff6 |
+ super(name);
|
|
|
33cff6 |
+ }
|
|
|
33cff6 |
+
|
|
|
33cff6 |
+ public void tearDown() {
|
|
|
33cff6 |
+ LogManager.resetConfiguration();
|
|
|
33cff6 |
+ }
|
|
|
33cff6 |
+
|
|
|
33cff6 |
+ public void testDisabled() throws Exception {
|
|
|
33cff6 |
+ Logger logger = Logger.getLogger(JNDITestCase.class);
|
|
|
33cff6 |
+ try {
|
|
|
33cff6 |
+ PropertyConfigurator.configure("input/JNDI0.properties");
|
|
|
33cff6 |
+ fail("IllegalStateException exception was expected");
|
|
|
33cff6 |
+ } catch (IllegalStateException e) {
|
|
|
33cff6 |
+ assertTrue(e.getMessage().startsWith("JMS appender is disabled"));
|
|
|
33cff6 |
+ }
|
|
|
33cff6 |
+ }
|
|
|
33cff6 |
+
|
|
|
33cff6 |
+ public void testEnabled() throws Exception {
|
|
|
33cff6 |
+ Logger logger = Logger.getLogger(JNDITestCase.class);
|
|
|
33cff6 |
+ PropertyConfigurator.configure("input/JNDI1.properties");
|
|
|
33cff6 |
+ }
|
|
|
33cff6 |
+}
|
|
|
33cff6 |
--
|
|
|
33cff6 |
2.33.1
|
|
|
33cff6 |
|