Introduce conditional testing for Hibernate.

Certain test cases should be disabled based on the version of Hibernate. We should also run the entire test suite against both Hibernate 6.1 and 6.2, to ensure maxiumum support.

Resolves #2927.
This commit is contained in:
Greg L. Turnquist
2023-04-25 22:53:54 -05:00
parent f778a43f28
commit 4d1c4adf6e
7 changed files with 184 additions and 5 deletions

17
Jenkinsfile vendored
View File

@@ -53,6 +53,23 @@ pipeline {
}
parallel {
stage("test: baseline (hibernate 6.1)") {
agent {
label 'data'
}
options { timeout(time: 30, unit: 'MINUTES')}
environment {
ARTIFACTORY = credentials("${p['artifactory.credentials']}")
}
steps {
script {
docker.image(p['docker.java.next.image']).inside(p['docker.java.inside.docker']) {
sh 'PROFILE=all-dbs,hibernate-61 ci/test.sh'
sh "ci/clean.sh"
}
}
}
}
stage("test: baseline (next)") {
agent {
label 'data'

View File

@@ -54,6 +54,12 @@
<profiles>
<profile>
<id>hibernate-61</id>
<properties>
<hibernate>6.1.7.Final</hibernate>
</properties>
</profile>
<profile>
<id>all-dbs</id>
<build>

View File

@@ -16,7 +16,7 @@
package org.springframework.data.jpa.repository.procedures;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.*;
import jakarta.persistence.Entity;
import jakarta.persistence.EntityManagerFactory;
@@ -36,7 +36,6 @@ import java.util.Properties;
import javax.sql.DataSource;
import org.hibernate.dialect.PostgreSQLDialect;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.postgresql.ds.PGSimpleDataSource;
@@ -48,6 +47,7 @@ import org.springframework.core.io.ClassPathResource;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.data.jpa.repository.query.Procedure;
import org.springframework.data.jpa.util.DisabledOnHibernate62;
import org.springframework.jdbc.datasource.init.DataSourceInitializer;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
import org.springframework.orm.jpa.AbstractEntityManagerFactoryBean;
@@ -68,7 +68,6 @@ import org.testcontainers.containers.PostgreSQLContainer;
* @author Greg Turnquist
* @author Yanming Zhou
*/
@Disabled
@Transactional
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = PostgresStoredProcedureIntegrationTests.Config.class)
@@ -116,6 +115,7 @@ class PostgresStoredProcedureIntegrationTests {
new Employee(4, "Gabriel"));
}
@DisabledOnHibernate62
@Test // 2256
void testSingleEntityFromResultSet() {

View File

@@ -15,7 +15,9 @@
*/
package org.springframework.data.jpa.repository.support;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.data.jpa.util.DisabledOnHibernate61;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@@ -26,11 +28,31 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
*/
@ExtendWith(SpringExtension.class)
@ContextConfiguration("classpath:infrastructure.xml")
class HibernateJpaMetamodelEntityInformationIntegrationTests
extends JpaMetamodelEntityInformationIntegrationTests {
class HibernateJpaMetamodelEntityInformationIntegrationTests extends JpaMetamodelEntityInformationIntegrationTests {
@Override
String getMetadadataPersistenceUnitName() {
return "metadata-id-handling";
}
@DisabledOnHibernate61
@Test
@Override
void correctlyDeterminesIdValueForNestedIdClassesWithNonPrimitiveNonManagedType() {
super.correctlyDeterminesIdValueForNestedIdClassesWithNonPrimitiveNonManagedType();
}
@DisabledOnHibernate61
@Test
@Override
void prefersPrivateGetterOverFieldAccess() {
super.prefersPrivateGetterOverFieldAccess();
}
@DisabledOnHibernate61
@Test
@Override
void findsIdClassOnMappedSuperclass() {
super.findsIdClassOnMappedSuperclass();
}
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright 2015-2023 the original author or authors.
*
* Licensed 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
*
* https://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.springframework.data.jpa.util;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.junit.jupiter.api.extension.ExtendWith;
/**
* Annotation to flag JUnit 5 test cases to ONLY activate when Hibernate 6.2 is on the classpath.
*
* @author Greg Turnquist
* @since 3.1
*/
@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)
@ExtendWith(HibernateSupport.DisabledWhenHibernate61OnClasspath.class)
public @interface DisabledOnHibernate61 {
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright 2015-2023 the original author or authors.
*
* Licensed 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
*
* https://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.springframework.data.jpa.util;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.junit.jupiter.api.extension.ExtendWith;
/**
* Annotation to flag JUnit 5 test cases to ONLY activate when Hibernate 6.1 is on the classpath.
*
* @author Greg Turnquist
* @since 3.1
*/
@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)
@ExtendWith(HibernateSupport.DisabledWhenHibernate62OnClasspath.class)
public @interface DisabledOnHibernate62 {
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright 2015-2023 the original author or authors.
*
* Licensed 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
*
* https://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.springframework.data.jpa.util;
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
import org.junit.jupiter.api.extension.ExecutionCondition;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.springframework.util.ClassUtils;
/**
* JUnit 5 utilities to support conditional test cases based upon Hibernate classpath settings.
*
* @author Greg Turnquist
* @since 3.1
*/
abstract class HibernateSupport {
/**
* {@literal org.hibernate.dialect.PostgreSQL91Dialect} is deprecated in Hibernate 6.1 and fully removed in Hibernate
* 6.2, making it a perfect detector between the two.
*/
private static final boolean HIBERNATE_61_ON_CLASSPATH = ClassUtils
.isPresent("org.hibernate.dialect.PostgreSQL91Dialect", HibernateSupport.class.getClassLoader());
private static final boolean HIBERNATE_62_ON_CLASSPATH = !HIBERNATE_61_ON_CLASSPATH;
static class DisabledWhenHibernate61OnClasspath implements ExecutionCondition {
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext extensionContext) {
return HibernateSupport.HIBERNATE_61_ON_CLASSPATH
? ConditionEvaluationResult.disabled("Disabled because Hibernate 6.1 is on the classpath")
: ConditionEvaluationResult.enabled("NOT disabled because Hibernate 6.2 is on the classpath");
}
}
static class DisabledWhenHibernate62OnClasspath implements ExecutionCondition {
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext extensionContext) {
return HibernateSupport.HIBERNATE_62_ON_CLASSPATH
? ConditionEvaluationResult.disabled("Disabled because Hibernate 6.2 is on the classpath")
: ConditionEvaluationResult.enabled("NOT disabled because Hibernate 6.1 is on the classpath");
}
}
}