You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by pk...@apache.org on 2024/03/26 05:09:55 UTC
(logging-log4j2) 01/01: Remove Log4j API 3.x
This is an automated email from the ASF dual-hosted git repository.
pkarwasz pushed a commit to branch fix/rollback-log4j-api
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit da5632a2a1b248dff876ddaa82584103413b076d
Author: Piotr P. Karwasz <pi...@karwasz.org>
AuthorDate: Tue Mar 26 06:09:31 2024 +0100
Remove Log4j API 3.x
---
log4j-api-test/pom.xml | 168 -
.../logging/log4j/test/ListStatusListener.java | 43 -
.../org/apache/logging/log4j/test/TestLogger.java | 268 --
.../logging/log4j/test/TestLoggerContext.java | 66 -
.../log4j/test/TestLoggerContextFactory.java | 54 -
.../apache/logging/log4j/test/TestProperties.java | 44 -
.../logging/log4j/test/ThreadContextHolder.java | 78 -
.../log4j/test/ThreadContextUtilityClass.java | 114 -
.../java/org/apache/logging/log4j/test/Timer.java | 294 --
.../log4j/test/junit/AbstractFileCleaner.java | 83 -
.../logging/log4j/test/junit/ClassMatchers.java | 36 -
.../log4j/test/junit/CleanUpDirectories.java | 44 -
.../logging/log4j/test/junit/CleanUpFiles.java | 44 -
.../logging/log4j/test/junit/DirectoryCleaner.java | 74 -
.../log4j/test/junit/ExtensionContextAnchor.java | 108 -
.../logging/log4j/test/junit/FileCleaner.java | 51 -
.../log4j/test/junit/InitializesThreadContext.java | 39 -
.../test/junit/Log4j2LauncherSessionListener.java | 34 -
.../test/junit/LoggerContextFactoryExtension.java | 53 -
.../apache/logging/log4j/test/junit/Mutable.java | 34 -
.../apache/logging/log4j/test/junit/Resources.java | 55 -
.../logging/log4j/test/junit/SetTestProperty.java | 61 -
.../log4j/test/junit/StatusLoggerExtension.java | 203 -
.../log4j/test/junit/StatusLoggerLevel.java | 42 -
.../test/junit/StatusLoggerLevelExtension.java | 48 -
.../org/apache/logging/log4j/test/junit/Tags.java | 33 -
.../logging/log4j/test/junit/TempLoggingDir.java | 45 -
.../log4j/test/junit/TempLoggingDirectory.java | 190 -
.../log4j/test/junit/TestPropertyResolver.java | 68 -
.../log4j/test/junit/TestPropertySource.java | 137 -
.../log4j/test/junit/ThreadContextInitializer.java | 49 -
.../test/junit/ThreadContextMapExtension.java | 44 -
.../log4j/test/junit/ThreadContextRule.java | 80 -
.../test/junit/ThreadContextStackExtension.java | 46 -
.../log4j/test/junit/ThreadContextStackRule.java | 39 -
.../log4j/test/junit/UsingAnyThreadContext.java | 38 -
.../log4j/test/junit/UsingStatusListener.java | 41 -
.../log4j/test/junit/UsingTestProperties.java | 44 -
.../log4j/test/junit/UsingThreadContextMap.java | 43 -
.../log4j/test/junit/UsingThreadContextStack.java | 40 -
.../logging/log4j/test/junit/package-info.java | 22 -
.../apache/logging/log4j/test/package-info.java | 22 -
.../org.apache.logging.log4j.util.PropertySource | 15 -
.../org.junit.jupiter.api.extension.Extension | 15 -
...junit.platform.launcher.LauncherSessionListener | 16 -
.../apache/logging/log4j/AbstractLoggerTest.java | 1472 ------
.../logging/log4j/CloseableThreadContextTest.java | 239 -
.../org/apache/logging/log4j/EventLoggerTest.java | 56 -
.../org/apache/logging/log4j/LambdaLoggerTest.java | 1413 ------
.../java/org/apache/logging/log4j/LevelTest.java | 284 --
.../org/apache/logging/log4j/LogManagerTest.java | 131 -
.../apache/logging/log4j/LoggerSupplierTest.java | 200 -
.../java/org/apache/logging/log4j/LoggerTest.java | 693 ---
.../java/org/apache/logging/log4j/MarkerTest.java | 109 -
.../logging/log4j/NoopThreadContextTest.java | 42 -
.../org/apache/logging/log4j/TestProvider.java | 29 -
.../log4j/ThreadContextInheritanceTest.java | 160 -
.../org/apache/logging/log4j/TraceLoggingTest.java | 381 --
.../log4j/internal/DefaultLogBuilderTest.java | 47 -
.../log4j/internal/recycler/ArrayQueueTest.java | 101 -
.../recycler/RecyclerFactoryRegistryTest.java | 85 -
.../internal/recycler/RecyclerFactoryTestUtil.java | 47 -
.../ThreadLocalRecyclerFactoryProviderTest.java | 114 -
.../log4j/message/FormattedMessageTest.java | 153 -
.../apache/logging/log4j/message/JsonMessage.java | 64 -
.../log4j/message/LocalizedMessageFactoryTest.java | 116 -
.../log4j/message/LocalizedMessageTest.java | 86 -
.../logging/log4j/message/MapMessageTest.java | 330 --
.../log4j/message/MessageFormatMessageTest.java | 115 -
.../log4j/message/ObjectArrayMessageTest.java | 41 -
.../logging/log4j/message/ObjectMapMessage.java | 19 -
.../logging/log4j/message/ObjectMessageTest.java | 80 -
.../log4j/message/ParameterFormatterTest.java | 158 -
.../log4j/message/ParameterizedMessageTest.java | 145 -
.../log4j/message/ReusableMessageFactoryTest.java | 136 -
.../log4j/message/ReusableObjectMessageTest.java | 124 -
.../message/ReusableParameterizedMessageTest.java | 178 -
.../log4j/message/ReusableSimpleMessageTest.java | 124 -
.../logging/log4j/message/SimpleMessageTest.java | 40 -
.../log4j/message/StringFormattedMessageTest.java | 132 -
.../log4j/message/StructuredDataMessageTest.java | 125 -
.../log4j/message/ThreadDumpMessageTest.java | 166 -
.../logging/log4j/simple/SimpleLoggerTest.java | 69 -
.../log4j/spi/DefaultThreadContextStackTest.java | 342 --
.../logging/log4j/spi/LoggerAdapterTest.java | 187 -
.../log4j/spi/MutableThreadContextStackTest.java | 371 --
.../log4j/status/StatusConsoleListenerTest.java | 147 -
.../apache/logging/log4j/test/BetterService.java | 19 -
.../org/apache/logging/log4j/test/Service.java | 19 -
.../org/apache/logging/log4j/test/Service1.java | 19 -
.../org/apache/logging/log4j/test/Service2.java | 19 -
.../logging/log4j/test/ThreadContextTest.java | 184 -
.../log4j/test/junit/TempLoggingDirectoryTest.java | 45 -
.../log4j/test/junit/TestPropertySourceTest.java | 57 -
.../org/apache/logging/log4j/util/AssertTest.java | 53 -
.../org/apache/logging/log4j/util/CharsTest.java | 46 -
.../logging/log4j/util/CharsetForNameMain.java | 37 -
.../apache/logging/log4j/util/ClassLocator.java | 27 -
.../logging/log4j/util/ClassNameLocator.java | 27 -
.../apache/logging/log4j/util/ConstantsTest.java | 32 -
.../logging/log4j/util/DeserializerHelper.java | 48 -
.../log4j/util/EnvironmentPropertySourceTest.java | 47 -
.../apache/logging/log4j/util/LambdaUtilTest.java | 117 -
.../org/apache/logging/log4j/util/LazyTest.java | 187 -
.../util/LegacyPropertiesCompatibilityTest.java | 82 -
.../apache/logging/log4j/util/LoaderUtilTest.java | 61 -
.../log4j/util/Log4jCharsetsPropertiesTest.java | 47 -
.../log4j/util/PropertiesPropertySourceTest.java | 47 -
.../log4j/util/PropertiesUtilOrderTest.java | 146 -
.../logging/log4j/util/PropertiesUtilTest.java | 228 -
.../log4j/util/PropertySourceCamelCaseTest.java | 43 -
.../log4j/util/PropertySourceTokenizerTest.java | 61 -
.../logging/log4j/util/ProviderUtilTest.java | 51 -
.../logging/log4j/util/ServiceLoaderUtilTest.java | 70 -
.../log4j/util/SortedArrayStringMapTest.java | 993 ----
.../logging/log4j/util/StackLocatorUtilTest.java | 169 -
.../logging/log4j/util/StringBuildersTest.java | 93 -
.../org/apache/logging/log4j/util/StringsTest.java | 89 -
.../logging/log4j/util/SystemPropertiesMain.java | 48 -
.../util/SystemPropertiesPropertySourceTest.java | 68 -
.../org/apache/logging/log4j/util/Unbox1Test.java | 187 -
.../logging/log4j/util/Unbox2ConfigurableTest.java | 81 -
.../src/test/resources/Jira3413Test.properties | 34 -
.../src/test/resources/META-INF/log4j2.my-app.json | 16 -
.../src/test/resources/MF_en_US.properties | 19 -
log4j-api-test/src/test/resources/MF_fr.properties | 19 -
.../src/test/resources/MF_fr_CH.properties | 18 -
.../resources/PropertiesUtilOrderTest.properties | 26 -
.../src/test/resources/PropertiesUtilTest.json | 25 -
.../test/resources/PropertiesUtilTest.properties | 32 -
.../src/test/resources/SF_en_US.properties | 19 -
log4j-api-test/src/test/resources/SF_fr.properties | 19 -
.../src/test/resources/SF_fr_CH.properties | 18 -
.../src/test/resources/log4j2.my-app.json | 16 -
.../src/test/resources/log4j2.propertyMapping.json | 96 -
.../src/test/resources/log4j2.system.properties | 17 -
.../logging/log4j/test/ForceLinkageError.class | 0
log4j-api/pom.xml | 55 -
.../java/org/apache/logging/log4j/BridgeAware.java | 33 -
.../logging/log4j/CloseableThreadContext.java | 227 -
.../java/org/apache/logging/log4j/EventLogger.java | 58 -
.../main/java/org/apache/logging/log4j/Level.java | 366 --
.../java/org/apache/logging/log4j/LogBuilder.java | 299 --
.../java/org/apache/logging/log4j/LogManager.java | 683 ---
.../main/java/org/apache/logging/log4j/Logger.java | 4788 --------------------
.../org/apache/logging/log4j/LoggingException.java | 56 -
.../main/java/org/apache/logging/log4j/Marker.java | 114 -
.../org/apache/logging/log4j/MarkerManager.java | 389 --
.../org/apache/logging/log4j/ThreadContext.java | 570 ---
.../log4j/internal/CopyOnWriteNavigableSet.java | 269 --
.../logging/log4j/internal/DefaultLogBuilder.java | 415 --
.../log4j/internal/DefaultObjectInputFilter.java | 92 -
.../log4j/internal/recycler/ArrayQueue.java | 100 -
.../recycler/DummyRecyclerFactoryProvider.java | 81 -
.../recycler/QueueingRecyclerFactoryProvider.java | 106 -
.../ThreadLocalRecyclerFactoryProvider.java | 124 -
.../org/apache/logging/log4j/lang/NonNull.java | 35 -
.../org/apache/logging/log4j/lang/NullMarked.java | 36 -
.../apache/logging/log4j/lang/NullUnmarked.java | 37 -
.../org/apache/logging/log4j/lang/Nullable.java | 36 -
.../apache/logging/log4j/lang/package-info.java | 28 -
.../log4j/message/AbstractMessageFactory.java | 26 -
.../log4j/message/AsynchronouslyFormattable.java | 59 -
.../log4j/message/BasicThreadInformation.java | 106 -
.../apache/logging/log4j/message/Clearable.java | 31 -
.../log4j/message/DefaultFlowMessageFactory.java | 261 --
.../apache/logging/log4j/message/EntryMessage.java | 26 -
.../apache/logging/log4j/message/ExitMessage.java | 26 -
.../apache/logging/log4j/message/FlowMessage.java | 39 -
.../logging/log4j/message/FlowMessageFactory.java | 87 -
.../logging/log4j/message/FormattedMessage.java | 237 -
.../log4j/message/FormattedMessageFactory.java | 176 -
.../logging/log4j/message/LocalizedMessage.java | 260 --
.../log4j/message/LocalizedMessageFactory.java | 92 -
.../log4j/message/LoggerNameAwareMessage.java | 34 -
.../apache/logging/log4j/message/MapMessage.java | 756 ----
.../log4j/message/MapMessageJsonFormatter.java | 394 --
.../org/apache/logging/log4j/message/Message.java | 97 -
.../log4j/message/MessageCollectionMessage.java | 23 -
.../logging/log4j/message/MessageFactory.java | 281 --
.../logging/log4j/message/MessageFactory2.java | 26 -
.../log4j/message/MessageFormatMessage.java | 142 -
.../log4j/message/MessageFormatMessageFactory.java | 177 -
.../logging/log4j/message/MultiformatMessage.java | 42 -
.../logging/log4j/message/ObjectArrayMessage.java | 118 -
.../logging/log4j/message/ObjectMessage.java | 128 -
.../logging/log4j/message/ParameterConsumer.java | 41 -
.../logging/log4j/message/ParameterFormatter.java | 624 ---
.../logging/log4j/message/ParameterVisitable.java | 45 -
.../log4j/message/ParameterizedMessage.java | 302 --
.../ParameterizedNoReferenceMessageFactory.java | 105 -
.../logging/log4j/message/ReusableMessage.java | 81 -
.../log4j/message/ReusableMessageFactory.java | 239 -
.../log4j/message/ReusableObjectMessage.java | 137 -
.../message/ReusableParameterizedMessage.java | 391 --
.../log4j/message/ReusableSimpleMessage.java | 111 -
.../logging/log4j/message/SimpleMessage.java | 144 -
.../log4j/message/SimpleMessageFactory.java | 191 -
.../log4j/message/StringFormattedMessage.java | 152 -
.../message/StringFormatterMessageFactory.java | 189 -
.../logging/log4j/message/StringMapMessage.java | 67 -
.../message/StructuredDataCollectionMessage.java | 100 -
.../logging/log4j/message/StructuredDataId.java | 268 --
.../log4j/message/StructuredDataMessage.java | 518 ---
.../logging/log4j/message/ThreadDumpMessage.java | 143 -
.../logging/log4j/message/ThreadInformation.java | 36 -
.../logging/log4j/message/TimestampMessage.java | 29 -
.../apache/logging/log4j/message/package-info.java | 26 -
.../org/apache/logging/log4j/package-info.java | 44 -
.../apache/logging/log4j/simple/SimpleLogger.java | 330 --
.../log4j/simple/SimpleLoggerConfiguration.java | 80 -
.../logging/log4j/simple/SimpleLoggerContext.java | 130 -
.../log4j/simple/SimpleLoggerContextFactory.java | 59 -
.../apache/logging/log4j/simple/package-info.java | 27 -
.../apache/logging/log4j/spi/AbstractLogger.java | 3760 ---------------
.../logging/log4j/spi/AbstractLoggerAdapter.java | 149 -
.../log4j/spi/CleanableThreadContextMap.java | 28 -
.../org/apache/logging/log4j/spi/CopyOnWrite.java | 25 -
.../CopyOnWriteSortedArrayThreadContextMap.java | 252 --
.../log4j/spi/DefaultThreadContextStack.java | 319 --
.../apache/logging/log4j/spi/ExtendedLogger.java | 668 ---
.../logging/log4j/spi/ExtendedLoggerWrapper.java | 281 --
.../GarbageFreeSortedArrayThreadContextMap.java | 255 --
.../apache/logging/log4j/spi/LoggerAdapter.java | 38 -
.../apache/logging/log4j/spi/LoggerContext.java | 178 -
.../logging/log4j/spi/LoggerContextFactory.java | 123 -
.../log4j/spi/LoggerContextShutdownAware.java | 26 -
.../log4j/spi/LoggerContextShutdownEnabled.java | 29 -
.../apache/logging/log4j/spi/LoggerRegistry.java | 188 -
.../apache/logging/log4j/spi/LoggingSystem.java | 242 -
.../logging/log4j/spi/LoggingSystemProperty.java | 490 --
.../logging/log4j/spi/MessageFactory2Adapter.java | 157 -
.../log4j/spi/MutableThreadContextStack.java | 255 --
.../logging/log4j/spi/NoOpThreadContextMap.java | 80 -
.../logging/log4j/spi/ObjectThreadContextMap.java | 28 -
.../logging/log4j/spi/PropertyComponent.java | 87 -
.../org/apache/logging/log4j/spi/Provider.java | 372 --
.../log4j/spi/ReadOnlyThreadContextMap.java | 96 -
.../apache/logging/log4j/spi/StandardLevel.java | 103 -
.../org/apache/logging/log4j/spi/Terminable.java | 32 -
.../apache/logging/log4j/spi/ThreadContextMap.java | 175 -
.../logging/log4j/spi/ThreadContextMap2.java | 28 -
.../logging/log4j/spi/ThreadContextStack.java | 26 -
.../org/apache/logging/log4j/spi/package-info.java | 26 -
.../log4j/spi/recycler/AbstractRecycler.java | 40 -
.../logging/log4j/spi/recycler/Recycler.java | 48 -
.../logging/log4j/spi/recycler/RecyclerAware.java | 25 -
.../log4j/spi/recycler/RecyclerFactory.java | 58 -
.../spi/recycler/RecyclerFactoryProvider.java | 59 -
.../spi/recycler/RecyclerFactoryRegistry.java | 119 -
.../logging/log4j/spi/recycler/package-info.java | 26 -
.../log4j/status/StatusConsoleListener.java | 132 -
.../apache/logging/log4j/status/StatusData.java | 158 -
.../logging/log4j/status/StatusListener.java | 39 -
.../apache/logging/log4j/status/StatusLogger.java | 435 --
.../log4j/status/StatusLoggerConfiguration.java | 58 -
.../logging/log4j/status/StatusLoggerFactory.java | 54 -
.../apache/logging/log4j/status/package-info.java | 26 -
.../org/apache/logging/log4j/util/BiConsumer.java | 39 -
.../java/org/apache/logging/log4j/util/Cast.java | 40 -
.../java/org/apache/logging/log4j/util/Chars.java | 88 -
.../org/apache/logging/log4j/util/Constants.java | 104 -
.../log4j/util/ContextAwarePropertySource.java | 195 -
.../apache/logging/log4j/util/EnglishEnums.java | 71 -
.../log4j/util/EnvironmentPropertySource.java | 71 -
.../log4j/util/FilteredObjectInputStream.java | 94 -
.../log4j/util/IndexedReadOnlyStringMap.java | 64 -
.../logging/log4j/util/IndexedStringMap.java | 34 -
.../org/apache/logging/log4j/util/InternalApi.java | 31 -
.../org/apache/logging/log4j/util/LambdaUtil.java | 95 -
.../java/org/apache/logging/log4j/util/Lazy.java | 95 -
.../org/apache/logging/log4j/util/LazyBoolean.java | 66 -
.../org/apache/logging/log4j/util/LazyUtil.java | 214 -
.../org/apache/logging/log4j/util/LoaderUtil.java | 508 ---
.../apache/logging/log4j/util/LowLevelLogUtil.java | 145 -
.../apache/logging/log4j/util/MessageSupplier.java | 36 -
.../util/MultiFormatStringBuilderFormattable.java | 40 -
.../logging/log4j/util/PerformanceSensitive.java | 39 -
.../log4j/util/PropertiesPropertySource.java | 92 -
.../apache/logging/log4j/util/PropertiesUtil.java | 997 ----
.../logging/log4j/util/PropertyEnvironment.java | 445 --
.../log4j/util/PropertyFilePropertySource.java | 54 -
.../org/apache/logging/log4j/util/PropertyKey.java | 35 -
.../apache/logging/log4j/util/PropertySource.java | 341 --
.../logging/log4j/util/ReadOnlyStringMap.java | 109 -
.../log4j/util/ReloadablePropertySource.java | 25 -
.../logging/log4j/util/ServiceLoaderUtil.java | 94 -
.../logging/log4j/util/SortedArrayStringMap.java | 473 --
.../apache/logging/log4j/util/StackLocator.java | 127 -
.../logging/log4j/util/StackLocatorUtil.java | 129 -
.../log4j/util/StringBuilderFormattable.java | 35 -
.../apache/logging/log4j/util/StringBuilders.java | 383 --
.../org/apache/logging/log4j/util/StringMap.java | 102 -
.../org/apache/logging/log4j/util/Strings.java | 323 --
.../org/apache/logging/log4j/util/Supplier.java | 35 -
.../log4j/util/SystemPropertiesPropertySource.java | 154 -
.../org/apache/logging/log4j/util/TimeUnit.java | 58 -
.../org/apache/logging/log4j/util/TriConsumer.java | 39 -
.../java/org/apache/logging/log4j/util/Unbox.java | 236 -
.../apache/logging/log4j/util/package-info.java | 27 -
.../src/main/resources/Log4j-charsets.properties | 50 -
.../src/main/resources/log4j2.propertyMapping.json | 64 -
302 files changed, 49676 deletions(-)
diff --git a/log4j-api-test/pom.xml b/log4j-api-test/pom.xml
deleted file mode 100644
index f615fd4121..0000000000
--- a/log4j-api-test/pom.xml
+++ /dev/null
@@ -1,168 +0,0 @@
-<?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.
- -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j</artifactId>
- <version>${revision}</version>
- <relativePath>../log4j-parent</relativePath>
- </parent>
-
- <artifactId>log4j-api-test</artifactId>
- <packaging>jar</packaging>
- <name>Apache Log4j API Tests</name>
- <description>The Apache Log4j API Test</description>
- <properties>
- <!-- Ignore less important (high rank) bugs for test artifacts -->
- <spotbugs.maxRank>9</spotbugs.maxRank>
-
- <!--
- ~ OSGi and JPMS options
- -->
- <bnd-module-name>org.apache.logging.log4j.test</bnd-module-name>
- <bnd-extra-package-options>
- org.apache.commons.lang3.*;resolution:=optional,
- <!-- Both JUnit 4 and JUnit 5 are not required -->
- org.junit.*;resolution:=optional,
- org.hamcrest.*;resolution:=optional,
- org.junitpioneer.*;resolution:=optional,
- org.apache.maven.*;resolution:=optional,
- org.codehaus.plexus.util.*;resolution:=optional,
- org.mockito.*;resolution:=optional
- </bnd-extra-package-options>
- <bnd-extra-module-options>
- <!-- Non-transitive static modules -->
- junit;transitive=false,
- org.hamcrest;transitive=false,
- org.junit.jupiter.api;transitive=false,
- org.junitpioneer;transitive=false,
- <!-- Filebased module names: MUST be static -->
- maven.core;substitute="maven-core";transitive=false;static=true,
- maven.model;substitute="maven-model";transitive=false;static=true,
- maven.model.builder;substitute="maven-model-builder";transitive=false;static=true,
- plexus.utils;substitute="plexus-utils";transitive=false;static=true
- </bnd-extra-module-options>
- </properties>
- <!--
- ~ The dependency list has been checked with:
- ~
- ~ ./mvnw dependency:analyze -pl log4j-api-test
- -->
- <dependencies>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest</artifactId>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.junit-pioneer</groupId>
- <artifactId>junit-pioneer</artifactId>
- </dependency>
- <dependency>
- <groupId>org.junit.platform</groupId>
- <artifactId>junit-platform-commons</artifactId>
- </dependency>
- <dependency>
- <groupId>org.junit.platform</groupId>
- <artifactId>junit-platform-launcher</artifactId>
- </dependency>
- <dependency>
- <groupId>org.opentest4j</groupId>
- <artifactId>opentest4j</artifactId>
- </dependency>
- <dependency>
- <groupId>org.assertj</groupId>
- <artifactId>assertj-core</artifactId>
- <scope>test</scope>
- </dependency>
- <!-- Required for JSON support -->
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-core</artifactId>
- <scope>test</scope>
- </dependency>
- <!-- Required for JSON support -->
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-databind</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-engine</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-params</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>uk.org.webcompere</groupId>
- <artifactId>system-stubs-core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>uk.org.webcompere</groupId>
- <artifactId>system-stubs-jupiter</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
- <build>
- <plugins>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-failsafe-plugin</artifactId>
- <configuration>
- <useModulePath>false</useModulePath>
- </configuration>
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <useModulePath>false</useModulePath>
- </configuration>
- </plugin>
-
- </plugins>
- </build>
-</project>
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/ListStatusListener.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/ListStatusListener.java
deleted file mode 100644
index fb19e5b7ae..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/ListStatusListener.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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.test;
-
-import java.util.stream.Stream;
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.status.StatusData;
-import org.apache.logging.log4j.status.StatusListener;
-import org.osgi.annotation.versioning.ProviderType;
-
-/**
- * A {@link StatusListener} that collects messages for further inspection.
- */
-@ProviderType
-public interface ListStatusListener extends StatusListener {
-
- void clear();
-
- Stream<StatusData> getStatusData();
-
- default Stream<StatusData> findStatusData(Level level) {
- return getStatusData().filter(data -> level.isLessSpecificThan(data.getLevel()));
- }
-
- default Stream<StatusData> findStatusData(Level level, String regex) {
- return findStatusData(level)
- .filter(data -> data.getMessage().getFormattedMessage().matches(regex));
- }
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/TestLogger.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/TestLogger.java
deleted file mode 100644
index a784637615..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/TestLogger.java
+++ /dev/null
@@ -1,268 +0,0 @@
-/*
- * 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.test;
-
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.Marker;
-import org.apache.logging.log4j.ThreadContext;
-import org.apache.logging.log4j.message.Message;
-import org.apache.logging.log4j.message.MessageFactory;
-import org.apache.logging.log4j.spi.AbstractLogger;
-
-/**
- *
- */
-public class TestLogger extends AbstractLogger {
-
- private static final long serialVersionUID = 1L;
-
- public TestLogger() {
- super();
- }
-
- public TestLogger(final String name, final MessageFactory messageFactory) {
- super(name, messageFactory);
- }
-
- public TestLogger(final String name) {
- super(name);
- }
-
- private final List<String> list = new ArrayList<>();
-
- public List<String> getEntries() {
- return list;
- }
-
- @Override
- public void logMessage(
- final String fqcn, final Level level, final Marker marker, final Message msg, final Throwable throwable) {
- log(level, marker, fqcn, null, msg, throwable);
- }
-
- @Override
- protected void log(
- final Level level,
- final Marker marker,
- final String fqcn,
- final StackTraceElement location,
- final Message message,
- final Throwable throwable) {
- final StringBuilder sb = new StringBuilder();
- if (marker != null) {
- sb.append(marker);
- }
- sb.append(' ');
- sb.append(level.toString());
- sb.append(' ');
- if (location != null) {
- sb.append(location.toString());
- sb.append(' ');
- }
- sb.append(message.getFormattedMessage());
- final Map<String, String> mdc = ThreadContext.getImmutableContext();
- if (mdc.size() > 0) {
- sb.append(' ');
- sb.append(mdc.toString());
- sb.append(' ');
- }
- final Object[] params = message.getParameters();
- Throwable t;
- if (throwable == null
- && params != null
- && params.length > 0
- && params[params.length - 1] instanceof Throwable) {
- t = (Throwable) params[params.length - 1];
- } else {
- t = throwable;
- }
- if (t != null) {
- sb.append(' ');
- final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- t.printStackTrace(new PrintStream(baos));
- sb.append(baos.toString());
- }
- list.add(sb.toString());
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final String msg) {
- return true;
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final String msg, final Throwable t) {
- return true;
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final String msg, final Object... p1) {
- return true;
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0) {
- return true;
- }
-
- @Override
- public boolean isEnabled(
- final Level level, final Marker marker, final String message, final Object p0, final Object p1) {
- return true;
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2) {
- return true;
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3) {
- return true;
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3,
- final Object p4) {
- return true;
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3,
- final Object p4,
- final Object p5) {
- return true;
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3,
- final Object p4,
- final Object p5,
- final Object p6) {
- return true;
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3,
- final Object p4,
- final Object p5,
- final Object p6,
- final Object p7) {
- return true;
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3,
- final Object p4,
- final Object p5,
- final Object p6,
- final Object p7,
- final Object p8) {
- return true;
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3,
- final Object p4,
- final Object p5,
- final Object p6,
- final Object p7,
- final Object p8,
- final Object p9) {
- return true;
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final CharSequence msg, final Throwable t) {
- return true;
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final Object msg, final Throwable t) {
- return true;
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final Message msg, final Throwable t) {
- return true;
- }
-
- @Override
- public Level getLevel() {
- return Level.ALL;
- }
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/TestLoggerContext.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/TestLoggerContext.java
deleted file mode 100644
index 7b0ae7c7ab..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/TestLoggerContext.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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.test;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import org.apache.logging.log4j.message.MessageFactory;
-import org.apache.logging.log4j.spi.ExtendedLogger;
-import org.apache.logging.log4j.spi.LoggerContext;
-
-/**
- *
- */
-public class TestLoggerContext implements LoggerContext {
- private final Map<String, ExtendedLogger> map = new ConcurrentHashMap<>();
-
- @Override
- public ExtendedLogger getLogger(final String name) {
- final ExtendedLogger extendedLogger = map.get(name);
- if (extendedLogger != null) {
- return extendedLogger;
- }
- final ExtendedLogger logger = new TestLogger(name);
- map.put(name, logger);
- return logger;
- }
-
- @Override
- public ExtendedLogger getLogger(final String name, final MessageFactory messageFactory) {
- return new TestLogger(name, messageFactory);
- }
-
- @Override
- public Object getExternalContext() {
- return null;
- }
-
- @Override
- public boolean hasLogger(final String name) {
- return false;
- }
-
- @Override
- public boolean hasLogger(final String name, final MessageFactory messageFactory) {
- return false;
- }
-
- @Override
- public boolean hasLogger(final String name, final Class<? extends MessageFactory> messageFactoryClass) {
- return false;
- }
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/TestLoggerContextFactory.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/TestLoggerContextFactory.java
deleted file mode 100644
index 132b04ee70..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/TestLoggerContextFactory.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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.test;
-
-import java.net.URI;
-import org.apache.logging.log4j.spi.LoggerContext;
-import org.apache.logging.log4j.spi.LoggerContextFactory;
-
-/**
- *
- */
-public class TestLoggerContextFactory implements LoggerContextFactory {
-
- private static final LoggerContext context = new TestLoggerContext();
-
- @Override
- public LoggerContext getContext(
- final String fqcn, final ClassLoader loader, final Object externalContext, final boolean currentContext) {
- return context;
- }
-
- @Override
- public LoggerContext getContext(
- final String fqcn,
- final ClassLoader loader,
- final Object externalContext,
- final boolean currentContext,
- final URI configLocation,
- final String name) {
- return context;
- }
-
- @Override
- public void removeContext(final LoggerContext context) {}
-
- @Override
- public boolean isClassLoaderDependent() {
- return false;
- }
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/TestProperties.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/TestProperties.java
deleted file mode 100644
index 9942990520..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/TestProperties.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.test;
-
-/**
- * A container for per-test properties.
- */
-public interface TestProperties {
-
- /**
- * Path to a directory specific to the test class,
- */
- public static final String LOGGING_PATH = "logging.path";
-
- String getProperty(final String key);
-
- boolean containsProperty(final String key);
-
- void setProperty(final String key, final String value);
-
- default void setProperty(final String key, final boolean value) {
- setProperty(key, value ? "true" : "false");
- }
-
- default void setProperty(final String key, final int value) {
- setProperty(key, Integer.toString(value));
- }
-
- void clearProperty(final String key);
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/ThreadContextHolder.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/ThreadContextHolder.java
deleted file mode 100644
index 2407e23730..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/ThreadContextHolder.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * 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.test;
-
-import java.util.Map;
-import org.apache.logging.log4j.ThreadContext;
-import org.apache.logging.log4j.ThreadContext.ContextStack;
-
-/**
- * Holds an immutable copy of the ThreadContext stack and map.
- *
- * TODO Use LOG4J2-1517 Add ThreadContext.setContext(Map<String, String>)
- *
- * or
- *
- * TODO Might be replaced by something from LOG4J2-1447.
- *
- * or do nothing.
- *
- * @since 2.7
- */
-public class ThreadContextHolder {
-
- private final Map<String, String> immutableContext;
- private final ContextStack immutableStack;
- private final boolean restoreContext;
- private final boolean restoreStack;
-
- /**
- * Constructs a new holder initialized with an immutable copy of the ThreadContext stack and map.
- *
- * @param restoreContext
- * @param restoreStack
- */
- public ThreadContextHolder(final boolean restoreContext, final boolean restoreStack) {
- this.restoreContext = restoreContext;
- this.restoreStack = restoreStack;
- this.immutableContext = restoreContext ? ThreadContext.getImmutableContext() : null;
- this.immutableStack = restoreStack ? ThreadContext.getImmutableStack() : null;
- }
-
- /**
- * Restores the ThreadContext stack and map based on the values saved in the constructor.
- */
- public void restore() {
- if (restoreStack) {
- ThreadContext.setStack(immutableStack);
- }
- if (restoreContext) {
- // TODO LOG4J2-1517 Add ThreadContext.setContext(Map<String, String>)
- // Use:
- // ThreadContext.setContext(immutableContext);
- // Instead of:
- ThreadContext.clearMap();
- ThreadContext.putAll(immutableContext);
- //
- // or:
- // ThreadContext.clearMap();
- // for (Map.Entry<String, String> entry : immutableContext.entrySet()) {
- // ThreadContext.put(entry.getKey(), entry.getValue());
- // }
- }
- }
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/ThreadContextUtilityClass.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/ThreadContextUtilityClass.java
deleted file mode 100644
index 61cd380829..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/ThreadContextUtilityClass.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * 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.test;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNotSame;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import java.util.Map;
-import org.apache.logging.log4j.ThreadContext;
-
-public class ThreadContextUtilityClass {
-
- public static void perfTest() {
- ThreadContext.clearMap();
- final Timer complete = new Timer("ThreadContextTest");
- complete.start();
- ThreadContext.put("Var1", "value 1");
- ThreadContext.put("Var2", "value 2");
- ThreadContext.put("Var3", "value 3");
- ThreadContext.put("Var4", "value 4");
- ThreadContext.put("Var5", "value 5");
- ThreadContext.put("Var6", "value 6");
- ThreadContext.put("Var7", "value 7");
- ThreadContext.put("Var8", "value 8");
- ThreadContext.put("Var9", "value 9");
- ThreadContext.put("Var10", "value 10");
- final int loopCount = 1000000;
- final Timer timer = new Timer("ThreadContextCopy", loopCount);
- timer.start();
- for (int i = 0; i < loopCount; ++i) {
- final Map<String, String> map = ThreadContext.getImmutableContext();
- assertNotNull(map);
- }
- timer.stop();
- complete.stop();
- System.out.println(timer.toString());
- System.out.println(complete.toString());
- }
-
- public static void testGetContextReturnsEmptyMapIfEmpty() {
- ThreadContext.clearMap();
- assertTrue(ThreadContext.getContext().isEmpty());
- }
-
- public static void testGetContextReturnsMutableCopy() {
- ThreadContext.clearMap();
- final Map<String, String> map1 = ThreadContext.getContext();
- assertTrue(map1.isEmpty());
- map1.put("K", "val"); // no error
- assertEquals("val", map1.get("K"));
-
- // adding to copy does not affect thread context map
- assertTrue(ThreadContext.getContext().isEmpty());
-
- ThreadContext.put("key", "val2");
- final Map<String, String> map2 = ThreadContext.getContext();
- assertEquals(1, map2.size());
- assertEquals("val2", map2.get("key"));
- map2.put("K", "val"); // no error
- assertEquals("val", map2.get("K"));
-
- // first copy is not affected
- assertNotSame(map1, map2);
- assertEquals(1, map1.size());
- }
-
- public static void testGetImmutableContextReturnsEmptyMapIfEmpty() {
- ThreadContext.clearMap();
- assertTrue(ThreadContext.getImmutableContext().isEmpty());
- }
-
- public static void testGetImmutableContextReturnsImmutableMapIfNonEmpty() {
- ThreadContext.clearMap();
- ThreadContext.put("key", "val");
- final Map<String, String> immutable = ThreadContext.getImmutableContext();
- assertThrows(UnsupportedOperationException.class, () -> immutable.put("otherkey", "otherval"));
- }
-
- public static void testGetImmutableContextReturnsImmutableMapIfEmpty() {
- ThreadContext.clearMap();
- final Map<String, String> immutable = ThreadContext.getImmutableContext();
- assertThrows(UnsupportedOperationException.class, () -> immutable.put("otherkey", "otherval"));
- }
-
- public static void testGetImmutableStackReturnsEmptyStackIfEmpty() {
- ThreadContext.clearStack();
- assertTrue(ThreadContext.getImmutableStack().asList().isEmpty());
- }
-
- public static void testPut() {
- ThreadContext.clearMap();
- assertNull(ThreadContext.get("testKey"));
- ThreadContext.put("testKey", "testValue");
- assertEquals("testValue", ThreadContext.get("testKey"));
- }
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/Timer.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/Timer.java
deleted file mode 100644
index 939e6e527f..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/Timer.java
+++ /dev/null
@@ -1,294 +0,0 @@
-/*
- * 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.test;
-
-import java.text.DecimalFormat;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
-import org.apache.logging.log4j.util.StringBuilderFormattable;
-import org.apache.logging.log4j.util.Strings;
-
-/**
- * Primarily used in unit tests, but can be used to track elapsed time for a request or portion of any other operation
- * so long as all the timer methods are called on the same thread in which it was started. Calling start on
- * multiple threads will cause the times to be aggregated.
- */
-public class Timer implements StringBuilderFormattable {
-
- private final String name; // The timer's name
-
- public enum Status {
- Started,
- Stopped,
- Paused
- }
-
- private Status status; // The timer's status
- private long elapsedTime; // The elapsed time
- private final int iterations;
- private static final long NANO_PER_SECOND = 1000000000L;
- private static final long NANO_PER_MINUTE = NANO_PER_SECOND * 60;
- private static final long NANO_PER_HOUR = NANO_PER_MINUTE * 60;
- private final ThreadLocal<Long> startTime = ThreadLocal.withInitial(() -> 0L);
- private final Lock stateChangeLock = new ReentrantLock();
-
- /**
- * Constructor.
- * @param name the timer name.
- */
- public Timer(final String name) {
- this(name, 0);
- }
-
- /**
- * Constructor.
- *
- * @param name the timer name.
- * @param iterations the number of iterations that will take place.
- */
- public Timer(final String name, final int iterations) {
- this.name = name;
- status = Status.Stopped;
- this.iterations = (iterations > 0) ? iterations : 0;
- }
-
- /**
- * Start the timer.
- */
- public void start() {
- stateChangeLock.lock();
- try {
- startTime.set(System.nanoTime());
- elapsedTime = 0;
- status = Status.Started;
- } finally {
- stateChangeLock.unlock();
- }
- }
-
- public void startOrResume() {
- stateChangeLock.lock();
- try {
- if (status == Status.Stopped) {
- start();
- } else {
- resume();
- }
- } finally {
- stateChangeLock.unlock();
- }
- }
-
- /**
- * Stop the timer.
- * @return the String result of the timer completing.
- */
- public String stop() {
- stateChangeLock.lock();
- try {
- elapsedTime += System.nanoTime() - startTime.get();
- startTime.set(0L);
- status = Status.Stopped;
- return toString();
- } finally {
- stateChangeLock.unlock();
- }
- }
-
- /**
- * Pause the timer.
- */
- public void pause() {
- stateChangeLock.lock();
- try {
- elapsedTime += System.nanoTime() - startTime.get();
- startTime.set(0L);
- status = Status.Paused;
- } finally {
- stateChangeLock.unlock();
- }
- }
-
- /**
- * Resume the timer.
- */
- public void resume() {
- stateChangeLock.lock();
- try {
- startTime.set(System.nanoTime());
- status = Status.Started;
- } finally {
- stateChangeLock.unlock();
- }
- }
-
- /**
- * Accessor for the name.
- * @return the timer's name.
- */
- public String getName() {
- return name;
- }
-
- /**
- * Access the elapsed time.
- *
- * @return the elapsed time.
- */
- public long getElapsedTime() {
- return elapsedTime / 1000000;
- }
-
- /**
- * Access the elapsed time.
- *
- * @return the elapsed time.
- */
- public long getElapsedNanoTime() {
- return elapsedTime;
- }
-
- /**
- * Returns the name of the last operation performed on this timer (Start, Stop, Pause or
- * Resume).
- * @return the string representing the last operation performed.
- */
- public Status getStatus() {
- return status;
- }
-
- /**
- * Returns the String representation of the timer based upon its current state
- */
- @Override
- public String toString() {
- final StringBuilder result = new StringBuilder();
- formatTo(result);
- return result.toString();
- }
-
- @Override
- public void formatTo(final StringBuilder buffer) {
- buffer.append("Timer ").append(name);
- switch (status) {
- case Started:
- buffer.append(" started");
- break;
- case Paused:
- buffer.append(" paused");
- break;
- case Stopped:
- long nanoseconds = elapsedTime;
- // Get elapsed hours
- long hours = nanoseconds / NANO_PER_HOUR;
- // Get remaining nanoseconds
- nanoseconds = nanoseconds % NANO_PER_HOUR;
- // Get minutes
- long minutes = nanoseconds / NANO_PER_MINUTE;
- // Get remaining nanoseconds
- nanoseconds = nanoseconds % NANO_PER_MINUTE;
- // Get seconds
- long seconds = nanoseconds / NANO_PER_SECOND;
- // Get remaining nanoseconds
- nanoseconds = nanoseconds % NANO_PER_SECOND;
-
- String elapsed = Strings.EMPTY;
-
- if (hours > 0) {
- elapsed += hours + " hours ";
- }
- if (minutes > 0 || hours > 0) {
- elapsed += minutes + " minutes ";
- }
-
- DecimalFormat numFormat;
- numFormat = new DecimalFormat("#0");
- elapsed += numFormat.format(seconds) + '.';
- numFormat = new DecimalFormat("000000000");
- elapsed += numFormat.format(nanoseconds) + " seconds";
- buffer.append(" stopped. Elapsed time: ").append(elapsed);
- if (iterations > 0) {
- nanoseconds = elapsedTime / iterations;
- // Get elapsed hours
- hours = nanoseconds / NANO_PER_HOUR;
- // Get remaining nanoseconds
- nanoseconds = nanoseconds % NANO_PER_HOUR;
- // Get minutes
- minutes = nanoseconds / NANO_PER_MINUTE;
- // Get remaining nanoseconds
- nanoseconds = nanoseconds % NANO_PER_MINUTE;
- // Get seconds
- seconds = nanoseconds / NANO_PER_SECOND;
- // Get remaining nanoseconds
- nanoseconds = nanoseconds % NANO_PER_SECOND;
-
- elapsed = Strings.EMPTY;
-
- if (hours > 0) {
- elapsed += hours + " hours ";
- }
- if (minutes > 0 || hours > 0) {
- elapsed += minutes + " minutes ";
- }
-
- numFormat = new DecimalFormat("#0");
- elapsed += numFormat.format(seconds) + '.';
- numFormat = new DecimalFormat("000000000");
- elapsed += numFormat.format(nanoseconds) + " seconds";
- buffer.append(" Average per iteration: ").append(elapsed);
- }
- break;
- default:
- buffer.append(' ').append(status);
- break;
- }
- }
-
- @Override
- public boolean equals(final Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof Timer)) {
- return false;
- }
-
- final Timer timer = (Timer) o;
-
- if (elapsedTime != timer.elapsedTime) {
- return false;
- }
- if (startTime != timer.startTime) {
- return false;
- }
- if (name != null ? !name.equals(timer.name) : timer.name != null) {
- return false;
- }
- return status != null ? status.equals(timer.status) : timer.status == null;
- }
-
- @Override
- public int hashCode() {
- int result;
- result = (name != null ? name.hashCode() : 0);
- result = 29 * result + (status != null ? status.hashCode() : 0);
- final long time = startTime.get();
- result = 29 * result + (int) (time ^ (time >>> 32));
- result = 29 * result + (int) (elapsedTime ^ (elapsedTime >>> 32));
- return result;
- }
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/AbstractFileCleaner.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/AbstractFileCleaner.java
deleted file mode 100644
index 113d83976c..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/AbstractFileCleaner.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * 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.test.junit;
-
-import static org.junit.jupiter.api.Assertions.fail;
-
-import java.io.IOException;
-import java.io.InterruptedIOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.Collection;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.locks.LockSupport;
-import java.util.stream.Collectors;
-import org.junit.jupiter.api.extension.BeforeEachCallback;
-import org.junit.jupiter.api.extension.ExtensionContext;
-
-abstract class AbstractFileCleaner implements BeforeEachCallback {
-
- private static final int MAX_TRIES = Integer.getInteger("log4j2.junit.fileCleanerMaxTries", 10);
-
- private static final int SLEEP_PERIOD_MILLIS = Integer.getInteger("log4j2.junit.fileCleanerSleepPeriodMillis", 200);
- private static final int SLEEP_BASE_PERIOD_MILLIS = SLEEP_PERIOD_MILLIS / MAX_TRIES;
-
- @Override
- public void beforeEach(final ExtensionContext context) throws Exception {
- clean(context);
- }
-
- private void clean(final ExtensionContext context) {
- final Collection<Path> paths = getPathsForTest(context);
- if (paths.isEmpty()) {
- return;
- }
- final Map<Path, IOException> failures = new ConcurrentHashMap<>();
- for (final Path path : paths) {
- if (Files.exists(path)) {
- for (int i = 0, sleepMillis = SLEEP_BASE_PERIOD_MILLIS; i < MAX_TRIES; i++, sleepMillis <<= 1) {
- try {
- if (delete(path)) {
- failures.remove(path);
- break;
- }
- } catch (final IOException e) {
- failures.put(path, e);
- }
- LockSupport.parkNanos(path, TimeUnit.MILLISECONDS.toNanos(sleepMillis));
- if (Thread.interrupted()) {
- failures.put(path, new InterruptedIOException());
- Thread.currentThread().interrupt();
- break;
- }
- }
- }
- }
- if (!failures.isEmpty()) {
- final String message = failures.entrySet().stream()
- .map(e -> e.getKey() + " failed with " + e.getValue())
- .collect(Collectors.joining(", "));
- fail(message);
- }
- }
-
- abstract Collection<Path> getPathsForTest(final ExtensionContext context);
-
- abstract boolean delete(final Path path) throws IOException;
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/ClassMatchers.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/ClassMatchers.java
deleted file mode 100644
index 4795f74a42..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/ClassMatchers.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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.test.junit;
-
-import org.apache.logging.log4j.util.LoaderUtil;
-import org.hamcrest.CustomTypeSafeMatcher;
-import org.hamcrest.Matcher;
-
-public final class ClassMatchers {
-
- private static final Matcher<String> LOADABLE_CLASS_NAME =
- new CustomTypeSafeMatcher<String>("a loadable class name") {
- @Override
- protected boolean matchesSafely(final String item) {
- return LoaderUtil.isClassAvailable(item);
- }
- };
-
- public static Matcher<String> loadableClassName() {
- return LOADABLE_CLASS_NAME;
- }
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/CleanUpDirectories.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/CleanUpDirectories.java
deleted file mode 100644
index 841f6d1fcc..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/CleanUpDirectories.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.test.junit;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-import org.junit.jupiter.api.extension.ExtendWith;
-
-/**
- * JUnit extension to automatically clean up a list of directories and their contents before and after test execution.
- * This will automatically retry deletion up to 10 times per file while pausing for 200ms each time.
- * These can be overridden with system properties {@code log4j2.junit.fileCleanerMaxTries} and
- * {@code log4j2.junit.fileCleanerSleepPeriodMillis}.
- *
- * @see DirectoryCleaner
- * @see CleanUpFiles
- * @since 2.14.0
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.TYPE, ElementType.METHOD})
-@Documented
-@Inherited
-@ExtendWith(DirectoryCleaner.class)
-public @interface CleanUpDirectories {
- String[] value();
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/CleanUpFiles.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/CleanUpFiles.java
deleted file mode 100644
index 7ab44f6d7b..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/CleanUpFiles.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.test.junit;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-import org.junit.jupiter.api.extension.ExtendWith;
-
-/**
- * JUnit extension to automatically clean up a list of files before and after test execution.
- * This will automatically retry deletion up to 10 times per file while pausing for 200ms each time.
- * These can be overridden with system properties {@code log4j2.junit.fileCleanerMaxTries} and
- * {@code log4j2.junit.fileCleanerSleepPeriodMillis}.
- *
- * @see FileCleaner
- * @see CleanUpDirectories
- * @since 2.14.0
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.TYPE, ElementType.METHOD})
-@Documented
-@Inherited
-@ExtendWith(FileCleaner.class)
-public @interface CleanUpFiles {
- String[] value();
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/DirectoryCleaner.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/DirectoryCleaner.java
deleted file mode 100644
index bfb146b0ef..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/DirectoryCleaner.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * 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.test.junit;
-
-import java.io.IOException;
-import java.nio.file.FileVisitResult;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.nio.file.SimpleFileVisitor;
-import java.nio.file.attribute.BasicFileAttributes;
-import java.util.Collection;
-import java.util.HashSet;
-import org.junit.jupiter.api.extension.ExtensionContext;
-
-class DirectoryCleaner extends AbstractFileCleaner {
- @Override
- Collection<Path> getPathsForTest(final ExtensionContext context) {
- final Collection<Path> paths = new HashSet<>();
- final CleanUpDirectories testClassAnnotation =
- context.getRequiredTestClass().getAnnotation(CleanUpDirectories.class);
- if (testClassAnnotation != null) {
- for (final String path : testClassAnnotation.value()) {
- paths.add(Paths.get(path));
- }
- }
- final CleanUpDirectories testMethodAnnotation =
- context.getRequiredTestMethod().getAnnotation(CleanUpDirectories.class);
- if (testMethodAnnotation != null) {
- for (final String path : testMethodAnnotation.value()) {
- paths.add(Paths.get(path));
- }
- }
- return paths;
- }
-
- @Override
- boolean delete(final Path path) throws IOException {
- return deleteDirectory(path);
- }
-
- static boolean deleteDirectory(final Path path) throws IOException {
- if (Files.exists(path) && Files.isDirectory(path)) {
- Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
- @Override
- public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
- Files.deleteIfExists(file);
- return FileVisitResult.CONTINUE;
- }
-
- @Override
- public FileVisitResult postVisitDirectory(final Path dir, final IOException exc) throws IOException {
- Files.deleteIfExists(dir);
- return FileVisitResult.CONTINUE;
- }
- });
- }
- return true;
- }
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/ExtensionContextAnchor.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/ExtensionContextAnchor.java
deleted file mode 100644
index da3e37c1c8..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/ExtensionContextAnchor.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * 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.test.junit;
-
-import org.apache.logging.log4j.lang.NullMarked;
-import org.apache.logging.log4j.lang.Nullable;
-import org.junit.jupiter.api.extension.AfterAllCallback;
-import org.junit.jupiter.api.extension.AfterEachCallback;
-import org.junit.jupiter.api.extension.BeforeAllCallback;
-import org.junit.jupiter.api.extension.BeforeEachCallback;
-import org.junit.jupiter.api.extension.ExtensionContext;
-import org.junit.jupiter.api.extension.ExtensionContext.Namespace;
-import org.junit.platform.commons.PreconditionViolationException;
-
-@NullMarked
-public class ExtensionContextAnchor
- implements BeforeAllCallback, BeforeEachCallback, AfterAllCallback, AfterEachCallback {
-
- public static Namespace LOG4J2_NAMESPACE = Namespace.create("org.apache.logging.log4j.junit");
- private static final ThreadLocal<@Nullable ExtensionContext> EXTENSION_CONTEXT = new InheritableThreadLocal<>();
-
- private static void bind(final ExtensionContext context) {
- EXTENSION_CONTEXT.set(context);
- }
-
- private static void unbind(final ExtensionContext context) {
- EXTENSION_CONTEXT.set(context.getParent().orElse(null));
- }
-
- public static @Nullable ExtensionContext getContext() {
- return EXTENSION_CONTEXT.get();
- }
-
- public static @Nullable ExtensionContext getContext(final @Nullable ExtensionContext context) {
- return context != null ? context : EXTENSION_CONTEXT.get();
- }
-
- public static ExtensionContext getRequiredContext(final @Nullable ExtensionContext context) {
- final ExtensionContext actualContext = getContext(context);
- if (actualContext == null) {
- throw new PreconditionViolationException("No ExtensionContext available");
- }
- return actualContext;
- }
-
- public static ExtensionContext.Store getRequiredStore(final @Nullable ExtensionContext context) {
- return getRequiredContext(context).getStore(LOG4J2_NAMESPACE);
- }
-
- public static <T> @Nullable T getAttribute(
- final Object key, final Class<T> clazz, final @Nullable ExtensionContext context) {
- return getRequiredStore(context).get(key, clazz);
- }
-
- public static <T> T getRequiredAttribute(
- final Object key, final Class<T> clazz, final @Nullable ExtensionContext context) {
- final T attribute = getRequiredStore(context).get(key, clazz);
- if (attribute == null) {
- throw new PreconditionViolationException("Unable to find instance of " + clazz.getCanonicalName());
- }
- return attribute;
- }
-
- public static void setAttribute(final Object key, final Object value, final @Nullable ExtensionContext context) {
- getRequiredStore(context).put(key, value);
- }
-
- public static void removeAttribute(final Object key, final @Nullable ExtensionContext context) {
- final ExtensionContext actualContext = getContext(context);
- if (actualContext != null) {
- actualContext.getStore(LOG4J2_NAMESPACE).remove(key);
- }
- }
-
- @Override
- public void afterEach(final ExtensionContext context) throws Exception {
- unbind(context);
- }
-
- @Override
- public void afterAll(final ExtensionContext context) throws Exception {
- unbind(context);
- }
-
- @Override
- public void beforeEach(final ExtensionContext context) throws Exception {
- bind(context);
- }
-
- @Override
- public void beforeAll(final ExtensionContext context) throws Exception {
- bind(context);
- }
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/FileCleaner.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/FileCleaner.java
deleted file mode 100644
index ece4b189d4..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/FileCleaner.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.test.junit;
-
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Collection;
-import java.util.HashSet;
-import org.junit.jupiter.api.extension.ExtensionContext;
-
-class FileCleaner extends AbstractFileCleaner {
- @Override
- Collection<Path> getPathsForTest(final ExtensionContext context) {
- final Collection<Path> paths = new HashSet<>();
- final CleanUpFiles testClassAnnotation = context.getRequiredTestClass().getAnnotation(CleanUpFiles.class);
- if (testClassAnnotation != null) {
- for (final String path : testClassAnnotation.value()) {
- paths.add(Paths.get(path));
- }
- }
- final CleanUpFiles testMethodAnnotation =
- context.getRequiredTestMethod().getAnnotation(CleanUpFiles.class);
- if (testMethodAnnotation != null) {
- for (final String path : testMethodAnnotation.value()) {
- paths.add(Paths.get(path));
- }
- }
- return paths;
- }
-
- @Override
- boolean delete(final Path path) throws IOException {
- return Files.deleteIfExists(path);
- }
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/InitializesThreadContext.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/InitializesThreadContext.java
deleted file mode 100644
index 7c55de82f1..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/InitializesThreadContext.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.test.junit;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-import org.apache.logging.log4j.ThreadContext;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.junit.jupiter.api.parallel.ResourceAccessMode;
-import org.junit.jupiter.api.parallel.ResourceLock;
-
-/**
- * Marks a test class that initializes the {@link ThreadContext} class;
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.TYPE, ElementType.METHOD})
-@Documented
-@Inherited
-@ExtendWith(ThreadContextInitializer.class)
-@ResourceLock(value = Resources.THREAD_CONTEXT, mode = ResourceAccessMode.READ_WRITE)
-public @interface InitializesThreadContext {}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/Log4j2LauncherSessionListener.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/Log4j2LauncherSessionListener.java
deleted file mode 100644
index 5ea29ff1c7..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/Log4j2LauncherSessionListener.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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.test.junit;
-
-import org.apache.logging.log4j.util.PropertiesUtil;
-import org.junit.platform.launcher.LauncherSession;
-import org.junit.platform.launcher.LauncherSessionListener;
-
-/**
- * Global Log4j2 test setup.
- */
-public class Log4j2LauncherSessionListener implements LauncherSessionListener {
-
- @Override
- public void launcherSessionOpened(final LauncherSession session) {
- // Prevents `PropertiesUtil` from initializing (and caching the results)
- // in the middle of a test.
- PropertiesUtil.getProperties();
- }
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/LoggerContextFactoryExtension.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/LoggerContextFactoryExtension.java
deleted file mode 100644
index f81ac73688..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/LoggerContextFactoryExtension.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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.test.junit;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.spi.LoggerContextFactory;
-import org.junit.jupiter.api.extension.AfterAllCallback;
-import org.junit.jupiter.api.extension.BeforeAllCallback;
-import org.junit.jupiter.api.extension.ExtensionContext;
-
-/**
- * JUnit 5 extension that sets a particular {@link LoggerContextFactory} for the entire run of tests in a class.
- *
- * @since 2.14.0
- */
-public class LoggerContextFactoryExtension implements BeforeAllCallback, AfterAllCallback {
-
- private static final String KEY = "previousFactory";
- private final LoggerContextFactory loggerContextFactory;
-
- public LoggerContextFactoryExtension(final LoggerContextFactory loggerContextFactory) {
- this.loggerContextFactory = loggerContextFactory;
- }
-
- @Override
- public void beforeAll(final ExtensionContext context) throws Exception {
- getStore(context).put(KEY, LogManager.getFactory());
- LogManager.setFactory(loggerContextFactory);
- }
-
- @Override
- public void afterAll(final ExtensionContext context) throws Exception {
- LogManager.setFactory(getStore(context).get(KEY, LoggerContextFactory.class));
- }
-
- private ExtensionContext.Store getStore(final ExtensionContext context) {
- return context.getStore(ExtensionContext.Namespace.create(getClass()));
- }
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/Mutable.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/Mutable.java
deleted file mode 100644
index f9f1a12185..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/Mutable.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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.test.junit;
-
-/**
- * Helper class for JUnit tests.
- */
-public class Mutable {
- private String value;
-
- public Mutable set(final String value) {
- this.value = value;
- return this;
- }
-
- @Override
- public String toString() {
- return this.value;
- }
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/Resources.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/Resources.java
deleted file mode 100644
index 8956311e49..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/Resources.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.test.junit;
-
-import org.junit.jupiter.api.parallel.ResourceLock;
-
-/**
- * Constants to use the {@link ResourceLock} annotation.
- */
-public final class Resources {
-
- /**
- * Marks tests that require access to {@link org.apache.logging.log4j.LogManager} methods or change its
- * underlying {@link org.apache.logging.log4j.spi.LoggerContextFactory} implementation.
- */
- public static final String LOG_MANAGER = "log4j.LogManager";
-
- /**
- * Marks tests that require access to {@link org.apache.logging.log4j.ThreadContext} methods or change its
- * underlying {@link org.apache.logging.log4j.spi.ThreadContextMap} implementation.
- */
- public static final String THREAD_CONTEXT = "log4j.ThreadContext";
-
- /**
- * Marks tests that require access to {@link org.apache.logging.log4j.MarkerManager} methods.
- */
- public static final String MARKER_MANAGER = "log4j.MarkerManager";
-
- /**
- * Marks tests that requires access to {@link org.apache.logging.log4j.Level} static methods to create new levels.
- */
- public static final String LEVEL = "log4j.Level";
-
- /**
- * Marks tests that require access to {@link org.apache.logging.log4j.status.StatusLogger} static methods or
- * change its underlying implementation.
- */
- public static final String STATUS_LOGGER = "log4j.StatusLogger";
-
- private Resources() {}
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/SetTestProperty.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/SetTestProperty.java
deleted file mode 100644
index ff9a175d7a..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/SetTestProperty.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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.test.junit;
-
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.TYPE;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Repeatable;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.junitpioneer.jupiter.ReadsEnvironmentVariable;
-import org.junitpioneer.jupiter.ReadsSystemProperty;
-
-/**
- * Registers a Log4j2 system property with the {@link TestPropertySource}. The
- * property will also be available in configuration files using the
- * {@code ${test:...} lookup.
- *
- */
-@Retention(RUNTIME)
-@Target({TYPE, METHOD})
-@Inherited
-@Documented
-@ExtendWith(ExtensionContextAnchor.class)
-@ExtendWith(TestPropertyResolver.class)
-@Repeatable(SetTestProperty.SetTestProperties.class)
-@ReadsSystemProperty
-@ReadsEnvironmentVariable
-public @interface SetTestProperty {
-
- String key();
-
- String value();
-
- @Retention(RUNTIME)
- @Target({TYPE, METHOD})
- @Documented
- @Inherited
- public @interface SetTestProperties {
-
- SetTestProperty[] value();
- }
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/StatusLoggerExtension.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/StatusLoggerExtension.java
deleted file mode 100644
index 7737023bda..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/StatusLoggerExtension.java
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * 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.test.junit;
-
-import java.io.IOException;
-import java.time.Instant;
-import java.time.ZoneId;
-import java.time.format.DateTimeFormatter;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.stream.Stream;
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.message.ParameterizedNoReferenceMessageFactory;
-import org.apache.logging.log4j.simple.SimpleLogger;
-import org.apache.logging.log4j.status.StatusData;
-import org.apache.logging.log4j.status.StatusLogger;
-import org.apache.logging.log4j.test.ListStatusListener;
-import org.junit.jupiter.api.extension.BeforeAllCallback;
-import org.junit.jupiter.api.extension.BeforeEachCallback;
-import org.junit.jupiter.api.extension.ExtensionContext;
-import org.junit.jupiter.api.extension.ExtensionContext.Store.CloseableResource;
-import org.junit.jupiter.api.extension.ExtensionContextException;
-import org.junit.jupiter.api.extension.ParameterContext;
-import org.junit.jupiter.api.extension.ParameterResolutionException;
-import org.junit.jupiter.api.extension.TestExecutionExceptionHandler;
-import org.junit.jupiter.api.extension.support.TypeBasedParameterResolver;
-import org.junit.platform.commons.support.HierarchyTraversalMode;
-import org.junit.platform.commons.support.ModifierSupport;
-import org.junit.platform.commons.support.ReflectionSupport;
-
-class StatusLoggerExtension extends TypeBasedParameterResolver<ListStatusListener>
- implements BeforeAllCallback, BeforeEachCallback, TestExecutionExceptionHandler {
-
- private static final Object KEY = ListStatusListener.class;
-
- @Override
- public void beforeAll(ExtensionContext context) throws Exception {
- // Stores the per-class status listener to catch the messages caused by other
- // `beforeAll` methods and extensions.
- final ListStatusListenerHolder holder = new ListStatusListenerHolder(context, null);
- ExtensionContextAnchor.setAttribute(KEY, holder, context);
- ReflectionSupport.findFields(
- context.getRequiredTestClass(),
- f -> ModifierSupport.isStatic(f) && f.getType().equals(ListStatusListener.class),
- HierarchyTraversalMode.TOP_DOWN)
- .forEach(f -> {
- try {
- f.setAccessible(true);
- f.set(null, holder.getStatusListener());
- } catch (final ReflectiveOperationException e) {
- throw new ExtensionContextException("Failed to inject field.", e);
- }
- });
- }
-
- @Override
- public void beforeEach(final ExtensionContext context) throws Exception {
- // Retrieves the per-class status listener
- final ListStatusListenerHolder parentHolder =
- ExtensionContextAnchor.getAttribute(KEY, ListStatusListenerHolder.class, context);
- final ListStatusListener parent = parentHolder != null ? parentHolder.getStatusListener() : null;
- final ListStatusListenerHolder holder = new ListStatusListenerHolder(context, parent);
- ExtensionContextAnchor.setAttribute(KEY, holder, context);
- ReflectionSupport.findFields(
- context.getRequiredTestClass(),
- f -> ModifierSupport.isNotStatic(f) && f.getType().equals(ListStatusListener.class),
- HierarchyTraversalMode.TOP_DOWN)
- .forEach(f -> {
- try {
- f.setAccessible(true);
- f.set(context.getRequiredTestInstance(), holder.getStatusListener());
- } catch (final ReflectiveOperationException e) {
- throw new ExtensionContextException("Failed to inject field.", e);
- }
- });
- }
-
- @Override
- public void handleTestExecutionException(final ExtensionContext context, final Throwable throwable)
- throws Throwable {
- final ListStatusListenerHolder holder =
- ExtensionContextAnchor.getAttribute(KEY, ListStatusListenerHolder.class, context);
- if (holder != null) {
- holder.handleException(context, throwable);
- }
- throw throwable;
- }
-
- @Override
- public ListStatusListener resolveParameter(
- final ParameterContext parameterContext, final ExtensionContext extensionContext)
- throws ParameterResolutionException {
- final ListStatusListenerHolder holder =
- ExtensionContextAnchor.getAttribute(KEY, ListStatusListenerHolder.class, extensionContext);
- if (holder == null) {
- throw new ParameterResolutionException("Unable to resolve ListStatusListener");
- }
- return holder.getStatusListener();
- }
-
- private static class ListStatusListenerHolder implements CloseableResource {
-
- private final StatusLogger statusLogger;
- private final ListStatusListener statusListener;
-
- public ListStatusListenerHolder(final ExtensionContext context, final ListStatusListener parent) {
- this.statusLogger = StatusLogger.getLogger();
- this.statusListener = new JUnitListStatusListener(context, parent);
- statusLogger.registerListener(statusListener);
- }
-
- public ListStatusListener getStatusListener() {
- return statusListener;
- }
-
- @Override
- public void close() throws Throwable {
- statusLogger.removeListener(statusListener);
- }
-
- public void handleException(final ExtensionContext context, final Throwable throwable) {
- final Logger logger = new SimpleLogger(
- "StatusLoggerExtension",
- ParameterizedNoReferenceMessageFactory.INSTANCE,
- System.err,
- Level.ALL,
- null,
- false);
- logger.error("Test {} failed.\nDumping status data:", context.getDisplayName());
- final DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_TIME.withZone(ZoneId.systemDefault());
- statusListener.getStatusData().forEach(data -> {
- logger.atLevel(data.getLevel())
- .withThrowable(data.getThrowable())
- .withLocation(data.getStackTraceElement())
- .log(
- "{} {}",
- formatter.format(Instant.ofEpochMilli(data.getTimestamp())),
- data.getMessage().getFormattedMessage());
- });
- }
- }
-
- private static class JUnitListStatusListener implements ListStatusListener {
-
- private final ExtensionContext context;
- private final ListStatusListener parent;
- private final ArrayList<StatusData> statusData = new ArrayList<>();
-
- public JUnitListStatusListener(final ExtensionContext context, final ListStatusListener parent) {
- this.context = context;
- this.parent = parent;
- }
-
- @Override
- public void log(final StatusData data) {
- if (context.equals(ExtensionContextAnchor.getContext())) {
- synchronized (statusData) {
- statusData.add(data);
- }
- }
- }
-
- @Override
- public Level getStatusLevel() {
- return Level.DEBUG;
- }
-
- @Override
- public void close() throws IOException {
- // NOP
- }
-
- @Override
- public Stream<StatusData> getStatusData() {
- synchronized (statusData) {
- final List<StatusData> clone = (List<StatusData>) statusData.clone();
- return parent != null ? Stream.concat(parent.getStatusData(), clone.stream()) : clone.stream();
- }
- }
-
- @Override
- public void clear() {
- synchronized (statusData) {
- statusData.clear();
- }
- }
- }
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/StatusLoggerLevel.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/StatusLoggerLevel.java
deleted file mode 100644
index ffeeee07a9..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/StatusLoggerLevel.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.test.junit;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.junit.jupiter.api.parallel.ResourceLock;
-
-/**
- * JUnit 5 test extension that sets a specific StatusLogger logging level for each test.
- *
- * @since 2.14.0
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.TYPE)
-@Documented
-@Inherited
-@ExtendWith(StatusLoggerLevelExtension.class)
-@ResourceLock("log4j2.StatusLogger")
-public @interface StatusLoggerLevel {
- /** Name of {@link org.apache.logging.log4j.Level} to use for status logger. */
- String value();
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/StatusLoggerLevelExtension.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/StatusLoggerLevelExtension.java
deleted file mode 100644
index 54534ed9dc..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/StatusLoggerLevelExtension.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.test.junit;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.status.StatusLogger;
-import org.junit.jupiter.api.extension.AfterEachCallback;
-import org.junit.jupiter.api.extension.BeforeEachCallback;
-import org.junit.jupiter.api.extension.ExtensionContext;
-
-class StatusLoggerLevelExtension implements BeforeEachCallback, AfterEachCallback {
-
- private static final String KEY = "previousLevel";
-
- @Override
- public void beforeEach(final ExtensionContext context) throws Exception {
- final StatusLoggerLevel annotation = context.getRequiredTestClass().getAnnotation(StatusLoggerLevel.class);
- if (annotation == null) {
- return;
- }
- final StatusLogger logger = StatusLogger.getLogger();
- getStore(context).put(KEY, logger.getLevel());
- logger.setLevel(Level.valueOf(annotation.value()));
- }
-
- @Override
- public void afterEach(final ExtensionContext context) throws Exception {
- StatusLogger.getLogger().setLevel(getStore(context).get(KEY, Level.class));
- }
-
- private ExtensionContext.Store getStore(final ExtensionContext context) {
- return context.getStore(ExtensionContext.Namespace.create(getClass(), context.getRequiredTestInstance()));
- }
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/Tags.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/Tags.java
deleted file mode 100644
index 06bef43b06..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/Tags.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.test.junit;
-
-/**
- * A set of tags for JUnit 5 tests.
- */
-public final class Tags {
-
- /**
- * Marks tests that don't modify the global environment.
- * <p>
- * These tests can safely be run in parallel.
- * </p>
- */
- public static final String PARALLEL = "parallel";
-
- private Tags() {}
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/TempLoggingDir.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/TempLoggingDir.java
deleted file mode 100644
index 8a6af4c820..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/TempLoggingDir.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.test.junit;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.junit.jupiter.api.io.CleanupMode;
-
-/**
- * Injects the given static field with a per test logging directory.
- * <p>
- * The same directory is set as "logging.path" Log4j2 property.
- * </p>
- */
-@Retention(RUNTIME)
-@Target({FIELD, PARAMETER})
-@Inherited
-@Documented
-@ExtendWith(ExtensionContextAnchor.class)
-@ExtendWith(TempLoggingDirectory.class)
-public @interface TempLoggingDir {
-
- CleanupMode cleanup() default CleanupMode.DEFAULT;
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/TempLoggingDirectory.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/TempLoggingDirectory.java
deleted file mode 100644
index 0b65f3ef88..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/TempLoggingDirectory.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * 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.test.junit;
-
-import static org.junit.jupiter.api.io.CleanupMode.NEVER;
-import static org.junit.jupiter.api.io.CleanupMode.ON_SUCCESS;
-
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Field;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.status.StatusLogger;
-import org.apache.logging.log4j.test.TestProperties;
-import org.junit.jupiter.api.extension.BeforeAllCallback;
-import org.junit.jupiter.api.extension.BeforeEachCallback;
-import org.junit.jupiter.api.extension.ExtensionContext;
-import org.junit.jupiter.api.extension.ExtensionContext.Store.CloseableResource;
-import org.junit.jupiter.api.extension.ExtensionContextException;
-import org.junit.jupiter.api.extension.ParameterContext;
-import org.junit.jupiter.api.extension.ParameterResolutionException;
-import org.junit.jupiter.api.extension.ParameterResolver;
-import org.junit.jupiter.api.io.CleanupMode;
-import org.junit.platform.commons.support.AnnotationSupport;
-import org.junit.platform.commons.support.ModifierSupport;
-
-public class TempLoggingDirectory implements BeforeAllCallback, BeforeEachCallback, ParameterResolver {
-
- private static final Logger LOGGER = StatusLogger.getLogger();
-
- @Override
- public void beforeAll(ExtensionContext context) throws Exception {
- final List<Field> fields = AnnotationSupport.findAnnotatedFields(
- context.getRequiredTestClass(), TempLoggingDir.class, ModifierSupport::isStatic);
- Path loggingPath = null;
- for (final Field field : fields) {
- if (loggingPath != null) {
- LOGGER.warn("Multiple fields with @TempLoggingDir annotation are not supported.");
- } else {
- final CleanupMode cleanup = determineCleanupMode(field);
- loggingPath = createLoggingPath(context, cleanup).getPath();
- }
- field.setAccessible(true);
- field.set(null, loggingPath);
- }
- }
-
- @Override
- public void beforeEach(ExtensionContext context) throws Exception {
- // JUnit 5 does not set an error on the parent context if one of the children
- // fail. We record the list of children.
- context.getParent().ifPresent(c -> {
- final PathHolder holder = ExtensionContextAnchor.getAttribute(PathHolder.class, PathHolder.class, c);
- if (holder != null) {
- holder.addContext(context);
- }
- });
- // Inject fields
- final List<Field> fields = AnnotationSupport.findAnnotatedFields(
- context.getRequiredTestClass(), TempLoggingDir.class, ModifierSupport::isNotStatic);
- Path loggingPath = null;
- final Object instance = context.getRequiredTestInstance();
- for (final Field field : fields) {
- if (loggingPath != null) {
- LOGGER.warn("Multiple fields with @TempLoggingDir annotation are not supported.");
- } else {
- final CleanupMode cleanup = determineCleanupMode(field);
- loggingPath = createLoggingPath(context, cleanup).getPath();
- }
- field.setAccessible(true);
- field.set(instance, loggingPath);
- }
- }
-
- @Override
- public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
- throws ParameterResolutionException {
- if (parameterContext.getParameter().getType().isAssignableFrom(Path.class)) {
- return parameterContext.findAnnotation(TempLoggingDir.class).isPresent();
- }
- return false;
- }
-
- @Override
- public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
- throws ParameterResolutionException {
- final TempLoggingDir annotation = parameterContext
- .findAnnotation(TempLoggingDir.class)
- .orElseThrow(() -> new ParameterResolutionException("No @TempLoggingDir annotation found"));
- // Get or create temporary directory
- PathHolder holder = ExtensionContextAnchor.getAttribute(PathHolder.class, PathHolder.class, extensionContext);
- if (holder == null || !extensionContext.equals(holder.getMainContext())) {
- final CleanupMode mode = determineCleanupMode(annotation);
- holder = createLoggingPath(extensionContext, mode);
- }
- return holder.getPath();
- }
-
- private PathHolder createLoggingPath(final ExtensionContext context, final CleanupMode cleanup) {
- final TestProperties props = TestPropertySource.createProperties(context);
- // Create temporary directory
- final String baseDir = System.getProperty("basedir");
- final Path basePath = (baseDir != null ? Paths.get(baseDir, "target") : Paths.get(".")).resolve("logs");
- final Class<?> clazz = context.getRequiredTestClass();
- final String dir = clazz.getName().replaceAll("[.$]", File.separatorChar == '\\' ? "\\\\" : File.separator);
- final Path perClassPath = basePath.resolve(dir);
- // Per test subfolder
- final Path loggingPath = context.getTestMethod()
- .map(m -> perClassPath.resolve(m.getName()))
- .orElse(perClassPath);
- try {
- Files.createDirectories(loggingPath);
- } catch (final IOException e) {
- throw new ExtensionContextException("Failed to create temporary directory.", e);
- }
- props.setProperty(TestProperties.LOGGING_PATH, loggingPath.toString());
- // Register deletion
- final PathHolder holder = new PathHolder(loggingPath, cleanup, context);
- ExtensionContextAnchor.setAttribute(PathHolder.class, holder, context);
- return holder;
- }
-
- private CleanupMode determineCleanupMode(final TempLoggingDir annotation) {
- final CleanupMode mode = annotation.cleanup();
- // TODO: use JupiterConfiguration
- return mode != CleanupMode.DEFAULT ? mode : CleanupMode.ON_SUCCESS;
- }
-
- private CleanupMode determineCleanupMode(final Field field) {
- return determineCleanupMode(field.getAnnotation(TempLoggingDir.class));
- }
-
- private static class PathHolder implements CloseableResource {
-
- private final Path path;
- private final CleanupMode cleanupMode;
- private final ExtensionContext mainContext;
- private final Map<ExtensionContext, Boolean> contexts = new ConcurrentHashMap<>();
-
- public PathHolder(final Path path, final CleanupMode cleanup, final ExtensionContext context) {
- this.path = path;
- this.cleanupMode = cleanup;
- this.contexts.put(context, Boolean.TRUE);
- this.mainContext = context;
- }
-
- public void addContext(final ExtensionContext context) {
- this.contexts.put(context, Boolean.TRUE);
- }
-
- public Path getPath() {
- return path;
- }
-
- public ExtensionContext getMainContext() {
- return mainContext;
- }
-
- @Override
- public void close() throws IOException {
- if (cleanupMode == NEVER
- || (cleanupMode == ON_SUCCESS
- && contexts.keySet().stream().anyMatch(context -> context.getExecutionException()
- .isPresent()))) {
- LOGGER.debug("Skipping cleanup of directory {}.", path);
- return;
- }
- DirectoryCleaner.deleteDirectory(path);
- }
- }
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/TestPropertyResolver.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/TestPropertyResolver.java
deleted file mode 100644
index 7957331d49..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/TestPropertyResolver.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * 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.test.junit;
-
-import org.apache.logging.log4j.test.TestProperties;
-import org.apache.logging.log4j.util.ReflectionUtil;
-import org.junit.jupiter.api.extension.BeforeAllCallback;
-import org.junit.jupiter.api.extension.BeforeEachCallback;
-import org.junit.jupiter.api.extension.ExtensionContext;
-import org.junit.jupiter.api.extension.ParameterContext;
-import org.junit.jupiter.api.extension.ParameterResolutionException;
-import org.junit.jupiter.api.extension.support.TypeBasedParameterResolver;
-import org.junit.platform.commons.support.AnnotationSupport;
-import org.junit.platform.commons.support.HierarchyTraversalMode;
-import org.junit.platform.commons.support.ModifierSupport;
-import org.junit.platform.commons.support.ReflectionSupport;
-
-public class TestPropertyResolver extends TypeBasedParameterResolver<TestProperties>
- implements BeforeAllCallback, BeforeEachCallback {
-
- @Override
- public void beforeEach(final ExtensionContext context) throws Exception {
- final TestProperties props = TestPropertySource.createProperties(context);
- AnnotationSupport.findRepeatableAnnotations(context.getRequiredTestMethod(), SetTestProperty.class)
- .forEach(setProperty -> props.setProperty(setProperty.key(), setProperty.value()));
- final Class<?> testClass = context.getRequiredTestClass();
- final Object testInstance = context.getRequiredTestInstance();
- ReflectionSupport.findFields(
- testClass,
- field -> ModifierSupport.isNotStatic(field) && TestProperties.class.equals(field.getType()),
- HierarchyTraversalMode.BOTTOM_UP)
- .forEach(field -> ReflectionUtil.setFieldValue(field, testInstance, props));
- }
-
- @Override
- public void beforeAll(final ExtensionContext context) throws Exception {
- final TestProperties props = TestPropertySource.createProperties(context);
- AnnotationSupport.findRepeatableAnnotations(context.getRequiredTestClass(), SetTestProperty.class)
- .forEach(setProperty -> props.setProperty(setProperty.key(), setProperty.value()));
- final Class<?> testClass = context.getRequiredTestClass();
- ReflectionSupport.findFields(
- testClass,
- field -> ModifierSupport.isStatic(field) && TestProperties.class.equals(field.getType()),
- HierarchyTraversalMode.BOTTOM_UP)
- .forEach(field -> ReflectionUtil.setStaticFieldValue(field, props));
- }
-
- @Override
- public TestProperties resolveParameter(
- final ParameterContext parameterContext, final ExtensionContext extensionContext)
- throws ParameterResolutionException {
- return TestPropertySource.createProperties(extensionContext);
- }
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/TestPropertySource.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/TestPropertySource.java
deleted file mode 100644
index b9331ef03b..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/TestPropertySource.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * 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.test.junit;
-
-import org.apache.logging.log4j.test.TestProperties;
-import org.apache.logging.log4j.util.PropertySource;
-import org.junit.jupiter.api.extension.ExtensionContext;
-import org.junit.jupiter.api.extension.ExtensionContext.Namespace;
-import org.junit.jupiter.api.extension.ExtensionContext.Store;
-
-public class TestPropertySource implements PropertySource {
-
- private static final String PREFIX = "log4j2.";
- private static final Namespace NAMESPACE = ExtensionContextAnchor.LOG4J2_NAMESPACE.append("properties");
- private static final TestProperties EMPTY_PROPERTIES = new EmptyTestProperties();
-
- @Override
- public int getPriority() {
- // Highest priority
- return Integer.MIN_VALUE;
- }
-
- public static TestProperties createProperties(final ExtensionContext context) {
- // Make sure that the properties do not come from the parent ExtensionContext
- if (getProperties(context) instanceof JUnitTestProperties props && context.equals(props.context)) {
- return props;
- }
- final TestProperties props = new JUnitTestProperties(context);
- ExtensionContextAnchor.setAttribute(TestProperties.class, props, context);
- return props;
- }
-
- public static TestProperties getProperties() {
- return getProperties(null);
- }
-
- private static TestProperties getProperties(final ExtensionContext context) {
- final ExtensionContext actualContext = context != null ? context : ExtensionContextAnchor.getContext();
- if (actualContext != null) {
- final TestProperties props =
- ExtensionContextAnchor.getAttribute(TestProperties.class, TestProperties.class, actualContext);
- if (props != null) {
- return props;
- }
- }
- return EMPTY_PROPERTIES;
- }
-
- @Override
- public CharSequence getNormalForm(final Iterable<? extends CharSequence> tokens) {
- final CharSequence camelCase = Util.joinAsCamelCase(tokens);
- // Do not use Strings to prevent recursive initialization
- return camelCase.length() > 0 ? camelCase.toString() : null;
- }
-
- @Override
- public String getProperty(final String key) {
- return getProperties().getProperty(removePrefix(key));
- }
-
- @Override
- public boolean containsProperty(final String key) {
- return getProperties().containsProperty(removePrefix(key));
- }
-
- private static String removePrefix(final String key) {
- return key.startsWith(PREFIX) ? key.substring(PREFIX.length()) : key;
- }
-
- private static class JUnitTestProperties implements TestProperties {
-
- private final ExtensionContext context;
- private final Store store;
-
- public JUnitTestProperties(final ExtensionContext context) {
- this.context = context;
- this.store = context.getStore(NAMESPACE);
- }
-
- @Override
- public String getProperty(final String key) {
- return store.get(key, String.class);
- }
-
- @Override
- public boolean containsProperty(final String key) {
- return getProperty(key) != null;
- }
-
- @Override
- public void setProperty(final String key, final String value) {
- store.put(key, value);
- }
-
- @Override
- public void clearProperty(final String key) {
- store.remove(key, String.class);
- }
- }
-
- private static class EmptyTestProperties implements TestProperties {
-
- @Override
- public String getProperty(final String key) {
- return null;
- }
-
- @Override
- public boolean containsProperty(final String key) {
- return false;
- }
-
- @Override
- public void setProperty(final String key, final String value) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void clearProperty(final String key) {
- throw new UnsupportedOperationException();
- }
- }
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/ThreadContextInitializer.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/ThreadContextInitializer.java
deleted file mode 100644
index 309fb2fcb4..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/ThreadContextInitializer.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.test.junit;
-
-import org.apache.logging.log4j.ThreadContext;
-import org.junit.jupiter.api.extension.BeforeAllCallback;
-import org.junit.jupiter.api.extension.BeforeEachCallback;
-import org.junit.jupiter.api.extension.ExtensionContext;
-import org.junit.jupiter.api.extension.ExtensionContext.Store.CloseableResource;
-import org.junit.platform.commons.support.AnnotationSupport;
-
-class ThreadContextInitializer implements BeforeAllCallback, BeforeEachCallback {
-
- @Override
- public void beforeAll(final ExtensionContext context) throws Exception {
- if (AnnotationSupport.isAnnotated(context.getRequiredTestClass(), InitializesThreadContext.class)) {
- resetThreadContext(context);
- }
- }
-
- @Override
- public void beforeEach(final ExtensionContext context) throws Exception {
- if (AnnotationSupport.isAnnotated(context.getRequiredTestMethod(), InitializesThreadContext.class)) {
- resetThreadContext(context);
- }
- }
-
- private void resetThreadContext(final ExtensionContext context) {
- ThreadContext.init();
- // We use `CloseableResource` instead of `afterAll` to reset the
- // ThreadContextFactory
- // *after* the `@SetSystemProperty` extension has restored the properties
- ExtensionContextAnchor.setAttribute(ThreadContext.class, (CloseableResource) ThreadContext::init, context);
- }
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/ThreadContextMapExtension.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/ThreadContextMapExtension.java
deleted file mode 100644
index 3afab2f9d4..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/ThreadContextMapExtension.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.test.junit;
-
-import java.util.Map;
-import org.apache.logging.log4j.ThreadContext;
-import org.junit.jupiter.api.extension.BeforeEachCallback;
-import org.junit.jupiter.api.extension.ExtensionContext;
-
-class ThreadContextMapExtension implements BeforeEachCallback {
- private static final class ThreadContextMapStore implements ExtensionContext.Store.CloseableResource {
- private final Map<String, String> previousMap = ThreadContext.getImmutableContext();
-
- private ThreadContextMapStore() {
- ThreadContext.clearMap();
- }
-
- @Override
- public void close() throws Throwable {
- // TODO LOG4J2-1517 Add ThreadContext.setContext(Map<String, String>)
- ThreadContext.clearMap();
- ThreadContext.putAll(previousMap);
- }
- }
-
- @Override
- public void beforeEach(final ExtensionContext context) throws Exception {
- context.getStore(ExtensionContextAnchor.LOG4J2_NAMESPACE).getOrComputeIfAbsent(ThreadContextMapStore.class);
- }
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/ThreadContextRule.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/ThreadContextRule.java
deleted file mode 100644
index 1a85c7c7a2..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/ThreadContextRule.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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.test.junit;
-
-import org.apache.logging.log4j.ThreadContext;
-import org.apache.logging.log4j.test.ThreadContextHolder;
-import org.junit.rules.ExternalResource;
-
-/**
- * Restores the ThreadContext to it's initial map and stack values after a JUnit test.
- *
- * Usage:
- *
- * <pre>
- * @Rule
- * public final ThreadContextRule threadContextRule = new ThreadContextRule();
- * </pre>
- *
- * @deprecated use {@link UsingAnyThreadContext} with JUnit 5
- */
-@Deprecated
-public class ThreadContextRule extends ExternalResource {
-
- private final boolean restoreMap;
- private final boolean restoreStack;
- private ThreadContextHolder threadContextHolder;
-
- /**
- * Constructs an instance initialized to restore the stack and map.
- */
- public ThreadContextRule() {
- this(true, true);
- }
-
- /**
- * Constructs an instance initialized to restore the given structures.
- *
- * @param restoreMap
- * Whether to restore the thread context map.
- * @param restoreStack
- * Whether to restore the thread context stack.
- */
- public ThreadContextRule(final boolean restoreMap, final boolean restoreStack) {
- super();
- this.restoreMap = restoreMap;
- this.restoreStack = restoreStack;
- }
-
- @Override
- protected void after() {
- if (threadContextHolder != null) {
- threadContextHolder.restore();
- }
- }
-
- @Override
- protected void before() throws Throwable {
- threadContextHolder = new ThreadContextHolder(restoreMap, restoreStack);
- if (restoreMap) {
- ThreadContext.clearMap();
- }
- if (restoreStack) {
- ThreadContext.clearStack();
- }
- }
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/ThreadContextStackExtension.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/ThreadContextStackExtension.java
deleted file mode 100644
index 75bb8fe4c0..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/ThreadContextStackExtension.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.test.junit;
-
-import java.util.Collection;
-import org.apache.logging.log4j.ThreadContext;
-import org.junit.jupiter.api.extension.BeforeEachCallback;
-import org.junit.jupiter.api.extension.ExtensionContext;
-import org.junit.jupiter.api.extension.ExtensionContext.Namespace;
-import org.junit.jupiter.api.extension.ExtensionContext.Store;
-
-class ThreadContextStackExtension implements BeforeEachCallback {
- private static final class ThreadContextStackStore implements Store.CloseableResource {
- private final Collection<String> previousStack = ThreadContext.getImmutableStack();
-
- private ThreadContextStackStore() {
- ThreadContext.clearStack();
- }
-
- @Override
- public void close() throws Throwable {
- ThreadContext.setStack(previousStack);
- }
- }
-
- @Override
- public void beforeEach(final ExtensionContext context) throws Exception {
- context.getStore(Namespace.create(
- ThreadContext.class, context.getRequiredTestClass(), context.getRequiredTestInstance()))
- .getOrComputeIfAbsent(ThreadContextStackStore.class);
- }
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/ThreadContextStackRule.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/ThreadContextStackRule.java
deleted file mode 100644
index 452c322a52..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/ThreadContextStackRule.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.test.junit;
-
-/**
- * Restores the ThreadContext to it's initial stack values after a JUnit test.
- *
- * Usage:
- *
- * <pre>
- * @Rule
- * public final ThreadContextStackRule threadContextRule = new ThreadContextStackRule();
- * </pre>
- * @deprecated use {@link UsingThreadContextStack} with JUnit 5
- */
-@Deprecated
-public class ThreadContextStackRule extends ThreadContextRule {
-
- /**
- * Constructs an initialized instance.
- */
- public ThreadContextStackRule() {
- super(false, true);
- }
-}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/UsingAnyThreadContext.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/UsingAnyThreadContext.java
deleted file mode 100644
index 6e8750da2f..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/UsingAnyThreadContext.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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.test.junit;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Marks a test class as using {@link org.apache.logging.log4j.ThreadContext} APIs. This will automatically clear and restore
- * both the thread context map and stack for each test invocation.
- *
- * @since 2.14.0
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.TYPE, ElementType.METHOD, ElementType.ANNOTATION_TYPE})
-@Documented
-@Inherited
-@UsingThreadContextMap
-@UsingThreadContextStack
-public @interface UsingAnyThreadContext {}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/UsingStatusListener.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/UsingStatusListener.java
deleted file mode 100644
index e54deb6b42..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/UsingStatusListener.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.test.junit;
-
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.TYPE;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-import org.apache.logging.log4j.status.StatusListener;
-import org.apache.logging.log4j.test.ListStatusListener;
-import org.junit.jupiter.api.extension.ExtendWith;
-
-/**
- * Configures and injects a {@link StatusListener} of type
- * {@link ListStatusListener}, that will collect status messages for the test
- * context.
- */
-@Retention(RUNTIME)
-@Target({TYPE, METHOD})
-@Documented
-@ExtendWith(ExtensionContextAnchor.class)
-@ExtendWith(TestPropertyResolver.class)
-@ExtendWith(StatusLoggerExtension.class)
-public @interface UsingStatusListener {}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/UsingTestProperties.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/UsingTestProperties.java
deleted file mode 100644
index 1a37b99832..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/UsingTestProperties.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.test.junit;
-
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.TYPE;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-import org.apache.logging.log4j.test.TestProperties;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.junitpioneer.jupiter.ReadsEnvironmentVariable;
-import org.junitpioneer.jupiter.ReadsSystemProperty;
-
-/**
- * A field or method parameter of type {@link TestProperties} will be injected with a per-test source of Log4j2's
- * system properties.
- */
-@Retention(RUNTIME)
-@Target({TYPE, METHOD})
-@Inherited
-@Documented
-@ExtendWith(ExtensionContextAnchor.class)
-@ExtendWith(TestPropertyResolver.class)
-@ReadsSystemProperty
-@ReadsEnvironmentVariable
-public @interface UsingTestProperties {}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/UsingThreadContextMap.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/UsingThreadContextMap.java
deleted file mode 100644
index 2995e4c804..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/UsingThreadContextMap.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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.test.junit;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.junit.jupiter.api.parallel.ResourceAccessMode;
-import org.junit.jupiter.api.parallel.ResourceLock;
-import org.junitpioneer.jupiter.ReadsSystemProperty;
-
-/**
- * Marks a test class as using {@link org.apache.logging.log4j.spi.ThreadContextMap} APIs. This will automatically clear and
- * restore the thread context map (MDC) for each test invocation.
- *
- * @since 2.14.0
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.TYPE, ElementType.METHOD, ElementType.ANNOTATION_TYPE})
-@Documented
-@Inherited
-@ExtendWith(ThreadContextMapExtension.class)
-@ReadsSystemProperty
-@ResourceLock(value = Resources.THREAD_CONTEXT, mode = ResourceAccessMode.READ)
-public @interface UsingThreadContextMap {}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/UsingThreadContextStack.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/UsingThreadContextStack.java
deleted file mode 100644
index 7a96355ea4..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/UsingThreadContextStack.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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.test.junit;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.junitpioneer.jupiter.ReadsSystemProperty;
-
-/**
- * Marks a test class as using {@link org.apache.logging.log4j.spi.ThreadContextStack} APIs. This will automatically clear and
- * restore the thread context stack (NDC) for each test invocation.
- *
- * @since 2.14.0
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.TYPE, ElementType.METHOD, ElementType.ANNOTATION_TYPE})
-@Documented
-@Inherited
-@ExtendWith(ThreadContextStackExtension.class)
-@ReadsSystemProperty
-public @interface UsingThreadContextStack {}
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/package-info.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/package-info.java
deleted file mode 100644
index f299b2f928..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * 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.
- */
-@Export
-@Version("3.0.0")
-package org.apache.logging.log4j.test.junit;
-
-import org.osgi.annotation.bundle.Export;
-import org.osgi.annotation.versioning.Version;
diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/package-info.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/package-info.java
deleted file mode 100644
index 676a0e74fe..0000000000
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * 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.
- */
-@Export
-@Version("3.0.0")
-package org.apache.logging.log4j.test;
-
-import org.osgi.annotation.bundle.Export;
-import org.osgi.annotation.versioning.Version;
diff --git a/log4j-api-test/src/main/resources/META-INF/services/org.apache.logging.log4j.util.PropertySource b/log4j-api-test/src/main/resources/META-INF/services/org.apache.logging.log4j.util.PropertySource
deleted file mode 100644
index 2c7cb498d9..0000000000
--- a/log4j-api-test/src/main/resources/META-INF/services/org.apache.logging.log4j.util.PropertySource
+++ /dev/null
@@ -1,15 +0,0 @@
-# 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.
-org.apache.logging.log4j.test.junit.TestPropertySource
diff --git a/log4j-api-test/src/main/resources/META-INF/services/org.junit.jupiter.api.extension.Extension b/log4j-api-test/src/main/resources/META-INF/services/org.junit.jupiter.api.extension.Extension
deleted file mode 100644
index ca7ce84edd..0000000000
--- a/log4j-api-test/src/main/resources/META-INF/services/org.junit.jupiter.api.extension.Extension
+++ /dev/null
@@ -1,15 +0,0 @@
-# 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.
-org.apache.logging.log4j.test.junit.ExtensionContextAnchor
\ No newline at end of file
diff --git a/log4j-api-test/src/main/resources/META-INF/services/org.junit.platform.launcher.LauncherSessionListener b/log4j-api-test/src/main/resources/META-INF/services/org.junit.platform.launcher.LauncherSessionListener
deleted file mode 100644
index e492405c76..0000000000
--- a/log4j-api-test/src/main/resources/META-INF/services/org.junit.platform.launcher.LauncherSessionListener
+++ /dev/null
@@ -1,16 +0,0 @@
-# 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.
-
-org.apache.logging.log4j.test.junit.Log4j2LauncherSessionListener
\ No newline at end of file
diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/AbstractLoggerTest.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/AbstractLoggerTest.java
deleted file mode 100644
index 0f1d4f0078..0000000000
--- a/log4j-api-test/src/test/java/org/apache/logging/log4j/AbstractLoggerTest.java
+++ /dev/null
@@ -1,1472 +0,0 @@
-/*
- * 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;
-
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
-
-import java.util.List;
-import org.apache.logging.log4j.message.Message;
-import org.apache.logging.log4j.message.ObjectMessage;
-import org.apache.logging.log4j.message.ParameterizedMessage;
-import org.apache.logging.log4j.message.ReusableMessageFactory;
-import org.apache.logging.log4j.message.SimpleMessage;
-import org.apache.logging.log4j.spi.AbstractLogger;
-import org.apache.logging.log4j.status.StatusData;
-import org.apache.logging.log4j.status.StatusLogger;
-import org.apache.logging.log4j.test.junit.Resources;
-import org.apache.logging.log4j.test.junit.StatusLoggerLevel;
-import org.apache.logging.log4j.util.MessageSupplier;
-import org.apache.logging.log4j.util.Supplier;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.parallel.ResourceAccessMode;
-import org.junit.jupiter.api.parallel.ResourceLock;
-
-@StatusLoggerLevel("WARN")
-@ResourceLock(value = Resources.MARKER_MANAGER, mode = ResourceAccessMode.READ)
-public class AbstractLoggerTest {
-
- private static final StringBuilder CHAR_SEQ = new StringBuilder("CharSeq");
-
- // TODO add proper tests for ReusableMessage
-
- @SuppressWarnings("ThrowableInstanceNeverThrown")
- private static final Throwable t = new UnsupportedOperationException("Test");
-
- private static final Class<AbstractLogger> obj = AbstractLogger.class;
- private static final String pattern = "{}, {}";
- private static final String p1 = "Long Beach";
-
- private static final String p2 = "California";
- private static final Message charSeq = new SimpleMessage(CHAR_SEQ);
- private static final Message simple = new SimpleMessage("Hello");
- private static final Message object = new ObjectMessage(obj);
-
- private static final Message param = new ParameterizedMessage(pattern, p1, p2);
-
- private final Marker MARKER = MarkerManager.getMarker("TEST");
- private static final String MARKER_NAME = "TEST";
-
- private static final LogEvent[] EVENTS = new LogEvent[] {
- new LogEvent(null, simple, null),
- new LogEvent(MARKER_NAME, simple, null),
- new LogEvent(null, simple, t),
- new LogEvent(MARKER_NAME, simple, t),
- new LogEvent(null, object, null),
- new LogEvent(MARKER_NAME, object, null),
- new LogEvent(null, object, t),
- new LogEvent(MARKER_NAME, object, t),
- new LogEvent(null, param, null),
- new LogEvent(MARKER_NAME, param, null),
- new LogEvent(null, simple, null),
- new LogEvent(null, simple, t),
- new LogEvent(MARKER_NAME, simple, null),
- new LogEvent(MARKER_NAME, simple, t),
- new LogEvent(MARKER_NAME, simple, null),
- new LogEvent(null, charSeq, null),
- new LogEvent(null, charSeq, t),
- new LogEvent(MARKER_NAME, charSeq, null),
- new LogEvent(MARKER_NAME, charSeq, t),
- };
-
- @Test
- public void testDebug() {
- final CountingLogger logger = new CountingLogger();
- logger.setCurrentLevel(Level.DEBUG);
-
- logger.setCurrentEvent(EVENTS[0]);
- logger.debug("Hello");
- logger.debug((Marker) null, "Hello");
- logger.setCurrentEvent(EVENTS[1]);
- logger.debug(MARKER, "Hello");
- logger.setCurrentEvent(EVENTS[2]);
- logger.debug("Hello", t);
- logger.debug((Marker) null, "Hello", t);
- logger.setCurrentEvent(EVENTS[3]);
- logger.debug(MARKER, "Hello", t);
- logger.setCurrentEvent(EVENTS[4]);
- logger.debug(obj);
- logger.setCurrentEvent(EVENTS[5]);
- logger.debug(MARKER, obj);
- logger.setCurrentEvent(EVENTS[6]);
- logger.debug(obj, t);
- logger.debug((Marker) null, obj, t);
- logger.setCurrentEvent(EVENTS[7]);
- logger.debug(MARKER, obj, t);
- logger.setCurrentEvent(EVENTS[8]);
- logger.debug(pattern, p1, p2);
- logger.setCurrentEvent(EVENTS[9]);
- logger.debug(MARKER, pattern, p1, p2);
- logger.setCurrentEvent(EVENTS[10]);
- logger.debug(simple);
- logger.debug((Marker) null, simple);
- logger.debug((Marker) null, simple, null);
- logger.setCurrentEvent(EVENTS[11]);
- logger.debug(simple, t);
- logger.debug((Marker) null, simple, t);
- logger.setCurrentEvent(EVENTS[12]);
- logger.debug(MARKER, simple, null);
- logger.setCurrentEvent(EVENTS[13]);
- logger.debug(MARKER, simple, t);
- logger.setCurrentEvent(EVENTS[14]);
- logger.debug(MARKER, simple);
-
- logger.setCurrentEvent(EVENTS[15]);
- logger.debug(CHAR_SEQ);
- logger.setCurrentEvent(EVENTS[16]);
- logger.debug(CHAR_SEQ, t);
- logger.setCurrentEvent(EVENTS[17]);
- logger.debug(MARKER, CHAR_SEQ);
- logger.setCurrentEvent(EVENTS[18]);
- logger.debug(MARKER, CHAR_SEQ, t);
-
- assertEquals(4, logger.getCharSeqCount(), "log(CharSeq) invocations");
- assertEquals(5, logger.getObjectCount(), "log(Object) invocations");
- }
-
- @Test
- public void testError() {
- final CountingLogger logger = new CountingLogger();
- logger.setCurrentLevel(Level.ERROR);
-
- logger.setCurrentEvent(EVENTS[0]);
- logger.error("Hello");
- logger.error((Marker) null, "Hello");
- logger.setCurrentEvent(EVENTS[1]);
- logger.error(MARKER, "Hello");
- logger.setCurrentEvent(EVENTS[2]);
- logger.error("Hello", t);
- logger.error((Marker) null, "Hello", t);
- logger.setCurrentEvent(EVENTS[3]);
- logger.error(MARKER, "Hello", t);
- logger.setCurrentEvent(EVENTS[4]);
- logger.error(obj);
- logger.setCurrentEvent(EVENTS[5]);
- logger.error(MARKER, obj);
- logger.setCurrentEvent(EVENTS[6]);
- logger.error(obj, t);
- logger.error((Marker) null, obj, t);
- logger.setCurrentEvent(EVENTS[7]);
- logger.error(MARKER, obj, t);
- logger.setCurrentEvent(EVENTS[8]);
- logger.error(pattern, p1, p2);
- logger.setCurrentEvent(EVENTS[9]);
- logger.error(MARKER, pattern, p1, p2);
- logger.setCurrentEvent(EVENTS[10]);
- logger.error(simple);
- logger.error((Marker) null, simple);
- logger.error((Marker) null, simple, null);
- logger.setCurrentEvent(EVENTS[11]);
- logger.error(simple, t);
- logger.error((Marker) null, simple, t);
- logger.setCurrentEvent(EVENTS[12]);
- logger.error(MARKER, simple, null);
- logger.setCurrentEvent(EVENTS[13]);
- logger.error(MARKER, simple, t);
- logger.setCurrentEvent(EVENTS[14]);
- logger.error(MARKER, simple);
-
- logger.setCurrentEvent(EVENTS[15]);
- logger.error(CHAR_SEQ);
- logger.setCurrentEvent(EVENTS[16]);
- logger.error(CHAR_SEQ, t);
- logger.setCurrentEvent(EVENTS[17]);
- logger.error(MARKER, CHAR_SEQ);
- logger.setCurrentEvent(EVENTS[18]);
- logger.error(MARKER, CHAR_SEQ, t);
-
- assertEquals(4, logger.getCharSeqCount(), "log(CharSeq) invocations");
- assertEquals(5, logger.getObjectCount(), "log(Object) invocations");
- }
-
- @Test
- public void testFatal() {
- final CountingLogger logger = new CountingLogger();
- logger.setCurrentLevel(Level.FATAL);
-
- logger.setCurrentEvent(EVENTS[0]);
- logger.fatal("Hello");
- logger.fatal((Marker) null, "Hello");
- logger.setCurrentEvent(EVENTS[1]);
- logger.fatal(MARKER, "Hello");
- logger.setCurrentEvent(EVENTS[2]);
- logger.fatal("Hello", t);
- logger.fatal((Marker) null, "Hello", t);
- logger.setCurrentEvent(EVENTS[3]);
- logger.fatal(MARKER, "Hello", t);
- logger.setCurrentEvent(EVENTS[4]);
- logger.fatal(obj);
- logger.setCurrentEvent(EVENTS[5]);
- logger.fatal(MARKER, obj);
- logger.setCurrentEvent(EVENTS[6]);
- logger.fatal(obj, t);
- logger.fatal((Marker) null, obj, t);
- logger.setCurrentEvent(EVENTS[7]);
- logger.fatal(MARKER, obj, t);
- logger.setCurrentEvent(EVENTS[8]);
- logger.fatal(pattern, p1, p2);
- logger.setCurrentEvent(EVENTS[9]);
- logger.fatal(MARKER, pattern, p1, p2);
- logger.setCurrentEvent(EVENTS[10]);
- logger.fatal(simple);
- logger.fatal((Marker) null, simple);
- logger.fatal((Marker) null, simple, null);
- logger.setCurrentEvent(EVENTS[11]);
- logger.fatal(simple, t);
- logger.fatal((Marker) null, simple, t);
- logger.setCurrentEvent(EVENTS[12]);
- logger.fatal(MARKER, simple, null);
- logger.setCurrentEvent(EVENTS[13]);
- logger.fatal(MARKER, simple, t);
- logger.setCurrentEvent(EVENTS[14]);
- logger.fatal(MARKER, simple);
-
- logger.setCurrentEvent(EVENTS[15]);
- logger.fatal(CHAR_SEQ);
- logger.setCurrentEvent(EVENTS[16]);
- logger.fatal(CHAR_SEQ, t);
- logger.setCurrentEvent(EVENTS[17]);
- logger.fatal(MARKER, CHAR_SEQ);
- logger.setCurrentEvent(EVENTS[18]);
- logger.fatal(MARKER, CHAR_SEQ, t);
-
- assertEquals(4, logger.getCharSeqCount(), "log(CharSeq) invocations");
- assertEquals(5, logger.getObjectCount(), "log(Object) invocations");
- }
-
- @Test
- public void testInfo() {
- final CountingLogger logger = new CountingLogger();
- logger.setCurrentLevel(Level.INFO);
-
- logger.setCurrentEvent(EVENTS[0]);
- logger.info("Hello");
- logger.info((Marker) null, "Hello");
- logger.setCurrentEvent(EVENTS[1]);
- logger.info(MARKER, "Hello");
- logger.setCurrentEvent(EVENTS[2]);
- logger.info("Hello", t);
- logger.info((Marker) null, "Hello", t);
- logger.setCurrentEvent(EVENTS[3]);
- logger.info(MARKER, "Hello", t);
- logger.setCurrentEvent(EVENTS[4]);
- logger.info(obj);
- logger.setCurrentEvent(EVENTS[5]);
- logger.info(MARKER, obj);
- logger.setCurrentEvent(EVENTS[6]);
- logger.info(obj, t);
- logger.info((Marker) null, obj, t);
- logger.setCurrentEvent(EVENTS[7]);
- logger.info(MARKER, obj, t);
- logger.setCurrentEvent(EVENTS[8]);
- logger.info(pattern, p1, p2);
- logger.setCurrentEvent(EVENTS[9]);
- logger.info(MARKER, pattern, p1, p2);
- logger.setCurrentEvent(EVENTS[10]);
- logger.info(simple);
- logger.info((Marker) null, simple);
- logger.info((Marker) null, simple, null);
- logger.setCurrentEvent(EVENTS[11]);
- logger.info(simple, t);
- logger.info((Marker) null, simple, t);
- logger.setCurrentEvent(EVENTS[12]);
- logger.info(MARKER, simple, null);
- logger.setCurrentEvent(EVENTS[13]);
- logger.info(MARKER, simple, t);
- logger.setCurrentEvent(EVENTS[14]);
- logger.info(MARKER, simple);
-
- logger.setCurrentEvent(EVENTS[15]);
- logger.info(CHAR_SEQ);
- logger.setCurrentEvent(EVENTS[16]);
- logger.info(CHAR_SEQ, t);
- logger.setCurrentEvent(EVENTS[17]);
- logger.info(MARKER, CHAR_SEQ);
- logger.setCurrentEvent(EVENTS[18]);
- logger.info(MARKER, CHAR_SEQ, t);
-
- assertEquals(4, logger.getCharSeqCount(), "log(CharSeq) invocations");
- assertEquals(5, logger.getObjectCount(), "log(Object) invocations");
- }
-
- @Test
- public void testLogDebug() {
- final CountingLogger logger = new CountingLogger();
- logger.setCurrentLevel(Level.DEBUG);
-
- logger.setCurrentEvent(EVENTS[0]);
- logger.log(Level.DEBUG, "Hello");
- logger.log(Level.DEBUG, (Marker) null, "Hello");
- logger.setCurrentEvent(EVENTS[1]);
- logger.log(Level.DEBUG, MARKER, "Hello");
- logger.setCurrentEvent(EVENTS[2]);
- logger.log(Level.DEBUG, "Hello", t);
- logger.log(Level.DEBUG, (Marker) null, "Hello", t);
- logger.setCurrentEvent(EVENTS[3]);
- logger.log(Level.DEBUG, MARKER, "Hello", t);
- logger.setCurrentEvent(EVENTS[4]);
- logger.log(Level.DEBUG, obj);
- logger.setCurrentEvent(EVENTS[5]);
- logger.log(Level.DEBUG, MARKER, obj);
- logger.setCurrentEvent(EVENTS[6]);
- logger.log(Level.DEBUG, obj, t);
- logger.log(Level.DEBUG, (Marker) null, obj, t);
- logger.setCurrentEvent(EVENTS[7]);
- logger.log(Level.DEBUG, MARKER, obj, t);
- logger.setCurrentEvent(EVENTS[8]);
- logger.log(Level.DEBUG, pattern, p1, p2);
- logger.setCurrentEvent(EVENTS[9]);
- logger.log(Level.DEBUG, MARKER, pattern, p1, p2);
- logger.setCurrentEvent(EVENTS[10]);
- logger.log(Level.DEBUG, simple);
- logger.log(Level.DEBUG, (Marker) null, simple);
- logger.log(Level.DEBUG, (Marker) null, simple, null);
- logger.setCurrentEvent(EVENTS[11]);
- logger.log(Level.DEBUG, simple, t);
- logger.log(Level.DEBUG, (Marker) null, simple, t);
- logger.setCurrentEvent(EVENTS[12]);
- logger.log(Level.DEBUG, MARKER, simple, null);
- logger.setCurrentEvent(EVENTS[13]);
- logger.log(Level.DEBUG, MARKER, simple, t);
- logger.setCurrentEvent(EVENTS[14]);
- logger.log(Level.DEBUG, MARKER, simple);
-
- logger.setCurrentEvent(EVENTS[15]);
- logger.log(Level.DEBUG, CHAR_SEQ);
- logger.setCurrentEvent(EVENTS[16]);
- logger.log(Level.DEBUG, CHAR_SEQ, t);
- logger.setCurrentEvent(EVENTS[17]);
- logger.log(Level.DEBUG, MARKER, CHAR_SEQ);
- logger.setCurrentEvent(EVENTS[18]);
- logger.log(Level.DEBUG, MARKER, CHAR_SEQ, t);
-
- assertEquals(4, logger.getCharSeqCount(), "log(CharSeq) invocations");
- assertEquals(5, logger.getObjectCount(), "log(Object) invocations");
- }
-
- @Test
- public void testLogError() {
- final CountingLogger logger = new CountingLogger();
- logger.setCurrentLevel(Level.ERROR);
-
- logger.setCurrentEvent(EVENTS[0]);
- logger.log(Level.ERROR, "Hello");
- logger.log(Level.ERROR, (Marker) null, "Hello");
- logger.setCurrentEvent(EVENTS[1]);
- logger.log(Level.ERROR, MARKER, "Hello");
- logger.setCurrentEvent(EVENTS[2]);
- logger.log(Level.ERROR, "Hello", t);
- logger.log(Level.ERROR, (Marker) null, "Hello", t);
- logger.setCurrentEvent(EVENTS[3]);
- logger.log(Level.ERROR, MARKER, "Hello", t);
- logger.setCurrentEvent(EVENTS[4]);
- logger.log(Level.ERROR, obj);
- logger.setCurrentEvent(EVENTS[5]);
- logger.log(Level.ERROR, MARKER, obj);
- logger.setCurrentEvent(EVENTS[6]);
- logger.log(Level.ERROR, obj, t);
- logger.log(Level.ERROR, (Marker) null, obj, t);
- logger.setCurrentEvent(EVENTS[7]);
- logger.log(Level.ERROR, MARKER, obj, t);
- logger.setCurrentEvent(EVENTS[8]);
- logger.log(Level.ERROR, pattern, p1, p2);
- logger.setCurrentEvent(EVENTS[9]);
- logger.log(Level.ERROR, MARKER, pattern, p1, p2);
- logger.setCurrentEvent(EVENTS[10]);
- logger.log(Level.ERROR, simple);
- logger.log(Level.ERROR, (Marker) null, simple);
- logger.log(Level.ERROR, (Marker) null, simple, null);
- logger.setCurrentEvent(EVENTS[11]);
- logger.log(Level.ERROR, simple, t);
- logger.log(Level.ERROR, (Marker) null, simple, t);
- logger.setCurrentEvent(EVENTS[12]);
- logger.log(Level.ERROR, MARKER, simple, null);
- logger.setCurrentEvent(EVENTS[13]);
- logger.log(Level.ERROR, MARKER, simple, t);
- logger.setCurrentEvent(EVENTS[14]);
- logger.log(Level.ERROR, MARKER, simple);
-
- logger.setCurrentEvent(EVENTS[15]);
- logger.log(Level.ERROR, CHAR_SEQ);
- logger.setCurrentEvent(EVENTS[16]);
- logger.log(Level.ERROR, CHAR_SEQ, t);
- logger.setCurrentEvent(EVENTS[17]);
- logger.log(Level.ERROR, MARKER, CHAR_SEQ);
- logger.setCurrentEvent(EVENTS[18]);
- logger.log(Level.ERROR, MARKER, CHAR_SEQ, t);
-
- assertEquals(4, logger.getCharSeqCount(), "log(CharSeq) invocations");
- assertEquals(5, logger.getObjectCount(), "log(Object) invocations");
- }
-
- @Test
- public void testLogFatal() {
- final CountingLogger logger = new CountingLogger();
- logger.setCurrentLevel(Level.FATAL);
-
- logger.setCurrentEvent(EVENTS[0]);
- logger.log(Level.FATAL, "Hello");
- logger.log(Level.FATAL, (Marker) null, "Hello");
- logger.setCurrentEvent(EVENTS[1]);
- logger.log(Level.FATAL, MARKER, "Hello");
- logger.setCurrentEvent(EVENTS[2]);
- logger.log(Level.FATAL, "Hello", t);
- logger.log(Level.FATAL, (Marker) null, "Hello", t);
- logger.setCurrentEvent(EVENTS[3]);
- logger.log(Level.FATAL, MARKER, "Hello", t);
- logger.setCurrentEvent(EVENTS[4]);
- logger.log(Level.FATAL, obj);
- logger.setCurrentEvent(EVENTS[5]);
- logger.log(Level.FATAL, MARKER, obj);
- logger.setCurrentEvent(EVENTS[6]);
- logger.log(Level.FATAL, obj, t);
- logger.log(Level.FATAL, (Marker) null, obj, t);
- logger.setCurrentEvent(EVENTS[7]);
- logger.log(Level.FATAL, MARKER, obj, t);
- logger.setCurrentEvent(EVENTS[8]);
- logger.log(Level.FATAL, pattern, p1, p2);
- logger.setCurrentEvent(EVENTS[9]);
- logger.log(Level.FATAL, MARKER, pattern, p1, p2);
- logger.setCurrentEvent(EVENTS[10]);
- logger.log(Level.FATAL, simple);
- logger.log(Level.FATAL, (Marker) null, simple);
- logger.log(Level.FATAL, (Marker) null, simple, null);
- logger.setCurrentEvent(EVENTS[11]);
- logger.log(Level.FATAL, simple, t);
- logger.log(Level.FATAL, (Marker) null, simple, t);
- logger.setCurrentEvent(EVENTS[12]);
- logger.log(Level.FATAL, MARKER, simple, null);
- logger.setCurrentEvent(EVENTS[13]);
- logger.log(Level.FATAL, MARKER, simple, t);
- logger.setCurrentEvent(EVENTS[14]);
- logger.log(Level.FATAL, MARKER, simple);
-
- logger.setCurrentEvent(EVENTS[15]);
- logger.log(Level.FATAL, CHAR_SEQ);
- logger.setCurrentEvent(EVENTS[16]);
- logger.log(Level.FATAL, CHAR_SEQ, t);
- logger.setCurrentEvent(EVENTS[17]);
- logger.log(Level.FATAL, MARKER, CHAR_SEQ);
- logger.setCurrentEvent(EVENTS[18]);
- logger.log(Level.FATAL, MARKER, CHAR_SEQ, t);
-
- assertEquals(4, logger.getCharSeqCount(), "log(CharSeq) invocations");
- assertEquals(5, logger.getObjectCount(), "log(Object) invocations");
- }
-
- @Test
- public void testLogInfo() {
- final CountingLogger logger = new CountingLogger();
- logger.setCurrentLevel(Level.INFO);
-
- logger.setCurrentEvent(EVENTS[0]);
- logger.log(Level.INFO, "Hello");
- logger.log(Level.INFO, (Marker) null, "Hello");
- logger.setCurrentEvent(EVENTS[1]);
- logger.log(Level.INFO, MARKER, "Hello");
- logger.setCurrentEvent(EVENTS[2]);
- logger.log(Level.INFO, "Hello", t);
- logger.log(Level.INFO, (Marker) null, "Hello", t);
- logger.setCurrentEvent(EVENTS[3]);
- logger.log(Level.INFO, MARKER, "Hello", t);
- logger.setCurrentEvent(EVENTS[4]);
- logger.log(Level.INFO, obj);
- logger.setCurrentEvent(EVENTS[5]);
- logger.log(Level.INFO, MARKER, obj);
- logger.setCurrentEvent(EVENTS[6]);
- logger.log(Level.INFO, obj, t);
- logger.log(Level.INFO, (Marker) null, obj, t);
- logger.setCurrentEvent(EVENTS[7]);
- logger.log(Level.INFO, MARKER, obj, t);
- logger.setCurrentEvent(EVENTS[8]);
- logger.log(Level.INFO, pattern, p1, p2);
- logger.setCurrentEvent(EVENTS[9]);
- logger.log(Level.INFO, MARKER, pattern, p1, p2);
- logger.setCurrentEvent(EVENTS[10]);
- logger.log(Level.INFO, simple);
- logger.log(Level.INFO, (Marker) null, simple);
- logger.log(Level.INFO, (Marker) null, simple, null);
- logger.setCurrentEvent(EVENTS[11]);
- logger.log(Level.INFO, simple, t);
- logger.log(Level.INFO, (Marker) null, simple, t);
- logger.setCurrentEvent(EVENTS[12]);
- logger.log(Level.INFO, MARKER, simple, null);
- logger.setCurrentEvent(EVENTS[13]);
- logger.log(Level.INFO, MARKER, simple, t);
- logger.setCurrentEvent(EVENTS[14]);
- logger.log(Level.INFO, MARKER, simple);
-
- logger.setCurrentEvent(EVENTS[15]);
- logger.log(Level.INFO, CHAR_SEQ);
- logger.setCurrentEvent(EVENTS[16]);
- logger.log(Level.INFO, CHAR_SEQ, t);
- logger.setCurrentEvent(EVENTS[17]);
- logger.log(Level.INFO, MARKER, CHAR_SEQ);
- logger.setCurrentEvent(EVENTS[18]);
- logger.log(Level.INFO, MARKER, CHAR_SEQ, t);
-
- assertEquals(4, logger.getCharSeqCount(), "log(CharSeq) invocations");
- assertEquals(5, logger.getObjectCount(), "log(Object) invocations");
- }
-
- @Test
- public void testLogTrace() {
- final CountingLogger logger = new CountingLogger();
- logger.setCurrentLevel(Level.TRACE);
-
- logger.setCurrentEvent(EVENTS[0]);
- logger.log(Level.TRACE, "Hello");
- logger.log(Level.TRACE, (Marker) null, "Hello");
- logger.setCurrentEvent(EVENTS[1]);
- logger.log(Level.TRACE, MARKER, "Hello");
- logger.setCurrentEvent(EVENTS[2]);
- logger.log(Level.TRACE, "Hello", t);
- logger.log(Level.TRACE, (Marker) null, "Hello", t);
- logger.setCurrentEvent(EVENTS[3]);
- logger.log(Level.TRACE, MARKER, "Hello", t);
- logger.setCurrentEvent(EVENTS[4]);
- logger.log(Level.TRACE, obj);
- logger.setCurrentEvent(EVENTS[5]);
- logger.log(Level.TRACE, MARKER, obj);
- logger.setCurrentEvent(EVENTS[6]);
- logger.log(Level.TRACE, obj, t);
- logger.log(Level.TRACE, (Marker) null, obj, t);
- logger.setCurrentEvent(EVENTS[7]);
- logger.log(Level.TRACE, MARKER, obj, t);
- logger.setCurrentEvent(EVENTS[8]);
- logger.log(Level.TRACE, pattern, p1, p2);
- logger.setCurrentEvent(EVENTS[9]);
- logger.log(Level.TRACE, MARKER, pattern, p1, p2);
- logger.setCurrentEvent(EVENTS[10]);
- logger.log(Level.TRACE, simple);
- logger.log(Level.TRACE, (Marker) null, simple);
- logger.log(Level.TRACE, (Marker) null, simple, null);
- logger.setCurrentEvent(EVENTS[11]);
- logger.log(Level.TRACE, simple, t);
- logger.log(Level.TRACE, (Marker) null, simple, t);
- logger.setCurrentEvent(EVENTS[12]);
- logger.log(Level.TRACE, MARKER, simple, null);
- logger.setCurrentEvent(EVENTS[13]);
- logger.log(Level.TRACE, MARKER, simple, t);
- logger.setCurrentEvent(EVENTS[14]);
- logger.log(Level.TRACE, MARKER, simple);
-
- logger.setCurrentEvent(EVENTS[15]);
- logger.log(Level.TRACE, CHAR_SEQ);
- logger.setCurrentEvent(EVENTS[16]);
- logger.log(Level.TRACE, CHAR_SEQ, t);
- logger.setCurrentEvent(EVENTS[17]);
- logger.log(Level.TRACE, MARKER, CHAR_SEQ);
- logger.setCurrentEvent(EVENTS[18]);
- logger.log(Level.TRACE, MARKER, CHAR_SEQ, t);
-
- assertEquals(4, logger.getCharSeqCount(), "log(CharSeq) invocations");
- assertEquals(5, logger.getObjectCount(), "log(Object) invocations");
- }
-
- @Test
- public void testLogWarn() {
- final CountingLogger logger = new CountingLogger();
- logger.setCurrentLevel(Level.WARN);
-
- logger.setCurrentEvent(EVENTS[0]);
- logger.log(Level.WARN, "Hello");
- logger.log(Level.WARN, (Marker) null, "Hello");
- logger.setCurrentEvent(EVENTS[1]);
- logger.log(Level.WARN, MARKER, "Hello");
- logger.setCurrentEvent(EVENTS[2]);
- logger.log(Level.WARN, "Hello", t);
- logger.log(Level.WARN, (Marker) null, "Hello", t);
- logger.setCurrentEvent(EVENTS[3]);
- logger.log(Level.WARN, MARKER, "Hello", t);
- logger.setCurrentEvent(EVENTS[4]);
- logger.log(Level.WARN, obj);
- logger.setCurrentEvent(EVENTS[5]);
- logger.log(Level.WARN, MARKER, obj);
- logger.setCurrentEvent(EVENTS[6]);
- logger.log(Level.WARN, obj, t);
- logger.log(Level.WARN, (Marker) null, obj, t);
- logger.setCurrentEvent(EVENTS[7]);
- logger.log(Level.WARN, MARKER, obj, t);
- logger.setCurrentEvent(EVENTS[8]);
- logger.log(Level.WARN, pattern, p1, p2);
- logger.setCurrentEvent(EVENTS[9]);
- logger.log(Level.WARN, MARKER, pattern, p1, p2);
- logger.setCurrentEvent(EVENTS[10]);
- logger.log(Level.WARN, simple);
- logger.log(Level.WARN, (Marker) null, simple);
- logger.log(Level.WARN, (Marker) null, simple, null);
- logger.setCurrentEvent(EVENTS[11]);
- logger.log(Level.WARN, simple, t);
- logger.log(Level.WARN, (Marker) null, simple, t);
- logger.setCurrentEvent(EVENTS[12]);
- logger.log(Level.WARN, MARKER, simple, null);
- logger.setCurrentEvent(EVENTS[13]);
- logger.log(Level.WARN, MARKER, simple, t);
- logger.setCurrentEvent(EVENTS[14]);
- logger.log(Level.WARN, MARKER, simple);
-
- logger.setCurrentEvent(EVENTS[15]);
- logger.log(Level.WARN, CHAR_SEQ);
- logger.setCurrentEvent(EVENTS[16]);
- logger.log(Level.WARN, CHAR_SEQ, t);
- logger.setCurrentEvent(EVENTS[17]);
- logger.log(Level.WARN, MARKER, CHAR_SEQ);
- logger.setCurrentEvent(EVENTS[18]);
- logger.log(Level.WARN, MARKER, CHAR_SEQ, t);
-
- assertEquals(4, logger.getCharSeqCount(), "log(CharSeq) invocations");
- assertEquals(5, logger.getObjectCount(), "log(Object) invocations");
- }
-
- @Test
- public void testTrace() {
- final CountingLogger logger = new CountingLogger();
- logger.setCurrentLevel(Level.TRACE);
-
- logger.setCurrentEvent(EVENTS[0]);
- logger.trace("Hello");
- logger.trace((Marker) null, "Hello");
- logger.setCurrentEvent(EVENTS[1]);
- logger.trace(MARKER, "Hello");
- logger.setCurrentEvent(EVENTS[2]);
- logger.trace("Hello", t);
- logger.trace((Marker) null, "Hello", t);
- logger.setCurrentEvent(EVENTS[3]);
- logger.trace(MARKER, "Hello", t);
- logger.setCurrentEvent(EVENTS[4]);
- logger.trace(obj);
- logger.setCurrentEvent(EVENTS[5]);
- logger.trace(MARKER, obj);
- logger.setCurrentEvent(EVENTS[6]);
- logger.trace(obj, t);
- logger.trace((Marker) null, obj, t);
- logger.setCurrentEvent(EVENTS[7]);
- logger.trace(MARKER, obj, t);
- logger.setCurrentEvent(EVENTS[8]);
- logger.trace(pattern, p1, p2);
- logger.setCurrentEvent(EVENTS[9]);
- logger.trace(MARKER, pattern, p1, p2);
- logger.setCurrentEvent(EVENTS[10]);
- logger.trace(simple);
- logger.trace((Marker) null, simple);
- logger.trace((Marker) null, simple, null);
- logger.setCurrentEvent(EVENTS[11]);
- logger.trace(simple, t);
- logger.trace((Marker) null, simple, t);
- logger.setCurrentEvent(EVENTS[12]);
- logger.trace(MARKER, simple, null);
- logger.setCurrentEvent(EVENTS[13]);
- logger.trace(MARKER, simple, t);
- logger.setCurrentEvent(EVENTS[14]);
- logger.trace(MARKER, simple);
-
- logger.setCurrentEvent(EVENTS[15]);
- logger.trace(CHAR_SEQ);
- logger.setCurrentEvent(EVENTS[16]);
- logger.trace(CHAR_SEQ, t);
- logger.setCurrentEvent(EVENTS[17]);
- logger.trace(MARKER, CHAR_SEQ);
- logger.setCurrentEvent(EVENTS[18]);
- logger.trace(MARKER, CHAR_SEQ, t);
-
- assertEquals(4, logger.getCharSeqCount(), "log(CharSeq) invocations");
- assertEquals(5, logger.getObjectCount(), "log(Object) invocations");
- }
-
- @Test
- public void testWarn() {
- final CountingLogger logger = new CountingLogger();
- logger.setCurrentLevel(Level.WARN);
-
- logger.setCurrentEvent(EVENTS[0]);
- logger.warn("Hello");
- logger.warn((Marker) null, "Hello");
- logger.setCurrentEvent(EVENTS[1]);
- logger.warn(MARKER, "Hello");
- logger.setCurrentEvent(EVENTS[2]);
- logger.warn("Hello", t);
- logger.warn((Marker) null, "Hello", t);
- logger.setCurrentEvent(EVENTS[3]);
- logger.warn(MARKER, "Hello", t);
- logger.setCurrentEvent(EVENTS[4]);
- logger.warn(obj);
- logger.setCurrentEvent(EVENTS[5]);
- logger.warn(MARKER, obj);
- logger.setCurrentEvent(EVENTS[6]);
- logger.warn(obj, t);
- logger.warn((Marker) null, obj, t);
- logger.setCurrentEvent(EVENTS[7]);
- logger.warn(MARKER, obj, t);
- logger.setCurrentEvent(EVENTS[8]);
- logger.warn(pattern, p1, p2);
- logger.setCurrentEvent(EVENTS[9]);
- logger.warn(MARKER, pattern, p1, p2);
- logger.setCurrentEvent(EVENTS[10]);
- logger.warn(simple);
- logger.warn((Marker) null, simple);
- logger.warn((Marker) null, simple, null);
- logger.setCurrentEvent(EVENTS[11]);
- logger.warn(simple, t);
- logger.warn((Marker) null, simple, t);
- logger.setCurrentEvent(EVENTS[12]);
- logger.warn(MARKER, simple, null);
- logger.setCurrentEvent(EVENTS[13]);
- logger.warn(MARKER, simple, t);
- logger.setCurrentEvent(EVENTS[14]);
- logger.warn(MARKER, simple);
-
- logger.setCurrentEvent(EVENTS[15]);
- logger.warn(CHAR_SEQ);
- logger.setCurrentEvent(EVENTS[16]);
- logger.warn(CHAR_SEQ, t);
- logger.setCurrentEvent(EVENTS[17]);
- logger.warn(MARKER, CHAR_SEQ);
- logger.setCurrentEvent(EVENTS[18]);
- logger.warn(MARKER, CHAR_SEQ, t);
-
- assertEquals(4, logger.getCharSeqCount(), "log(CharSeq) invocations");
- assertEquals(5, logger.getObjectCount(), "log(Object) invocations");
- }
-
- @Test
- public void testMessageWithThrowable() {
- final ThrowableExpectingLogger logger = new ThrowableExpectingLogger(true);
- final ThrowableMessage message = new ThrowableMessage(t);
-
- logger.debug(message);
- logger.error(message);
- logger.fatal(message);
- logger.info(message);
- logger.trace(message);
- logger.warn(message);
- logger.log(Level.INFO, message);
-
- logger.debug(MARKER, message);
- logger.error(MARKER, message);
- logger.fatal(MARKER, message);
- logger.info(MARKER, message);
- logger.trace(MARKER, message);
- logger.warn(MARKER, message);
- logger.log(Level.INFO, MARKER, message);
- }
-
- @Test
- public void testMessageWithoutThrowable() {
- final ThrowableExpectingLogger logger = new ThrowableExpectingLogger(false);
- final ThrowableMessage message = new ThrowableMessage(null);
-
- logger.debug(message);
- logger.error(message);
- logger.fatal(message);
- logger.info(message);
- logger.trace(message);
- logger.warn(message);
- logger.log(Level.INFO, message);
-
- logger.debug(MARKER, message);
- logger.error(MARKER, message);
- logger.fatal(MARKER, message);
- logger.info(MARKER, message);
- logger.trace(MARKER, message);
- logger.warn(MARKER, message);
- logger.log(Level.INFO, MARKER, message);
- }
-
- @Test
- public void testMessageSupplierWithThrowable() {
- final ThrowableExpectingLogger logger = new ThrowableExpectingLogger(true);
- final ThrowableMessage message = new ThrowableMessage(t);
- final MessageSupplier supplier = () -> message;
-
- logger.debug(supplier);
- logger.error(supplier);
- logger.fatal(supplier);
- logger.info(supplier);
- logger.trace(supplier);
- logger.warn(supplier);
- logger.log(Level.INFO, supplier);
-
- logger.debug(MARKER, supplier);
- logger.error(MARKER, supplier);
- logger.fatal(MARKER, supplier);
- logger.info(MARKER, supplier);
- logger.trace(MARKER, supplier);
- logger.warn(MARKER, supplier);
- logger.log(Level.INFO, MARKER, supplier);
- }
-
- @Test
- public void testMessageSupplierWithoutThrowable() {
- final ThrowableExpectingLogger logger = new ThrowableExpectingLogger(false);
- final ThrowableMessage message = new ThrowableMessage(null);
- final MessageSupplier supplier = () -> message;
-
- logger.debug(supplier);
- logger.error(supplier);
- logger.fatal(supplier);
- logger.info(supplier);
- logger.trace(supplier);
- logger.warn(supplier);
- logger.log(Level.INFO, supplier);
-
- logger.debug(MARKER, supplier);
- logger.error(MARKER, supplier);
- logger.fatal(MARKER, supplier);
- logger.info(MARKER, supplier);
- logger.trace(MARKER, supplier);
- logger.warn(MARKER, supplier);
- logger.log(Level.INFO, MARKER, supplier);
- }
-
- @Test
- public void testSupplierWithThrowable() {
- final ThrowableExpectingLogger logger = new ThrowableExpectingLogger(true);
- final ThrowableMessage message = new ThrowableMessage(t);
- final Supplier<Message> supplier = () -> message;
-
- logger.debug(supplier);
- logger.error(supplier);
- logger.fatal(supplier);
- logger.info(supplier);
- logger.trace(supplier);
- logger.warn(supplier);
- logger.log(Level.INFO, supplier);
-
- logger.debug(MARKER, supplier);
- logger.error(MARKER, supplier);
- logger.fatal(MARKER, supplier);
- logger.info(MARKER, supplier);
- logger.trace(MARKER, supplier);
- logger.warn(MARKER, supplier);
- logger.log(Level.INFO, MARKER, supplier);
- }
-
- @Test
- public void testSupplierWithoutThrowable() {
- final ThrowableExpectingLogger logger = new ThrowableExpectingLogger(false);
- final ThrowableMessage message = new ThrowableMessage(null);
- final Supplier<Message> supplier = () -> message;
-
- logger.debug(supplier);
- logger.error(supplier);
- logger.fatal(supplier);
- logger.info(supplier);
- logger.trace(supplier);
- logger.warn(supplier);
- logger.log(Level.INFO, supplier);
-
- logger.debug(MARKER, supplier);
- logger.error(MARKER, supplier);
- logger.fatal(MARKER, supplier);
- logger.info(MARKER, supplier);
- logger.trace(MARKER, supplier);
- logger.warn(MARKER, supplier);
- logger.log(Level.INFO, MARKER, supplier);
- }
-
- @Test
- @ResourceLock("log4j2.StatusLogger")
- public void testMessageThrows() {
- final ThrowableExpectingLogger logger = new ThrowableExpectingLogger(false);
- logger.error(new TestMessage(
- () -> {
- throw new IllegalStateException("Oops!");
- },
- "Message Format"));
- final List<StatusData> statusDatalist = StatusLogger.getLogger().getStatusData();
- final StatusData mostRecent = statusDatalist.get(statusDatalist.size() - 1);
- assertEquals(Level.WARN, mostRecent.getLevel());
- assertThat(
- mostRecent.getFormattedStatus(),
- containsString("org.apache.logging.log4j.spi.AbstractLogger caught "
- + "java.lang.IllegalStateException logging TestMessage: Message Format"));
- }
-
- @Test
- @ResourceLock("log4j2.StatusLogger")
- public void testMessageThrowsAndNullFormat() {
- final ThrowableExpectingLogger logger = new ThrowableExpectingLogger(false);
- logger.error(new TestMessage(
- () -> {
- throw new IllegalStateException("Oops!");
- },
- null /* format */));
- final List<StatusData> statusDatalist = StatusLogger.getLogger().getStatusData();
- final StatusData mostRecent = statusDatalist.get(statusDatalist.size() - 1);
- assertEquals(Level.WARN, mostRecent.getLevel());
- assertThat(
- mostRecent.getFormattedStatus(),
- containsString("org.apache.logging.log4j.spi.AbstractLogger caught "
- + "java.lang.IllegalStateException logging TestMessage: "));
- }
-
- private static final class TestMessage implements Message {
- private static final long serialVersionUID = 1L;
- private final FormattedMessageSupplier formattedMessageSupplier;
- private final String format;
-
- TestMessage(final FormattedMessageSupplier formattedMessageSupplier, final String format) {
- this.formattedMessageSupplier = formattedMessageSupplier;
- this.format = format;
- }
-
- @Override
- public String getFormattedMessage() {
- return formattedMessageSupplier.getFormattedMessage();
- }
-
- @Override
- public String getFormat() {
- return format;
- }
-
- @Override
- public Object[] getParameters() {
- return new Object[0];
- }
-
- @Override
- public Throwable getThrowable() {
- return null;
- }
-
- interface FormattedMessageSupplier {
- String getFormattedMessage();
- }
- }
-
- private static class CountingLogger extends AbstractLogger {
- private static final long serialVersionUID = -3171452617952475480L;
-
- private Level currentLevel;
- private LogEvent currentEvent;
- private int charSeqCount;
- private int objectCount;
-
- CountingLogger() {
- super("CountingLogger", new ReusableMessageFactory());
- }
-
- void setCurrentLevel(final Level currentLevel) {
- this.currentLevel = currentLevel;
- }
-
- void setCurrentEvent(final LogEvent currentEvent) {
- this.currentEvent = currentEvent;
- }
-
- int getCharSeqCount() {
- return charSeqCount;
- }
-
- int getObjectCount() {
- return objectCount;
- }
-
- @Override
- public Level getLevel() {
- return currentLevel;
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final Message data, final Throwable t) {
- assertEquals(level, currentLevel, "Incorrect Level. Expected " + currentLevel + ", actual " + level);
- if (marker == null) {
- if (currentEvent.markerName != null) {
- fail("Incorrect marker. Expected " + currentEvent.markerName + ", actual is null");
- }
- } else {
- if (currentEvent.markerName == null) {
- fail("Incorrect marker. Expected null. Actual is " + marker.getName());
- } else {
- assertEquals(
- currentEvent.markerName,
- marker.getName(),
- "Incorrect marker. Expected " + currentEvent.markerName + ", actual " + marker.getName());
- }
- }
- if (data == null) {
- if (currentEvent.data != null) {
- fail("Incorrect message. Expected " + currentEvent.data + ", actual is null");
- }
- } else {
- if (currentEvent.data == null) {
- fail("Incorrect message. Expected null. Actual is " + data.getFormattedMessage());
- } else {
- assertTrue(
- data.getClass().isAssignableFrom(currentEvent.data.getClass()),
- "Incorrect message type. Expected " + currentEvent.data + ", actual " + data);
- assertEquals(
- currentEvent.data.getFormattedMessage(),
- data.getFormattedMessage(),
- "Incorrect message. Expected " + currentEvent.data.getFormattedMessage() + ", actual "
- + data.getFormattedMessage());
- }
- }
- if (t == null) {
- if (currentEvent.t != null) {
- fail("Incorrect Throwable. Expected " + currentEvent.t + ", actual is null");
- }
- } else {
- if (currentEvent.t == null) {
- fail("Incorrect Throwable. Expected null. Actual is " + t);
- } else {
- assertEquals(
- currentEvent.t, t, "Incorrect Throwable. Expected " + currentEvent.t + ", actual " + t);
- }
- }
- return true;
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final CharSequence data, final Throwable t) {
- charSeqCount++;
- return isEnabled(level, marker, (Message) new SimpleMessage(data), t);
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final Object data, final Throwable t) {
- objectCount++;
- return isEnabled(level, marker, new ObjectMessage(data), t);
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final String data) {
- return isEnabled(level, marker, (Message) new SimpleMessage(data), null);
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final String data, final Object... p1) {
- return isEnabled(level, marker, new ParameterizedMessage(data, p1), null);
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0) {
- return isEnabled(level, marker, new ParameterizedMessage(message, p0), null);
- }
-
- @Override
- public boolean isEnabled(
- final Level level, final Marker marker, final String message, final Object p0, final Object p1) {
- return isEnabled(level, marker, new ParameterizedMessage(message, p0, p1), null);
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2) {
- return isEnabled(level, marker, new ParameterizedMessage(message, p0, p1, p2), null);
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3) {
- return isEnabled(level, marker, new ParameterizedMessage(message, p0, p1, p2, p3), null);
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3,
- final Object p4) {
- return isEnabled(level, marker, new ParameterizedMessage(message, p0, p1, p2, p3, p4), null);
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3,
- final Object p4,
- final Object p5) {
- return isEnabled(level, marker, new ParameterizedMessage(message, p0, p1, p2, p3, p4, p5), null);
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3,
- final Object p4,
- final Object p5,
- final Object p6) {
- return isEnabled(level, marker, new ParameterizedMessage(message, p0, p1, p2, p3, p4, p5, p6), null);
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3,
- final Object p4,
- final Object p5,
- final Object p6,
- final Object p7) {
- return isEnabled(level, marker, new ParameterizedMessage(message, p0, p1, p2, p3, p4, p5, p6, p7), null);
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3,
- final Object p4,
- final Object p5,
- final Object p6,
- final Object p7,
- final Object p8) {
- return isEnabled(
- level, marker, new ParameterizedMessage(message, p0, p1, p2, p3, p4, p5, p6, p7, p8), null);
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3,
- final Object p4,
- final Object p5,
- final Object p6,
- final Object p7,
- final Object p8,
- final Object p9) {
- return isEnabled(
- level, marker, new ParameterizedMessage(message, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9), null);
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final String data, final Throwable t) {
- return isEnabled(level, marker, (Message) new SimpleMessage(data), t);
- }
-
- @Override
- public void logMessage(
- final String fqcn, final Level level, final Marker marker, final Message data, final Throwable t) {
- assertEquals(level, currentLevel, "Incorrect Level. Expected " + currentLevel + ", actual " + level);
- if (marker == null) {
- if (currentEvent.markerName != null) {
- fail("Incorrect marker. Expected " + currentEvent.markerName + ", actual is null");
- }
- } else {
- if (currentEvent.markerName == null) {
- fail("Incorrect marker. Expected null. Actual is " + marker.getName());
- } else {
- assertEquals(
- currentEvent.markerName,
- marker.getName(),
- "Incorrect marker. Expected " + currentEvent.markerName + ", actual " + marker.getName());
- }
- }
- if (data == null) {
- if (currentEvent.data != null) {
- fail("Incorrect message. Expected " + currentEvent.data + ", actual is null");
- }
- } else {
- if (currentEvent.data == null) {
- fail("Incorrect message. Expected null. Actual is " + data.getFormattedMessage());
- } else {
- assertTrue(
- data.getClass().isAssignableFrom(currentEvent.data.getClass()),
- "Incorrect message type. Expected " + currentEvent.data + ", actual " + data);
- assertEquals(
- currentEvent.data.getFormattedMessage(),
- data.getFormattedMessage(),
- "Incorrect message. Expected " + currentEvent.data.getFormattedMessage() + ", actual "
- + data.getFormattedMessage());
- }
- }
- if (t == null) {
- if (currentEvent.t != null) {
- fail("Incorrect Throwable. Expected " + currentEvent.t + ", actual is null");
- }
- } else {
- if (currentEvent.t == null) {
- fail("Incorrect Throwable. Expected null. Actual is " + t);
- } else {
- assertEquals(
- currentEvent.t, t, "Incorrect Throwable. Expected " + currentEvent.t + ", actual " + t);
- }
- }
- }
- }
-
- private static class LogEvent {
- String markerName;
- Message data;
- Throwable t;
-
- public LogEvent(final String markerName, final Message data, final Throwable t) {
- this.markerName = markerName;
- this.data = data;
- this.t = t;
- }
- }
-
- private static class ThrowableExpectingLogger extends AbstractLogger {
- private final boolean expectingThrowables;
-
- ThrowableExpectingLogger(final boolean expectingThrowables) {
- super("ThrowableExpectingLogger", new ReusableMessageFactory());
- this.expectingThrowables = expectingThrowables;
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final Message message, final Throwable t) {
- return true;
- }
-
- @Override
- public boolean isEnabled(
- final Level level, final Marker marker, final CharSequence message, final Throwable t) {
- return true;
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final Object message, final Throwable t) {
- return true;
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final String message, final Throwable t) {
- return true;
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final String message) {
- return true;
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final String message, final Object... params) {
- return true;
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0) {
- return true;
- }
-
- @Override
- public boolean isEnabled(
- final Level level, final Marker marker, final String message, final Object p0, final Object p1) {
- return true;
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2) {
- return true;
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3) {
- return true;
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3,
- final Object p4) {
- return true;
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3,
- final Object p4,
- final Object p5) {
- return true;
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3,
- final Object p4,
- final Object p5,
- final Object p6) {
- return true;
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3,
- final Object p4,
- final Object p5,
- final Object p6,
- final Object p7) {
- return true;
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3,
- final Object p4,
- final Object p5,
- final Object p6,
- final Object p7,
- final Object p8) {
- return true;
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3,
- final Object p4,
- final Object p5,
- final Object p6,
- final Object p7,
- final Object p8,
- final Object p9) {
- return true;
- }
-
- @Override
- public void logMessage(
- final String fqcn, final Level level, final Marker marker, final Message message, final Throwable t) {
- if (expectingThrowables) {
- assertNotNull(t, "Expected a Throwable but received null!");
- } else {
- assertNull(t, "Expected null but received a Throwable! " + t);
- }
- if (message != null) {
- message.getFormattedMessage();
- }
- }
-
- @Override
- public Level getLevel() {
- return Level.INFO;
- }
- }
-
- private static class ThrowableMessage implements Message {
- private final Throwable throwable;
-
- public ThrowableMessage(final Throwable throwable) {
- this.throwable = throwable;
- }
-
- @Override
- public String getFormattedMessage() {
- return null;
- }
-
- @Override
- public String getFormat() {
- return null;
- }
-
- @Override
- public Object[] getParameters() {
- return new Object[0];
- }
-
- @Override
- public Throwable getThrowable() {
- return throwable;
- }
- }
-}
diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/CloseableThreadContextTest.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/CloseableThreadContextTest.java
deleted file mode 100644
index fb1e8df5f6..0000000000
--- a/log4j-api-test/src/test/java/org/apache/logging/log4j/CloseableThreadContextTest.java
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
- * 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;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import org.apache.logging.log4j.test.junit.UsingAnyThreadContext;
-import org.junit.jupiter.api.Test;
-import org.junitpioneer.jupiter.ReadsSystemProperty;
-
-/**
- * Tests {@link CloseableThreadContext}.
- *
- * @since 2.6
- */
-@ReadsSystemProperty
-@UsingAnyThreadContext
-public class CloseableThreadContextTest {
-
- private final String key = "key";
- private final String value = "value";
-
- @Test
- public void shouldAddAnEntryToTheMap() {
- try (final CloseableThreadContext.Instance ignored = CloseableThreadContext.put(key, value)) {
- assertNotNull(ignored);
- assertEquals(value, ThreadContext.get(key));
- }
- }
-
- @Test
- public void shouldAddTwoEntriesToTheMap() {
- final String key2 = "key2";
- final String value2 = "value2";
- try (final CloseableThreadContext.Instance ignored =
- CloseableThreadContext.put(key, value).put(key2, value2)) {
- assertNotNull(ignored);
- assertEquals(value, ThreadContext.get(key));
- assertEquals(value2, ThreadContext.get(key2));
- }
- }
-
- @Test
- public void shouldNestEntries() {
- final String oldValue = "oldValue";
- final String innerValue = "innerValue";
- ThreadContext.put(key, oldValue);
- try (final CloseableThreadContext.Instance ignored = CloseableThreadContext.put(key, value)) {
- assertNotNull(ignored);
- assertEquals(value, ThreadContext.get(key));
- try (final CloseableThreadContext.Instance ignored2 = CloseableThreadContext.put(key, innerValue)) {
- assertNotNull(ignored2);
- assertEquals(innerValue, ThreadContext.get(key));
- }
- assertEquals(value, ThreadContext.get(key));
- }
- assertEquals(oldValue, ThreadContext.get(key));
- }
-
- @Test
- public void shouldPreserveOldEntriesFromTheMapWhenAutoClosed() {
- final String oldValue = "oldValue";
- ThreadContext.put(key, oldValue);
- try (final CloseableThreadContext.Instance ignored = CloseableThreadContext.put(key, value)) {
- assertNotNull(ignored);
- assertEquals(value, ThreadContext.get(key));
- }
- assertEquals(oldValue, ThreadContext.get(key));
- }
-
- @Test
- public void ifTheSameKeyIsAddedTwiceTheOriginalShouldBeUsed() {
- final String oldValue = "oldValue";
- final String secondValue = "innerValue";
- ThreadContext.put(key, oldValue);
- try (final CloseableThreadContext.Instance ignored =
- CloseableThreadContext.put(key, value).put(key, secondValue)) {
- assertNotNull(ignored);
- assertEquals(secondValue, ThreadContext.get(key));
- }
- assertEquals(oldValue, ThreadContext.get(key));
- }
-
- @Test
- public void shouldPushAndPopAnEntryToTheStack() {
- final String message = "message";
- try (final CloseableThreadContext.Instance ignored = CloseableThreadContext.push(message)) {
- assertNotNull(ignored);
- assertEquals(message, ThreadContext.peek());
- }
- assertEquals("", ThreadContext.peek());
- }
-
- @Test
- public void shouldPushAndPopTwoEntriesToTheStack() {
- final String message1 = "message1";
- final String message2 = "message2";
- try (final CloseableThreadContext.Instance ignored =
- CloseableThreadContext.push(message1).push(message2)) {
- assertNotNull(ignored);
- assertEquals(message2, ThreadContext.peek());
- }
- assertEquals("", ThreadContext.peek());
- }
-
- @Test
- public void shouldPushAndPopAParameterizedEntryToTheStack() {
- final String parameterizedMessage = "message {}";
- final String parameterizedMessageParameter = "param";
- final String formattedMessage = parameterizedMessage.replace("{}", parameterizedMessageParameter);
- try (final CloseableThreadContext.Instance ignored =
- CloseableThreadContext.push(parameterizedMessage, parameterizedMessageParameter)) {
- assertNotNull(ignored);
- assertEquals(formattedMessage, ThreadContext.peek());
- }
- assertEquals("", ThreadContext.peek());
- }
-
- @Test
- public void shouldRemoveAnEntryFromTheMapWhenAutoClosed() {
- try (final CloseableThreadContext.Instance ignored = CloseableThreadContext.put(key, value)) {
- assertNotNull(ignored);
- assertEquals(value, ThreadContext.get(key));
- }
- assertFalse(ThreadContext.containsKey(key));
- }
-
- @Test
- public void shouldAddEntriesToBothStackAndMap() {
- final String stackValue = "something";
- try (final CloseableThreadContext.Instance ignored =
- CloseableThreadContext.put(key, value).push(stackValue)) {
- assertNotNull(ignored);
- assertEquals(value, ThreadContext.get(key));
- assertEquals(stackValue, ThreadContext.peek());
- }
- assertFalse(ThreadContext.containsKey(key));
- assertEquals("", ThreadContext.peek());
- }
-
- @Test
- public void canReuseCloseableThreadContext() {
- final String stackValue = "something";
- // Create a ctc and close it
- final CloseableThreadContext.Instance ctc =
- CloseableThreadContext.push(stackValue).put(key, value);
- assertNotNull(ctc);
- assertEquals(value, ThreadContext.get(key));
- assertEquals(stackValue, ThreadContext.peek());
- ctc.close();
-
- assertFalse(ThreadContext.containsKey(key));
- assertEquals("", ThreadContext.peek());
-
- final String anotherKey = "key2";
- final String anotherValue = "value2";
- final String anotherStackValue = "something else";
- // Use it again
- ctc.push(anotherStackValue).put(anotherKey, anotherValue);
- assertEquals(anotherValue, ThreadContext.get(anotherKey));
- assertEquals(anotherStackValue, ThreadContext.peek());
- ctc.close();
-
- assertFalse(ThreadContext.containsKey(anotherKey));
- assertEquals("", ThreadContext.peek());
- }
-
- @Test
- public void closeIsIdempotent() {
-
- final String originalMapValue = "map to keep";
- final String originalStackValue = "stack to keep";
- ThreadContext.put(key, originalMapValue);
- ThreadContext.push(originalStackValue);
-
- final String newMapValue = "temp map value";
- final String newStackValue = "temp stack to keep";
- final CloseableThreadContext.Instance ctc =
- CloseableThreadContext.push(newStackValue).put(key, newMapValue);
- assertNotNull(ctc);
-
- ctc.close();
- assertEquals(originalMapValue, ThreadContext.get(key));
- assertEquals(originalStackValue, ThreadContext.peek());
-
- ctc.close();
- assertEquals(originalMapValue, ThreadContext.get(key));
- assertEquals(originalStackValue, ThreadContext.peek());
- }
-
- @Test
- public void putAllWillPutAllValues() {
-
- final String oldValue = "oldValue";
- ThreadContext.put(key, oldValue);
-
- final Map<String, String> valuesToPut = new HashMap<>();
- valuesToPut.put(key, value);
-
- try (final CloseableThreadContext.Instance ignored = CloseableThreadContext.putAll(valuesToPut)) {
- assertNotNull(ignored);
- assertEquals(value, ThreadContext.get(key));
- }
- assertEquals(oldValue, ThreadContext.get(key));
- }
-
- @Test
- public void pushAllWillPushAllValues() {
-
- ThreadContext.push(key);
- final List<String> messages = ThreadContext.getImmutableStack().asList();
- ThreadContext.pop();
-
- try (final CloseableThreadContext.Instance ignored = CloseableThreadContext.pushAll(messages)) {
- assertNotNull(ignored);
- assertEquals(key, ThreadContext.peek());
- }
- assertEquals("", ThreadContext.peek());
- }
-}
diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/EventLoggerTest.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/EventLoggerTest.java
deleted file mode 100644
index 3b2176a4be..0000000000
--- a/log4j-api-test/src/test/java/org/apache/logging/log4j/EventLoggerTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.util.List;
-import java.util.Locale;
-import org.apache.logging.log4j.message.StructuredDataMessage;
-import org.apache.logging.log4j.test.TestLogger;
-import org.apache.logging.log4j.test.junit.UsingThreadContextMap;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-@UsingThreadContextMap
-public class EventLoggerTest {
-
- TestLogger logger = (TestLogger) LogManager.getLogger("EventLogger");
- List<String> results = logger.getEntries();
-
- @BeforeEach
- public void setup() {
- results.clear();
- }
-
- @Test
- public void structuredData() {
- ThreadContext.put("loginId", "JohnDoe");
- ThreadContext.put("ipAddress", "192.168.0.120");
- ThreadContext.put("locale", Locale.US.getDisplayName());
- final StructuredDataMessage msg = new StructuredDataMessage("Transfer@18060", "Transfer Complete", "Audit");
- msg.put("ToAccount", "123456");
- msg.put("FromAccount", "123457");
- msg.put("Amount", "200.00");
- EventLogger.logEvent(msg);
- ThreadContext.clearMap();
- assertThat(results).hasSize(1);
- final String expected =
- "EVENT OFF Audit [Transfer@18060 Amount=\"200.00\" FromAccount=\"123457\" ToAccount=\"123456\"] Transfer Complete";
- assertThat(results.get(0)).startsWith(expected);
- }
-}
diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/LambdaLoggerTest.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/LambdaLoggerTest.java
deleted file mode 100644
index bbe04b2446..0000000000
--- a/log4j-api-test/src/test/java/org/apache/logging/log4j/LambdaLoggerTest.java
+++ /dev/null
@@ -1,1413 +0,0 @@
-/*
- * 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;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertSame;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.logging.log4j.message.Message;
-import org.apache.logging.log4j.message.ReusableMessage;
-import org.apache.logging.log4j.message.SimpleMessage;
-import org.apache.logging.log4j.spi.AbstractLogger;
-import org.apache.logging.log4j.util.Supplier;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-/**
- * Tests the AbstractLogger implementation of the Logger2 interface.
- */
-public class LambdaLoggerTest {
-
- private static class LogEvent {
- @SuppressWarnings("unused")
- final String fqcn;
-
- final Level level;
- final Marker marker;
- final Message message;
- final Throwable throwable;
-
- public LogEvent(
- final String fqcn, final Level level, final Marker marker, final Message message, final Throwable t) {
- this.fqcn = fqcn;
- this.level = level;
- this.marker = marker;
- this.message = (message instanceof ReusableMessage) ? ((ReusableMessage) message).memento() : message;
- this.throwable = t;
- }
- }
-
- private static class Logger2Impl extends AbstractLogger {
- private static final long serialVersionUID = 1L;
-
- boolean enabled = true;
- final List<LambdaLoggerTest.LogEvent> list = new ArrayList<>();
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final Message message, final Throwable t) {
- return enabled;
- }
-
- @Override
- public boolean isEnabled(
- final Level level, final Marker marker, final CharSequence message, final Throwable t) {
- return enabled;
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final Object message, final Throwable t) {
- return enabled;
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final String message, final Throwable t) {
- return enabled;
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final String message) {
- return enabled;
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final String message, final Object... params) {
- return enabled;
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0) {
- return enabled;
- }
-
- @Override
- public boolean isEnabled(
- final Level level, final Marker marker, final String message, final Object p0, final Object p1) {
- return enabled;
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2) {
- return enabled;
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3) {
- return enabled;
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3,
- final Object p4) {
- return enabled;
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3,
- final Object p4,
- final Object p5) {
- return enabled;
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3,
- final Object p4,
- final Object p5,
- final Object p6) {
- return enabled;
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3,
- final Object p4,
- final Object p5,
- final Object p6,
- final Object p7) {
- return enabled;
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3,
- final Object p4,
- final Object p5,
- final Object p6,
- final Object p7,
- final Object p8) {
- return enabled;
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3,
- final Object p4,
- final Object p5,
- final Object p6,
- final Object p7,
- final Object p8,
- final Object p9) {
- return enabled;
- }
-
- @Override
- public void logMessage(
- final String fqcn, final Level level, final Marker marker, final Message message, final Throwable t) {
- list.add(new LogEvent(fqcn, level, marker, message, t));
- }
-
- @Override
- public Level getLevel() {
- return null;
- }
-
- public AbstractLogger disable() {
- enabled = false;
- return this;
- }
-
- public AbstractLogger enable() {
- enabled = true;
- return this;
- }
- }
-
- final Logger2Impl logger2 = new Logger2Impl();
- final String stringMessage = "Hi";
- final Message message = new SimpleMessage("HiMessage");
- final Throwable throwable = new Error("I'm Bad");
- final Marker marker = MarkerManager.getMarker("test");
-
- private class MyMessageSupplier implements Supplier<Message> {
- public boolean invoked = false;
-
- @Override
- public Message get() {
- invoked = true;
- return message;
- }
- }
-
- final MyMessageSupplier messageSupplier = new MyMessageSupplier();
-
- private class MySupplier implements Supplier<String> {
- public boolean invoked = false;
-
- @Override
- public String get() {
- invoked = true;
- return stringMessage;
- }
- }
-
- final MySupplier supplier = new MySupplier();
- final MySupplier supplier2 = new MySupplier();
- final Supplier<?>[] supplierArray1 = new Supplier<?>[] {supplier};
- final Supplier<?>[] supplierArray2 = new Supplier<?>[] {supplier, supplier2};
-
- @BeforeEach
- public void beforeEachTest() {
- logger2.list.clear();
- supplier.invoked = false;
- messageSupplier.invoked = false;
- }
-
- @Test
- public void testDebugMarkerMessageSupplier() {
- logger2.disable().debug(marker, messageSupplier);
- assertTrue(logger2.list.isEmpty());
- assertFalse(messageSupplier.invoked);
-
- logger2.enable().debug(marker, messageSupplier);
- assertEquals(1, logger2.list.size());
- assertTrue(messageSupplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.DEBUG, event.level);
- assertSame(message, event.message);
- assertSame(marker, event.marker);
- }
-
- @Test
- public void testDebugMessageSupplier() {
- logger2.disable().debug(messageSupplier);
- assertTrue(logger2.list.isEmpty());
- assertFalse(messageSupplier.invoked);
-
- logger2.enable().debug(messageSupplier);
- assertEquals(1, logger2.list.size());
- assertTrue(messageSupplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.DEBUG, event.level);
- assertSame(message, event.message);
- }
-
- @Test
- public void testDebugMarkerMessageSupplierThrowable() {
- logger2.disable().debug(marker, messageSupplier, throwable);
- assertTrue(logger2.list.isEmpty());
- assertFalse(messageSupplier.invoked);
-
- logger2.enable().debug(marker, messageSupplier, throwable);
- assertEquals(1, logger2.list.size());
- assertTrue(messageSupplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.DEBUG, event.level);
- assertSame(marker, event.marker);
- assertSame(message, event.message);
- assertSame(throwable, event.throwable);
- }
-
- @Test
- public void testDebugMessageSupplierThrowable() {
- logger2.disable().debug(messageSupplier, throwable);
- assertTrue(logger2.list.isEmpty());
- assertFalse(messageSupplier.invoked);
-
- logger2.enable().debug(messageSupplier, throwable);
- assertEquals(1, logger2.list.size());
- assertTrue(messageSupplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.DEBUG, event.level);
- assertSame(message, event.message);
- assertSame(throwable, event.throwable);
- }
-
- @Test
- public void testDebugMarkerSupplier() {
- logger2.disable().debug(marker, supplier);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().debug(marker, supplier);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.DEBUG, event.level);
- assertSame(stringMessage, event.message.getFormattedMessage());
- assertSame(marker, event.marker);
- }
-
- @Test
- public void testDebugSupplier() {
- logger2.disable().debug(supplier);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().debug(supplier);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.DEBUG, event.level);
- assertSame(stringMessage, event.message.getFormattedMessage());
- }
-
- @Test
- public void testDebugMarkerSupplierThrowable() {
- logger2.disable().debug(marker, supplier, throwable);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().debug(marker, supplier, throwable);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.DEBUG, event.level);
- assertSame(marker, event.marker);
- assertSame(stringMessage, event.message.getFormattedMessage());
- assertSame(throwable, event.throwable);
- }
-
- @Test
- public void testDebugSupplierThrowable() {
- logger2.disable().debug(supplier, throwable);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().debug(supplier, throwable);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.DEBUG, event.level);
- assertSame(stringMessage, event.message.getFormattedMessage());
- assertSame(throwable, event.throwable);
- }
-
- @Test
- public void testDebugStringParamSupplier() {
- logger2.disable().debug("abc {}", supplierArray1);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().debug("abc {}", supplierArray1);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.DEBUG, event.level);
- assertEquals("abc Hi", event.message.getFormattedMessage());
- }
-
- @Test
- public void testDebugMarkerStringParamSupplier() {
- logger2.disable().debug(marker, "abc {}", supplierArray1);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().debug(marker, "abc {}", supplierArray1);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.DEBUG, event.level);
- assertSame(marker, event.marker);
- assertEquals("abc Hi", event.message.getFormattedMessage());
- }
-
- @Test
- public void testErrorMarkerMessageSupplier() {
- logger2.disable().error(marker, messageSupplier);
- assertTrue(logger2.list.isEmpty());
- assertFalse(messageSupplier.invoked);
-
- logger2.enable().error(marker, messageSupplier);
- assertEquals(1, logger2.list.size());
- assertTrue(messageSupplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.ERROR, event.level);
- assertSame(message, event.message);
- assertSame(marker, event.marker);
- }
-
- @Test
- public void testErrorMessageSupplier() {
- logger2.disable().error(messageSupplier);
- assertTrue(logger2.list.isEmpty());
- assertFalse(messageSupplier.invoked);
-
- logger2.enable().error(messageSupplier);
- assertEquals(1, logger2.list.size());
- assertTrue(messageSupplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.ERROR, event.level);
- assertSame(message, event.message);
- }
-
- @Test
- public void testErrorMarkerMessageSupplierThrowable() {
- logger2.disable().error(marker, messageSupplier, throwable);
- assertTrue(logger2.list.isEmpty());
- assertFalse(messageSupplier.invoked);
-
- logger2.enable().error(marker, messageSupplier, throwable);
- assertEquals(1, logger2.list.size());
- assertTrue(messageSupplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.ERROR, event.level);
- assertSame(marker, event.marker);
- assertSame(message, event.message);
- assertSame(throwable, event.throwable);
- }
-
- @Test
- public void testErrorMessageSupplierThrowable() {
- logger2.disable().error(messageSupplier, throwable);
- assertTrue(logger2.list.isEmpty());
- assertFalse(messageSupplier.invoked);
-
- logger2.enable().error(messageSupplier, throwable);
- assertEquals(1, logger2.list.size());
- assertTrue(messageSupplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.ERROR, event.level);
- assertSame(message, event.message);
- assertSame(throwable, event.throwable);
- }
-
- @Test
- public void testErrorMarkerSupplier() {
- logger2.disable().error(marker, supplier);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().error(marker, supplier);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.ERROR, event.level);
- assertSame(stringMessage, event.message.getFormattedMessage());
- assertSame(marker, event.marker);
- }
-
- @Test
- public void testErrorSupplier() {
- logger2.disable().error(supplier);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().error(supplier);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.ERROR, event.level);
- assertSame(stringMessage, event.message.getFormattedMessage());
- }
-
- @Test
- public void testErrorMarkerSupplierThrowable() {
- logger2.disable().error(marker, supplier, throwable);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().error(marker, supplier, throwable);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.ERROR, event.level);
- assertSame(marker, event.marker);
- assertSame(stringMessage, event.message.getFormattedMessage());
- assertSame(throwable, event.throwable);
- }
-
- @Test
- public void testErrorSupplierThrowable() {
- logger2.disable().error(supplier, throwable);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().error(supplier, throwable);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.ERROR, event.level);
- assertSame(stringMessage, event.message.getFormattedMessage());
- assertSame(throwable, event.throwable);
- }
-
- @Test
- public void testErrorStringParamSupplier() {
- logger2.disable().error("abc {}", supplierArray1);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().error("abc {}", supplierArray1);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.ERROR, event.level);
- assertEquals("abc Hi", event.message.getFormattedMessage());
- }
-
- @Test
- public void testErrorMarkerStringParamSupplier() {
- logger2.disable().error(marker, "abc {}", supplierArray1);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().error(marker, "abc {}", supplierArray1);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.ERROR, event.level);
- assertSame(marker, event.marker);
- assertEquals("abc Hi", event.message.getFormattedMessage());
- }
-
- @Test
- public void testFatalMarkerMessageSupplier() {
- logger2.disable().fatal(marker, messageSupplier);
- assertTrue(logger2.list.isEmpty());
- assertFalse(messageSupplier.invoked);
-
- logger2.enable().fatal(marker, messageSupplier);
- assertEquals(1, logger2.list.size());
- assertTrue(messageSupplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.FATAL, event.level);
- assertSame(message, event.message);
- assertSame(marker, event.marker);
- }
-
- @Test
- public void testFatalMessageSupplier() {
- logger2.disable().fatal(messageSupplier);
- assertTrue(logger2.list.isEmpty());
- assertFalse(messageSupplier.invoked);
-
- logger2.enable().fatal(messageSupplier);
- assertEquals(1, logger2.list.size());
- assertTrue(messageSupplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.FATAL, event.level);
- assertSame(message, event.message);
- }
-
- @Test
- public void testFatalMarkerMessageSupplierThrowable() {
- logger2.disable().fatal(marker, messageSupplier, throwable);
- assertTrue(logger2.list.isEmpty());
- assertFalse(messageSupplier.invoked);
-
- logger2.enable().fatal(marker, messageSupplier, throwable);
- assertEquals(1, logger2.list.size());
- assertTrue(messageSupplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.FATAL, event.level);
- assertSame(marker, event.marker);
- assertSame(message, event.message);
- assertSame(throwable, event.throwable);
- }
-
- @Test
- public void testFatalMessageSupplierThrowable() {
- logger2.disable().fatal(messageSupplier, throwable);
- assertTrue(logger2.list.isEmpty());
- assertFalse(messageSupplier.invoked);
-
- logger2.enable().fatal(messageSupplier, throwable);
- assertEquals(1, logger2.list.size());
- assertTrue(messageSupplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.FATAL, event.level);
- assertSame(message, event.message);
- assertSame(throwable, event.throwable);
- }
-
- @Test
- public void testFatalMarkerSupplier() {
- logger2.disable().fatal(marker, supplier);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().fatal(marker, supplier);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.FATAL, event.level);
- assertSame(stringMessage, event.message.getFormattedMessage());
- assertSame(marker, event.marker);
- }
-
- @Test
- public void testFatalSupplier() {
- logger2.disable().fatal(supplier);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().fatal(supplier);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.FATAL, event.level);
- assertSame(stringMessage, event.message.getFormattedMessage());
- }
-
- @Test
- public void testFatalMarkerSupplierThrowable() {
- logger2.disable().fatal(marker, supplier, throwable);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().fatal(marker, supplier, throwable);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.FATAL, event.level);
- assertSame(marker, event.marker);
- assertSame(stringMessage, event.message.getFormattedMessage());
- assertSame(throwable, event.throwable);
- }
-
- @Test
- public void testFatalSupplierThrowable() {
- logger2.disable().fatal(supplier, throwable);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().fatal(supplier, throwable);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.FATAL, event.level);
- assertSame(stringMessage, event.message.getFormattedMessage());
- assertSame(throwable, event.throwable);
- }
-
- @Test
- public void testFatalStringParamSupplier() {
- logger2.disable().fatal("abc {}", supplierArray1);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().fatal("abc {}", supplierArray1);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.FATAL, event.level);
- assertEquals("abc Hi", event.message.getFormattedMessage());
- }
-
- @Test
- public void testFatalStringParam2Suppliers() {
- logger2.disable().fatal("abc {}{}", supplierArray2);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
- assertFalse(supplier2.invoked);
-
- logger2.enable().fatal("abc {}{}", supplierArray2);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
- assertTrue(supplier2.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.FATAL, event.level);
- assertEquals("abc HiHi", event.message.getFormattedMessage());
- }
-
- @Test
- public void testFatalMarkerStringParamSupplier() {
- logger2.disable().fatal(marker, "abc {}", supplierArray1);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().fatal(marker, "abc {}", supplierArray1);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.FATAL, event.level);
- assertSame(marker, event.marker);
- assertEquals("abc Hi", event.message.getFormattedMessage());
- }
-
- @Test
- public void testInfoMarkerMessageSupplier() {
- logger2.disable().info(marker, messageSupplier);
- assertTrue(logger2.list.isEmpty());
- assertFalse(messageSupplier.invoked);
-
- logger2.enable().info(marker, messageSupplier);
- assertEquals(1, logger2.list.size());
- assertTrue(messageSupplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.INFO, event.level);
- assertSame(message, event.message);
- assertSame(marker, event.marker);
- }
-
- @Test
- public void testInfoMessageSupplier() {
- logger2.disable().info(messageSupplier);
- assertTrue(logger2.list.isEmpty());
- assertFalse(messageSupplier.invoked);
-
- logger2.enable().info(messageSupplier);
- assertEquals(1, logger2.list.size());
- assertTrue(messageSupplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.INFO, event.level);
- assertSame(message, event.message);
- }
-
- @Test
- public void testInfoMarkerMessageSupplierThrowable() {
- logger2.disable().info(marker, messageSupplier, throwable);
- assertTrue(logger2.list.isEmpty());
- assertFalse(messageSupplier.invoked);
-
- logger2.enable().info(marker, messageSupplier, throwable);
- assertEquals(1, logger2.list.size());
- assertTrue(messageSupplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.INFO, event.level);
- assertSame(marker, event.marker);
- assertSame(message, event.message);
- assertSame(throwable, event.throwable);
- }
-
- @Test
- public void testInfoMessageSupplierThrowable() {
- logger2.disable().info(messageSupplier, throwable);
- assertTrue(logger2.list.isEmpty());
- assertFalse(messageSupplier.invoked);
-
- logger2.enable().info(messageSupplier, throwable);
- assertEquals(1, logger2.list.size());
- assertTrue(messageSupplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.INFO, event.level);
- assertSame(message, event.message);
- assertSame(throwable, event.throwable);
- }
-
- @Test
- public void testInfoMarkerSupplier() {
- logger2.disable().info(marker, supplier);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().info(marker, supplier);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.INFO, event.level);
- assertSame(stringMessage, event.message.getFormattedMessage());
- assertSame(marker, event.marker);
- }
-
- @Test
- public void testInfoSupplier() {
- logger2.disable().info(supplier);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().info(supplier);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.INFO, event.level);
- assertSame(stringMessage, event.message.getFormattedMessage());
- }
-
- @Test
- public void testInfoMarkerSupplierThrowable() {
- logger2.disable().info(marker, supplier, throwable);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().info(marker, supplier, throwable);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.INFO, event.level);
- assertSame(marker, event.marker);
- assertSame(stringMessage, event.message.getFormattedMessage());
- assertSame(throwable, event.throwable);
- }
-
- @Test
- public void testInfoSupplierThrowable() {
- logger2.disable().info(supplier, throwable);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().info(supplier, throwable);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.INFO, event.level);
- assertSame(stringMessage, event.message.getFormattedMessage());
- assertSame(throwable, event.throwable);
- }
-
- @Test
- public void testInfoStringParamSupplier() {
- logger2.disable().info("abc {}", supplierArray1);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().info("abc {}", supplierArray1);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.INFO, event.level);
- assertEquals("abc Hi", event.message.getFormattedMessage());
- }
-
- @Test
- public void testInfoMarkerStringParamSupplier() {
- logger2.disable().info(marker, "abc {}", supplierArray1);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().info(marker, "abc {}", supplierArray1);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.INFO, event.level);
- assertSame(marker, event.marker);
- assertEquals("abc Hi", event.message.getFormattedMessage());
- }
-
- @Test
- public void testTraceMarkerMessageSupplier() {
- logger2.disable().trace(marker, messageSupplier);
- assertTrue(logger2.list.isEmpty());
- assertFalse(messageSupplier.invoked);
-
- logger2.enable().trace(marker, messageSupplier);
- assertEquals(1, logger2.list.size());
- assertTrue(messageSupplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.TRACE, event.level);
- assertSame(message, event.message);
- assertSame(marker, event.marker);
- }
-
- @Test
- public void testTraceMessageSupplier() {
- logger2.disable().trace(messageSupplier);
- assertTrue(logger2.list.isEmpty());
- assertFalse(messageSupplier.invoked);
-
- logger2.enable().trace(messageSupplier);
- assertEquals(1, logger2.list.size());
- assertTrue(messageSupplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.TRACE, event.level);
- assertSame(message, event.message);
- }
-
- @Test
- public void testTraceMarkerMessageSupplierThrowable() {
- logger2.disable().trace(marker, messageSupplier, throwable);
- assertTrue(logger2.list.isEmpty());
- assertFalse(messageSupplier.invoked);
-
- logger2.enable().trace(marker, messageSupplier, throwable);
- assertEquals(1, logger2.list.size());
- assertTrue(messageSupplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.TRACE, event.level);
- assertSame(marker, event.marker);
- assertSame(message, event.message);
- assertSame(throwable, event.throwable);
- }
-
- @Test
- public void testTraceMessageSupplierThrowable() {
- logger2.disable().trace(messageSupplier, throwable);
- assertTrue(logger2.list.isEmpty());
- assertFalse(messageSupplier.invoked);
-
- logger2.enable().trace(messageSupplier, throwable);
- assertEquals(1, logger2.list.size());
- assertTrue(messageSupplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.TRACE, event.level);
- assertSame(message, event.message);
- assertSame(throwable, event.throwable);
- }
-
- @Test
- public void testTraceMarkerSupplier() {
- logger2.disable().trace(marker, supplier);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().trace(marker, supplier);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.TRACE, event.level);
- assertSame(stringMessage, event.message.getFormattedMessage());
- assertSame(marker, event.marker);
- }
-
- @Test
- public void testTraceSupplier() {
- logger2.disable().trace(supplier);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().trace(supplier);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.TRACE, event.level);
- assertSame(stringMessage, event.message.getFormattedMessage());
- }
-
- @Test
- public void testTraceMarkerSupplierThrowable() {
- logger2.disable().trace(marker, supplier, throwable);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().trace(marker, supplier, throwable);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.TRACE, event.level);
- assertSame(marker, event.marker);
- assertSame(stringMessage, event.message.getFormattedMessage());
- assertSame(throwable, event.throwable);
- }
-
- @Test
- public void testTraceSupplierThrowable() {
- logger2.disable().trace(supplier, throwable);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().trace(supplier, throwable);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.TRACE, event.level);
- assertSame(stringMessage, event.message.getFormattedMessage());
- assertSame(throwable, event.throwable);
- }
-
- @Test
- public void testTraceStringParamSupplier() {
- logger2.disable().trace("abc {}", supplierArray1);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().trace("abc {}", supplierArray1);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.TRACE, event.level);
- assertEquals("abc Hi", event.message.getFormattedMessage());
- }
-
- @Test
- public void testTraceMarkerStringParamSupplier() {
- logger2.disable().trace(marker, "abc {}", supplierArray1);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().trace(marker, "abc {}", supplierArray1);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.TRACE, event.level);
- assertSame(marker, event.marker);
- assertEquals("abc Hi", event.message.getFormattedMessage());
- }
-
- @Test
- public void testWarnMarkerMessageSupplier() {
- logger2.disable().warn(marker, messageSupplier);
- assertTrue(logger2.list.isEmpty());
- assertFalse(messageSupplier.invoked);
-
- logger2.enable().warn(marker, messageSupplier);
- assertEquals(1, logger2.list.size());
- assertTrue(messageSupplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.WARN, event.level);
- assertSame(message, event.message);
- assertSame(marker, event.marker);
- }
-
- @Test
- public void testWarnMessageSupplier() {
- logger2.disable().warn(messageSupplier);
- assertTrue(logger2.list.isEmpty());
- assertFalse(messageSupplier.invoked);
-
- logger2.enable().warn(messageSupplier);
- assertEquals(1, logger2.list.size());
- assertTrue(messageSupplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.WARN, event.level);
- assertSame(message, event.message);
- }
-
- @Test
- public void testWarnMarkerMessageSupplierThrowable() {
- logger2.disable().warn(marker, messageSupplier, throwable);
- assertTrue(logger2.list.isEmpty());
- assertFalse(messageSupplier.invoked);
-
- logger2.enable().warn(marker, messageSupplier, throwable);
- assertEquals(1, logger2.list.size());
- assertTrue(messageSupplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.WARN, event.level);
- assertSame(marker, event.marker);
- assertSame(message, event.message);
- assertSame(throwable, event.throwable);
- }
-
- @Test
- public void testWarnMessageSupplierThrowable() {
- logger2.disable().warn(messageSupplier, throwable);
- assertTrue(logger2.list.isEmpty());
- assertFalse(messageSupplier.invoked);
-
- logger2.enable().warn(messageSupplier, throwable);
- assertEquals(1, logger2.list.size());
- assertTrue(messageSupplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.WARN, event.level);
- assertSame(message, event.message);
- assertSame(throwable, event.throwable);
- }
-
- @Test
- public void testWarnMarkerSupplier() {
- logger2.disable().warn(marker, supplier);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().warn(marker, supplier);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.WARN, event.level);
- assertSame(stringMessage, event.message.getFormattedMessage());
- assertSame(marker, event.marker);
- }
-
- @Test
- public void testWarnSupplier() {
- logger2.disable().warn(supplier);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().warn(supplier);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.WARN, event.level);
- assertSame(stringMessage, event.message.getFormattedMessage());
- }
-
- @Test
- public void testWarnMarkerSupplierThrowable() {
- logger2.disable().warn(marker, supplier, throwable);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().warn(marker, supplier, throwable);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.WARN, event.level);
- assertSame(marker, event.marker);
- assertSame(stringMessage, event.message.getFormattedMessage());
- assertSame(throwable, event.throwable);
- }
-
- @Test
- public void testWarnSupplierThrowable() {
- logger2.disable().warn(supplier, throwable);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().warn(supplier, throwable);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.WARN, event.level);
- assertSame(stringMessage, event.message.getFormattedMessage());
- assertSame(throwable, event.throwable);
- }
-
- @Test
- public void testWarnStringParamSupplier() {
- logger2.disable().warn("abc {}", supplierArray1);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().warn("abc {}", supplierArray1);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.WARN, event.level);
- assertEquals("abc Hi", event.message.getFormattedMessage());
- }
-
- @Test
- public void testWarnMarkerStringParamSupplier() {
- logger2.disable().warn(marker, "abc {}", supplierArray1);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().warn(marker, "abc {}", supplierArray1);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.WARN, event.level);
- assertSame(marker, event.marker);
- assertEquals("abc Hi", event.message.getFormattedMessage());
- }
-
- @Test
- public void testLogMarkerMessageSupplier() {
- logger2.disable().log(Level.WARN, marker, messageSupplier);
- assertTrue(logger2.list.isEmpty());
- assertFalse(messageSupplier.invoked);
-
- logger2.enable().log(Level.WARN, marker, messageSupplier);
- assertEquals(1, logger2.list.size());
- assertTrue(messageSupplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.WARN, event.level);
- assertSame(message, event.message);
- assertSame(marker, event.marker);
- }
-
- @Test
- public void testLogMessageSupplier() {
- logger2.disable().log(Level.WARN, messageSupplier);
- assertTrue(logger2.list.isEmpty());
- assertFalse(messageSupplier.invoked);
-
- logger2.enable().log(Level.WARN, messageSupplier);
- assertEquals(1, logger2.list.size());
- assertTrue(messageSupplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.WARN, event.level);
- assertSame(message, event.message);
- }
-
- @Test
- public void testLogMarkerMessageSupplierThrowable() {
- logger2.disable().log(Level.WARN, marker, messageSupplier, throwable);
- assertTrue(logger2.list.isEmpty());
- assertFalse(messageSupplier.invoked);
-
- logger2.enable().log(Level.WARN, marker, messageSupplier, throwable);
- assertEquals(1, logger2.list.size());
- assertTrue(messageSupplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.WARN, event.level);
- assertSame(marker, event.marker);
- assertSame(message, event.message);
- assertSame(throwable, event.throwable);
- }
-
- @Test
- public void testLogMessageSupplierThrowable() {
- logger2.disable().log(Level.WARN, messageSupplier, throwable);
- assertTrue(logger2.list.isEmpty());
- assertFalse(messageSupplier.invoked);
-
- logger2.enable().log(Level.WARN, messageSupplier, throwable);
- assertEquals(1, logger2.list.size());
- assertTrue(messageSupplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.WARN, event.level);
- assertSame(message, event.message);
- assertSame(throwable, event.throwable);
- }
-
- @Test
- public void testLogMarkerSupplier() {
- logger2.disable().log(Level.WARN, marker, supplier);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().log(Level.WARN, marker, supplier);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.WARN, event.level);
- assertSame(stringMessage, event.message.getFormattedMessage());
- assertSame(marker, event.marker);
- }
-
- @Test
- public void testLogSupplier() {
- logger2.disable().log(Level.WARN, supplier);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().log(Level.WARN, supplier);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.WARN, event.level);
- assertSame(stringMessage, event.message.getFormattedMessage());
- }
-
- @Test
- public void testLogMarkerSupplierThrowable() {
- logger2.disable().log(Level.WARN, marker, supplier, throwable);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().log(Level.WARN, marker, supplier, throwable);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.WARN, event.level);
- assertSame(marker, event.marker);
- assertSame(stringMessage, event.message.getFormattedMessage());
- assertSame(throwable, event.throwable);
- }
-
- @Test
- public void testLogSupplierThrowable() {
- logger2.disable().log(Level.WARN, supplier, throwable);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().log(Level.WARN, supplier, throwable);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.WARN, event.level);
- assertSame(stringMessage, event.message.getFormattedMessage());
- assertSame(throwable, event.throwable);
- }
-
- @Test
- public void testLogStringParamSupplier() {
- logger2.disable().log(Level.WARN, "abc {}", supplierArray1);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().log(Level.WARN, "abc {}", supplierArray1);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.WARN, event.level);
- assertEquals("abc Hi", event.message.getFormattedMessage());
- }
-
- @Test
- public void testLogMarkerStringParamSupplier() {
- logger2.disable().log(Level.WARN, marker, "abc {}", supplierArray1);
- assertTrue(logger2.list.isEmpty());
- assertFalse(supplier.invoked);
-
- logger2.enable().log(Level.WARN, marker, "abc {}", supplierArray1);
- assertEquals(1, logger2.list.size());
- assertTrue(supplier.invoked);
-
- final LogEvent event = logger2.list.get(0);
- assertEquals(Level.WARN, event.level);
- assertSame(marker, event.marker);
- assertEquals("abc Hi", event.message.getFormattedMessage());
- }
-}
diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/LevelTest.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/LevelTest.java
deleted file mode 100644
index a666126872..0000000000
--- a/log4j-api-test/src/test/java/org/apache/logging/log4j/LevelTest.java
+++ /dev/null
@@ -1,284 +0,0 @@
-/*
- * 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;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import org.junit.jupiter.api.Test;
-
-public class LevelTest {
-
- @Test
- public void testDefault() {
- final Level level = Level.toLevel("Information", Level.ERROR);
- assertNotNull(level);
- assertEquals(Level.ERROR, level);
- }
-
- @Test
- public void testForNameEquals() {
- final String name = "Foo";
- final int intValue = 1;
- final Level level = Level.forName(name, intValue);
- assertNotNull(level);
- assertEquals(level, Level.forName(name, intValue));
- assertEquals(level, Level.getLevel(name));
- assertEquals(level, Level.toLevel(name));
- assertEquals(intValue, Level.getLevel(name).intLevel());
- }
-
- @Test
- public void testThrowsOnNull() {
- assertThrowsExactly(IllegalArgumentException.class, () -> Level.forName(null, 100));
- assertThrowsExactly(IllegalArgumentException.class, () -> Level.getLevel(null));
- // the intLevel should be checked only if we create a new level
- assertNull(Level.getLevel("Bar"));
- assertThrowsExactly(IllegalArgumentException.class, () -> Level.forName("Bar", -1));
- }
-
- @Test
- public void testGoodLevels() {
- final Level level = Level.toLevel("INFO");
- assertNotNull(level);
- assertEquals(Level.INFO, level);
- }
-
- @Test
- public void testLevelsWithSpaces() {
- Level level = Level.toLevel(" INFO ");
- assertNotNull(level);
- assertEquals(Level.INFO, level);
-
- level = Level.valueOf(" INFO ");
- assertNotNull(level);
- assertEquals(Level.INFO, level);
- }
-
- @Test
- public void testIsInRangeErrorToDebug() {
- assertFalse(Level.OFF.isInRange(Level.ERROR, Level.DEBUG));
- assertFalse(Level.FATAL.isInRange(Level.ERROR, Level.DEBUG));
- assertTrue(Level.ERROR.isInRange(Level.ERROR, Level.DEBUG));
- assertTrue(Level.WARN.isInRange(Level.ERROR, Level.DEBUG));
- assertTrue(Level.INFO.isInRange(Level.ERROR, Level.DEBUG));
- assertTrue(Level.DEBUG.isInRange(Level.ERROR, Level.DEBUG));
- assertFalse(Level.TRACE.isInRange(Level.ERROR, Level.DEBUG));
- assertFalse(Level.ALL.isInRange(Level.ERROR, Level.DEBUG));
- }
-
- @Test
- public void testIsInRangeFatalToTrace() {
- assertFalse(Level.OFF.isInRange(Level.FATAL, Level.TRACE));
- assertTrue(Level.FATAL.isInRange(Level.FATAL, Level.TRACE));
- assertTrue(Level.ERROR.isInRange(Level.FATAL, Level.TRACE));
- assertTrue(Level.WARN.isInRange(Level.FATAL, Level.TRACE));
- assertTrue(Level.INFO.isInRange(Level.FATAL, Level.TRACE));
- assertTrue(Level.DEBUG.isInRange(Level.FATAL, Level.TRACE));
- assertTrue(Level.TRACE.isInRange(Level.FATAL, Level.TRACE));
- assertFalse(Level.ALL.isInRange(Level.FATAL, Level.TRACE));
- }
-
- @Test
- public void testIsInRangeOffToAll() {
- assertTrue(Level.OFF.isInRange(Level.OFF, Level.ALL));
- assertTrue(Level.FATAL.isInRange(Level.OFF, Level.ALL));
- assertTrue(Level.ERROR.isInRange(Level.OFF, Level.ALL));
- assertTrue(Level.WARN.isInRange(Level.OFF, Level.ALL));
- assertTrue(Level.INFO.isInRange(Level.OFF, Level.ALL));
- assertTrue(Level.DEBUG.isInRange(Level.OFF, Level.ALL));
- assertTrue(Level.TRACE.isInRange(Level.OFF, Level.ALL));
- assertTrue(Level.ALL.isInRange(Level.OFF, Level.ALL));
- }
-
- @Test
- public void testIsInRangeSameLevels() {
- // Level.OFF
- assertTrue(Level.OFF.isInRange(Level.OFF, Level.OFF));
- assertFalse(Level.OFF.isInRange(Level.FATAL, Level.FATAL));
- assertFalse(Level.OFF.isInRange(Level.ERROR, Level.ERROR));
- assertFalse(Level.OFF.isInRange(Level.WARN, Level.WARN));
- assertFalse(Level.OFF.isInRange(Level.INFO, Level.INFO));
- assertFalse(Level.OFF.isInRange(Level.DEBUG, Level.DEBUG));
- assertFalse(Level.OFF.isInRange(Level.TRACE, Level.TRACE));
- assertFalse(Level.OFF.isInRange(Level.ALL, Level.ALL));
- // Level.FATAL
- assertFalse(Level.FATAL.isInRange(Level.OFF, Level.OFF));
- assertTrue(Level.FATAL.isInRange(Level.FATAL, Level.FATAL));
- assertFalse(Level.FATAL.isInRange(Level.ERROR, Level.ERROR));
- assertFalse(Level.FATAL.isInRange(Level.WARN, Level.WARN));
- assertFalse(Level.FATAL.isInRange(Level.INFO, Level.INFO));
- assertFalse(Level.FATAL.isInRange(Level.DEBUG, Level.DEBUG));
- assertFalse(Level.FATAL.isInRange(Level.TRACE, Level.TRACE));
- assertFalse(Level.FATAL.isInRange(Level.ALL, Level.ALL));
- // Level.ERROR
- assertFalse(Level.ERROR.isInRange(Level.OFF, Level.OFF));
- assertFalse(Level.ERROR.isInRange(Level.FATAL, Level.FATAL));
- assertTrue(Level.ERROR.isInRange(Level.ERROR, Level.ERROR));
- assertFalse(Level.ERROR.isInRange(Level.WARN, Level.WARN));
- assertFalse(Level.ERROR.isInRange(Level.INFO, Level.INFO));
- assertFalse(Level.ERROR.isInRange(Level.DEBUG, Level.DEBUG));
- assertFalse(Level.ERROR.isInRange(Level.TRACE, Level.TRACE));
- assertFalse(Level.ERROR.isInRange(Level.ALL, Level.ALL));
- // Level.WARN
- assertFalse(Level.WARN.isInRange(Level.OFF, Level.OFF));
- assertFalse(Level.WARN.isInRange(Level.FATAL, Level.FATAL));
- assertFalse(Level.WARN.isInRange(Level.ERROR, Level.ERROR));
- assertTrue(Level.WARN.isInRange(Level.WARN, Level.WARN));
- assertFalse(Level.WARN.isInRange(Level.INFO, Level.INFO));
- assertFalse(Level.WARN.isInRange(Level.DEBUG, Level.DEBUG));
- assertFalse(Level.WARN.isInRange(Level.TRACE, Level.TRACE));
- assertFalse(Level.WARN.isInRange(Level.ALL, Level.ALL));
- // Level.INFO
- assertFalse(Level.INFO.isInRange(Level.OFF, Level.OFF));
- assertFalse(Level.INFO.isInRange(Level.FATAL, Level.FATAL));
- assertFalse(Level.INFO.isInRange(Level.ERROR, Level.ERROR));
- assertFalse(Level.INFO.isInRange(Level.WARN, Level.WARN));
- assertTrue(Level.INFO.isInRange(Level.INFO, Level.INFO));
- assertFalse(Level.INFO.isInRange(Level.DEBUG, Level.DEBUG));
- assertFalse(Level.INFO.isInRange(Level.TRACE, Level.TRACE));
- assertFalse(Level.INFO.isInRange(Level.ALL, Level.ALL));
- // Level.DEBUG
- assertFalse(Level.DEBUG.isInRange(Level.OFF, Level.OFF));
- assertFalse(Level.DEBUG.isInRange(Level.FATAL, Level.FATAL));
- assertFalse(Level.DEBUG.isInRange(Level.ERROR, Level.ERROR));
- assertFalse(Level.DEBUG.isInRange(Level.WARN, Level.WARN));
- assertFalse(Level.DEBUG.isInRange(Level.INFO, Level.INFO));
- assertTrue(Level.DEBUG.isInRange(Level.DEBUG, Level.DEBUG));
- assertFalse(Level.DEBUG.isInRange(Level.TRACE, Level.TRACE));
- assertFalse(Level.DEBUG.isInRange(Level.ALL, Level.ALL));
- // Level.TRACE
- assertFalse(Level.TRACE.isInRange(Level.OFF, Level.OFF));
- assertFalse(Level.TRACE.isInRange(Level.FATAL, Level.FATAL));
- assertFalse(Level.TRACE.isInRange(Level.ERROR, Level.ERROR));
- assertFalse(Level.TRACE.isInRange(Level.WARN, Level.WARN));
- assertFalse(Level.TRACE.isInRange(Level.INFO, Level.INFO));
- assertFalse(Level.TRACE.isInRange(Level.DEBUG, Level.DEBUG));
- assertTrue(Level.TRACE.isInRange(Level.TRACE, Level.TRACE));
- assertFalse(Level.TRACE.isInRange(Level.ALL, Level.ALL));
- // Level.ALL
- assertFalse(Level.ALL.isInRange(Level.OFF, Level.OFF));
- assertFalse(Level.ALL.isInRange(Level.FATAL, Level.FATAL));
- assertFalse(Level.ALL.isInRange(Level.ERROR, Level.ERROR));
- assertFalse(Level.ALL.isInRange(Level.WARN, Level.WARN));
- assertFalse(Level.ALL.isInRange(Level.INFO, Level.INFO));
- assertFalse(Level.ALL.isInRange(Level.DEBUG, Level.DEBUG));
- assertFalse(Level.ALL.isInRange(Level.TRACE, Level.TRACE));
- assertTrue(Level.ALL.isInRange(Level.ALL, Level.ALL));
- }
-
- @Test
- public void testIsInRangeWarnToInfo() {
- assertFalse(Level.OFF.isInRange(Level.WARN, Level.INFO));
- assertFalse(Level.FATAL.isInRange(Level.WARN, Level.INFO));
- assertFalse(Level.ERROR.isInRange(Level.WARN, Level.INFO));
- assertTrue(Level.WARN.isInRange(Level.WARN, Level.INFO));
- assertTrue(Level.INFO.isInRange(Level.WARN, Level.INFO));
- assertFalse(Level.DEBUG.isInRange(Level.WARN, Level.INFO));
- assertFalse(Level.TRACE.isInRange(Level.WARN, Level.INFO));
- assertFalse(Level.ALL.isInRange(Level.WARN, Level.INFO));
- }
-
- @Test
- public void testIsLessSpecificThan() {
- // Level.OFF
- assertTrue(Level.OFF.isLessSpecificThan(Level.OFF));
- assertFalse(Level.OFF.isLessSpecificThan(Level.FATAL));
- assertFalse(Level.OFF.isLessSpecificThan(Level.ERROR));
- assertFalse(Level.OFF.isLessSpecificThan(Level.WARN));
- assertFalse(Level.OFF.isLessSpecificThan(Level.INFO));
- assertFalse(Level.OFF.isLessSpecificThan(Level.DEBUG));
- assertFalse(Level.OFF.isLessSpecificThan(Level.TRACE));
- assertFalse(Level.OFF.isLessSpecificThan(Level.ALL));
- // Level.FATAL
- assertTrue(Level.FATAL.isLessSpecificThan(Level.OFF));
- assertTrue(Level.FATAL.isLessSpecificThan(Level.FATAL));
- assertFalse(Level.FATAL.isLessSpecificThan(Level.ERROR));
- assertFalse(Level.FATAL.isLessSpecificThan(Level.WARN));
- assertFalse(Level.FATAL.isLessSpecificThan(Level.INFO));
- assertFalse(Level.FATAL.isLessSpecificThan(Level.DEBUG));
- assertFalse(Level.FATAL.isLessSpecificThan(Level.TRACE));
- assertFalse(Level.FATAL.isLessSpecificThan(Level.ALL));
- // Level.ERROR
- assertTrue(Level.ERROR.isLessSpecificThan(Level.OFF));
- assertTrue(Level.ERROR.isLessSpecificThan(Level.FATAL));
- assertTrue(Level.ERROR.isLessSpecificThan(Level.ERROR));
- assertFalse(Level.ERROR.isLessSpecificThan(Level.WARN));
- assertFalse(Level.ERROR.isLessSpecificThan(Level.INFO));
- assertFalse(Level.ERROR.isLessSpecificThan(Level.DEBUG));
- assertFalse(Level.ERROR.isLessSpecificThan(Level.TRACE));
- assertFalse(Level.ERROR.isLessSpecificThan(Level.ALL));
- // Level.ERROR
- assertTrue(Level.WARN.isLessSpecificThan(Level.OFF));
- assertTrue(Level.WARN.isLessSpecificThan(Level.FATAL));
- assertTrue(Level.WARN.isLessSpecificThan(Level.ERROR));
- assertTrue(Level.WARN.isLessSpecificThan(Level.WARN));
- assertFalse(Level.WARN.isLessSpecificThan(Level.INFO));
- assertFalse(Level.WARN.isLessSpecificThan(Level.DEBUG));
- assertFalse(Level.WARN.isLessSpecificThan(Level.TRACE));
- assertFalse(Level.WARN.isLessSpecificThan(Level.ALL));
- // Level.WARN
- assertTrue(Level.WARN.isLessSpecificThan(Level.OFF));
- assertTrue(Level.WARN.isLessSpecificThan(Level.FATAL));
- assertTrue(Level.WARN.isLessSpecificThan(Level.ERROR));
- assertTrue(Level.WARN.isLessSpecificThan(Level.WARN));
- assertFalse(Level.WARN.isLessSpecificThan(Level.INFO));
- assertFalse(Level.WARN.isLessSpecificThan(Level.DEBUG));
- assertFalse(Level.WARN.isLessSpecificThan(Level.TRACE));
- assertFalse(Level.WARN.isLessSpecificThan(Level.ALL));
- // Level.INFO
- assertTrue(Level.INFO.isLessSpecificThan(Level.OFF));
- assertTrue(Level.INFO.isLessSpecificThan(Level.FATAL));
- assertTrue(Level.INFO.isLessSpecificThan(Level.ERROR));
- assertTrue(Level.INFO.isLessSpecificThan(Level.WARN));
- assertTrue(Level.INFO.isLessSpecificThan(Level.INFO));
- assertFalse(Level.INFO.isLessSpecificThan(Level.DEBUG));
- assertFalse(Level.INFO.isLessSpecificThan(Level.TRACE));
- assertFalse(Level.INFO.isLessSpecificThan(Level.ALL));
- // Level.DEBUG
- assertTrue(Level.DEBUG.isLessSpecificThan(Level.OFF));
- assertTrue(Level.DEBUG.isLessSpecificThan(Level.FATAL));
- assertTrue(Level.DEBUG.isLessSpecificThan(Level.ERROR));
- assertTrue(Level.DEBUG.isLessSpecificThan(Level.WARN));
- assertTrue(Level.DEBUG.isLessSpecificThan(Level.INFO));
- assertTrue(Level.DEBUG.isLessSpecificThan(Level.DEBUG));
- assertFalse(Level.DEBUG.isLessSpecificThan(Level.TRACE));
- assertFalse(Level.DEBUG.isLessSpecificThan(Level.ALL));
- // Level.TRACE
- assertTrue(Level.TRACE.isLessSpecificThan(Level.OFF));
- assertTrue(Level.TRACE.isLessSpecificThan(Level.FATAL));
- assertTrue(Level.TRACE.isLessSpecificThan(Level.ERROR));
- assertTrue(Level.TRACE.isLessSpecificThan(Level.WARN));
- assertTrue(Level.TRACE.isLessSpecificThan(Level.INFO));
- assertTrue(Level.TRACE.isLessSpecificThan(Level.DEBUG));
- assertTrue(Level.TRACE.isLessSpecificThan(Level.TRACE));
- assertFalse(Level.TRACE.isLessSpecificThan(Level.ALL));
- // Level.ALL
- assertTrue(Level.ALL.isLessSpecificThan(Level.OFF));
- assertTrue(Level.ALL.isLessSpecificThan(Level.FATAL));
- assertTrue(Level.ALL.isLessSpecificThan(Level.ERROR));
- assertTrue(Level.ALL.isLessSpecificThan(Level.WARN));
- assertTrue(Level.ALL.isLessSpecificThan(Level.INFO));
- assertTrue(Level.ALL.isLessSpecificThan(Level.DEBUG));
- assertTrue(Level.ALL.isLessSpecificThan(Level.TRACE));
- assertTrue(Level.ALL.isLessSpecificThan(Level.ALL));
- }
-}
diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/LogManagerTest.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/LogManagerTest.java
deleted file mode 100644
index 2e767bc7cf..0000000000
--- a/log4j-api-test/src/test/java/org/apache/logging/log4j/LogManagerTest.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * 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;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-
-import java.io.Closeable;
-import java.io.IOException;
-import org.apache.logging.log4j.message.ReusableMessageFactory;
-import org.apache.logging.log4j.spi.LoggerContext;
-import org.junit.jupiter.api.Test;
-import org.junitpioneer.jupiter.ReadsSystemProperty;
-
-@ReadsSystemProperty
-public class LogManagerTest {
-
- @SuppressWarnings("InnerClassMayBeStatic")
- class Inner {
- final Logger LOGGER = LogManager.getLogger();
- }
-
- @SuppressWarnings("InnerClassMayBeStatic")
- class InnerByClass {
- final Logger LOGGER = LogManager.getLogger(InnerByClass.class);
- }
-
- static class StaticInner {
- static final Logger LOGGER = LogManager.getLogger();
- }
-
- static class StaticInnerByClass {
- static final Logger LOGGER = LogManager.getLogger(StaticInnerByClass.class);
- }
-
- @Test
- public void testGetLogger() {
- Logger logger = LogManager.getLogger();
- assertNotNull(logger, "No Logger returned");
- assertEquals(LogManagerTest.class.getName(), logger.getName(), "Incorrect Logger name: " + logger.getName());
- final ReusableMessageFactory messageFactory = new ReusableMessageFactory();
- logger = LogManager.getLogger(messageFactory);
- assertNotNull(logger, "No Logger returned");
- assertEquals(LogManagerTest.class.getName(), logger.getName(), "Incorrect Logger name: " + logger.getName());
- logger = LogManager.getLogger((Class<?>) null);
- assertNotNull(logger, "No Logger returned");
- assertEquals(LogManagerTest.class.getName(), logger.getName(), "Incorrect Logger name: " + logger.getName());
- logger = LogManager.getLogger((Class<?>) null, messageFactory);
- assertNotNull(logger, "No Logger returned");
- assertEquals(LogManagerTest.class.getName(), logger.getName(), "Incorrect Logger name: " + logger.getName());
- logger = LogManager.getLogger((String) null);
- assertNotNull(logger, "No Logger returned");
- assertEquals(LogManagerTest.class.getName(), logger.getName(), "Incorrect Logger name: " + logger.getName());
- logger = LogManager.getLogger((String) null, messageFactory);
- assertNotNull(logger, "No Logger returned");
- assertEquals(LogManagerTest.class.getName(), logger.getName(), "Incorrect Logger name: " + logger.getName());
- logger = LogManager.getLogger((Object) null);
- assertNotNull(logger, "No Logger returned");
- assertEquals(LogManagerTest.class.getName(), logger.getName(), "Incorrect Logger name: " + logger.getName());
- logger = LogManager.getLogger((Object) null, messageFactory);
- assertNotNull(logger, "No Logger returned");
- assertEquals(LogManagerTest.class.getName(), logger.getName(), "Incorrect Logger name: " + logger.getName());
- }
-
- @Test
- public void testGetLoggerForAnonymousInnerClass1() throws IOException {
- final Closeable closeable = new Closeable() {
-
- final Logger LOGGER = LogManager.getLogger();
-
- @Override
- public void close() throws IOException {
- assertEquals("org.apache.logging.log4j.LogManagerTest$1", LOGGER.getName());
- }
- };
- closeable.close();
- }
-
- @Test
- public void testGetLoggerForAnonymousInnerClass2() throws IOException {
- final Closeable closeable = new Closeable() {
-
- final Logger LOGGER = LogManager.getLogger(getClass());
-
- @Override
- public void close() throws IOException {
- assertEquals("org.apache.logging.log4j.LogManagerTest$2", LOGGER.getName());
- }
- };
- closeable.close();
- }
-
- @Test
- public void testGetLoggerForInner() {
- assertEquals("org.apache.logging.log4j.LogManagerTest.Inner", new Inner().LOGGER.getName());
- }
-
- @Test
- public void testGetLoggerForInnerByClass() {
- assertEquals("org.apache.logging.log4j.LogManagerTest.InnerByClass", new InnerByClass().LOGGER.getName());
- }
-
- @Test
- public void testGetLoggerForStaticInner() {
- assertEquals("org.apache.logging.log4j.LogManagerTest.StaticInner", StaticInner.LOGGER.getName());
- }
-
- @Test
- public void testGetLoggerForStaticInnerByClass() {
- assertEquals("org.apache.logging.log4j.LogManagerTest.StaticInnerByClass", StaticInnerByClass.LOGGER.getName());
- }
-
- @Test
- public void testShutdown() {
- final LoggerContext loggerContext = LogManager.getContext(false);
- }
-}
diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/LoggerSupplierTest.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/LoggerSupplierTest.java
deleted file mode 100644
index 609807d8e2..0000000000
--- a/log4j-api-test/src/test/java/org/apache/logging/log4j/LoggerSupplierTest.java
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * 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;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.util.List;
-import java.util.Locale;
-import java.util.Properties;
-import org.apache.logging.log4j.message.FormattedMessage;
-import org.apache.logging.log4j.message.JsonMessage;
-import org.apache.logging.log4j.message.LocalizedMessage;
-import org.apache.logging.log4j.message.MessageFormatMessage;
-import org.apache.logging.log4j.message.ObjectArrayMessage;
-import org.apache.logging.log4j.message.ObjectMessage;
-import org.apache.logging.log4j.message.ParameterizedMessage;
-import org.apache.logging.log4j.message.SimpleMessage;
-import org.apache.logging.log4j.message.StringFormattedMessage;
-import org.apache.logging.log4j.message.ThreadDumpMessage;
-import org.apache.logging.log4j.test.TestLogger;
-import org.apache.logging.log4j.test.junit.UsingThreadContextMap;
-import org.apache.logging.log4j.util.Supplier;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.parallel.ResourceLock;
-import org.junit.jupiter.api.parallel.Resources;
-
-/**
- * Tests Logger APIs with {@link Supplier}.
- */
-@ResourceLock(Resources.LOCALE)
-@UsingThreadContextMap
-public class LoggerSupplierTest {
-
- private final TestLogger logger = (TestLogger) LogManager.getLogger(LoggerSupplierTest.class);
-
- private final List<String> results = logger.getEntries();
-
- Locale defaultLocale;
-
- @Test
- public void flowTracing_SupplierOfFormattedMessage() {
- logger.traceEntry(() -> new FormattedMessage("int foo={}", 1234567890));
- assertThat(results).hasSize(1);
- final String entry = results.get(0);
- assertThat(entry)
- .startsWith("ENTER[ FLOW ] TRACE Enter")
- .contains("(int foo=1234567890)")
- .doesNotContain("FormattedMessage");
- }
-
- @Test
- public void flowTracing_SupplierOfJsonMessage() {
- final Properties props = new Properties();
- props.setProperty("foo", "bar");
- logger.traceEntry(() -> new JsonMessage(props));
- assertThat(results).hasSize(1);
- final String entry = results.get(0);
- assertThat(entry)
- .startsWith("ENTER[ FLOW ] TRACE Enter")
- .contains("\"foo\":\"bar\"")
- .doesNotContain("JsonMessage");
- }
-
- @Test
- public void flowTracing_SupplierOfLocalizedMessage() {
- logger.traceEntry(() -> new LocalizedMessage("int foo={}", 1234567890));
- assertThat(results).hasSize(1);
- final String entry = results.get(0);
- assertThat(entry)
- .startsWith("ENTER[ FLOW ] TRACE Enter")
- .contains("(int foo=1234567890)")
- .doesNotContain("LocalizedMessage");
- }
-
- @Test
- public void flowTracing_SupplierOfLong() {
- logger.traceEntry(() -> 1234567890L);
- assertThat(results).hasSize(1);
- final String entry = results.get(0);
- assertThat(entry)
- .startsWith("ENTER[ FLOW ] TRACE Enter")
- .contains("(1234567890)")
- .doesNotContain("SimpleMessage");
- }
-
- @Test
- public void flowTracing_SupplierOfMessageFormatMessage() {
- logger.traceEntry(() -> new MessageFormatMessage("int foo={0}", 1234567890));
- assertThat(results).hasSize(1);
- final String entry = results.get(0);
- assertThat(entry)
- .startsWith("ENTER[ FLOW ] TRACE Enter")
- .contains("(int foo=1,234,567,890)")
- .doesNotContain("MessageFormatMessage");
- }
-
- @Test
- public void flowTracing_SupplierOfObjectArrayMessage() {
- logger.traceEntry(() -> new ObjectArrayMessage(1234567890));
- assertThat(results).hasSize(1);
- final String entry = results.get(0);
- assertThat(entry)
- .startsWith("ENTER[ FLOW ] TRACE Enter")
- .contains("([1234567890])")
- .doesNotContain("ObjectArrayMessage");
- }
-
- @Test
- public void flowTracing_SupplierOfObjectMessage() {
- logger.traceEntry(() -> new ObjectMessage(1234567890));
- assertThat(results).hasSize(1);
- final String entry = results.get(0);
- assertThat(entry)
- .startsWith("ENTER[ FLOW ] TRACE Enter")
- .contains("(1234567890)")
- .doesNotContain("ObjectMessage");
- }
-
- @Test
- public void flowTracing_SupplierOfParameterizedMessage() {
- logger.traceEntry(() -> new ParameterizedMessage("int foo={}", 1234567890));
- assertThat(results).hasSize(1);
- final String entry = results.get(0);
- assertThat(entry)
- .startsWith("ENTER[ FLOW ] TRACE Enter")
- .contains("(int foo=1234567890)")
- .doesNotContain("ParameterizedMessage");
- }
-
- @Test
- public void flowTracing_SupplierOfSimpleMessage() {
- logger.traceEntry(() -> new SimpleMessage("1234567890"));
- assertThat(results).hasSize(1);
- final String entry = results.get(0);
- assertThat(entry)
- .startsWith("ENTER[ FLOW ] TRACE Enter")
- .contains("(1234567890)")
- .doesNotContain("SimpleMessage");
- }
-
- @Test
- public void flowTracing_SupplierOfString() {
- logger.traceEntry(() -> "1234567890");
- assertThat(results).hasSize(1);
- final String entry = results.get(0);
- assertThat(entry)
- .startsWith("ENTER[ FLOW ] TRACE Enter")
- .contains("(1234567890)")
- .doesNotContain("SimpleMessage");
- }
-
- @Test
- public void flowTracing_SupplierOfStringFormattedMessage() {
- logger.traceEntry(() -> new StringFormattedMessage("int foo=%,d", 1234567890));
- assertThat(results).hasSize(1);
- final String entry = results.get(0);
- assertThat(entry)
- .startsWith("ENTER[ FLOW ] TRACE Enter")
- .contains("(int foo=1,234,567,890)")
- .doesNotContain("StringFormattedMessage");
- }
-
- @Test
- public void flowTracing_SupplierOfThreadDumpMessage() {
- logger.traceEntry(() -> new ThreadDumpMessage("Title of ..."));
- assertThat(results).hasSize(1);
- final String entry = results.get(0);
- assertThat(entry)
- .startsWith("ENTER[ FLOW ] TRACE Enter")
- .contains("RUNNABLE", "Title of ...", getClass().getName());
- }
-
- @BeforeEach
- public void setup() {
- results.clear();
- defaultLocale = Locale.getDefault(Locale.Category.FORMAT);
- Locale.setDefault(Locale.Category.FORMAT, java.util.Locale.US);
- }
-
- @AfterEach
- public void tearDown() {
- Locale.setDefault(Locale.Category.FORMAT, defaultLocale);
- }
-}
diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/LoggerTest.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/LoggerTest.java
deleted file mode 100644
index 7f4d6b8b37..0000000000
--- a/log4j-api-test/src/test/java/org/apache/logging/log4j/LoggerTest.java
+++ /dev/null
@@ -1,693 +0,0 @@
-/*
- * 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;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.startsWith;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import java.util.Date;
-import java.util.List;
-import java.util.Locale;
-import java.util.Properties;
-import org.apache.logging.log4j.message.EntryMessage;
-import org.apache.logging.log4j.message.JsonMessage;
-import org.apache.logging.log4j.message.Message;
-import org.apache.logging.log4j.message.MessageFactory;
-import org.apache.logging.log4j.message.ObjectMessage;
-import org.apache.logging.log4j.message.ReusableMessageFactory;
-import org.apache.logging.log4j.message.SimpleMessage;
-import org.apache.logging.log4j.message.SimpleMessageFactory;
-import org.apache.logging.log4j.message.StringFormatterMessageFactory;
-import org.apache.logging.log4j.message.StructuredDataMessage;
-import org.apache.logging.log4j.test.TestLogger;
-import org.apache.logging.log4j.test.TestLoggerContextFactory;
-import org.apache.logging.log4j.test.junit.LoggerContextFactoryExtension;
-import org.apache.logging.log4j.test.junit.Resources;
-import org.apache.logging.log4j.test.junit.UsingThreadContextMap;
-import org.apache.logging.log4j.util.Strings;
-import org.apache.logging.log4j.util.Supplier;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.RegisterExtension;
-import org.junit.jupiter.api.parallel.ResourceAccessMode;
-import org.junit.jupiter.api.parallel.ResourceLock;
-import org.junitpioneer.jupiter.ReadsSystemProperty;
-
-@ResourceLock(value = Resources.MARKER_MANAGER, mode = ResourceAccessMode.READ)
-@ReadsSystemProperty
-public class LoggerTest {
-
- @RegisterExtension
- public static final LoggerContextFactoryExtension EXTENSION =
- new LoggerContextFactoryExtension(new TestLoggerContextFactory());
-
- private static class TestReusableMessageFactory {
- // empty
- }
-
- private static class TestStringFormatterMessageFactory {
- // empty
- }
-
- private final TestLogger logger = (TestLogger) LogManager.getLogger(LoggerTest.class);
- private final Marker marker = MarkerManager.getMarker("test");
- private final List<String> results = logger.getEntries();
-
- @Test
- public void builder() {
- logger.atDebug().withLocation().log("Hello");
- logger.atError().withMarker(marker).log("Hello {}", "John");
- logger.atWarn().withThrowable(new Throwable("This is a test")).log((Message) new SimpleMessage("Log4j rocks!"));
- assertEquals(3, results.size());
- assertThat(
- "Incorrect message 1",
- results.get(0),
- equalTo(" DEBUG org.apache.logging.log4j.LoggerTest.builder(LoggerTest.java:78) Hello"));
- assertThat("Incorrect message 2", results.get(1), equalTo("test ERROR Hello John"));
- assertThat(
- "Incorrect message 3",
- results.get(2),
- startsWith(" WARN Log4j rocks! java.lang.Throwable: This is a test"));
- assertThat(
- "Throwable incorrect in message 3",
- results.get(2),
- containsString("org.apache.logging.log4j.LoggerTest.builder(LoggerTest.java:80)"));
- }
-
- @Test
- public void basicFlow() {
- logger.traceEntry();
- logger.traceExit();
- assertEquals(2, results.size());
- assertThat(results.get(0)).isEqualTo("ENTER[ FLOW ] TRACE Enter");
- assertThat(results.get(1)).isEqualTo("EXIT[ FLOW ] TRACE Exit");
- }
-
- @Test
- public void flowTracingMessage() {
- final Properties props = new Properties();
- props.setProperty("foo", "bar");
- logger.traceEntry(new JsonMessage(props));
- final Response response = new Response(-1, "Generic error");
- logger.traceExit(new JsonMessage(response), response);
- assertThat(results).hasSize(2);
- assertThat(results.get(0)).startsWith("ENTER[ FLOW ] TRACE Enter").contains("\"foo\":\"bar\"");
- assertThat(results.get(1)).startsWith("EXIT[ FLOW ] TRACE Exit").contains("\"message\":\"Generic error\"");
- }
-
- @Test
- public void flowTracingString_ObjectArray1() {
- logger.traceEntry("doFoo(a={}, b={})", 1, 2);
- logger.traceExit("doFoo(a=1, b=2): {}", 3);
- assertThat(results).hasSize(2);
- assertThat(results.get(0)).startsWith("ENTER[ FLOW ] TRACE Enter").contains("doFoo(a=1, b=2)");
- assertThat(results.get(1)).startsWith("EXIT[ FLOW ] TRACE Exit").contains("doFoo(a=1, b=2): 3");
- }
-
- @Test
- public void flowTracingExitValueOnly() {
- logger.traceEntry("doFoo(a={}, b={})", 1, 2);
- logger.traceExit(3);
- assertThat(results).hasSize(2);
- assertThat(results.get(0)).startsWith("ENTER[ FLOW ] TRACE Enter").contains("doFoo(a=1, b=2)");
- assertThat(results.get(1)).startsWith("EXIT[ FLOW ] TRACE Exit").contains("3");
- }
-
- @Test
- public void flowTracingString_ObjectArray2() {
- final EntryMessage msg = logger.traceEntry("doFoo(a={}, b={})", 1, 2);
- logger.traceExit(msg, 3);
- assertThat(results).hasSize(2);
- assertThat(results.get(0)).startsWith("ENTER[ FLOW ] TRACE Enter").contains("doFoo(a=1, b=2)");
- assertThat(results.get(1)).startsWith("EXIT[ FLOW ] TRACE Exit").contains("doFoo(a=1, b=2): 3");
- }
-
- @Test
- public void flowTracingVoidReturn() {
- final EntryMessage msg = logger.traceEntry("doFoo(a={}, b={})", 1, 2);
- logger.traceExit(msg);
- assertThat(results).hasSize(2);
- assertThat(results.get(0)).startsWith("ENTER[ FLOW ] TRACE Enter").contains("doFoo(a=1, b=2)");
- assertThat(results.get(1)).startsWith("EXIT[ FLOW ] TRACE Exit").endsWith("doFoo(a=1, b=2)");
- }
-
- @Test
- public void flowTracingNoExitArgs() {
- logger.traceEntry();
- logger.traceExit();
- assertThat(results).hasSize(2);
- assertThat(results.get(0)).startsWith("ENTER[ FLOW ] TRACE Enter");
- assertThat(results.get(1)).startsWith("EXIT[ FLOW ] TRACE Exit");
- }
-
- @Test
- public void flowTracingNoArgs() {
- final EntryMessage message = logger.traceEntry();
- logger.traceExit(message);
- assertThat(results).hasSize(2);
- assertThat(results.get(0)).startsWith("ENTER[ FLOW ] TRACE Enter");
- assertThat(results.get(1)).startsWith("EXIT[ FLOW ] TRACE Exit");
- }
-
- @Test
- public void flowTracingString_SupplierOfObjectMessages() {
- final EntryMessage msg = logger.traceEntry(
- "doFoo(a={}, b={})",
- new Supplier<Message>() {
- @Override
- public Message get() {
- return new ObjectMessage(1);
- }
- },
- new Supplier<Message>() {
- @Override
- public Message get() {
- return new ObjectMessage(2);
- }
- });
- logger.traceExit(msg, 3);
- assertThat(results).hasSize(2);
- assertThat(results.get(0)).startsWith("ENTER[ FLOW ] TRACE Enter").contains("doFoo(a=1, b=2)");
- assertThat(results.get(1)).startsWith("EXIT[ FLOW ] TRACE Exit").contains("doFoo(a=1, b=2): 3");
- }
-
- @Test
- public void flowTracingString_SupplierOfStrings() {
- final EntryMessage msg = logger.traceEntry(
- "doFoo(a={}, b={})",
- new Supplier<String>() {
- @Override
- public String get() {
- return "1";
- }
- },
- new Supplier<String>() {
- @Override
- public String get() {
- return "2";
- }
- });
- logger.traceExit(msg, 3);
- assertThat(results).hasSize(2);
- assertThat(results.get(0)).startsWith("ENTER[ FLOW ] TRACE Enter").contains("doFoo(a=1, b=2)");
- assertThat(results.get(1)).startsWith("EXIT[ FLOW ] TRACE Exit").contains("doFoo(a=1, b=2): 3");
- }
-
- @Test
- public void flowTracingNoFormat() {
- logger.traceEntry(null, 1, "2", new ObjectMessage(3));
- logger.traceExit((String) null, 4);
- assertThat(results).hasSize(2);
- assertThat(results.get(0)).isEqualTo("ENTER[ FLOW ] TRACE Enter params(1, 2, 3)");
- assertThat(results.get(1)).isEqualTo("EXIT[ FLOW ] TRACE Exit with(4)");
- }
-
- @Test
- public void catching() {
- try {
- throw new NullPointerException();
- } catch (final Exception e) {
- logger.catching(e);
- assertEquals(1, results.size());
- assertThat(
- "Incorrect Catching",
- results.get(0),
- startsWith("CATCHING[ EXCEPTION ] ERROR Catching java.lang.NullPointerException"));
- }
- }
-
- @Test
- public void debug() {
- logger.debug("Debug message");
- assertEquals(1, results.size());
- assertTrue(results.get(0).startsWith(" DEBUG Debug message"), "Incorrect message");
- }
-
- @Test
- public void debugObject() {
- logger.debug(new Date());
- assertEquals(1, results.size());
- assertTrue(results.get(0).length() > 7, "Invalid length");
- }
-
- @Test
- public void debugWithParms() {
- logger.debug("Hello, {}", "World");
- assertEquals(1, results.size());
- assertTrue(results.get(0).startsWith(" DEBUG Hello, World"), "Incorrect substitution");
- }
-
- @Test
- public void debugWithParmsAndThrowable() {
- logger.debug("Hello, {}", "World", new RuntimeException("Test Exception"));
- assertEquals(1, results.size());
- assertTrue(
- results.get(0).startsWith(" DEBUG Hello, World java.lang.RuntimeException: Test Exception"),
- "Unexpected results: " + results.get(0));
- }
-
- @Test
- @ResourceLock("log4j2.TestLogger")
- @ResourceLock(value = org.junit.jupiter.api.parallel.Resources.LOCALE, mode = ResourceAccessMode.READ)
- public void getFormatterLogger() {
- // The TestLogger logger was already created in an instance variable for this class.
- // The message factory is only used when the logger is created.
- final TestLogger testLogger = (TestLogger) LogManager.getFormatterLogger();
- final TestLogger altLogger = (TestLogger) LogManager.getFormatterLogger(getClass());
- assertEquals(testLogger.getName(), altLogger.getName());
- assertNotNull(testLogger);
- assertMessageFactoryInstanceOf(testLogger.getMessageFactory(), StringFormatterMessageFactory.class);
- assertEqualMessageFactory(StringFormatterMessageFactory.INSTANCE, testLogger);
- testLogger.debug("%,d", Integer.MAX_VALUE);
- assertEquals(1, testLogger.getEntries().size());
- assertEquals(
- String.format(" DEBUG %,d", Integer.MAX_VALUE),
- testLogger.getEntries().get(0));
- }
-
- @Test
- @ResourceLock("log4j2.TestLogger")
- @ResourceLock(value = org.junit.jupiter.api.parallel.Resources.LOCALE, mode = ResourceAccessMode.READ)
- public void getFormatterLogger_Class() {
- // The TestLogger logger was already created in an instance variable for this class.
- // The message factory is only used when the logger is created.
- final TestLogger testLogger =
- (TestLogger) LogManager.getFormatterLogger(TestStringFormatterMessageFactory.class);
- assertNotNull(testLogger);
- assertMessageFactoryInstanceOf(testLogger.getMessageFactory(), StringFormatterMessageFactory.class);
- assertEqualMessageFactory(StringFormatterMessageFactory.INSTANCE, testLogger);
- testLogger.debug("%,d", Integer.MAX_VALUE);
- assertEquals(1, testLogger.getEntries().size());
- assertEquals(
- String.format(" DEBUG %,d", Integer.MAX_VALUE),
- testLogger.getEntries().get(0));
- }
-
- private static void assertMessageFactoryInstanceOf(final MessageFactory factory, final Class<?> cls) {
- assertTrue(factory.getClass().isAssignableFrom(cls));
- }
-
- @Test
- @ResourceLock("log4j2.TestLogger")
- @ResourceLock(value = org.junit.jupiter.api.parallel.Resources.LOCALE, mode = ResourceAccessMode.READ)
- public void getFormatterLogger_Object() {
- // The TestLogger logger was already created in an instance variable for this class.
- // The message factory is only used when the logger is created.
- final TestLogger testLogger =
- (TestLogger) LogManager.getFormatterLogger(new TestStringFormatterMessageFactory());
- assertNotNull(testLogger);
- assertMessageFactoryInstanceOf(testLogger.getMessageFactory(), StringFormatterMessageFactory.class);
- assertEqualMessageFactory(StringFormatterMessageFactory.INSTANCE, testLogger);
- testLogger.debug("%,d", Integer.MAX_VALUE);
- assertEquals(1, testLogger.getEntries().size());
- assertEquals(
- String.format(" DEBUG %,d", Integer.MAX_VALUE),
- testLogger.getEntries().get(0));
- }
-
- @Test
- @ResourceLock("log4j2.TestLogger")
- @ResourceLock(value = org.junit.jupiter.api.parallel.Resources.LOCALE, mode = ResourceAccessMode.READ)
- public void getFormatterLogger_String() {
- final StringFormatterMessageFactory messageFactory = StringFormatterMessageFactory.INSTANCE;
- final TestLogger testLogger =
- (TestLogger) LogManager.getFormatterLogger("getLogger_String_StringFormatterMessageFactory");
- assertNotNull(testLogger);
- assertMessageFactoryInstanceOf(testLogger.getMessageFactory(), StringFormatterMessageFactory.class);
- assertEqualMessageFactory(messageFactory, testLogger);
- testLogger.debug("%,d", Integer.MAX_VALUE);
- assertEquals(1, testLogger.getEntries().size());
- assertEquals(
- String.format(" DEBUG %,d", Integer.MAX_VALUE),
- testLogger.getEntries().get(0));
- }
-
- @Test
- @ResourceLock("log4j2.TestLogger")
- public void getLogger_Class_ReusableMessageFactory() {
- // The TestLogger logger was already created in an instance variable for this class.
- // The message factory is only used when the logger is created.
- final MessageFactory messageFactory = new ReusableMessageFactory();
- final TestLogger testLogger =
- (TestLogger) LogManager.getLogger(TestReusableMessageFactory.class, messageFactory);
- assertNotNull(testLogger);
- assertEqualMessageFactory(messageFactory, testLogger);
- testLogger.debug("{}", Integer.MAX_VALUE);
- assertEquals(1, testLogger.getEntries().size());
- assertEquals(" DEBUG " + Integer.MAX_VALUE, testLogger.getEntries().get(0));
- }
-
- @Test
- @ResourceLock("log4j2.TestLogger")
- public void getLogger_Class_StringFormatterMessageFactory() {
- // The TestLogger logger was already created in an instance variable for this class.
- // The message factory is only used when the logger is created.
- final TestLogger testLogger = (TestLogger)
- LogManager.getLogger(TestStringFormatterMessageFactory.class, StringFormatterMessageFactory.INSTANCE);
- assertNotNull(testLogger);
- assertEqualMessageFactory(StringFormatterMessageFactory.INSTANCE, testLogger);
- testLogger.debug("%,d", Integer.MAX_VALUE);
- assertEquals(1, testLogger.getEntries().size());
- assertEquals(
- String.format(" DEBUG %,d", Integer.MAX_VALUE),
- testLogger.getEntries().get(0));
- }
-
- @Test
- @ResourceLock("log4j2.TestLogger")
- public void getLogger_Object_ReusableMessageFactory() {
- // The TestLogger logger was already created in an instance variable for this class.
- // The message factory is only used when the logger is created.
- final MessageFactory messageFactory = new ReusableMessageFactory();
- final TestLogger testLogger =
- (TestLogger) LogManager.getLogger(new TestReusableMessageFactory(), messageFactory);
- assertNotNull(testLogger);
- assertEqualMessageFactory(messageFactory, testLogger);
- testLogger.debug("{}", Integer.MAX_VALUE);
- assertEquals(1, testLogger.getEntries().size());
- assertEquals(" DEBUG " + Integer.MAX_VALUE, testLogger.getEntries().get(0));
- }
-
- private void assertEqualMessageFactory(final MessageFactory messageFactory, final TestLogger testLogger) {
- final MessageFactory actual = testLogger.getMessageFactory();
- assertEquals(messageFactory, actual);
- }
-
- @Test
- @ResourceLock("log4j2.TestLogger")
- public void getLogger_Object_StringFormatterMessageFactory() {
- // The TestLogger logger was already created in an instance variable for this class.
- // The message factory is only used when the logger is created.
- final StringFormatterMessageFactory messageFactory = StringFormatterMessageFactory.INSTANCE;
- final TestLogger testLogger =
- (TestLogger) LogManager.getLogger(new TestStringFormatterMessageFactory(), messageFactory);
- assertNotNull(testLogger);
- assertEqualMessageFactory(messageFactory, testLogger);
- testLogger.debug("%,d", Integer.MAX_VALUE);
- assertEquals(1, testLogger.getEntries().size());
- assertEquals(
- String.format(" DEBUG %,d", Integer.MAX_VALUE),
- testLogger.getEntries().get(0));
- }
-
- @Test
- @ResourceLock("log4j2.TestLogger")
- public void getLogger_String_MessageFactoryMismatch() {
- final StringFormatterMessageFactory messageFactory = StringFormatterMessageFactory.INSTANCE;
- final TestLogger testLogger =
- (TestLogger) LogManager.getLogger("getLogger_String_MessageFactoryMismatch", messageFactory);
- assertNotNull(testLogger);
- assertEqualMessageFactory(messageFactory, testLogger);
- final TestLogger testLogger2 = (TestLogger)
- LogManager.getLogger("getLogger_String_MessageFactoryMismatch", new ReusableMessageFactory());
- assertNotNull(testLogger2);
- // TODO: How to test?
- // This test context always creates new loggers, other test context impls I tried fail other tests.
- // assertEquals(messageFactory, testLogger2.getMessageFactory());
- testLogger.debug("%,d", Integer.MAX_VALUE);
- assertEquals(1, testLogger.getEntries().size());
- assertEquals(
- String.format(" DEBUG %,d", Integer.MAX_VALUE),
- testLogger.getEntries().get(0));
- }
-
- @Test
- @ResourceLock("log4j2.TestLogger")
- public void getLogger_String_ReusableMessageFactory() {
- final MessageFactory messageFactory = new ReusableMessageFactory();
- final TestLogger testLogger =
- (TestLogger) LogManager.getLogger("getLogger_String_ReusableMessageFactory", messageFactory);
- assertNotNull(testLogger);
- assertEqualMessageFactory(messageFactory, testLogger);
- testLogger.debug("{}", Integer.MAX_VALUE);
- assertEquals(1, testLogger.getEntries().size());
- assertEquals(" DEBUG " + Integer.MAX_VALUE, testLogger.getEntries().get(0));
- }
-
- @Test
- @ResourceLock("log4j2.TestLogger")
- public void getLogger_String_SimpleMessageFactory() {
- final SimpleMessageFactory messageFactory = SimpleMessageFactory.INSTANCE;
- final TestLogger testLogger =
- (TestLogger) LogManager.getLogger("getLogger_String_StringFormatterMessageFactory", messageFactory);
- assertNotNull(testLogger);
- assertEqualMessageFactory(messageFactory, testLogger);
- testLogger.debug("{} %,d {foo}", Integer.MAX_VALUE);
- assertEquals(1, testLogger.getEntries().size());
- assertEquals(" DEBUG {} %,d {foo}", testLogger.getEntries().get(0));
- }
-
- @Test
- @ResourceLock("log4j2.TestLogger")
- public void getLogger_String_StringFormatterMessageFactory() {
- final StringFormatterMessageFactory messageFactory = StringFormatterMessageFactory.INSTANCE;
- final TestLogger testLogger =
- (TestLogger) LogManager.getLogger("getLogger_String_StringFormatterMessageFactory", messageFactory);
- assertNotNull(testLogger);
- assertEqualMessageFactory(messageFactory, testLogger);
- testLogger.debug("%,d", Integer.MAX_VALUE);
- assertEquals(1, testLogger.getEntries().size());
- assertEquals(
- String.format(" DEBUG %,d", Integer.MAX_VALUE),
- testLogger.getEntries().get(0));
- }
-
- @Test
- public void getLoggerByClass() {
- final Logger classLogger = LogManager.getLogger(LoggerTest.class);
- assertNotNull(classLogger);
- }
-
- @Test
- public void getLoggerByNullClass() {
- // Returns a SimpleLogger
- assertNotNull(LogManager.getLogger((Class<?>) null));
- }
-
- @Test
- public void getLoggerByNullObject() {
- // Returns a SimpleLogger
- assertNotNull(LogManager.getLogger((Object) null));
- }
-
- @Test
- public void getLoggerByNullString() {
- // Returns a SimpleLogger
- assertNotNull(LogManager.getLogger((String) null));
- }
-
- @Test
- public void getLoggerByObject() {
- final Logger classLogger = LogManager.getLogger(this);
- assertNotNull(classLogger);
- assertEquals(classLogger, LogManager.getLogger(LoggerTest.class));
- }
-
- @Test
- public void getRootLogger() {
- assertNotNull(LogManager.getRootLogger());
- assertNotNull(LogManager.getLogger(Strings.EMPTY));
- assertNotNull(LogManager.getLogger(LogManager.ROOT_LOGGER_NAME));
- assertEquals(LogManager.getRootLogger(), LogManager.getLogger(Strings.EMPTY));
- assertEquals(LogManager.getRootLogger(), LogManager.getLogger(LogManager.ROOT_LOGGER_NAME));
- }
-
- @Test
- public void isAllEnabled() {
- assertTrue(logger.isEnabled(Level.ALL), "Incorrect level");
- }
-
- @Test
- public void isDebugEnabled() {
- assertTrue(logger.isDebugEnabled(), "Incorrect level");
- assertTrue(logger.isEnabled(Level.DEBUG), "Incorrect level");
- }
-
- @Test
- public void isErrorEnabled() {
- assertTrue(logger.isErrorEnabled(), "Incorrect level");
- assertTrue(logger.isEnabled(Level.ERROR), "Incorrect level");
- }
-
- @Test
- public void isFatalEnabled() {
- assertTrue(logger.isFatalEnabled(), "Incorrect level");
- assertTrue(logger.isEnabled(Level.FATAL), "Incorrect level");
- }
-
- @Test
- public void isInfoEnabled() {
- assertTrue(logger.isInfoEnabled(), "Incorrect level");
- assertTrue(logger.isEnabled(Level.INFO), "Incorrect level");
- }
-
- @Test
- public void isOffEnabled() {
- assertTrue(logger.isEnabled(Level.OFF), "Incorrect level");
- }
-
- @Test
- public void isTraceEnabled() {
- assertTrue(logger.isTraceEnabled(), "Incorrect level");
- assertTrue(logger.isEnabled(Level.TRACE), "Incorrect level");
- }
-
- @Test
- public void isWarnEnabled() {
- assertTrue(logger.isWarnEnabled(), "Incorrect level");
- assertTrue(logger.isEnabled(Level.WARN), "Incorrect level");
- }
-
- @Test
- public void isAllEnabledWithMarker() {
- assertTrue(logger.isEnabled(Level.ALL, marker), "Incorrect level");
- }
-
- @Test
- public void isDebugEnabledWithMarker() {
- assertTrue(logger.isDebugEnabled(marker), "Incorrect level");
- assertTrue(logger.isEnabled(Level.DEBUG, marker), "Incorrect level");
- }
-
- @Test
- public void isErrorEnabledWithMarker() {
- assertTrue(logger.isErrorEnabled(marker), "Incorrect level");
- assertTrue(logger.isEnabled(Level.ERROR, marker), "Incorrect level");
- }
-
- @Test
- public void isFatalEnabledWithMarker() {
- assertTrue(logger.isFatalEnabled(marker), "Incorrect level");
- assertTrue(logger.isEnabled(Level.FATAL, marker), "Incorrect level");
- }
-
- @Test
- public void isInfoEnabledWithMarker() {
- assertTrue(logger.isInfoEnabled(marker), "Incorrect level");
- assertTrue(logger.isEnabled(Level.INFO, marker), "Incorrect level");
- }
-
- @Test
- public void isOffEnabledWithMarker() {
- assertTrue(logger.isEnabled(Level.OFF, marker), "Incorrect level");
- }
-
- @Test
- public void isTraceEnabledWithMarker() {
- assertTrue(logger.isTraceEnabled(marker), "Incorrect level");
- assertTrue(logger.isEnabled(Level.TRACE, marker), "Incorrect level");
- }
-
- @Test
- public void isWarnEnabledWithMarker() {
- assertTrue(logger.isWarnEnabled(marker), "Incorrect level");
- assertTrue(logger.isEnabled(Level.WARN, marker), "Incorrect level");
- }
-
- @Test
- @UsingThreadContextMap
- public void mdc() {
- ThreadContext.put("TestYear", Integer.valueOf(2010).toString());
- logger.debug("Debug message");
- final String testYear = ThreadContext.get("TestYear");
- assertNotNull(testYear, "Test Year is null");
- assertEquals("2010", testYear, "Incorrect test year: " + testYear);
- ThreadContext.clearMap();
- logger.debug("Debug message");
- assertEquals(2, results.size());
- System.out.println("Log line 1: " + results.get(0));
- System.out.println("log line 2: " + results.get(1));
- assertTrue(
- results.get(0).startsWith(" DEBUG Debug message {TestYear=2010}"), "Incorrect MDC: " + results.get(0));
- assertTrue(results.get(1).startsWith(" DEBUG Debug message"), "MDC not cleared?: " + results.get(1));
- }
-
- @Test
- public void printf() {
- logger.printf(Level.DEBUG, "Debug message %d", 1);
- logger.printf(Level.DEBUG, MarkerManager.getMarker("Test"), "Debug message %d", 2);
- assertEquals(2, results.size());
- assertThat("Incorrect message", results.get(0), startsWith(" DEBUG Debug message 1"));
- assertThat("Incorrect message", results.get(1), startsWith("Test DEBUG Debug message 2"));
- }
-
- @BeforeEach
- public void setup() {
- results.clear();
- }
-
- @Test
- public void structuredData() {
- ThreadContext.put("loginId", "JohnDoe");
- ThreadContext.put("ipAddress", "192.168.0.120");
- ThreadContext.put("locale", Locale.US.getDisplayName());
- final StructuredDataMessage msg = new StructuredDataMessage("Audit@18060", "Transfer Complete", "Transfer");
- msg.put("ToAccount", "123456");
- msg.put("FromAccount", "123457");
- msg.put("Amount", "200.00");
- logger.info(MarkerManager.getMarker("EVENT"), msg);
- ThreadContext.clearMap();
- assertEquals(1, results.size());
- assertThat(
- "Incorrect structured data: ",
- results.get(0),
- startsWith(
- "EVENT INFO Transfer [Audit@18060 Amount=\"200.00\" FromAccount=\"123457\" ToAccount=\"123456\"] Transfer Complete"));
- }
-
- @Test
- public void throwing() {
- logger.throwing(new IllegalArgumentException("Test Exception"));
- assertEquals(1, results.size());
- assertThat(
- "Incorrect Throwing",
- results.get(0),
- startsWith("THROWING[ EXCEPTION ] ERROR Throwing java.lang.IllegalArgumentException: Test Exception"));
- }
-
- private static class Response {
- int status;
- String message;
-
- public Response(final int status, final String message) {
- this.status = status;
- this.message = message;
- }
-
- public int getStatus() {
- return status;
- }
-
- public void setStatus(final int status) {
- this.status = status;
- }
-
- public String getMessage() {
- return message;
- }
-
- public void setMessage(final String message) {
- this.message = message;
- }
- }
-}
diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/MarkerTest.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/MarkerTest.java
deleted file mode 100644
index 598aac9388..0000000000
--- a/log4j-api-test/src/test/java/org/apache/logging/log4j/MarkerTest.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * 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;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import org.apache.logging.log4j.test.junit.Resources;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.parallel.ResourceAccessMode;
-import org.junit.jupiter.api.parallel.ResourceLock;
-
-@ResourceLock(value = Resources.MARKER_MANAGER, mode = ResourceAccessMode.READ_WRITE)
-public class MarkerTest {
-
- @BeforeEach
- public void setUp() {
- MarkerManager.clear();
- }
-
- @Test
- public void testGetMarker() {
- final Marker expected = MarkerManager.getMarker("A");
- assertNull(expected.getParents());
- }
-
- @Test
- public void testGetMarkerWithParents() {
- final Marker expected = MarkerManager.getMarker("A");
- final Marker p1 = MarkerManager.getMarker("P1");
- p1.addParents(MarkerManager.getMarker("PP1"));
- final Marker p2 = MarkerManager.getMarker("P2");
- expected.addParents(p1);
- expected.addParents(p2);
- assertEquals(2, expected.getParents().length);
- }
-
- @Test
- public void testHasParents() {
- final Marker parent = MarkerManager.getMarker("PARENT");
- final Marker existing = MarkerManager.getMarker("EXISTING");
- assertFalse(existing.hasParents());
- existing.setParents(parent);
- assertTrue(existing.hasParents());
- }
-
- @Test
- public void testMarker() {
- final Marker parent = MarkerManager.getMarker("PARENT");
- final Marker test1 = MarkerManager.getMarker("TEST1").setParents(parent);
- final Marker test2 = MarkerManager.getMarker("TEST2").addParents(parent);
- assertTrue(test1.isInstanceOf(parent), "TEST1 is not an instance of PARENT");
- assertTrue(test2.isInstanceOf(parent), "TEST2 is not an instance of PARENT");
- }
-
- @Test
- public void testMultipleParents() {
- final Marker parent1 = MarkerManager.getMarker("PARENT1");
- final Marker parent2 = MarkerManager.getMarker("PARENT2");
- final Marker test1 = MarkerManager.getMarker("TEST1").setParents(parent1, parent2);
- final Marker test2 = MarkerManager.getMarker("TEST2").addParents(parent1, parent2);
- assertTrue(test1.isInstanceOf(parent1), "TEST1 is not an instance of PARENT1");
- assertTrue(test1.isInstanceOf(parent2), "TEST1 is not an instance of PARENT2");
- assertTrue(test2.isInstanceOf(parent1), "TEST2 is not an instance of PARENT1");
- assertTrue(test2.isInstanceOf(parent2), "TEST2 is not an instance of PARENT2");
- }
-
- @Test
- public void testAddToExistingParents() {
- final Marker parent = MarkerManager.getMarker("PARENT");
- final Marker existing = MarkerManager.getMarker("EXISTING");
- final Marker test1 = MarkerManager.getMarker("TEST1").setParents(existing);
- test1.addParents(parent);
- assertTrue(test1.isInstanceOf(parent), "TEST1 is not an instance of PARENT");
- assertTrue(test1.isInstanceOf(existing), "TEST1 is not an instance of EXISTING");
- }
-
- @Test
- public void testDuplicateParents() {
- final Marker parent = MarkerManager.getMarker("PARENT");
- final Marker existing = MarkerManager.getMarker("EXISTING");
- final Marker test1 = MarkerManager.getMarker("TEST1").setParents(existing);
- test1.addParents(parent);
- final Marker[] parents = test1.getParents();
- test1.addParents(existing);
- assertEquals(parents.length, test1.getParents().length, "duplicate add allowed");
- test1.addParents(existing, MarkerManager.getMarker("EXTRA"));
- assertEquals(parents.length + 1, test1.getParents().length, "incorrect add");
- assertTrue(test1.isInstanceOf(parent), "TEST1 is not an instance of PARENT");
- assertTrue(test1.isInstanceOf(existing), "TEST1 is not an instance of EXISTING");
- }
-}
diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/NoopThreadContextTest.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/NoopThreadContextTest.java
deleted file mode 100644
index ef51fdf7d3..0000000000
--- a/log4j-api-test/src/test/java/org/apache/logging/log4j/NoopThreadContextTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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;
-
-import static org.junit.jupiter.api.Assertions.assertNull;
-
-import org.apache.logging.log4j.spi.LoggingSystemProperty;
-import org.apache.logging.log4j.test.junit.InitializesThreadContext;
-import org.apache.logging.log4j.test.junit.UsingThreadContextMap;
-import org.junit.jupiter.api.Test;
-import org.junitpioneer.jupiter.SetSystemProperty;
-
-/**
- * Tests {@link ThreadContext}.
- */
-public class NoopThreadContextTest {
-
- @Test
- @SetSystemProperty(key = LoggingSystemProperty.Constant.THREAD_CONTEXT_ENABLED, value = "false")
- @SetSystemProperty(key = LoggingSystemProperty.Constant.THREAD_CONTEXT_MAP_ENABLED, value = "false")
- @InitializesThreadContext
- @UsingThreadContextMap
- public void testNoop() {
- ThreadContext.put("Test", "Test");
- final String value = ThreadContext.get("Test");
- assertNull(value, "value was saved");
- }
-}
diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/TestProvider.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/TestProvider.java
deleted file mode 100644
index 1fb46b581c..0000000000
--- a/log4j-api-test/src/test/java/org/apache/logging/log4j/TestProvider.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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;
-
-import org.apache.logging.log4j.spi.Provider;
-import org.apache.logging.log4j.test.TestLoggerContextFactory;
-
-/**
- * Binding for the Log4j API.
- */
-public class TestProvider extends Provider {
- public TestProvider() {
- super(0, "3.0.0", TestLoggerContextFactory.class);
- }
-}
diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/ThreadContextInheritanceTest.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/ThreadContextInheritanceTest.java
deleted file mode 100644
index 08f216ba90..0000000000
--- a/log4j-api-test/src/test/java/org/apache/logging/log4j/ThreadContextInheritanceTest.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * 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;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import org.apache.logging.log4j.spi.LoggingSystemProperty;
-import org.apache.logging.log4j.test.ThreadContextUtilityClass;
-import org.apache.logging.log4j.test.junit.InitializesThreadContext;
-import org.apache.logging.log4j.test.junit.UsingThreadContextMap;
-import org.apache.logging.log4j.test.junit.UsingThreadContextStack;
-import org.junit.jupiter.api.Tag;
-import org.junit.jupiter.api.Test;
-import org.junitpioneer.jupiter.SetSystemProperty;
-
-/**
- * Tests {@link ThreadContext}.
- */
-@SetSystemProperty(key = LoggingSystemProperty.Constant.THREAD_CONTEXT_MAP_INHERITABLE, value = "true")
-@InitializesThreadContext
-public class ThreadContextInheritanceTest {
-
- @Test
- @UsingThreadContextStack
- public void testPush() {
- ThreadContext.push("Hello");
- ThreadContext.push("{} is {}", ThreadContextInheritanceTest.class.getSimpleName(), "running");
- assertEquals(
- ThreadContext.pop(), "ThreadContextInheritanceTest is running", "Incorrect parameterized stack value");
- assertEquals(ThreadContext.pop(), "Hello", "Incorrect simple stack value");
- }
-
- @Test
- @SetSystemProperty(key = LoggingSystemProperty.Constant.THREAD_CONTEXT_MAP_INHERITABLE, value = "true")
- @InitializesThreadContext
- public void testInheritanceSwitchedOn() throws Exception {
- ThreadContext.put("Greeting", "Hello");
- StringBuilder sb = new StringBuilder();
- TestThread thread = new TestThread(sb);
- thread.start();
- thread.join();
- String str = sb.toString();
- assertEquals("Hello", str, "Unexpected ThreadContext value. Expected Hello. Actual " + str);
- sb = new StringBuilder();
- thread = new TestThread(sb);
- thread.start();
- thread.join();
- str = sb.toString();
- assertEquals("Hello", str, "Unexpected ThreadContext value. Expected Hello. Actual " + str);
- }
-
- @Test
- @Tag("performance")
- @UsingThreadContextMap
- public void perfTest() {
- ThreadContextUtilityClass.perfTest();
- }
-
- @Test
- @UsingThreadContextMap
- public void testGetContextReturnsEmptyMapIfEmpty() {
- ThreadContextUtilityClass.testGetContextReturnsEmptyMapIfEmpty();
- }
-
- @Test
- @UsingThreadContextMap
- public void testGetContextReturnsMutableCopy() {
- ThreadContextUtilityClass.testGetContextReturnsMutableCopy();
- }
-
- @Test
- @UsingThreadContextMap
- public void testGetImmutableContextReturnsEmptyMapIfEmpty() {
- ThreadContextUtilityClass.testGetImmutableContextReturnsEmptyMapIfEmpty();
- }
-
- @Test
- @UsingThreadContextMap
- public void testGetImmutableContextReturnsImmutableMapIfNonEmpty() {
- ThreadContextUtilityClass.testGetImmutableContextReturnsImmutableMapIfNonEmpty();
- }
-
- @Test
- @UsingThreadContextMap
- public void testGetImmutableContextReturnsImmutableMapIfEmpty() {
- ThreadContextUtilityClass.testGetImmutableContextReturnsImmutableMapIfEmpty();
- }
-
- @Test
- @UsingThreadContextStack
- public void testGetImmutableStackReturnsEmptyStackIfEmpty() {
- ThreadContextUtilityClass.testGetImmutableStackReturnsEmptyStackIfEmpty();
- }
-
- @Test
- @UsingThreadContextMap
- public void testPut() {
- ThreadContextUtilityClass.testPut();
- }
-
- @Test
- @UsingThreadContextMap
- public void testRemove() {
- assertNull(ThreadContext.get("testKey"));
- ThreadContext.put("testKey", "testValue");
- assertEquals("testValue", ThreadContext.get("testKey"));
-
- ThreadContext.remove("testKey");
- assertNull(ThreadContext.get("testKey"));
- assertTrue(ThreadContext.isEmpty());
- }
-
- @Test
- @UsingThreadContextMap
- public void testContainsKey() {
- assertFalse(ThreadContext.containsKey("testKey"));
- ThreadContext.put("testKey", "testValue");
- assertTrue(ThreadContext.containsKey("testKey"));
-
- ThreadContext.remove("testKey");
- assertFalse(ThreadContext.containsKey("testKey"));
- }
-
- private static class TestThread extends Thread {
-
- private final StringBuilder sb;
-
- public TestThread(final StringBuilder sb) {
- this.sb = sb;
- }
-
- @Override
- public void run() {
- final String greeting = ThreadContext.get("Greeting");
- if (greeting == null) {
- sb.append("null");
- } else {
- sb.append(greeting);
- }
- ThreadContext.clearMap();
- }
- }
-}
diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/TraceLoggingTest.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/TraceLoggingTest.java
deleted file mode 100644
index dcdd6bd4cf..0000000000
--- a/log4j-api-test/src/test/java/org/apache/logging/log4j/TraceLoggingTest.java
+++ /dev/null
@@ -1,381 +0,0 @@
-/*
- * 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;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
-
-import org.apache.logging.log4j.message.DefaultFlowMessageFactory;
-import org.apache.logging.log4j.message.EntryMessage;
-import org.apache.logging.log4j.message.FlowMessageFactory;
-import org.apache.logging.log4j.message.Message;
-import org.apache.logging.log4j.message.ObjectMessage;
-import org.apache.logging.log4j.message.ParameterizedMessage;
-import org.apache.logging.log4j.message.ReusableParameterizedMessage;
-import org.apache.logging.log4j.message.ReusableParameterizedMessageTest;
-import org.apache.logging.log4j.message.SimpleMessage;
-import org.apache.logging.log4j.spi.AbstractLogger;
-import org.junit.jupiter.api.Test;
-
-public class TraceLoggingTest extends AbstractLogger {
- static final StringBuilder CHAR_SEQ = new StringBuilder("CharSeq");
- private int charSeqCount;
- private int objectCount;
-
- private static class LogEvent {
-
- String markerName;
- Message data;
- Throwable t;
-
- public LogEvent(final String markerName, final Message data, final Throwable t) {
- this.markerName = markerName;
- this.data = data;
- this.t = t;
- }
- }
-
- private static final long serialVersionUID = 1L;
-
- private static Level currentLevel;
-
- private LogEvent currentEvent;
-
- private static final Throwable t = new UnsupportedOperationException("Test");
-
- private static final Class<AbstractLogger> obj = AbstractLogger.class;
- private static final String pattern = "{}, {}";
- private static final String p1 = "Long Beach";
-
- private static final String p2 = "California";
- private static final Message charSeq = new SimpleMessage(CHAR_SEQ);
- private static final Message simple = new SimpleMessage("Hello");
- private static final Message object = new ObjectMessage(obj);
-
- private static final Message param = new ParameterizedMessage(pattern, p1, p2);
-
- private static final String marker = "TEST";
-
- @Override
- public Level getLevel() {
- return currentLevel;
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final Message data, final Throwable t) {
- return true;
- // assertTrue("Incorrect Level. Expected " + currentLevel + ", actual " + level,
- // level.equals(currentLevel));
- // if (marker == null) {
- // if (currentEvent.markerName != null) {
- // fail("Incorrect marker. Expected " + currentEvent.markerName + ", actual is null");
- // }
- // } else {
- // if (currentEvent.markerName == null) {
- // fail("Incorrect marker. Expected null. Actual is " + marker.getName());
- // } else {
- // assertTrue("Incorrect marker. Expected " + currentEvent.markerName + ", actual " +
- // marker.getName(), currentEvent.markerName.equals(marker.getName()));
- // }
- // }
- // if (data == null) {
- // if (currentEvent.data != null) {
- // fail("Incorrect message. Expected " + currentEvent.data + ", actual is null");
- // }
- // } else {
- // if (currentEvent.data == null) {
- // fail("Incorrect message. Expected null. Actual is " + data.getFormattedMessage());
- // } else {
- // assertTrue("Incorrect message type. Expected " + currentEvent.data + ", actual " + data,
- // data.getClass().isAssignableFrom(currentEvent.data.getClass()));
- // assertTrue("Incorrect message. Expected " + currentEvent.data.getFormattedMessage() + ",
- // actual " +
- // data.getFormattedMessage(),
- // currentEvent.data.getFormattedMessage().equals(data.getFormattedMessage()));
- // }
- // }
- // if (t == null) {
- // if (currentEvent.t != null) {
- // fail("Incorrect Throwable. Expected " + currentEvent.t + ", actual is null");
- // }
- // } else {
- // if (currentEvent.t == null) {
- // fail("Incorrect Throwable. Expected null. Actual is " + t);
- // } else {
- // assertTrue("Incorrect Throwable. Expected " + currentEvent.t + ", actual " + t,
- // currentEvent.t.equals(t));
- // }
- // }
- // return true;
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final CharSequence data, final Throwable t) {
- charSeqCount++;
- return isEnabled(level, marker, (Message) new SimpleMessage(data), t);
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final Object data, final Throwable t) {
- objectCount++;
- return isEnabled(level, marker, new ObjectMessage(data), t);
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final String data) {
- return isEnabled(level, marker, (Message) new SimpleMessage(data), null);
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final String data, final Object... p1) {
- return isEnabled(level, marker, new ParameterizedMessage(data, p1), null);
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0) {
- return isEnabled(level, marker, new ParameterizedMessage(message, p0), null);
- }
-
- @Override
- public boolean isEnabled(
- final Level level, final Marker marker, final String message, final Object p0, final Object p1) {
- return isEnabled(level, marker, new ParameterizedMessage(message, p0, p1), null);
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2) {
- return isEnabled(level, marker, new ParameterizedMessage(message, p0, p1, p2), null);
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3) {
- return isEnabled(level, marker, new ParameterizedMessage(message, p0, p1, p2, p3), null);
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3,
- final Object p4) {
- return isEnabled(level, marker, new ParameterizedMessage(message, p0, p1, p2, p3, p4), null);
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3,
- final Object p4,
- final Object p5) {
- return isEnabled(level, marker, new ParameterizedMessage(message, p0, p1, p2, p3, p4, p5), null);
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3,
- final Object p4,
- final Object p5,
- final Object p6) {
- return isEnabled(level, marker, new ParameterizedMessage(message, p0, p1, p2, p3, p4, p5, p6), null);
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3,
- final Object p4,
- final Object p5,
- final Object p6,
- final Object p7) {
- return isEnabled(level, marker, new ParameterizedMessage(message, p0, p1, p2, p3, p4, p5, p6, p7), null);
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3,
- final Object p4,
- final Object p5,
- final Object p6,
- final Object p7,
- final Object p8) {
- return isEnabled(level, marker, new ParameterizedMessage(message, p0, p1, p2, p3, p4, p5, p6, p7, p8), null);
- }
-
- @Override
- public boolean isEnabled(
- final Level level,
- final Marker marker,
- final String message,
- final Object p0,
- final Object p1,
- final Object p2,
- final Object p3,
- final Object p4,
- final Object p5,
- final Object p6,
- final Object p7,
- final Object p8,
- final Object p9) {
- return isEnabled(
- level, marker, new ParameterizedMessage(message, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9), null);
- }
-
- @Override
- public boolean isEnabled(final Level level, final Marker marker, final String data, final Throwable t) {
- return isEnabled(level, marker, (Message) new SimpleMessage(data), t);
- }
-
- @Override
- public void logMessage(
- final String fqcn, final Level level, final Marker marker, final Message data, final Throwable t) {
- assertEquals(level, currentLevel, "Incorrect Level. Expected " + currentLevel + ", actual " + level);
- if (marker == null) {
- if (currentEvent.markerName != null) {
- fail("Incorrect marker. Expected " + currentEvent.markerName + ", actual is null");
- }
- } else {
- if (currentEvent.markerName == null) {
- fail("Incorrect marker. Expected null. Actual is " + marker.getName());
- } else {
- assertEquals(
- currentEvent.markerName,
- marker.getName(),
- "Incorrect marker. Expected " + currentEvent.markerName + ", actual " + marker.getName());
- }
- }
- if (data == null) {
- if (currentEvent.data != null) {
- fail("Incorrect message. Expected " + currentEvent.data + ", actual is null");
- }
- } else {
- if (currentEvent.data == null) {
- fail("Incorrect message. Expected null. Actual is " + data.getFormattedMessage());
- } else {
- assertTrue(
- data.getClass().isAssignableFrom(currentEvent.data.getClass()),
- "Incorrect message type. Expected " + currentEvent.data + ", actual " + data);
- assertEquals(
- currentEvent.data.getFormattedMessage(),
- data.getFormattedMessage(),
- "Incorrect message. Expected " + currentEvent.data.getFormattedMessage() + ", actual "
- + data.getFormattedMessage());
- }
- }
- if (t == null) {
- if (currentEvent.t != null) {
- fail("Incorrect Throwable. Expected " + currentEvent.t + ", actual is null");
- }
- } else {
- if (currentEvent.t == null) {
- fail("Incorrect Throwable. Expected null. Actual is " + t);
- } else {
- assertEquals(currentEvent.t, t, "Incorrect Throwable. Expected " + currentEvent.t + ", actual " + t);
- }
- }
- }
-
- @Test
- public void testTraceEntryExit() {
- currentLevel = Level.TRACE;
- final FlowMessageFactory fact = new DefaultFlowMessageFactory();
-
- final ParameterizedMessage paramMsg = new ParameterizedMessage("Tracy {}", "Logan");
- currentEvent = new LogEvent(ENTRY_MARKER.getName(), fact.newEntryMessage(paramMsg), null);
- final EntryMessage entry = traceEntry("Tracy {}", "Logan");
-
- final ReusableParameterizedMessage msg =
- ReusableParameterizedMessageTest.set(new ReusableParameterizedMessage(), "Tracy {}", "Logan");
- ReusableParameterizedMessageTest.set(msg, "Some other message {}", 123);
- currentEvent = new LogEvent(null, msg, null);
- trace("Some other message {}", 123);
-
- // ensure original entry message not overwritten
- assertEquals("Tracy Logan", entry.getMessage().getFormattedMessage());
-
- currentEvent = new LogEvent(EXIT_MARKER.getName(), fact.newExitMessage(entry), null);
- traceExit(entry);
-
- // ensure original entry message not overwritten
- assertEquals("Tracy Logan", entry.getMessage().getFormattedMessage());
- }
-
- @Test
- public void testTraceEntryMessage() {
- currentLevel = Level.TRACE;
- final FlowMessageFactory fact = new DefaultFlowMessageFactory();
-
- final ParameterizedMessage paramMsg = new ParameterizedMessage("Tracy {}", "Logan");
- currentEvent = new LogEvent(ENTRY_MARKER.getName(), fact.newEntryMessage(paramMsg), null);
-
- final ReusableParameterizedMessage msg =
- ReusableParameterizedMessageTest.set(new ReusableParameterizedMessage(), "Tracy {}", "Logan");
- final EntryMessage entry = traceEntry(msg);
-
- ReusableParameterizedMessageTest.set(msg, "Some other message {}", 123);
- currentEvent = new LogEvent(null, msg, null);
- trace("Some other message {}", 123);
-
- // ensure original entry message not overwritten
- assertEquals("Tracy Logan", entry.getMessage().getFormattedMessage());
-
- currentEvent = new LogEvent(EXIT_MARKER.getName(), fact.newExitMessage(entry), null);
- traceExit(entry);
-
- // ensure original entry message not overwritten
- assertEquals("Tracy Logan", entry.getMessage().getFormattedMessage());
- }
-}
diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/internal/DefaultLogBuilderTest.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/internal/DefaultLogBuilderTest.java
deleted file mode 100644
index 3ed88257cb..0000000000
--- a/log4j-api-test/src/test/java/org/apache/logging/log4j/internal/DefaultLogBuilderTest.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.internal;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.util.Arrays;
-import java.util.List;
-import org.apache.logging.log4j.LogBuilder;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.test.TestLogger;
-import org.junit.jupiter.api.Test;
-
-public class DefaultLogBuilderTest {
-
- private final TestLogger logger1 = (TestLogger) LogManager.getLogger(DefaultLogBuilderTest.class);
- private final TestLogger logger2 = (TestLogger) LogManager.getLogger("second.logger");
-
- @Test
- public void testConcurrentUsage() {
- logger1.getEntries().clear();
- logger2.getEntries().clear();
- final List<LogBuilder> logBuilders =
- Arrays.asList(logger1.atDebug(), logger1.atInfo(), logger2.atDebug(), logger2.atInfo());
- logBuilders.forEach(logBuilder -> logBuilder.log("Hello LogBuilder!"));
- assertThat(logger1.getEntries())
- .hasSize(2)
- .containsExactly(" DEBUG Hello LogBuilder!", " INFO Hello LogBuilder!");
- assertThat(logger2.getEntries())
- .hasSize(2)
- .containsExactly(" DEBUG Hello LogBuilder!", " INFO Hello LogBuilder!");
- }
-}
diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/internal/recycler/ArrayQueueTest.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/internal/recycler/ArrayQueueTest.java
deleted file mode 100644
index 2ded8ff7a8..0000000000
--- a/log4j-api-test/src/test/java/org/apache/logging/log4j/internal/recycler/ArrayQueueTest.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * 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.internal.recycler;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-
-import java.util.Queue;
-import java.util.Random;
-import java.util.concurrent.ArrayBlockingQueue;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.CsvSource;
-import org.junit.jupiter.params.provider.ValueSource;
-
-public class ArrayQueueTest {
-
- @ParameterizedTest
- @ValueSource(ints = {-1, 0})
- void invalid_capacity_should_not_be_allowed(final int invalidCapacity) {
- assertThatThrownBy(() -> new ArrayQueue<>(invalidCapacity))
- .isInstanceOf(IllegalArgumentException.class)
- .hasMessage("invalid capacity: " + invalidCapacity);
- }
-
- @Test
- void should_work_with_capacity_1() {
-
- // Verify initials
- final Queue<String> queue = new ArrayQueue<>(1);
- assertThat(queue.size()).isEqualTo(0);
- assertThat(queue.peek()).isNull();
- assertThat(queue.poll()).isNull();
- assertThat(queue).isEmpty();
-
- // Verify enqueue & deque
- assertThat(queue.offer("foo")).isTrue();
- assertThat(queue.offer("bar")).isFalse();
- assertThat(queue.size()).isEqualTo(1);
- assertThat(queue).containsOnly("foo");
- assertThat(queue.peek()).isEqualTo("foo");
- assertThat(queue.poll()).isEqualTo("foo");
-
- // Verify final state
- assertThat(queue.size()).isEqualTo(0);
- assertThat(queue.peek()).isNull();
- assertThat(queue.poll()).isNull();
- assertThat(queue).isEmpty();
- }
-
- @ParameterizedTest
- @CsvSource({
- "1,0.3", "1,0.5", "1,0.8", "2,0.3", "2,0.5", "2,0.8", "3,0.3", "3,0.5", "3,0.8", "4,0.3", "4,0.5", "4,0.8"
- })
- void ops_should_match_with_std_lib(final int capacity, final double pollRatio) {
-
- // Set the stage
- final Random random = new Random(0);
- final int opCount = random.nextInt(100);
- final Queue<String> queueRef = new ArrayBlockingQueue<>(capacity);
- final Queue<String> queueTarget = new ArrayQueue<>(capacity);
-
- for (int opIndex = 0; opIndex < opCount; opIndex++) {
-
- // Verify entry
- assertThat(queueTarget.size()).isEqualTo(queueRef.size());
- assertThat(queueTarget.peek()).isEqualTo(queueRef.peek());
- assertThat(queueTarget).containsExactlyElementsOf(queueRef);
-
- // Is this a `poll()`?
- if (pollRatio >= random.nextDouble()) {
- assertThat(queueTarget.poll()).isEqualTo(queueRef.poll());
- }
-
- // Then this is an `offer()`
- else {
- final String item = "op@" + opIndex;
- assertThat(queueTarget.offer(item)).isEqualTo(queueRef.offer(item));
- }
-
- // Verify exit
- assertThat(queueTarget.size()).isEqualTo(queueRef.size());
- assertThat(queueTarget.peek()).isEqualTo(queueRef.peek());
- assertThat(queueTarget).containsExactlyElementsOf(queueRef);
- }
- }
-}
diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/internal/recycler/RecyclerFactoryRegistryTest.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/internal/recycler/RecyclerFactoryRegistryTest.java
deleted file mode 100644
index f6684f63cc..0000000000
--- a/log4j-api-test/src/test/java/org/apache/logging/log4j/internal/recycler/RecyclerFactoryRegistryTest.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * 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.internal.recycler;
-
-import static org.apache.logging.log4j.internal.recycler.RecyclerFactoryTestUtil.createForEnvironment;
-import static org.apache.logging.log4j.spi.recycler.Recycler.DEFAULT_CAPACITY;
-import static org.assertj.core.api.Assertions.assertThat;
-
-import org.apache.logging.log4j.internal.recycler.DummyRecyclerFactoryProvider.DummyRecyclerFactory;
-import org.apache.logging.log4j.internal.recycler.QueueingRecyclerFactoryProvider.QueueingRecyclerFactory;
-import org.apache.logging.log4j.internal.recycler.ThreadLocalRecyclerFactoryProvider.ThreadLocalRecyclerFactory;
-import org.apache.logging.log4j.spi.recycler.RecyclerFactory;
-import org.apache.logging.log4j.spi.recycler.RecyclerFactoryProvider;
-import org.assertj.core.api.InstanceOfAssertFactories;
-import org.junit.jupiter.api.Test;
-
-public class RecyclerFactoryRegistryTest {
-
- @Test
- void DummyRecyclerFactory_should_work() {
- final RecyclerFactory factory = createForEnvironment(null, "dummy", null);
- assertThat(factory).isInstanceOf(DummyRecyclerFactory.class);
- }
-
- @Test
- void ThreadLocalRecyclerFactory_should_work() {
- final RecyclerFactory factory = createForEnvironment(null, "threadLocal", null);
- assertThat(factory)
- .asInstanceOf(InstanceOfAssertFactories.type(ThreadLocalRecyclerFactory.class))
- .extracting(factory_ -> factory_.capacity)
- .isEqualTo(DEFAULT_CAPACITY);
- }
-
- @Test
- void ThreadLocalRecyclerFactory_should_work_with_capacity() {
- final int capacity = 13;
- final RecyclerFactory factory = createForEnvironment(null, "threadLocal", capacity);
- assertThat(factory)
- .asInstanceOf(InstanceOfAssertFactories.type(ThreadLocalRecyclerFactory.class))
- .extracting(factory_ -> factory_.capacity)
- .isEqualTo(capacity);
- }
-
- @Test
- void QueueingRecyclerFactory_should_work() {
- final RecyclerFactory factory = createForEnvironment(null, "queue", null);
- assertThat(factory)
- .asInstanceOf(InstanceOfAssertFactories.type(QueueingRecyclerFactory.class))
- .extracting(factory_ -> factory_.capacity)
- .isEqualTo(DEFAULT_CAPACITY);
- }
-
- @Test
- void QueueingRecyclerFactory_should_work_with_capacity() {
- final int capacity = 100;
- final RecyclerFactory factory = createForEnvironment(null, "queue", capacity);
- assertThat(factory)
- .asInstanceOf(InstanceOfAssertFactories.type(QueueingRecyclerFactory.class))
- .extracting(factory_ -> factory_.capacity)
- .isEqualTo(capacity);
- }
-
- @Test
- void verify_order() {
- final RecyclerFactoryProvider dummyProvider = new DummyRecyclerFactoryProvider();
- final RecyclerFactoryProvider threadLocalProvider = new ThreadLocalRecyclerFactoryProvider();
- final RecyclerFactoryProvider queueProvider = new QueueingRecyclerFactoryProvider();
- assertThat(dummyProvider.getOrder()).isGreaterThan(queueProvider.getOrder());
- assertThat(queueProvider.getOrder()).isGreaterThan(threadLocalProvider.getOrder());
- }
-}
diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/internal/recycler/RecyclerFactoryTestUtil.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/internal/recycler/RecyclerFactoryTestUtil.java
deleted file mode 100644
index 85ec0c3cdb..0000000000
--- a/log4j-api-test/src/test/java/org/apache/logging/log4j/internal/recycler/RecyclerFactoryTestUtil.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.internal.recycler;
-
-import edu.umd.cs.findbugs.annotations.Nullable;
-import java.util.Properties;
-import org.apache.logging.log4j.spi.LoggingSystemProperty;
-import org.apache.logging.log4j.spi.recycler.RecyclerFactory;
-import org.apache.logging.log4j.spi.recycler.RecyclerFactoryRegistry;
-import org.apache.logging.log4j.util.PropertiesUtil;
-import org.apache.logging.log4j.util.PropertyEnvironment;
-
-final class RecyclerFactoryTestUtil {
-
- private RecyclerFactoryTestUtil() {}
-
- @Nullable
- static RecyclerFactory createForEnvironment(
- @Nullable Boolean webApp, @Nullable final String factory, @Nullable final Integer capacity) {
- final Properties properties = new Properties();
- if (webApp != null) {
- properties.setProperty(LoggingSystemProperty.IS_WEBAPP.getSystemKey(), webApp + "");
- }
- if (factory != null) {
- properties.setProperty(LoggingSystemProperty.RECYCLER_FACTORY.getSystemKey(), factory);
- }
- if (capacity != null) {
- properties.setProperty(LoggingSystemProperty.RECYCLER_CAPACITY.getSystemKey(), capacity + "");
- }
- final PropertyEnvironment env = new PropertiesUtil(properties);
- return RecyclerFactoryRegistry.findRecyclerFactory(env);
- }
-}
diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/internal/recycler/ThreadLocalRecyclerFactoryProviderTest.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/internal/recycler/ThreadLocalRecyclerFactoryProviderTest.java
deleted file mode 100644
index 2d2bdf3710..0000000000
--- a/log4j-api-test/src/test/java/org/apache/logging/log4j/internal/recycler/ThreadLocalRecyclerFactoryProviderTest.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * 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.internal.recycler;
-
-import static org.apache.logging.log4j.internal.recycler.RecyclerFactoryTestUtil.createForEnvironment;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-
-import java.util.List;
-import java.util.Queue;
-import java.util.stream.Collectors;
-import java.util.stream.IntStream;
-import org.apache.logging.log4j.internal.recycler.ThreadLocalRecyclerFactoryProvider.ThreadLocalRecyclerFactory;
-import org.apache.logging.log4j.internal.recycler.ThreadLocalRecyclerFactoryProvider.ThreadLocalRecyclerFactory.ThreadLocalRecycler;
-import org.apache.logging.log4j.spi.recycler.RecyclerFactory;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junitpioneer.jupiter.params.IntRangeSource;
-
-class ThreadLocalRecyclerFactoryProviderTest {
-
- private static final int CAPACITY = 13;
-
- private static class RecyclableObject {}
-
- private ThreadLocalRecycler<RecyclableObject> recycler;
-
- private Queue<RecyclableObject> recyclerQueue;
-
- @BeforeEach
- void setUp() {
- final RecyclerFactory recyclerFactory = createForEnvironment(false, "threadLocal", CAPACITY);
- assertThat(recyclerFactory).isInstanceOf(ThreadLocalRecyclerFactory.class);
- assert recyclerFactory != null;
- recycler = (ThreadLocalRecycler<RecyclableObject>) recyclerFactory.create(RecyclableObject::new);
- recyclerQueue = recycler.queueRef.get();
- }
-
- @Test
- void should_not_be_configured_for_webapps() {
- assertThatThrownBy(() -> createForEnvironment(true, "threadLocal", null))
- .isInstanceOf(IllegalArgumentException.class)
- .hasMessageStartingWith("failed to configure recycler");
- }
-
- @ParameterizedTest
- @IntRangeSource(from = 1, to = CAPACITY, closed = true)
- void nested_acquires_should_not_interfere(final int acquisitionCount) {
-
- // pool should start empty
- assertThat(recyclerQueue).isEmpty();
-
- final List<RecyclableObject> acquiredObjects = IntStream.range(0, acquisitionCount)
- .mapToObj(i -> recycler.acquire())
- .collect(Collectors.toList());
-
- // still nothing returned to pool
- assertThat(recyclerQueue).isEmpty();
-
- // don't want any duplicate instances
- assertThat(acquiredObjects).containsOnlyOnceElementsOf(acquiredObjects);
- acquiredObjects.forEach(recycler::release);
-
- // and now they should be back in the pool
- assertThat(recyclerQueue).hasSize(acquisitionCount);
-
- // then reacquire them to see that they're still the same object as we've filled in
- // the thread-local queue with returned objects
- final List<RecyclableObject> reacquiredObjects = IntStream.range(0, acquisitionCount)
- .mapToObj(i -> recycler.acquire())
- .collect(Collectors.toList());
-
- assertThat(reacquiredObjects).containsExactlyElementsOf(acquiredObjects);
- }
-
- @Test
- void nested_acquires_past_max_queue_size_should_discard_extra_releases() {
-
- assertThat(recyclerQueue).isEmpty();
-
- // Simulate a callstack with excessive logging
- final int acquisitionCount = Math.addExact(CAPACITY, 1024);
- final List<RecyclableObject> acquiredObjects = IntStream.range(0, acquisitionCount)
- .mapToObj(i -> recycler.acquire())
- .toList();
-
- // Verify collected instances are all new
- assertThat(acquiredObjects).doesNotHaveDuplicates();
-
- // Verify the pool is still empty
- assertThat(recyclerQueue).isEmpty();
-
- // Release all acquired instances
- acquiredObjects.forEach(recycler::release);
-
- // Verify the queue size is capped
- assertThat(recyclerQueue).hasSize(CAPACITY);
- }
-}
diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/message/FormattedMessageTest.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/message/FormattedMessageTest.java
deleted file mode 100644
index 638f31b932..0000000000
--- a/log4j-api-test/src/test/java/org/apache/logging/log4j/message/FormattedMessageTest.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * 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.message;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import java.util.Locale;
-import org.apache.logging.log4j.test.junit.Mutable;
-import org.apache.logging.log4j.util.Constants;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.parallel.ResourceAccessMode;
-import org.junit.jupiter.api.parallel.ResourceLock;
-import org.junit.jupiter.api.parallel.Resources;
-
-@ResourceLock(value = Resources.LOCALE, mode = ResourceAccessMode.READ)
-public class FormattedMessageTest {
-
- private static final String SPACE = Constants.JAVA_MAJOR_VERSION < 9 ? " " : "\u00a0";
-
- private static final int LOOP_CNT = 500;
- String[] array = new String[LOOP_CNT];
-
- @Test
- public void testStringNoArgs() {
- final String testMsg = "Test message %1s";
- FormattedMessage msg = new FormattedMessage(testMsg, (Object[]) null);
- String result = msg.getFormattedMessage();
- final String expected = "Test message null";
- assertEquals(expected, result);
- final Object[] array = null;
- msg = new FormattedMessage(testMsg, array, null);
- result = msg.getFormattedMessage();
- assertEquals(expected, result);
- }
-
- @Test
- public void tesStringOneStringArg() {
- final String testMsg = "Test message %1s";
- final FormattedMessage msg = new FormattedMessage(testMsg, "Apache");
- final String result = msg.getFormattedMessage();
- final String expected = "Test message Apache";
- assertEquals(expected, result);
- }
-
- @Test
- public void tesStringOneArgLocaleFrance_StringFormattedMessage() {
- final String testMsg = "Test message e = %+10.4f";
- final FormattedMessage msg = new FormattedMessage(Locale.FRANCE, testMsg, Math.E);
- final String result = msg.getFormattedMessage();
- final String expected = "Test message e = +2,7183";
- assertEquals(expected, result);
- }
-
- @Test
- public void tesStringOneArgLocaleFrance_MessageFormatMessage() {
- final String testMsg = "Test message {0,number,currency}";
- final FormattedMessage msg = new FormattedMessage(Locale.FRANCE, testMsg, 12);
- final String result = msg.getFormattedMessage();
- final String expected = "Test message 12,00" + SPACE + "€";
- assertEquals(expected, result);
- }
-
- @Test
- public void tesStringOneArgLocaleUs_MessageFormatMessage() {
- final String testMsg = "Test message {0,number,currency}";
- final FormattedMessage msg = new FormattedMessage(Locale.US, testMsg, 12);
- final String result = msg.getFormattedMessage();
- final String expected = "Test message $12.00";
- assertEquals(expected, result);
- }
-
- @Test
- public void tesStringOneArgLocaleUs() {
- final String testMsg = "Test message e = %+10.4f";
- final FormattedMessage msg = new FormattedMessage(Locale.US, testMsg, Math.E);
- final String result = msg.getFormattedMessage();
- final String expected = "Test message e = +2.7183";
- assertEquals(expected, result);
- }
-
- @Test
- public void testNoArgs() {
- final String testMsg = "Test message {0}";
- FormattedMessage msg = new FormattedMessage(testMsg, (Object[]) null);
- String result = msg.getFormattedMessage();
- final String expected = "Test message {0}";
- assertEquals(expected, result);
- final Object[] array = null;
- msg = new FormattedMessage(testMsg, array, null);
- result = msg.getFormattedMessage();
- assertEquals(expected, result);
- }
-
- @Test
- public void testOneArg() {
- final String testMsg = "Test message {0}";
- final FormattedMessage msg = new FormattedMessage(testMsg, "Apache");
- final String result = msg.getFormattedMessage();
- final String expected = "Test message Apache";
- assertEquals(expected, result);
- }
-
- @Test
- public void testParamNoArgs() {
- final String testMsg = "Test message {}";
- FormattedMessage msg = new FormattedMessage(testMsg, (Object[]) null);
- String result = msg.getFormattedMessage();
- assertEquals(testMsg, result);
- final Object[] array = null;
- msg = new FormattedMessage(testMsg, array, null);
- result = msg.getFormattedMessage();
- assertEquals(testMsg, result);
- }
-
- @Test
- public void testUnsafeWithMutableParams() { // LOG4J2-763
- final String testMsg = "Test message %s";
- final Mutable param = new Mutable().set("abc");
- final FormattedMessage msg = new FormattedMessage(testMsg, param);
-
- // modify parameter before calling msg.getFormattedMessage
- param.set("XYZ");
- final String actual = msg.getFormattedMessage();
- assertEquals("Test message XYZ", actual, "Expected most recent param value");
- }
-
- @Test
- public void testSafeAfterGetFormattedMessageIsCalled() { // LOG4J2-763
- final String testMsg = "Test message %s";
- final Mutable param = new Mutable().set("abc");
- final FormattedMessage msg = new FormattedMessage(testMsg, param);
-
- // modify parameter after calling msg.getFormattedMessage
- msg.getFormattedMessage(); // freeze the formatted message
- param.set("XYZ");
- final String actual = msg.getFormattedMessage();
- assertEquals("Test message abc", actual, "Should use initial param value");
- }
-}
diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/message/JsonMessage.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/message/JsonMessage.java
deleted file mode 100644
index ebcebca3ab..0000000000
--- a/log4j-api-test/src/test/java/org/apache/logging/log4j/message/JsonMessage.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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.message;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.apache.logging.log4j.status.StatusLogger;
-
-/**
- * Converts an Object to a JSON String.
- */
-public class JsonMessage implements Message {
-
- private static final ObjectMapper mapper = new ObjectMapper();
- private final Object object;
-
- /**
- * Constructs a JsonMessage.
- *
- * @param object the Object to serialize.
- */
- public JsonMessage(final Object object) {
- this.object = object;
- }
-
- @Override
- public String getFormattedMessage() {
- try {
- return mapper.writeValueAsString(object);
- } catch (final JsonProcessingException e) {
- StatusLogger.getLogger().catching(e);
- return object.toString();
- }
- }
-
- @Override
- public String getFormat() {
- return object.toString();
- }
-
- @Override
- public Object[] getParameters() {
- return new Object[] {object};
- }
-
- @Override
- public Throwable getThrowable() {
- return null;
- }
-}
diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/message/LocalizedMessageFactoryTest.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/message/LocalizedMessageFactoryTest.java
deleted file mode 100644
index 8ae12a1337..0000000000
--- a/log4j-api-test/src/test/java/org/apache/logging/log4j/message/LocalizedMessageFactoryTest.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * 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.message;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import java.util.Locale;
-import java.util.ResourceBundle;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.parallel.ResourceAccessMode;
-import org.junit.jupiter.api.parallel.ResourceLock;
-import org.junit.jupiter.api.parallel.Resources;
-
-/**
- * Tests {@link LocalizedMessageFactory}.
- */
-@ResourceLock(value = Resources.LOCALE, mode = ResourceAccessMode.READ)
-public class LocalizedMessageFactoryTest {
-
- @Test
- public void testMessageMarkersDataNo() {
- final LocalizedMessageFactory localizedMessageFactory =
- new LocalizedMessageFactory(ResourceBundle.getBundle("MF", Locale.US));
- final Message message = localizedMessageFactory.newMessage("msg1");
- assertEquals("This is test number {0} with string argument {1}.", message.getFormattedMessage());
- }
-
- @Test
- public void testMessageMarkersNoDataYes() {
- final LocalizedMessageFactory localizedMessageFactory =
- new LocalizedMessageFactory(ResourceBundle.getBundle("MF", Locale.US));
- final Message message = localizedMessageFactory.newMessage("msg1", 1, "two");
- assertEquals("This is test number 1 with string argument two.", message.getFormattedMessage());
- }
-
- @Test
- public void testNewMessage() {
- final LocalizedMessageFactory localizedMessageFactory =
- new LocalizedMessageFactory(ResourceBundle.getBundle("MF", Locale.US));
- final Message message = localizedMessageFactory.newMessage("hello_world");
- assertEquals("Hello world.", message.getFormattedMessage());
- }
-
- @Test
- @ResourceLock(Resources.LOCALE)
- public void testNewMessageUsingBaseName() {
- final Locale defaultLocale = Locale.getDefault();
- Locale.setDefault(Locale.US);
- try {
- final LocalizedMessageFactory localizedMessageFactory = new LocalizedMessageFactory("MF");
- final String testMsg = "hello_world";
- final Message message = localizedMessageFactory.newMessage(testMsg);
- assertEquals("Hello world.", message.getFormattedMessage());
- } finally {
- Locale.setDefault(defaultLocale);
- }
- }
-
- @Test
- public void testNoMatch() {
- final LocalizedMessageFactory localizedMessageFactory =
- new LocalizedMessageFactory(ResourceBundle.getBundle("MF", Locale.US));
- final Message message = localizedMessageFactory.newMessage("no match");
- assertEquals("no match", message.getFormattedMessage());
- }
-
- @Test
- public void testNoMatchPercentInMessageArgsYes() {
- final LocalizedMessageFactory localizedMessageFactory =
- new LocalizedMessageFactory(ResourceBundle.getBundle("MF", Locale.US));
- final Message message = localizedMessageFactory.newMessage(
- "C:/Program%20Files/Some%20Company/Some%20Product%20Name/{0}", "One");
- assertEquals("C:/Program%20Files/Some%20Company/Some%20Product%20Name/One", message.getFormattedMessage());
- }
-
- @Test
- public void testNoMatchPercentInMessageNoArgsNo() {
- // LOG4J2-3458 LocalizedMessage causes a lot of noise on the console
- //
- // ERROR StatusLogger Unable to format msg: C:/Program%20Files/Some%20Company/Some%20Product%20Name/
- // java.util.UnknownFormatConversionException: Conversion = 'F'
- // at java.util.Formatter$FormatSpecifier.conversion(Formatter.java:2691)
- // at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2720)
- // at java.util.Formatter.parse(Formatter.java:2560)
- // at java.util.Formatter.format(Formatter.java:2501)
- // at java.util.Formatter.format(Formatter.java:2455)
- // at java.lang.String.format(String.java:2981)
- // at org.apache.logging.log4j.message.StringFormattedMessage.formatMessage(StringFormattedMessage.java:116)
- // at
- // org.apache.logging.log4j.message.StringFormattedMessage.getFormattedMessage(StringFormattedMessage.java:88)
- // at org.apache.logging.log4j.message.FormattedMessage.getFormattedMessage(FormattedMessage.java:178)
- // at org.apache.logging.log4j.message.LocalizedMessage.getFormattedMessage(LocalizedMessage.java:196)
- // at
- // org.apache.logging.log4j.message.LocalizedMessageFactoryTest.testNoMatchPercentInMessage(LocalizedMessageFactoryTest.java:60)
- //
- final LocalizedMessageFactory localizedMessageFactory =
- new LocalizedMessageFactory(ResourceBundle.getBundle("MF", Locale.US));
- final Message message =
- localizedMessageFactory.newMessage("C:/Program%20Files/Some%20Company/Some%20Product%20Name/");
- assertEquals("C:/Program%20Files/Some%20Company/Some%20Product%20Name/", message.getFormattedMessage());
- }
-}
diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/message/LocalizedMessageTest.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/message/LocalizedMessageTest.java
deleted file mode 100644
index 14ad3ffeab..0000000000
--- a/log4j-api-test/src/test/java/org/apache/logging/log4j/message/LocalizedMessageTest.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * 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.message;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import java.util.Locale;
-import org.apache.logging.log4j.test.junit.Mutable;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.parallel.ResourceAccessMode;
-import org.junit.jupiter.api.parallel.ResourceLock;
-import org.junit.jupiter.api.parallel.Resources;
-
-/**
- * Tests LocalizedMessage.
- */
-@ResourceLock(value = Resources.LOCALE, mode = ResourceAccessMode.READ)
-public class LocalizedMessageTest {
-
- @Test
- public void testMessageFormat() {
- final LocalizedMessage msg =
- new LocalizedMessage("MF", new Locale("en", "US"), "msg1", new Object[] {"1", "Test"});
- assertEquals("This is test number 1 with string argument Test.", msg.getFormattedMessage());
- }
-
- @Test
- public void testStringFormat() {
- final LocalizedMessage msg =
- new LocalizedMessage("SF", new Locale("en", "US"), "msg1", new Object[] {"1", "Test"});
- assertEquals("This is test number 1 with string argument Test.", msg.getFormattedMessage());
- }
-
- @Test
- public void testUnsafeWithMutableParams() { // LOG4J2-763
- final String testMsg = "Test message %s";
- final Mutable param = new Mutable().set("abc");
- final LocalizedMessage msg = new LocalizedMessage(testMsg, param);
-
- // modify parameter before calling msg.getFormattedMessage
- param.set("XYZ");
- final String actual = msg.getFormattedMessage();
- assertEquals("Test message XYZ", actual, "Expected most recent param value");
- }
-
- @Test
- public void testSafeAfterGetFormattedMessageIsCalled() { // LOG4J2-763
- final String testMsg = "Test message %s";
- final Mutable param = new Mutable().set("abc");
- final LocalizedMessage msg = new LocalizedMessage(testMsg, param);
-
- // modify parameter after calling msg.getFormattedMessage
- msg.getFormattedMessage();
- param.set("XYZ");
- final String actual = msg.getFormattedMessage();
- assertEquals("Test message abc", actual, "Should use initial param value");
- }
-
- @Test
- @ResourceLock(Resources.LOCALE)
- public void testMessageUsingBaseName() { // LOG4J2-2850
- final Locale defaultLocale = Locale.getDefault();
- Locale.setDefault(Locale.US);
- try {
- final String testMsg = "hello_world";
- final LocalizedMessage msg = new LocalizedMessage("MF", testMsg, null);
- assertEquals("Hello world.", msg.getFormattedMessage());
- } finally {
- Locale.setDefault(defaultLocale);
- }
- }
-}
diff --git a/log4j-api-test/src/test/java/org/apache/logging/log4j/message/MapMessageTest.java b/log4j-api-test/src/test/java/org/apache/logging/log4j/message/MapMessageTest.java
deleted file mode 100644
index 048801128d..0000000000
--- a/log4j-api-test/src/test/java/org/apache/logging/log4j/message/MapMessageTest.java
+++ /dev/null
@@ -1,330 +0,0 @@
-/*
- * 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.message;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
-import java.math.BigDecimal;
-import java.sql.Date;
-import java.sql.Time;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.logging.log4j.util.StringBuilderFormattable;
-import org.junit.jupiter.api.Test;
-
-/**
- *
- */
-public class MapMessageTest {
-
- @Test
- public void testMap() {
- final String testMsg = "Test message {}";
- final StringMapMessage msg = new StringMapMessage();
- msg.put("message", testMsg);
- msg.put("project", "Log4j");
- final String result = msg.getFormattedMessage();
- final String expected = "message=\"Test message {}\" project=\"Log4j\"";
- assertEquals(expected, result);
- }
-
- @Test
- public void testBuilder() {
- final String testMsg = "Test message {}";
- final StringMapMessage msg =
- new StringMapMessage().with("message", testMsg).with("project", "Log4j");
- final String result = msg.getFormattedMessage();
- final String expected = "message=\"Test message {}\" project=\"Log4j\"";
- assertEquals(expected, result);
- }
-
- @Test
- public void testXML() {
- final String testMsg = "Test message {}";
- final StringMapMessage msg = new StringMapMessage();
- msg.put("message", testMsg);
- msg.put("project", "Log4j");
- final String result = msg.getFormattedMessage(new String[] {"XML"});
- final String expected = "<Map>\n <Entry key=\"message\">Test message {}</Entry>\n"
- + " <Entry key=\"project\">Log4j</Entry>\n" + "</Map>";
- assertEquals(expected, result);
- }
-
- @Test
- public void testXMLEscape() {
- final String testMsg = "Test message <foo>";
- final StringMapMessage msg = new StringMapMessage();
- msg.put("message", testMsg);
- final String result = msg.getFormattedMessage(new String[] {"XML"});
- final String expected = "<Map>\n <Entry key=\"message\">Test message <foo></Entry>\n" + "</Map>";
- assertEquals(expected, result);
- }
-
- @Test
- public void testJSON() {
- final String testMsg = "Test message {}";
- final StringMapMessage msg = new StringMapMessage();
- msg.put("message", testMsg);
- msg.put("project", "Log4j");
- final String result = msg.getFormattedMessage(new String[] {"JSON"});
- final String expected = "{'message':'Test message {}','project':'Log4j'}".replace('\'', '"');
- assertEquals(expected, result);
- }
-
... 41800 lines suppressed ...