Skip to content

Commit 390c761

Browse files
committed
Introduce conditional testing for Hibernate.
Certain test cases only work with Hibernate 6.1 or 6.2. This introduces the means to run them contextually. We also will run additional CI jobs to verify everything works on both Hibernate 6.1 as well as Hibernate 6.2. Resolves #2927.
1 parent 6db9a6b commit 390c761

File tree

7 files changed

+179
-5
lines changed

7 files changed

+179
-5
lines changed

Jenkinsfile

+17
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,23 @@ pipeline {
5353
}
5454

5555
parallel {
56+
stage("test: baseline (hibernate 6.1)") {
57+
agent {
58+
label 'data'
59+
}
60+
options { timeout(time: 30, unit: 'MINUTES')}
61+
environment {
62+
ARTIFACTORY = credentials("${p['artifactory.credentials']}")
63+
}
64+
steps {
65+
script {
66+
docker.image(p['docker.java.next.image']).inside(p['docker.java.inside.docker']) {
67+
sh 'PROFILE=all-dbs,hibernate-61 ci/test.sh'
68+
sh "ci/clean.sh"
69+
}
70+
}
71+
}
72+
}
5673
stage("test: baseline (next)") {
5774
agent {
5875
label 'data'

pom.xml

+6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@
5454

5555

5656
<profiles>
57+
<profile>
58+
<id>hibernate-61</id>
59+
<properties>
60+
<hibernate>6.1.7.Final</hibernate>
61+
</properties>
62+
</profile>
5763
<profile>
5864
<id>all-dbs</id>
5965
<build>

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/procedures/PostgresStoredProcedureIntegrationTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.data.jpa.repository.procedures;
1818

19-
import static org.assertj.core.api.Assertions.assertThat;
19+
import static org.assertj.core.api.Assertions.*;
2020

2121
import jakarta.persistence.Entity;
2222
import jakarta.persistence.EntityManagerFactory;
@@ -36,7 +36,6 @@
3636
import javax.sql.DataSource;
3737

3838
import org.hibernate.dialect.PostgreSQLDialect;
39-
import org.junit.jupiter.api.Disabled;
4039
import org.junit.jupiter.api.Test;
4140
import org.junit.jupiter.api.extension.ExtendWith;
4241
import org.postgresql.ds.PGSimpleDataSource;
@@ -48,6 +47,7 @@
4847
import org.springframework.data.jpa.repository.JpaRepository;
4948
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
5049
import org.springframework.data.jpa.repository.query.Procedure;
50+
import org.springframework.data.jpa.util.DisabledOnHibernate62;
5151
import org.springframework.jdbc.datasource.init.DataSourceInitializer;
5252
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
5353
import org.springframework.orm.jpa.AbstractEntityManagerFactoryBean;
@@ -68,7 +68,6 @@
6868
* @author Greg Turnquist
6969
* @author Yanming Zhou
7070
*/
71-
@Disabled
7271
@Transactional
7372
@ExtendWith(SpringExtension.class)
7473
@ContextConfiguration(classes = PostgresStoredProcedureIntegrationTests.Config.class)
@@ -116,6 +115,7 @@ void testNamedOutputParameter() {
116115
new Employee(4, "Gabriel"));
117116
}
118117

118+
@DisabledOnHibernate62
119119
@Test // 2256
120120
void testSingleEntityFromResultSet() {
121121

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/support/HibernateJpaMetamodelEntityInformationIntegrationTests.java

+24-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
*/
1616
package org.springframework.data.jpa.repository.support;
1717

18+
import org.junit.jupiter.api.Test;
1819
import org.junit.jupiter.api.extension.ExtendWith;
20+
import org.springframework.data.jpa.util.DisabledOnHibernate61;
1921
import org.springframework.test.context.ContextConfiguration;
2022
import org.springframework.test.context.junit.jupiter.SpringExtension;
2123

@@ -26,11 +28,31 @@
2628
*/
2729
@ExtendWith(SpringExtension.class)
2830
@ContextConfiguration("classpath:infrastructure.xml")
29-
class HibernateJpaMetamodelEntityInformationIntegrationTests
30-
extends JpaMetamodelEntityInformationIntegrationTests {
31+
class HibernateJpaMetamodelEntityInformationIntegrationTests extends JpaMetamodelEntityInformationIntegrationTests {
3132

3233
@Override
3334
String getMetadadataPersistenceUnitName() {
3435
return "metadata-id-handling";
3536
}
37+
38+
@DisabledOnHibernate61
39+
@Test
40+
@Override
41+
void correctlyDeterminesIdValueForNestedIdClassesWithNonPrimitiveNonManagedType() {
42+
super.correctlyDeterminesIdValueForNestedIdClassesWithNonPrimitiveNonManagedType();
43+
}
44+
45+
@DisabledOnHibernate61
46+
@Test
47+
@Override
48+
void prefersPrivateGetterOverFieldAccess() {
49+
super.prefersPrivateGetterOverFieldAccess();
50+
}
51+
52+
@DisabledOnHibernate61
53+
@Test
54+
@Override
55+
void findsIdClassOnMappedSuperclass() {
56+
super.findsIdClassOnMappedSuperclass();
57+
}
3658
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2015-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.jpa.util;
17+
18+
import java.lang.annotation.ElementType;
19+
import java.lang.annotation.Retention;
20+
import java.lang.annotation.RetentionPolicy;
21+
import java.lang.annotation.Target;
22+
23+
import org.junit.jupiter.api.extension.ExtendWith;
24+
25+
/**
26+
* Annotation to flag JUnit 5 test cases to ONLY activate when Hibernate 6.2 is on the classpath.
27+
*
28+
* @author Greg Turnquist
29+
* @since 3.1
30+
*/
31+
@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.ANNOTATION_TYPE })
32+
@Retention(RetentionPolicy.RUNTIME)
33+
@ExtendWith(HibernateSupport.Hibernate62OnClassPath.class)
34+
public @interface DisabledOnHibernate61 {
35+
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2015-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.jpa.util;
17+
18+
import java.lang.annotation.ElementType;
19+
import java.lang.annotation.Retention;
20+
import java.lang.annotation.RetentionPolicy;
21+
import java.lang.annotation.Target;
22+
23+
import org.junit.jupiter.api.extension.ExtendWith;
24+
25+
/**
26+
* Annotation to flag JUnit 5 test cases to ONLY activate when Hibernate 6.1 is on the classpath.
27+
*
28+
* @author Greg Turnquist
29+
* @since 3.1
30+
*/
31+
@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.ANNOTATION_TYPE })
32+
@Retention(RetentionPolicy.RUNTIME)
33+
@ExtendWith(HibernateSupport.Hibernate61OnClassPath.class)
34+
public @interface DisabledOnHibernate62 {
35+
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2015-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.jpa.util;
17+
18+
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
19+
import org.junit.jupiter.api.extension.ExecutionCondition;
20+
import org.junit.jupiter.api.extension.ExtensionContext;
21+
import org.springframework.util.ClassUtils;
22+
23+
/**
24+
* JUnit 5 utilities to support conditionalizing test cases based upon Hibernate classpath settings.
25+
*
26+
* @author Greg Turnquist
27+
* @since 3.1
28+
*/
29+
abstract class HibernateSupport {
30+
31+
private static final boolean HIBERNATE_61_ON_CLASSPATH = ClassUtils
32+
.isPresent("org.hibernate.dialect.PostgreSQL91Dialect", HibernateSupport.class.getClassLoader());
33+
34+
private static final boolean HIBERNATE_62_ON_CLASSPATH = !HIBERNATE_61_ON_CLASSPATH;
35+
36+
static class Hibernate61OnClassPath implements ExecutionCondition {
37+
38+
@Override
39+
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext extensionContext) {
40+
41+
return HibernateSupport.HIBERNATE_61_ON_CLASSPATH
42+
? ConditionEvaluationResult.enabled("NOT disabled because Hibernate 6.1 is on the classpath")
43+
: ConditionEvaluationResult.disabled("Disabled because Hibernate 6.2 is on the classpath");
44+
}
45+
}
46+
47+
static class Hibernate62OnClassPath implements ExecutionCondition {
48+
49+
@Override
50+
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext extensionContext) {
51+
52+
return HibernateSupport.HIBERNATE_62_ON_CLASSPATH
53+
? ConditionEvaluationResult.enabled("NOT disabled because Hibernate 6.2 is on the classpath")
54+
: ConditionEvaluationResult.disabled("Disabled because Hibernate 6.1 is on the classpath");
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)