This is an automated email from the ASF dual-hosted git repository.
rgoers pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/release-2.x by this push:
new c43f563 LOG4J2-2240 - Add unit tests
c43f563 is described below
commit c43f5634cdeed72483c4e5e521114b0fd8d93633
Author: Ralph Goers <[email protected]>
AuthorDate: Sun Feb 13 19:10:12 2022 -0700
LOG4J2-2240 - Add unit tests
---
.../core/config/ReconfigurationFailureTest.java | 80 ++++++++++++++++++++++
log4j-core/src/test/resources/InvalidConfig.xml | 31 +++++++++
log4j-core/src/test/resources/InvalidXML.xml | 31 +++++++++
3 files changed, 142 insertions(+)
diff --git
a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ReconfigurationFailureTest.java
b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ReconfigurationFailureTest.java
new file mode 100644
index 0000000..cf2dd8b
--- /dev/null
+++
b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ReconfigurationFailureTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.logging.log4j.core.config;
+
+import java.io.File;
+import java.net.URI;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Performs reconfiguration against bad configurations.
+ *
+ */
+@Disabled // Remove this when LOG4J2-2240 is addressed.
+public class ReconfigurationFailureTest {
+
+ LoggerContext loggerContext;
+
+ @BeforeEach
+ public void setup() {
+ loggerContext = (LoggerContext) LogManager.getContext();
+ }
+
+ @AfterEach
+ public void stopExecutor() throws InterruptedException {
+ loggerContext.stop();
+ }
+
+ @Test
+ public void setNonExistant() throws Exception {
+
+ URI original = loggerContext.getConfigLocation();
+ URI nonExistant = new File("target/file.does.not.exist.xml").toURI();
+ loggerContext.setConfigLocation(nonExistant);
+ assertEquals(original, loggerContext.getConfigLocation(), "URI after
failure is not the original");
+ }
+
+
+ @Test
+ public void setInvalidXML() throws Exception {
+
+ URI original = loggerContext.getConfigLocation();
+ URI nonExistant = new File("target/InvalidXML.xml").toURI();
+ loggerContext.setConfigLocation(nonExistant);
+ assertEquals(original, loggerContext.getConfigLocation(), "URI after
failure is not the original");
+ }
+
+ @Test
+ public void setInvalidConfig() throws Exception {
+
+ URI original = loggerContext.getConfigLocation();
+ URI nonExistant = new File("target/InvalidConfig.xml").toURI();
+ loggerContext.setConfigLocation(nonExistant);
+ assertEquals(original, loggerContext.getConfigLocation(), "URI after
failure is not the original");
+ }
+
+
+
+}
diff --git a/log4j-core/src/test/resources/InvalidConfig.xml
b/log4j-core/src/test/resources/InvalidConfig.xml
new file mode 100644
index 0000000..803dfd1
--- /dev/null
+++ b/log4j-core/src/test/resources/InvalidConfig.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+
+-->
+<Configuration status="OFF">
+ <Apenders>
+ <Console name="Console" target="SYSTEM_OUT">
+ <PatternLayout pattern="%d [%t] %-5level: %msg%n%throwable" />
+ </Console>
+ </Apenders>
+ <Loggers>
+ <Logger name="org.foo" level="DEBUG" />
+ <Root level="TRACE">
+ <AppenderRef ref="Console" />
+ </Root>
+ </Loggers>
+</Configuration>
diff --git a/log4j-core/src/test/resources/InvalidXML.xml
b/log4j-core/src/test/resources/InvalidXML.xml
new file mode 100644
index 0000000..5266770
--- /dev/null
+++ b/log4j-core/src/test/resources/InvalidXML.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+
+-->
+Configuration status="OFF">
+ <Appenders>
+ <Console name="Console" target="SYSTEM_OUT">
+ <PatternLayout pattern="%d [%t] %-5level: %msg%n%throwable" />
+ </Console>
+ </Appenders>
+ <Loggers>
+ <Logger name="org.foo" level="DEBUG" />
+ <Root level="TRACE">
+ <AppenderRef ref="Console" />
+ </Root>
+ </Loggers>
+</Configuration>