Browse Source

Update code due to upgrade to Jakarta EE 11 APIs

pull/34021/head
Sam Brannen 1 year ago
parent
commit
d41d674c4f
  1. 2
      spring-context/src/test/java/org/springframework/validation/DataBinderConstructTests.java
  2. 18
      spring-orm/src/test/java/org/springframework/orm/jpa/hibernate/HibernateNativeEntityManagerFactoryIntegrationTests.java
  3. 1
      spring-orm/src/test/java/org/springframework/orm/jpa/hibernate/HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests.java
  4. 8
      spring-test/src/test/java/org/springframework/test/context/junit4/orm/repository/hibernate/HibernatePersonRepository.java
  5. 3
      spring-web/src/test/java/org/springframework/web/bind/support/WebExchangeDataBinderTests.java

2
spring-context/src/test/java/org/springframework/validation/DataBinderConstructTests.java

@ -207,7 +207,7 @@ class DataBinderConstructTests {
} }
private static class NestedDataClass { static class NestedDataClass {
private final String param1; private final String param1;

18
spring-orm/src/test/java/org/springframework/orm/jpa/hibernate/HibernateNativeEntityManagerFactoryIntegrationTests.java

@ -53,11 +53,11 @@ class HibernateNativeEntityManagerFactoryIntegrationTests extends AbstractContai
} }
@Override
@Test @Test
@Override
protected void testEntityManagerFactoryImplementsEntityManagerFactoryInfo() { protected void testEntityManagerFactoryImplementsEntityManagerFactoryInfo() {
boolean condition = entityManagerFactory instanceof EntityManagerFactoryInfo; assertThat(entityManagerFactory).as("Must not have introduced config interface")
assertThat(condition).as("Must not have introduced config interface").isFalse(); .isNotInstanceOf(EntityManagerFactoryInfo.class);
} }
@Test @Test
@ -66,23 +66,21 @@ class HibernateNativeEntityManagerFactoryIntegrationTests extends AbstractContai
String firstName = "Tony"; String firstName = "Tony";
insertPerson(firstName); insertPerson(firstName);
List<Person> people = sharedEntityManager.createQuery("select p from Person as p").getResultList(); List<Person> people = sharedEntityManager.createQuery("select p from Person as p", Person.class).getResultList();
assertThat(people).hasSize(1); assertThat(people).hasSize(1);
assertThat(people.get(0).getFirstName()).isEqualTo(firstName); assertThat(people.get(0).getFirstName()).isEqualTo(firstName);
assertThat(people.get(0).postLoaded).isSameAs(applicationContext); assertThat(people.get(0).postLoaded).isSameAs(applicationContext);
} }
@Test @Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testCurrentSession() { public void testCurrentSession() {
String firstName = "Tony"; String firstName = "Tony";
insertPerson(firstName); insertPerson(firstName);
Query q = sessionFactory.getCurrentSession().createQuery("select p from Person as p"); Query<Person> q = sessionFactory.getCurrentSession().createQuery("select p from Person as p", Person.class);
List<Person> people = q.getResultList(); assertThat(q.getResultList()).hasSize(1);
assertThat(people).hasSize(1); assertThat(q.getResultList().get(0).getFirstName()).isEqualTo(firstName);
assertThat(people.get(0).getFirstName()).isEqualTo(firstName); assertThat(q.getResultList().get(0).postLoaded).isSameAs(applicationContext);
assertThat(people.get(0).postLoaded).isSameAs(applicationContext);
} }
@Test // SPR-16956 @Test // SPR-16956

1
spring-orm/src/test/java/org/springframework/orm/jpa/hibernate/HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests.java

@ -56,6 +56,7 @@ class HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests
"/org/springframework/orm/jpa/hibernate/inject-hibernate-spring-bean-container-tests.xml"}; "/org/springframework/orm/jpa/hibernate/inject-hibernate-spring-bean-container-tests.xml"};
} }
@SuppressWarnings("deprecation")
private ManagedBeanRegistry getManagedBeanRegistry() { private ManagedBeanRegistry getManagedBeanRegistry() {
SessionFactory sessionFactory = entityManagerFactory.unwrap(SessionFactory.class); SessionFactory sessionFactory = entityManagerFactory.unwrap(SessionFactory.class);
ServiceRegistry serviceRegistry = sessionFactory.getSessionFactoryOptions().getServiceRegistry(); ServiceRegistry serviceRegistry = sessionFactory.getSessionFactoryOptions().getServiceRegistry();

8
spring-test/src/test/java/org/springframework/test/context/junit4/orm/repository/hibernate/HibernatePersonRepository.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -48,8 +48,10 @@ public class HibernatePersonRepository implements PersonRepository {
@Override @Override
public Person findByName(String name) { public Person findByName(String name) {
return (Person) this.sessionFactory.getCurrentSession().createQuery( return this.sessionFactory.getCurrentSession()
"from Person person where person.name = :name").setParameter("name", name).getSingleResult(); .createQuery("from Person person where person.name = :name", Person.class)
.setParameter("name", name)
.getSingleResult();
} }
} }

3
spring-web/src/test/java/org/springframework/web/bind/support/WebExchangeDataBinderTests.java

@ -330,7 +330,7 @@ class WebExchangeDataBinderTests {
} }
private static class MultipartDataClass { static class MultipartDataClass {
private final FilePart part; private final FilePart part;
@ -351,4 +351,5 @@ class WebExchangeDataBinderTests {
return nullablePart; return nullablePart;
} }
} }
} }

Loading…
Cancel
Save