diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/boot/DeprecatedProviderCheckerTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/boot/DeprecatedProviderCheckerTest.java index c269a2fe4c..68fb8c08a9 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/boot/DeprecatedProviderCheckerTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/boot/DeprecatedProviderCheckerTest.java @@ -11,11 +11,12 @@ import org.hibernate.internal.HEMLogging; import org.hibernate.jpa.boot.spi.ProviderChecker; import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.logger.LoggerInspectionRule; import org.hibernate.testing.logger.Triggerable; -import org.junit.Rule; +import org.hibernate.testing.orm.logger.LogInspector; +import org.hibernate.testing.orm.logger.LoggerInspectionExtension; +import org.hibernate.testing.orm.logger.Inspector; import org.junit.jupiter.api.Test; - +import org.junit.jupiter.api.extension.ExtendWith; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -26,18 +27,16 @@ import static org.junit.jupiter.api.Assertions.assertTrue; * * @author Gail Badner */ +@ExtendWith(LoggerInspectionExtension.class) public class DeprecatedProviderCheckerTest { final static String DEPRECATED_PROVIDER_NAME = "org.hibernate.ejb.HibernatePersistence"; - @Rule - public LoggerInspectionRule logInspection = new LoggerInspectionRule( - HEMLogging.messageLogger( ProviderChecker.class.getName() ) - ); - @Test - @TestForIssue( jiraKey = "HHH-13027") - public void testDeprecatedProvider() { - Triggerable triggerable = logInspection.watchForLogMessages( "HHH015016" ); + @TestForIssue(jiraKey = "HHH-13027") + public void testDeprecatedProvider(@LogInspector Inspector logger) { + logger.init( HEMLogging.messageLogger( ProviderChecker.class.getName() ) ); + + Triggerable triggerable = logger.watchForLogMessages( "HHH015016" ); triggerable.reset(); assertTrue( ProviderChecker.hibernateProviderNamesContain( DEPRECATED_PROVIDER_NAME ) ); triggerable.wasTriggered(); diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/logger/LogInspectionHelper.java b/hibernate-testing/src/main/java/org/hibernate/testing/logger/LogInspectionHelper.java index b189410a39..133d5e4267 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/logger/LogInspectionHelper.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/logger/LogInspectionHelper.java @@ -19,16 +19,16 @@ import org.jboss.logging.DelegatingBasicLogger; * * @author Sanne Grinovero (C) 2015 Red Hat Inc. */ -final class LogInspectionHelper { +public final class LogInspectionHelper { private LogInspectionHelper() { } - static void registerListener(LogListener listener, BasicLogger log) { + public static void registerListener(LogListener listener, BasicLogger log) { convertType( log ).registerListener( listener ); } - static void clearAllListeners(BasicLogger log) { + public static void clearAllListeners(BasicLogger log) { convertType( log ).clearAllListeners(); } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/logger/TriggerOnPrefixLogListener.java b/hibernate-testing/src/main/java/org/hibernate/testing/logger/TriggerOnPrefixLogListener.java index 65a92ada14..84d457aaf0 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/logger/TriggerOnPrefixLogListener.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/logger/TriggerOnPrefixLogListener.java @@ -15,7 +15,7 @@ import java.util.concurrent.atomic.AtomicReference; import org.jboss.logging.Logger.Level; -final class TriggerOnPrefixLogListener implements LogListener, Triggerable { +public final class TriggerOnPrefixLogListener implements LogListener, Triggerable { private Set expectedPrefixes = new HashSet<>(); diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/BaseUnitTest.java b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/BaseUnitTest.java index d918effebe..70339edd93 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/BaseUnitTest.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/BaseUnitTest.java @@ -13,6 +13,7 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.extension.ParameterContext; @Inherited @Target( ElementType.TYPE ) diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/orm/logger/Inspector.java b/hibernate-testing/src/main/java/org/hibernate/testing/orm/logger/Inspector.java new file mode 100644 index 0000000000..eb41c42d2f --- /dev/null +++ b/hibernate-testing/src/main/java/org/hibernate/testing/orm/logger/Inspector.java @@ -0,0 +1,44 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.testing.orm.logger; + +import java.util.Set; + +import org.hibernate.testing.logger.LogInspectionHelper; +import org.hibernate.testing.logger.LogListener; +import org.hibernate.testing.logger.TriggerOnPrefixLogListener; +import org.hibernate.testing.logger.Triggerable; + +import org.jboss.logging.BasicLogger; + +public class Inspector { + private BasicLogger log; + + public void init(BasicLogger logger){ + log = logger; + } + + public BasicLogger getLog(){ + return log; + } + + public Triggerable watchForLogMessages(String prefix) { + TriggerOnPrefixLogListener listener = new TriggerOnPrefixLogListener( prefix ); + registerListener( listener ); + return listener; + } + + public Triggerable watchForLogMessages(Set prefixes) { + TriggerOnPrefixLogListener listener = new TriggerOnPrefixLogListener( prefixes ); + registerListener( listener ); + return listener; + } + + public void registerListener(LogListener listener) { + LogInspectionHelper.registerListener( listener, log ); + } +} diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/orm/logger/LogInspector.java b/hibernate-testing/src/main/java/org/hibernate/testing/orm/logger/LogInspector.java new file mode 100644 index 0000000000..bc04d2f41c --- /dev/null +++ b/hibernate-testing/src/main/java/org/hibernate/testing/orm/logger/LogInspector.java @@ -0,0 +1,17 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.testing.orm.logger; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.PARAMETER) +public @interface LogInspector { +} diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/orm/logger/LoggerInspectionExtension.java b/hibernate-testing/src/main/java/org/hibernate/testing/orm/logger/LoggerInspectionExtension.java new file mode 100644 index 0000000000..e89e1a17f0 --- /dev/null +++ b/hibernate-testing/src/main/java/org/hibernate/testing/orm/logger/LoggerInspectionExtension.java @@ -0,0 +1,46 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.testing.orm.logger; + +import org.hibernate.testing.logger.LogInspectionHelper; +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 final class LoggerInspectionExtension implements AfterEachCallback, BeforeEachCallback, ParameterResolver { + + private Inspector inspector; + + public LoggerInspectionExtension() { + inspector = new Inspector(); + } + + @Override + public void beforeEach(ExtensionContext context) throws Exception { + // do nothing + } + + @Override + public void afterEach(ExtensionContext context) throws Exception { + LogInspectionHelper.clearAllListeners( inspector.getLog() ); + } + + @Override + public boolean supportsParameter( + ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { + return parameterContext.isAnnotated( LogInspector.class ); + } + + @Override + public Object resolveParameter( + ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { + return inspector; + } +}