Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
c278ec9
refactor: Migrate asynclogger tests to junit5
ninetteadhikari Oct 1, 2024
a2d608f
update version of core.test.junit and core.test.layout
hulkoba Nov 18, 2024
29b13ce
update more appender/rolling tests to junit5
ninetteadhikari Nov 19, 2024
bfcab2e
update junit5: appender/rolling
ninetteadhikari Nov 21, 2024
f4bdb5b
update cleanfolder extension timeout
ninetteadhikari Nov 27, 2024
51591ea
Migrate JndiLookupTest test to JUnit 5
AlbaHerrerias Nov 27, 2024
99dfd3d
Migrate AsyncRootReloadTest test to JUnit 5
AlbaHerrerias Nov 27, 2024
35ae3fc
Migrate TypeConvertersTest test to JUnit 5
AlbaHerrerias Nov 27, 2024
a83050b
Migrate InterpolatorTest test to JUnit 5
AlbaHerrerias Nov 27, 2024
3e8244e
Run spotless
AlbaHerrerias Nov 27, 2024
11531e3
Migrate tests to JUnit 5
AlbaHerrerias Nov 27, 2024
86f8842
junit5 update for appender/rolling
ninetteadhikari Nov 27, 2024
459416a
Migrate CsvJsonParameterLayoutFileAppenderTest to JUnit 5.java
AlbaHerrerias Dec 2, 2024
03a389c
Migrate JsonCompleteFileAppenderTest to JUnit 5
AlbaHerrerias Dec 3, 2024
0ff6ecf
Migrate XmlCompleteFileAppenderTest to JUnit 5
AlbaHerrerias Dec 3, 2024
ed38dc5
Extract setup/teardown methods in JdbcRule
jcoglan Dec 3, 2024
1f345d0
Implement {Before,After}EachCallback on JdbcRule
jcoglan Dec 3, 2024
a49000b
Migrate JdbcAppenderColumnMappingLiteralTest to JUnit 5
jcoglan Dec 3, 2024
baa5c43
Migrate NoSqlDatabaseManagerTes to JUnit 5
jcoglan Dec 3, 2024
3978464
Migrate RandomAccessFileAppenderTest to JUnit 5
jcoglan Dec 4, 2024
b7d4704
Migrate JmsAppenderTest to JUnit 5
jcoglan Dec 4, 2024
83e4eba
Update JdbcAppenderColumnMappingPatternTest.java
AlbaHerrerias Dec 3, 2024
27ee7dd
Migrate JdbcAppenderMapMessageDataSourceTest to JUnit 5
AlbaHerrerias Dec 3, 2024
76bcca9
Migrate AbstractJdbcAppenderDataSourceTest and dependants into JUnit 5
AlbaHerrerias Dec 3, 2024
d375acb
Migrate AbstractH2Test into JUnit 5
AlbaHerrerias Dec 4, 2024
a4eee9e
Migrate LogEventFactoryTest to JUnit 5
jcoglan Dec 4, 2024
d462055
Migrate RollingAppenderSizeMaxWidthTest to JUnit 5
jcoglan Dec 5, 2024
0a8cfe1
Migrate ContextMapLookupTest to JUnit 5
jcoglan Dec 5, 2024
a34f61d
Migrate RollingAppenderCountTest to JUnit 5
jcoglan Dec 5, 2024
eca78a0
Add missing import
AlbaHerrerias Dec 5, 2024
b122b5e
Update RollingAppenderNoUnconditionalDeleteTest.java
AlbaHerrerias Dec 5, 2024
0068e00
Migrate AbstractJdbcAppenderFactoryMethodTest and dependants to JUnit 5
AlbaHerrerias Dec 5, 2024
b458c81
Migrate DataSourceConnectionSourceTest to JUnit 5
AlbaHerrerias Dec 5, 2024
8127791
Replace JUnit 4 parameterised tests with subclasses that override the…
jcoglan Nov 29, 2024
472fcfc
Migrate DefaultRouteScriptAppenderTest to JUnit 5
jcoglan Nov 29, 2024
436bea1
Set LoggerContextSource.reconfigure on DefaultRouteScriptAppenderTest…
jcoglan Dec 2, 2024
f36fa0e
Fix CleanFiles extension
AlbaHerrerias Dec 5, 2024
4cf4a4a
Fix with spotless
AlbaHerrerias Dec 5, 2024
882dee3
Rename children of DefaultRouteScriptAppenderTest to have a common na…
jcoglan Dec 5, 2024
759bac3
Migrate RoutesScriptAppenderTest to JUnit 5, using subclasses to repl…
jcoglan Dec 5, 2024
2ca0db0
refactor: core routing assertions
Realtin Nov 27, 2024
9eee11f
refactor: JsonRoutingAppender2Test
Realtin Nov 28, 2024
c9dd41b
refactor: JsonRoutingAppenderTest
Realtin Nov 28, 2024
3f5d505
refactor: PropertiesRoutingAppenderTest
Realtin Nov 28, 2024
eaa1f97
refactor: RoutingDefaultAppenderTest
Realtin Nov 28, 2024
2071938
refactor: RoutingAppenderTest
Realtin Nov 28, 2024
da11f81
fix RoutingAppenderTest
Realtin Dec 2, 2024
e8f1020
fix PropertiesRoutingAppenderTest
Realtin Dec 2, 2024
a467c78
refactor RoutingAppender2767Test
Realtin Dec 3, 2024
1732c48
refactor RoutingAppender3350Test
Realtin Dec 3, 2024
e8d160f
refactor RoutingAppenderKeyLookupEvaluationTest
Realtin Dec 4, 2024
39b107d
refactor: RoutingAppenderWithPurgingTest
Realtin Dec 5, 2024
9d4d5fa
refactor RoutingAppenderWithJndiTest
Realtin Dec 5, 2024
53c8ef9
Revert "Fix CleanFiles extension"
AlbaHerrerias Dec 9, 2024
dc8e5fa
Trying deleting only on the after hook
AlbaHerrerias Dec 9, 2024
3436fe5
Remove comments
AlbaHerrerias Dec 9, 2024
684870b
Clean ups
AlbaHerrerias Dec 9, 2024
e7d8552
Update RoutingDefaultAppenderTest.java
AlbaHerrerias Dec 9, 2024
b988711
Update usage of CleanFiles
AlbaHerrerias Dec 9, 2024
02c500c
Fix the usage of cleanFiles
AlbaHerrerias Dec 9, 2024
9c947c5
Attempt 2 to fix CleanFiles
AlbaHerrerias Dec 9, 2024
3fc6485
Attempt 3 to fix CleanFiles
AlbaHerrerias Dec 9, 2024
99cc17d
Oops
AlbaHerrerias Dec 9, 2024
2a3b558
Remove unused files
AlbaHerrerias Dec 9, 2024
bff03ca
Small fixes
AlbaHerrerias Dec 9, 2024
c77fbf7
Put back an assertion that was commented out
AlbaHerrerias Dec 9, 2024
f7798cf
Rename loggerContextRule to loggerContext
AlbaHerrerias Dec 9, 2024
111609a
Update KafkaAppenderCloseTimeoutTest.java
AlbaHerrerias Dec 9, 2024
5d98ebc
Update KafkaAppenderTest.java
AlbaHerrerias Dec 9, 2024
b6de65f
Update JsonCompleteFileAppenderTest.java
AlbaHerrerias Dec 9, 2024
3bb8cb8
Update CsvParameterLayoutTest.java
AlbaHerrerias Dec 10, 2024
36d81c2
Update RandomRollingAppenderOnStartupTest.java
AlbaHerrerias Dec 10, 2024
c0c776c
Remove `junit-vintage` dependency
AlbaHerrerias Dec 11, 2024
9075246
Make Log4j2_1482_Test use CleanFoldersRuleExtension
jcoglan Dec 11, 2024
f9c51cd
Make RollingAppenderUncompressedTest use CleanFoldersRuleExtension
jcoglan Dec 11, 2024
baf780f
Make RollingAppenderDirectWriteStartupSizeTest use CleanFoldersRuleEx…
jcoglan Dec 11, 2024
3467ba4
Make CleanFoldersRuleExtension invoke the before/after behaviour of C…
jcoglan Dec 12, 2024
b1802e9
Make RollingFileAppenderInterruptedThreadTest actually trigger the Cl…
jcoglan Dec 12, 2024
f591542
Comment out `CleanFoldersRuleExtension` in `RollingAppenderUncompress…
AlbaHerrerias Dec 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions log4j-core-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,6 @@
<scope>test</scope>
</dependency>

<!-- JUnit, naturally -->
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>

<!-- Used for Kafka appender -->
<dependency>
<groupId>org.apache.kafka</groupId>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@
import java.util.Map;
import java.util.Set;
import org.junit.Assert;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.rules.ExternalResource;

/**
* This class should not perform logging using Log4j to avoid accidentally
* loading or re-loading Log4j configurations.
*/
public abstract class AbstractExternalFileCleaner extends ExternalResource {
public abstract class AbstractExternalFileCleaner extends ExternalResource
implements BeforeEachCallback, AfterEachCallback {

protected static final String CLEANER_MARKER = "CLEANER";

Expand Down Expand Up @@ -91,13 +95,23 @@ public AbstractExternalFileCleaner(
}
}

@Override
public void afterEach(ExtensionContext context) {
after();
}

@Override
protected void after() {
if (cleanAfter()) {
this.clean();
}
}

@Override
public void beforeEach(ExtensionContext context) {
before();
}

@Override
protected void before() {
if (cleanBefore()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.logging.log4j.core.test.junit;

import java.util.concurrent.TimeUnit;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configurator;
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;
import org.junit.jupiter.api.extension.ParameterContext;
import org.junit.jupiter.api.extension.ParameterResolutionException;
import org.junit.jupiter.api.extension.ParameterResolver;

public class CleanFoldersRuleExtension implements BeforeEachCallback, AfterEachCallback, ParameterResolver {

private final String CONFIG;
private final String ClassName;
private final ClassLoader ClassNameLoader;
private LoggerContext context;
private CleanFolders cleanFolders;

public CleanFoldersRuleExtension(
final String DIR, final String CONFIG, final String ClassName, final ClassLoader ClassNameLoader) {
this.CONFIG = CONFIG;
this.ClassName = ClassName;
this.ClassNameLoader = ClassNameLoader;
this.cleanFolders = new CleanFolders(DIR);
}

public CleanFoldersRuleExtension(
final String DIR,
final String CONFIG,
final String ClassName,
final ClassLoader ClassNameLoader,
final boolean before,
final boolean after,
final int maxTries) {
this.CONFIG = CONFIG;
this.ClassName = ClassName;
this.ClassNameLoader = ClassNameLoader;
this.cleanFolders = new CleanFolders(before, after, maxTries, DIR);
}

@Override
public void beforeEach(final ExtensionContext ctx) throws Exception {
this.cleanFolders.beforeEach(ctx);
this.context = Configurator.initialize(ClassName, ClassNameLoader, CONFIG);
}

@Override
public void afterEach(final ExtensionContext ctx) throws Exception {
if (this.context != null) {
Configurator.shutdown(this.context, 10, TimeUnit.SECONDS);
StatusLogger.getLogger().reset();
}
this.cleanFolders.afterEach(ctx);
}

@Override
public boolean supportsParameter(final ParameterContext parameterContext, final ExtensionContext extensionContext)
throws ParameterResolutionException {
// Check if the parameter is of type LoggerContext
return parameterContext.getParameter().getType().equals(LoggerContext.class);
}

@Override
public Object resolveParameter(final ParameterContext parameterContext, final ExtensionContext extensionContext)
throws ParameterResolutionException {
// Return the LoggerContext instance
return this.context;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.core.appender.db.jdbc.ConnectionSource;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.rules.TestRule;
import org.junit.runner.Description;

Expand All @@ -35,12 +38,15 @@
* @since 2.8
*/
@SuppressFBWarnings("SQL_INJECTION_JDBC")
public class JdbcRule implements TestRule {
public class JdbcRule implements TestRule, BeforeEachCallback, AfterEachCallback {

private final ConnectionSource connectionSource;
private final String createTableStatement;
private final String dropTableStatement;

private Connection connection;
private Statement statement;

/**
* Creates a JdbcRule using a {@link ConnectionSource} and a table creation statement.
*
Expand All @@ -63,24 +69,45 @@ public org.junit.runners.model.Statement apply(
return new org.junit.runners.model.Statement() {
@Override
public void evaluate() throws Throwable {
try (final Connection connection = getConnection();
final Statement statement = connection.createStatement()) {
try {
if (StringUtils.isNotEmpty(createTableStatement)) {
statement.executeUpdate(createTableStatement);
}
base.evaluate();
} finally {
if (StringUtils.isNotEmpty(dropTableStatement)) {
statement.executeUpdate(dropTableStatement);
}
statement.execute("SHUTDOWN");
}
try {
setupConnection();
base.evaluate();
} finally {
closeConnection();
}
}
};
}

@Override
public void beforeEach(ExtensionContext context) throws Exception {
setupConnection();
}

@Override
public void afterEach(ExtensionContext context) throws Exception {
closeConnection();
}

void setupConnection() throws SQLException {
connection = getConnection();
statement = connection.createStatement();

if (StringUtils.isNotEmpty(createTableStatement)) {
statement.executeUpdate(createTableStatement);
}
}

void closeConnection() throws SQLException {
if (StringUtils.isNotEmpty(dropTableStatement)) {
statement.executeUpdate(dropTableStatement);
}
statement.execute("SHUTDOWN");

statement.close();
connection.close();
}

public Connection getConnection() throws SQLException {
return connectionSource.getConnection();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.logging.log4j.core.test.junit;

import java.util.Collections;
import java.util.Map;
import javax.naming.Context;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.springframework.mock.jndi.SimpleNamingContextBuilder;

/**
* JUnit Extension to create a mock {@link Context} and bind an object to a name.
*
*/
public class JndiExtension implements BeforeEachCallback {

private final Map<String, Object> initialBindings;

public JndiExtension(final String name, final Object value) {
this.initialBindings = Collections.singletonMap(name, value);
}

public JndiExtension(final Map<String, Object> initialBindings) {
this.initialBindings = initialBindings;
}

public void beforeEach(ExtensionContext ctx) throws Exception {
final SimpleNamingContextBuilder builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
for (final Map.Entry<String, Object> entry : initialBindings.entrySet()) {
builder.bind(entry.getKey(), entry.getValue());
}
}
}
Loading
Loading