Skip to content

Commit

Permalink
Upgrade to Hibernate 6.1.x; fix JPA tests
Browse files Browse the repository at this point in the history
  • Loading branch information
artembilan committed Jul 12, 2022
1 parent 5ded860 commit b074f19
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 60 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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"
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -110,9 +110,9 @@ protected ExpressionEvaluatingParameterSource(Object input, List<JpaParameter> p
@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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -208,7 +208,7 @@ public void testResultStartingFromThirdRecordForJPAQuery() {
@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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;

Expand All @@ -34,7 +33,6 @@
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;
Expand Down Expand Up @@ -79,10 +77,6 @@ public class JpaOutboundGatewayIntegrationTests {
@Qualifier("findResultChannel")
private PollableChannel findResultChannel;

@Autowired
@Qualifier("invalidIdType")
private SubscribableChannel invalidIdTypeChannel;

@Autowired
private EntityManager entityManager;

Expand Down Expand Up @@ -151,28 +145,9 @@ public void testFindAndDelete() {
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));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -24,14 +24,16 @@
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;

/**
*
* @author Gunnar Hillert
* @author Artem Bilan
*
* @since 2.2
*
*/
Expand All @@ -57,7 +59,6 @@ public void testMapInput() {

@Test
public void testListOfMapsInput() {
@SuppressWarnings("unchecked")
ParameterSource source = factory.createParameterSource(Arrays.asList(Collections.singletonMap("foo", "bar"),
Collections.singletonMap("foo", "bucket")));
String expression = "foo";
Expand All @@ -83,8 +84,7 @@ public void testMapInputWithMappedExpression() {

@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);
Expand All @@ -97,7 +97,6 @@ public void testMapInputWithMappedExpressionResolveStatic() {
@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";
Expand All @@ -107,39 +106,39 @@ public void testListOfMapsInputWithExpression() {

@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");
}

@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");
}

@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()"));
Expand All @@ -148,8 +147,8 @@ public void testPositionalExpressionParameters2() {

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");
Expand Down

0 comments on commit b074f19

Please sign in to comment.