Upgrade to Hibernate 6.1.x; fix JPA tests

This commit is contained in:
Artem Bilan
2022-07-12 12:18:19 -04:00
parent 5ded860e78
commit b074f1961f
7 changed files with 26 additions and 60 deletions

View File

@@ -65,7 +65,7 @@ ext {
groovyVersion = '3.0.10'
hamcrestVersion = '2.2'
hazelcastVersion = '5.1.1'
hibernateVersion = '5.6.8.Final'
hibernateVersion = '6.1.1.Final'
hsqldbVersion = '2.6.1'
h2Version = '2.1.212'
jacksonVersion = '2.13.3'
@@ -759,7 +759,7 @@ project('spring-integration-jpa') {
exclude group: 'org.springframework'
}
testImplementation "com.h2database:h2:$h2Version"
testImplementation "org.hibernate:hibernate-core-jakarta:$hibernateVersion"
testImplementation "org.hibernate.orm:hibernate-core:$hibernateVersion"
testImplementation "org.hamcrest:hamcrest-core:$hamcrestVersion"
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2022 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.
@@ -110,9 +110,9 @@ public class ExpressionEvaluatingParameterSourceFactory implements ParameterSour
@Override
@Nullable
public Object getValueByPosition(int position) {
Assert.isTrue(position >= 0, "The position must be non-negative.");
Assert.isTrue(position > 0, "The position must be non-negative.");
if (position <= this.parameters.size()) {
JpaParameter parameter = this.parameters.get(position);
JpaParameter parameter = this.parameters.get(position - 1);
String parameterName = parameter.getName();
if (parameterName != null) {
return getValue(parameterName);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 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.
@@ -208,7 +208,7 @@ public class JpaExecutorTests {
@Test
public void testResultStartingFromThirdRecordForNativeQuery() {
final JpaExecutor jpaExecutor = new JpaExecutor(entityManager);
jpaExecutor.setNativeQuery("select * from Student s");
jpaExecutor.setJpaQuery("select s from Student s");
jpaExecutor.setFirstResultExpression(new LiteralExpression("2"));
jpaExecutor.setBeanFactory(this.beanFactory);
jpaExecutor.afterPropertiesSet();

View File

@@ -63,12 +63,4 @@
<int-jpa:transactional/>
</int-jpa:retrieving-outbound-gateway>
<int:channel id="invalidIdType"/>
<int-jpa:retrieving-outbound-gateway
entity-manager="entityManager"
request-channel="invalidIdType"
entity-class="org.springframework.integration.jpa.test.entity.StudentDomain"
id-expression="payload"/>
</beans>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 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.
@@ -17,13 +17,12 @@
package org.springframework.integration.jpa.outbound;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import java.util.List;
import jakarta.persistence.EntityManager;
import org.hibernate.TypeMismatchException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
@@ -34,7 +33,6 @@ import org.springframework.integration.jpa.test.entity.StudentDomain;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessageHandlingException;
import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.SubscribableChannel;
import org.springframework.test.annotation.DirtiesContext;
@@ -79,10 +77,6 @@ public class JpaOutboundGatewayIntegrationTests {
@Qualifier("findResultChannel")
private PollableChannel findResultChannel;
@Autowired
@Qualifier("invalidIdType")
private SubscribableChannel invalidIdTypeChannel;
@Autowired
private EntityManager entityManager;
@@ -151,28 +145,9 @@ public class JpaOutboundGatewayIntegrationTests {
Message<?> receive = this.findResultChannel.receive(2000);
assertThat(receive).isNotNull();
try {
this.findAndDeleteChannel.send(message);
}
catch (Exception e) {
assertThat(e).isInstanceOf(ReplyRequiredException.class);
}
}
@Test
public void testInvalidIdType() {
Message<Integer> message = MessageBuilder.withPayload(1).build();
try {
this.invalidIdTypeChannel.send(message);
fail("PersistenceException expected");
}
catch (Exception e) {
assertThat(e).isInstanceOf(MessageHandlingException.class);
assertThat(e.getCause()).isInstanceOf(IllegalArgumentException.class);
assertThat(e.getCause().getCause()).isInstanceOf(TypeMismatchException.class);
assertThat(e.getCause().getMessage())
.contains("Expected: class java.lang.Long, got class java.lang.Integer");
}
assertThatExceptionOfType(ReplyRequiredException.class)
.isThrownBy(() -> this.findAndDeleteChannel.send(message));
}
}

View File

@@ -186,7 +186,7 @@
<bean class="org.springframework.integration.jpa.core.JpaExecutor">
<constructor-arg name="entityManager" ref="entityManager"/>
<property name="entityClass" value="org.springframework.integration.jpa.test.entity.StudentDomain"/>
<property name="jpaQuery" value="from Student s where s.firstName = ?0 and s.lastName = ?1"/>
<property name="jpaQuery" value="from Student s where s.firstName = ?1 and s.lastName = ?2"/>
<property name="expectSingleResult" value="true"/>
<property name="jpaParameters" >
<util:list>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2022 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.
@@ -24,7 +24,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.integration.jpa.support.JpaParameter;
@@ -32,6 +32,8 @@ import org.springframework.integration.jpa.support.JpaParameter;
/**
*
* @author Gunnar Hillert
* @author Artem Bilan
*
* @since 2.2
*
*/
@@ -57,7 +59,6 @@ public class ExpressionEvaluatingParameterSourceFactoryTests {
@Test
public void testListOfMapsInput() {
@SuppressWarnings("unchecked")
ParameterSource source = factory.createParameterSource(Arrays.asList(Collections.singletonMap("foo", "bar"),
Collections.singletonMap("foo", "bucket")));
String expression = "foo";
@@ -83,8 +84,7 @@ public class ExpressionEvaluatingParameterSourceFactoryTests {
@Test
public void testMapInputWithMappedExpressionResolveStatic() {
List<JpaParameter> parameters = new ArrayList<JpaParameter>();
List<JpaParameter> parameters = new ArrayList<>();
parameters.add(new JpaParameter("spam", null, "#staticParameters['foo'].toUpperCase()"));
parameters.add(new JpaParameter("foo", "bar", null));
factory.setParameters(parameters);
@@ -97,7 +97,6 @@ public class ExpressionEvaluatingParameterSourceFactoryTests {
@Test
public void testListOfMapsInputWithExpression() {
factory.setParameters(Collections.singletonList(new JpaParameter("spam", null, "foo.toUpperCase()")));
@SuppressWarnings("unchecked")
ParameterSource source = factory.createParameterSource(Arrays.asList(Collections.singletonMap("foo", "bar"),
Collections.singletonMap("foo", "bucket")));
String expression = "spam";
@@ -107,15 +106,15 @@ public class ExpressionEvaluatingParameterSourceFactoryTests {
@Test
public void testPositionalStaticParameters() {
List<JpaParameter> parameters = new ArrayList<JpaParameter>();
List<JpaParameter> parameters = new ArrayList<>();
parameters.add(new JpaParameter("foo", null));
parameters.add(new JpaParameter("bar", null));
factory.setParameters(parameters);
PositionSupportingParameterSource source = factory.createParameterSource("not important");
String position0 = (String) source.getValueByPosition(0);
String position1 = (String) source.getValueByPosition(1);
String position0 = (String) source.getValueByPosition(1);
String position1 = (String) source.getValueByPosition(2);
assertThat(position0).isEqualTo("foo");
assertThat(position1).isEqualTo("bar");
@@ -123,15 +122,15 @@ public class ExpressionEvaluatingParameterSourceFactoryTests {
@Test
public void testPositionalExpressionParameters() {
List<JpaParameter> parameters = new ArrayList<JpaParameter>();
List<JpaParameter> parameters = new ArrayList<>();
parameters.add(new JpaParameter(null, "#root.toUpperCase()"));
parameters.add(new JpaParameter("bar", null));
factory.setParameters(parameters);
PositionSupportingParameterSource source = factory.createParameterSource("very important");
String position0 = (String) source.getValueByPosition(0);
String position1 = (String) source.getValueByPosition(1);
String position0 = (String) source.getValueByPosition(1);
String position1 = (String) source.getValueByPosition(2);
assertThat(position0).isEqualTo("VERY IMPORTANT");
assertThat(position1).isEqualTo("bar");
@@ -139,7 +138,7 @@ public class ExpressionEvaluatingParameterSourceFactoryTests {
@Test
public void testPositionalExpressionParameters2() {
List<JpaParameter> parameters = new ArrayList<JpaParameter>();
List<JpaParameter> parameters = new ArrayList<>();
parameters.add(new JpaParameter("bar", null));
parameters.add(new JpaParameter(null, "#root.toUpperCase()"));
@@ -148,8 +147,8 @@ public class ExpressionEvaluatingParameterSourceFactoryTests {
PositionSupportingParameterSource source = factory.createParameterSource("very important");
String position0 = (String) source.getValueByPosition(0);
String position1 = (String) source.getValueByPosition(1);
String position0 = (String) source.getValueByPosition(1);
String position1 = (String) source.getValueByPosition(2);
assertThat(position1).isEqualTo("VERY IMPORTANT");
assertThat(position0).isEqualTo("bar");