Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion documentation/documentation.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ configurations {

javadocClasspath {
description = 'Class files for the javadoc to be built'
resolutionStrategy.capabilitiesResolution.withCapability('org.junit.jupiter:junit-jupiter-params:'+testLibs.versions.junit5.get()) { details ->
resolutionStrategy.capabilitiesResolution.withCapability('org.junit.jupiter:junit-jupiter-params:'+testLibs.versions.junitJupiter.get()) { details ->
details.select( details.candidates.first() ).because( 'first' )
}

Expand Down
4 changes: 2 additions & 2 deletions hibernate-testing/README.adoc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
The `hibernate-testing` module of Hibernate ORM defines utilities for writing
tests easier.

This documentation focuses on the JUnit 5 & annotation based testing support...
This documentation focuses on the JUnit 6 & annotation based testing support...


// todo (6.1) : write more (duh)
// todo (6.1) : write more (duh)
8 changes: 4 additions & 4 deletions hibernate-testing/hibernate-testing.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ dependencies {
api project( ':hibernate-community-dialects' )

api testLibs.junit4
api testLibs.junit5Api
api testLibs.junit5Params
api testLibs.junitJupiterApi
api testLibs.junitJupiterParams

api testLibs.hamcrest
api testLibs.assertjCore
Expand Down Expand Up @@ -55,8 +55,8 @@ dependencies {
// Since we don't need WildFly Elytron in our tests, we'll just exclude it.
exclude group: 'org.wildfly.security', module: 'wildfly-elytron'
}
implementation testLibs.junit5Engine
implementation testLibs.junit5Launcher
implementation testLibs.junitJupiterEngine
implementation testLibs.junitJupiterLauncher

annotationProcessor project( ':hibernate-processor' )
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* except this annotation need not be attached to a static method
*
* @author Steve Ebersole
* @deprecated Use JUnit 5 along with one of the Hibernate ORM's class-level test annotations
* @deprecated Use JUnit Jupiter along with one of the Hibernate ORM's class-level test annotations
* ({@link org.hibernate.testing.orm.junit.BaseUnitTest},
* {@link org.hibernate.testing.orm.junit.SessionFactory},
* {@link org.hibernate.testing.orm.junit.Jpa},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* except this annotation need not be attached to a static method
*
* @author Steve Ebersole
* @deprecated Use JUnit 5 along with one of the Hibernate ORM's class-level test annotations
* @deprecated Use JUnit Jupiter along with one of the Hibernate ORM's class-level test annotations
* ({@link org.hibernate.testing.orm.junit.BaseUnitTest},
* {@link org.hibernate.testing.orm.junit.SessionFactory},
* {@link org.hibernate.testing.orm.junit.Jpa},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* @author Hardy Ferentschik
* @author Steve Ebersole
* @deprecated Use JUnit 5 and {@link org.hibernate.testing.orm.junit.FailureExpected} instead.
* @deprecated Use JUnit Jupiter and {@link org.hibernate.testing.orm.junit.FailureExpected} instead.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.TYPE })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Annotation used to identify a method as a callback to be executed whenever a {@link FailureExpected} is handled.
*
* @author Steve Ebersole
* @deprecated No replacement with JUnit 5 at the moment.
* @deprecated No replacement with JUnit Jupiter at the moment.
*/
@Retention( RetentionPolicy.RUNTIME )
@Target( ElementType.METHOD )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Annotation used to identify a method as a callback to be executed on test failures.
*
* @author Steve Ebersole
* @deprecated No replacement with JUnit 5 at the moment.
* @deprecated No replacement with JUnit Jupiter at the moment.
*/
@Retention( RetentionPolicy.RUNTIME )
@Target( ElementType.METHOD )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @see RequiresDialects
*
* @author Hardy Ferentschik
* @deprecated Use JUnit 5 and {@link org.hibernate.testing.orm.junit.RequiresDialect} instead.
* @deprecated Use JUnit Jupiter and {@link org.hibernate.testing.orm.junit.RequiresDialect} instead.
*/
@Target({ ElementType.METHOD, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* specified feature.
*
* @author Hardy Ferentschik
* @deprecated Use JUnit 5 and {@link org.hibernate.testing.orm.junit.RequiresDialectFeature} instead.
* @deprecated Use JUnit Jupiter and {@link org.hibernate.testing.orm.junit.RequiresDialectFeature} instead.
*/
@Target({ ElementType.METHOD, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* Useful when test needs to be run against more than one dialect because of a different reason.
*
* @author Lukasz Antoniak
* @deprecated Use JUnit 5 and {@link org.hibernate.testing.orm.junit.RequiresDialects} instead.
* @deprecated Use JUnit Jupiter and {@link org.hibernate.testing.orm.junit.RequiresDialects} instead.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.TYPE })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* An annotation, used in combination with {@link Matcher}, to determine when/if tests should be skipped.
*
* @author Steve Ebersole
* @deprecated Use JUnit 5 and {@link org.junit.jupiter.api.condition.DisabledOnOs}
* @deprecated Use JUnit Jupiter and {@link org.junit.jupiter.api.condition.DisabledOnOs}
* or {@link org.junit.jupiter.api.condition.DisabledIf}.
*/
@Retention( RetentionPolicy.RUNTIME )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @author Hardy Ferentschik
* @author Steve Ebersole
* @deprecated Use JUnit 5 and {@link org.hibernate.testing.orm.junit.SkipForDialect} instead.
* @deprecated Use JUnit Jupiter and {@link org.hibernate.testing.orm.junit.SkipForDialect} instead.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.TYPE })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* Useful when more than one dialect needs to be skipped because of a different reason.
*
* @author Lukasz Antoniak
* @deprecated Use JUnit 5 and {@link org.hibernate.testing.orm.junit.SkipForDialectGroup} instead.
* @deprecated Use JUnit Jupiter and {@link org.hibernate.testing.orm.junit.SkipForDialectGroup} instead.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.TYPE })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static org.junit.platform.commons.util.AnnotationUtils.isAnnotated;

import org.hibernate.testing.bytecode.enhancement.extension.engine.BytecodeEnhancedEngineDescriptor;
import org.hibernate.testing.bytecode.enhancement.extension.engine.BytecodeEnhancedTestEngine;
import org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor;
import org.junit.platform.engine.FilterResult;
import org.junit.platform.engine.TestDescriptor;
Expand All @@ -24,6 +25,11 @@ public FilterResult apply(TestDescriptor testDescriptor) {
}

boolean isEnhanced = isAnnotated( descriptor.getTestClass(), BytecodeEnhanced.class );
if ( isEnhanced && !BytecodeEnhancedTestEngine.isEnabled() ) {
throw new IllegalStateException(
"BytecodeEnhancedTestEngine is disabled. But the tests rely on the @BytecodeEnhanced extensions: %s. In order to run this test, make sure to exactly align your dependency to JUnit with that of hibernate-testing, and set system property '%s=true'.".formatted(
descriptor, BytecodeEnhancedTestEngine.ENHANCEMENT_EXTENSION_ENGINE_ENABLED ) );
}
if ( root instanceof BytecodeEnhancedEngineDescriptor ) {
if ( !isEnhanced ) {
return FilterResult.excluded( "Not bytecode enhanced." );
Expand All @@ -32,7 +38,7 @@ public FilterResult apply(TestDescriptor testDescriptor) {
else {
if ( isEnhanced ) {
testDescriptor.removeFromHierarchy();
return FilterResult.excluded( "Not bytecode enhanced." );
return FilterResult.excluded( "Not bytecode enhanced engine, but test requires bytecode enhancement." );
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExecutionCondition;
import org.junit.jupiter.api.extension.Extension;
import org.junit.jupiter.api.extension.ExtensionConfigurationException;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestInstantiationAwareExtension;
import org.junit.jupiter.api.io.CleanupMode;
Expand All @@ -41,29 +42,54 @@
import org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor;
import org.junit.jupiter.engine.descriptor.ClassTestDescriptor;
import org.junit.jupiter.engine.descriptor.JupiterEngineDescriptor;
import org.junit.jupiter.engine.descriptor.LauncherStoreFacade;
import org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor;
import org.junit.jupiter.engine.descriptor.TestTemplateTestDescriptor;
import org.junit.jupiter.engine.execution.JupiterEngineExecutionContext;
import org.junit.jupiter.engine.execution.LauncherStoreFacade;
import org.junit.platform.engine.EngineDiscoveryRequest;
import org.junit.platform.engine.EngineExecutionListener;
import org.junit.platform.engine.ExecutionRequest;
import org.junit.platform.engine.OutputDirectoryCreator;
import org.junit.platform.engine.TestDescriptor;
import org.junit.platform.engine.UniqueId;
import org.junit.platform.engine.reporting.OutputDirectoryProvider;
import org.junit.platform.engine.support.descriptor.EngineDescriptor;
import org.junit.platform.engine.support.hierarchical.EngineExecutionContext;
import org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine;
import org.junit.platform.engine.support.hierarchical.ThrowableCollector;

public class BytecodeEnhancedTestEngine extends HierarchicalTestEngine<JupiterEngineExecutionContext> {

public static final String ENHANCEMENT_EXTENSION_ENGINE_ENABLED = "hibernate.testing.bytecode.enhancement.extension.engine.enabled";

public static boolean isEnabled() {
return "true".equalsIgnoreCase( System.getProperty( ENHANCEMENT_EXTENSION_ENGINE_ENABLED, "false" ) );
}

@Override
public String getId() {
return "bytecode-enhanced-engine";
}

@Override
public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
if ( isEnabled() ) {
try {
return doDiscover( discoveryRequest, uniqueId );
}
catch (OutOfMemoryError e) {
throw e;
}
catch (Error e) {
throw new ExtensionConfigurationException(
"Encountered a problem when enhancing the test classes. It is highly likely that @BytecodeEnhanced extension is incompatible with the provided version of JUnit.",
e );
}
}

return new EngineDescriptor( uniqueId, getId() );
}

public TestDescriptor doDiscover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
final BytecodeEnhancedEngineDescriptor engineDescriptor = new BytecodeEnhancedEngineDescriptor(
(JupiterEngineDescriptor) new JupiterTestEngine().discover( discoveryRequest, uniqueId )
);
Expand Down Expand Up @@ -235,8 +261,12 @@ protected JupiterEngineExecutionContext createExecutionContext(ExecutionRequest
}

private JupiterConfiguration getJupiterConfiguration(ExecutionRequest request) {
JupiterEngineDescriptor engineDescriptor = (JupiterEngineDescriptor) request.getRootTestDescriptor();
return engineDescriptor.getConfiguration();
if ( request.getRootTestDescriptor() instanceof JupiterEngineDescriptor descriptor ) {
return descriptor.getConfiguration();
}
else {
return null;
}
}

public Optional<String> getGroupId() {
Expand Down Expand Up @@ -278,8 +308,8 @@ public Optional<String> getRawConfigurationParameter(String s) {
}

@Override
public <T> Optional<T> getRawConfigurationParameter(String s, Function<String, T> function) {
return configuration.getRawConfigurationParameter( s, function );
public <T> Optional<T> getRawConfigurationParameter(String key, Function<? super String, ? extends T> transformer) {
return configuration.getRawConfigurationParameter( key, transformer );
}

@Override
Expand Down Expand Up @@ -353,8 +383,8 @@ public TestInstantiationAwareExtension.ExtensionContextScope getDefaultTestInsta
}

@Override
public OutputDirectoryProvider getOutputDirectoryProvider() {
return configuration.getOutputDirectoryProvider();
public OutputDirectoryCreator getOutputDirectoryCreator() {
return configuration.getOutputDirectoryCreator();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.jboss.logging.Logger;

/**
* JUnit 5 extension used to add {@link RequiresDialect} and {@link SkipForDialect}
* JUnit Jupiter extension used to add {@link RequiresDialect} and {@link SkipForDialect}
* handling
*
* @author Steve Ebersole
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.jboss.logging.Logger;

/**
* JUnit 5 extension used to support {@link FailureExpected} handling
* JUnit Jupiter extension used to support {@link FailureExpected} handling
*
* @author Steve Ebersole
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static org.hibernate.testing.orm.junit.FailureExpectedExtension.failureExpectedValidation;

/**
* JUnit 5 extension used to support {@link NotImplementedYet} handling
* JUnit Jupiter extension used to support {@link NotImplementedYet} handling
*
* @author Jan Schatteman
*/
Expand Down
14 changes: 8 additions & 6 deletions local-build-plugins/src/main/groovy/local.java-module.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ dependencies {
}

// JUnit dependencies made up of:
// * JUnit 5
// * the Jupiter engine which runs JUnit 5 based tests
// * JUnit (version 5 or later)
// * the Jupiter engine which runs JUnit 6 based tests
// * the "vintage" engine - which runs JUnit 3 and 4 based tests
testImplementation testLibs.junit5Api
testImplementation testLibs.junit5Engine
testImplementation testLibs.junit5Params
testImplementation testLibs.junit5Launcher
testImplementation testLibs.junitJupiterApi
testImplementation testLibs.junitJupiterEngine
testImplementation testLibs.junitJupiterParams
testImplementation testLibs.junitJupiterLauncher
testImplementation testLibs.junit4
testImplementation testLibs.junit4Engine
testImplementation testLibs.assertjCore
Expand Down Expand Up @@ -212,6 +212,8 @@ tasks.withType( Test.class ).each { test ->

test.maxHeapSize = '3G'

// Enable bytecode enhanced engine:
test.systemProperties['hibernate.testing.bytecode.enhancement.extension.engine.enabled'] = true
test.systemProperties['hibernate.test.validatefailureexpected'] = true
test.systemProperties['hibernate.highlight_sql'] = false
test.systemProperties += System.properties.findAll { it.key.startsWith( "hibernate." ) }
Expand Down
51 changes: 51 additions & 0 deletions migration-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,51 @@ Interestingly, this now also aligns with handling for auto-flush events which al
The behavior of `noInterceptor()` for `SharedSessionBuilder` and (the new) `SharedStatelessSessionBuilder` was aligned with the preexisting semantics of this method on `SessionBuilder` and `StatelessSessionBuilder`.
The previous behavior may be recovered by calling `noSessionInterceptorCreation()`.

[[test-util-bytecodeenhanced-engine]]
=== JUnit `BytecodeEnhancedTestEngine`

With this version, `BytecodeEnhancedTestEngine` will be disabled by default.
To be able to run the tests annotated with `@BytecodeEnhanced`, this engine has to be explicitly enabled via a system property:

[source, properties]
----
hibernate.testing.bytecode.enhancement.extension.engine.enabled=true
----

For a Maven-based project this can be done as part of the failsafe/surefire plugin configuration:

[source, xml]
----
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<hibernate.testing.bytecode.enhancement.extension.engine.enabled>true</hibernate.testing.bytecode.enhancement.extension.engine.enabled>
<!-- Any other system properties required by your tests -->
</systemPropertyVariables>
<!-- The rest of the testing plugin configuration -->
<!-- ... -->
</configuration>
</plugin>
----

While for a Gradle-based project this can be done in multiple ways, it essentially comes down to configuring the
link:https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html#org.gradle.api.tasks.testing.Test:systemProperties[`systemProperties`]
of a `Test` task:

[source, groovy]
----
tasks.withType(Test.class) {
// Enable bytecode enhanced engine:
systemProperties.systemProperties['hibernate.testing.bytecode.enhancement.extension.engine.enabled'] = true
// Any other test task configurations
// ...
}
----

Also, this engine is expected to only work with the exact version of JUnit that `org.hibernate.orm:hibernate-testing` depends on.
While it may work with other versions as well, there is no guarantee of that.

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// DDL changes
Expand All @@ -120,3 +165,9 @@ Such changes typically do not impact programs using a relational schema managed

This section describes changes to dependencies used by Hibernate ORM.

[[junit6]]
=== JUnit 6 update

Hibernate ORM test utils distributed as `org.hibernate.orm:hibernate-testing` are now based on JUnit 6.0.
In general, this update is compatible with previous JUnit 5 versions unless the tests depended on the
<<test-util-bytecodeenhanced-engine,@BytecodeEnhanced extension>>.
Loading