From 4c962ce4c1356e94b66a5599a2c32c30eb3369e3 Mon Sep 17 00:00:00 2001 From: Mikolaj Izdebski Date: Wed, 15 Dec 2021 17:26:22 +0100 Subject: [PATCH 1/2] Add test case for JNDI disablement --- tests/build.xml | 14 +++++++- tests/input/JNDI0.properties | 3 ++ tests/input/JNDI1.properties | 4 +++ .../java/org/apache/log4j/JNDITestCase.java | 34 +++++++++++++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 tests/input/JNDI0.properties create mode 100644 tests/input/JNDI1.properties create mode 100644 tests/src/java/org/apache/log4j/JNDITestCase.java diff --git a/tests/build.xml b/tests/build.xml index 74a7139d..7cac1424 100644 --- a/tests/build.xml +++ b/tests/build.xml @@ -38,6 +38,8 @@ + @@ -71,6 +73,7 @@ + @@ -158,7 +161,7 @@ - + @@ -262,6 +265,15 @@ + + + + + + + + diff --git a/tests/input/JNDI0.properties b/tests/input/JNDI0.properties new file mode 100644 index 00000000..1fd92627 --- /dev/null +++ b/tests/input/JNDI0.properties @@ -0,0 +1,3 @@ +log4j.rootLogger=DEBUG, testAppender +log4j.appender.testAppender=org.apache.log4j.net.JMSAppender +log4j.appender.testAppender.TopicConnectionFactoryBindingName=foo diff --git a/tests/input/JNDI1.properties b/tests/input/JNDI1.properties new file mode 100644 index 00000000..28202fed --- /dev/null +++ b/tests/input/JNDI1.properties @@ -0,0 +1,4 @@ +log4j.rootLogger=DEBUG, testAppender +log4j.appender.testAppender=org.apache.log4j.net.JMSAppender +log4j.appender.testAppender.TopicConnectionFactoryBindingName=foo +log4j.appender.testAppender.Enabled=true diff --git a/tests/src/java/org/apache/log4j/JNDITestCase.java b/tests/src/java/org/apache/log4j/JNDITestCase.java new file mode 100644 index 00000000..6ef8ec90 --- /dev/null +++ b/tests/src/java/org/apache/log4j/JNDITestCase.java @@ -0,0 +1,34 @@ +package org.apache.log4j; + +import junit.framework.TestCase; + +/** + * Test for JNDI disablement. + * + * @author Mikolaj Izdebski + */ +public class JNDITestCase extends TestCase { + + public JNDITestCase(String name) { + super(name); + } + + public void tearDown() { + LogManager.resetConfiguration(); + } + + public void testDisabled() throws Exception { + Logger logger = Logger.getLogger(JNDITestCase.class); + try { + PropertyConfigurator.configure("input/JNDI0.properties"); + fail("IllegalStateException exception was expected"); + } catch (IllegalStateException e) { + assertTrue(e.getMessage().startsWith("JMS appender is disabled")); + } + } + + public void testEnabled() throws Exception { + Logger logger = Logger.getLogger(JNDITestCase.class); + PropertyConfigurator.configure("input/JNDI1.properties"); + } +} -- 2.33.1