Skip to content

Commit 3c7c6f3

Browse files
committed
back-port JUnit5 based testing support
1 parent 4eb683b commit 3c7c6f3

File tree

156 files changed

+11721
-36
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+11721
-36
lines changed

documentation/documentation.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,10 @@ task buildTutorialZip(type: Zip) {
216216
from 'src/main/asciidoc/quickstart/tutorials'
217217
destinationDir = tasks.renderGettingStartedGuides.outputDir
218218
archiveName = 'hibernate-tutorials.zip'
219-
expand(
219+
expand(
220220
version: project.version,
221221
slf4j: "1.7.5",
222-
junit: project.junitVersion,
222+
junit: project.junit4Version,
223223
h2: project.h2Version
224224
)
225225
}

gradle/libraries.gradle

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
// build a map of the dependency artifacts to use. Allows centralized definition of the version of artifacts to
99
// use. In that respect it serves a role similar to <dependencyManagement> in Maven
1010
ext {
11+
junit5Version = '5.8.2'
12+
junitVintageVersion = junit5Version
13+
junit4Version = '4.13.2'
1114

12-
junitVersion = '4.13.2'
1315
h2Version = '1.4.197'
1416
bytemanVersion = '4.0.16' //Compatible with JDK 17
1517
jnpVersion = '5.0.6.CR1'
@@ -116,8 +118,14 @@ ext {
116118

117119
// ~~~~~~~~~~~~~~~~~~~~~~~~~~ testing
118120

121+
junit5_api: "org.junit.jupiter:junit-jupiter-api:${junit5Version}",
122+
junit5_jupiter: "org.junit.jupiter:junit-jupiter-engine:${junit5Version}",
123+
junit5_params : "org.junit.jupiter:junit-jupiter-params:${junit5Version}",
124+
junit: "junit:junit:${junit4Version}",
125+
junit5_vintage: "org.junit.vintage:junit-vintage-engine:${junitVintageVersion}",
126+
119127
log4j2: "org.apache.logging.log4j:log4j-core:2.17.1",
120-
junit: "junit:junit:${junitVersion}",
128+
121129
byteman: "org.jboss.byteman:byteman:${bytemanVersion}",
122130
byteman_install: "org.jboss.byteman:byteman-install:${bytemanVersion}",
123131
byteman_bmunit: "org.jboss.byteman:byteman-bmunit:${bytemanVersion}",

hibernate-core/src/main/java/org/hibernate/internal/util/ReflectHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ private static Field locateField(Class clazz, String propertyName) {
435435
}
436436
}
437437

438-
private static boolean isStaticField(Field field) {
438+
public static boolean isStaticField(Field field) {
439439
return field != null && ( field.getModifiers() & Modifier.STATIC ) == Modifier.STATIC;
440440
}
441441

hibernate-core/src/main/java/org/hibernate/sql/JoinType.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,28 @@
1313
*/
1414

1515
public enum JoinType {
16-
NONE( -666 ),
17-
INNER_JOIN( 0 ),
18-
LEFT_OUTER_JOIN( 1 ),
19-
RIGHT_OUTER_JOIN( 2 ),
20-
FULL_JOIN( 4 );
21-
private int joinTypeValue;
22-
23-
JoinType(int joinTypeValue) {
16+
NONE( -666, null ),
17+
INNER_JOIN( 0, "inner" ),
18+
LEFT_OUTER_JOIN( 1, "left" ),
19+
RIGHT_OUTER_JOIN( 2, "right" ),
20+
FULL_JOIN( 4, "full" );
21+
22+
private final int joinTypeValue;
23+
private final String sqlText;
24+
25+
JoinType(int joinTypeValue, String sqlText) {
2426
this.joinTypeValue = joinTypeValue;
27+
this.sqlText = sqlText;
2528
}
2629

2730
public int getJoinTypeValue() {
2831
return joinTypeValue;
2932
}
3033

34+
public String getSqlText() {
35+
return sqlText;
36+
}
37+
3138
public static JoinType parse(int joinType) {
3239
if ( joinType < 0 ) {
3340
return NONE;

hibernate-core/src/main/java/org/hibernate/tool/schema/Action.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ public enum Action {
7676
this.externalHbm2ddlName = externalHbm2ddlName;
7777
}
7878

79+
public String getExternalJpaName() {
80+
return externalJpaName;
81+
}
82+
83+
public String getExternalHbm2ddlName() {
84+
return externalHbm2ddlName;
85+
}
86+
7987
@Override
8088
public String toString() {
8189
return getClass().getSimpleName() + "(externalJpaName=" + externalJpaName + ", externalHbm2ddlName=" + externalHbm2ddlName + ")";

hibernate-core/src/main/java/org/hibernate/tool/schema/spi/SchemaManagementToolCoordinator.java

Lines changed: 66 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
package org.hibernate.tool.schema.spi;
88

99
import java.util.EnumSet;
10+
import java.util.HashSet;
1011
import java.util.Map;
12+
import java.util.Set;
1113

1214
import org.hibernate.boot.Metadata;
1315
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
@@ -41,6 +43,8 @@
4143
import static org.hibernate.cfg.AvailableSettings.JAKARTA_HBM2DDL_SCRIPTS_ACTION;
4244
import static org.hibernate.cfg.AvailableSettings.JAKARTA_HBM2DDL_SCRIPTS_CREATE_TARGET;
4345
import static org.hibernate.cfg.AvailableSettings.JAKARTA_HBM2DDL_SCRIPTS_DROP_TARGET;
46+
import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER;
47+
import static org.hibernate.internal.util.NullnessHelper.coalesceSuppliedValues;
4448

4549
/**
4650
* Responsible for coordinating SchemaManagementTool execution(s) for auto-tooling whether
@@ -527,27 +531,71 @@ public Action getScriptAction() {
527531
}
528532

529533
public static ActionGrouping interpret(Map configurationValues) {
530-
Object databaseActionSetting = configurationValues.get( HBM2DDL_DATABASE_ACTION );
531-
Object scriptsActionSetting = configurationValues.get( HBM2DDL_SCRIPTS_ACTION );
532-
if ( databaseActionSetting == null ) {
533-
databaseActionSetting = configurationValues.get( JAKARTA_HBM2DDL_DATABASE_ACTION );
534-
}
535-
if ( scriptsActionSetting == null ) {
536-
scriptsActionSetting = configurationValues.get( JAKARTA_HBM2DDL_SCRIPTS_ACTION );
537-
}
538-
// interpret the JPA settings first
539-
Action databaseAction = Action.interpretJpaSetting( databaseActionSetting );
540-
Action scriptAction = Action.interpretJpaSetting( scriptsActionSetting );
541-
542-
// if no JPA settings were specified, look at the legacy HBM2DDL_AUTO setting...
543-
if ( databaseAction == Action.NONE && scriptAction == Action.NONE ) {
544-
final Action hbm2ddlAutoAction = Action.interpretHbm2ddlSetting( configurationValues.get( HBM2DDL_AUTO ) );
545-
if ( hbm2ddlAutoAction != Action.NONE ) {
546-
databaseAction = hbm2ddlAutoAction;
534+
// default to the JPA settings
535+
Action databaseActionToUse = determineJpaDbActionSetting( configurationValues );
536+
Action scriptActionToUse = determineJpaScriptActionSetting( configurationValues );
537+
Action autoAction = determineAutoSettingImpliedAction( configurationValues, null );
538+
539+
if ( databaseActionToUse == null && scriptActionToUse == null ) {
540+
// no JPA (jakarta nor javax) settings were specified, use the legacy Hibernate
541+
// `hbm2ddl.auto` setting to possibly set the database-action
542+
if ( autoAction != null ) {
543+
databaseActionToUse = autoAction;
547544
}
548545
}
549546

550-
return new ActionGrouping( databaseAction, scriptAction );
547+
if ( databaseActionToUse == null ) {
548+
databaseActionToUse = Action.NONE;
549+
}
550+
551+
if ( scriptActionToUse == null ) {
552+
scriptActionToUse = Action.NONE;
553+
}
554+
555+
if ( databaseActionToUse == Action.NONE && scriptActionToUse == Action.NONE ) {
556+
log.debugf( "No schema actions specified" );
557+
}
558+
559+
return new ActionGrouping( databaseActionToUse, scriptActionToUse );
560+
}
561+
562+
private static Action determineJpaDbActionSetting(Map<?,?> configurationValues) {
563+
final Object scriptsActionSetting = coalesceSuppliedValues(
564+
() -> configurationValues.get( JAKARTA_HBM2DDL_DATABASE_ACTION ),
565+
() -> {
566+
final Object setting = configurationValues.get( HBM2DDL_DATABASE_ACTION );
567+
if ( setting != null ) {
568+
DEPRECATION_LOGGER.deprecatedSetting( HBM2DDL_DATABASE_ACTION, JAKARTA_HBM2DDL_DATABASE_ACTION );
569+
}
570+
return setting;
571+
}
572+
);
573+
574+
return scriptsActionSetting == null ? null : Action.interpretJpaSetting( scriptsActionSetting );
575+
}
576+
577+
private static Action determineJpaScriptActionSetting(Map<?,?> configurationValues) {
578+
final Object scriptsActionSetting = coalesceSuppliedValues(
579+
() -> configurationValues.get( JAKARTA_HBM2DDL_SCRIPTS_ACTION ),
580+
() -> {
581+
final Object setting = configurationValues.get( HBM2DDL_SCRIPTS_ACTION );
582+
if ( setting != null ) {
583+
DEPRECATION_LOGGER.deprecatedSetting( HBM2DDL_SCRIPTS_ACTION, JAKARTA_HBM2DDL_SCRIPTS_ACTION );
584+
}
585+
return setting;
586+
}
587+
);
588+
589+
return scriptsActionSetting == null ? null : Action.interpretJpaSetting( scriptsActionSetting );
590+
}
591+
592+
public static Action determineAutoSettingImpliedAction(Map<?,?> settings, Action defaultValue) {
593+
final Object autoActionSetting = settings.get( HBM2DDL_AUTO );
594+
if ( autoActionSetting == null ) {
595+
return defaultValue;
596+
}
597+
598+
return Action.interpretHbm2ddlSetting( autoActionSetting );
551599
}
552600
}
553601
}

hibernate-testing/hibernate-testing.gradle

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,22 @@ apply from: rootProject.file( 'gradle/published-java-module.gradle' )
1313
dependencies {
1414
compile project( ':hibernate-core' )
1515
compile( libraries.jta )
16-
compile( libraries.junit )
16+
17+
compile libraries.junit
18+
compile libraries.junit5_api
19+
compile libraries.junit5_params
20+
21+
compile libraries.assertj
22+
23+
compile libraries.log4j2
24+
25+
compile 'javax.money:money-api:1.0.1'
26+
compile 'org.javamoney:moneta:1.1'
27+
1728
compile( libraries.byteman )
1829
compile( libraries.byteman_install )
1930
compile( libraries.byteman_bmunit )
2031
compile( libraries.xapool )
21-
compile( libraries.log4j2 )
2232
compile( libraries.jboss_tx_spi ) {
2333
transitive=false;
2434
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
5+
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
6+
*/
7+
package org.hibernate.testing.boot;
8+
9+
import java.lang.reflect.InvocationTargetException;
10+
import java.util.ArrayList;
11+
import java.util.Collection;
12+
import java.util.List;
13+
14+
import org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl;
15+
16+
/**
17+
* @author Steve Ebersole
18+
*/
19+
public class ExtraJavaServicesClassLoaderService extends ClassLoaderServiceImpl {
20+
private final List<JavaServiceDescriptor<?>> extraJavaServices;
21+
22+
public ExtraJavaServicesClassLoaderService(List<JavaServiceDescriptor<?>> extraJavaServices) {
23+
this.extraJavaServices = extraJavaServices;
24+
}
25+
26+
@Override
27+
public <S> Collection<S> loadJavaServices(Class<S> serviceContract) {
28+
final Collection<S> baseServices = super.loadJavaServices( serviceContract );
29+
final List<S> services = new ArrayList<>( baseServices );
30+
31+
applyExtraJavaServices( serviceContract, services );
32+
33+
return services;
34+
}
35+
36+
private <S> void applyExtraJavaServices(Class<S> serviceContract, List<S> services) {
37+
extraJavaServices.forEach(
38+
(javaServiceDescriptor) -> {
39+
if ( serviceContract.isAssignableFrom( javaServiceDescriptor.role ) ) {
40+
try {
41+
final Object serviceInstance = javaServiceDescriptor.impl.getDeclaredConstructor().newInstance();
42+
//noinspection unchecked
43+
services.add( (S) serviceInstance );
44+
}
45+
catch (NoSuchMethodException | IllegalAccessException e) {
46+
throw new RuntimeException( "Unable to access constructor for specified 'extra' Java service : " + javaServiceDescriptor.impl.getName(), e );
47+
}
48+
catch (InstantiationException | InvocationTargetException e) {
49+
throw new RuntimeException( "Unable to instantiate specified 'extra' Java service : " + javaServiceDescriptor.impl.getName(), e );
50+
}
51+
}
52+
}
53+
);
54+
}
55+
56+
public static class JavaServiceDescriptor<ROLE> {
57+
private final Class<ROLE> role;
58+
private final Class<? extends ROLE> impl;
59+
60+
public JavaServiceDescriptor(Class<ROLE> role, Class<? extends ROLE> impl) {
61+
this.role = role;
62+
this.impl = impl;
63+
}
64+
65+
public Class<ROLE> getRole() {
66+
return role;
67+
}
68+
69+
public Class<? extends ROLE> getImpl() {
70+
return impl;
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)