From 32b87079cb46767305172caa4b8832c38f54327d Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Wed, 2 Jul 2014 13:10:19 +0200 Subject: [PATCH] Re-enable Hibernate EntityManagerFactory tests HibernateEntityManagerFactoryIntegrationTests in the spring-orm module has been disabled for quite some time due to a dependency on the AnnotationBeanConfigurerAspect from the spring-aspects module. Since spring-aspects depends on spring-orm, a cyclical dependency would result if this code were re-enabled "as is". This commit removes the dependency on AnnotationBeanConfigurerAspect in HibernateEntityManagerFactoryIntegrationTests by deleting all test code and configuration related to @Configurable. In addition, this commit also deletes all SessionFactory-specific test code in HibernateEntityManagerFactoryIntegrationTests, allowing the test class to focus on Hibernate as a JPA provider. Issue: SPR-11922 --- ...rEntityManagerFactoryIntegrationTests.java | 6 - .../orm/jpa/domain/ContextualPerson.java | 104 ------------------ .../orm/jpa/domain/Person.java | 17 ++- .../orm/jpa/domain/persistence-context.xml | 8 +- .../orm/jpa/domain/persistence-multi.xml | 9 +- .../orm/jpa/domain/persistence.xml | 7 +- ...eEntityManagerFactoryIntegrationTests.java | 39 ------- .../orm/jpa/hibernate/hibernate-manager.xml | 35 ++---- 8 files changed, 29 insertions(+), 196 deletions(-) delete mode 100644 spring-orm/src/test/java/org/springframework/orm/jpa/domain/ContextualPerson.java diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractContainerEntityManagerFactoryIntegrationTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractContainerEntityManagerFactoryIntegrationTests.java index 5f01f4101e..a46c23ad93 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractContainerEntityManagerFactoryIntegrationTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractContainerEntityManagerFactoryIntegrationTests.java @@ -165,12 +165,6 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests exte } } - // public void testAspectJInjectionOfConfigurableEntity() { - // Person p = new Person(); - // assertNotNull("Was injected", p.getTestBean()); - // assertEquals("Ramnivas", p.getTestBean().getName()); - // } - public void testInstantiateAndSaveWithSharedEmProxy() { testInstantiateAndSave(sharedEntityManager); } diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/domain/ContextualPerson.java b/spring-orm/src/test/java/org/springframework/orm/jpa/domain/ContextualPerson.java deleted file mode 100644 index b9e6fcff08..0000000000 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/domain/ContextualPerson.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2002-2013 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 - * - * http://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.orm.jpa.domain; - -import javax.persistence.Basic; -import javax.persistence.CascadeType; -import javax.persistence.Entity; -import javax.persistence.EntityManager; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.OneToOne; -import javax.persistence.PersistenceContext; - -import org.springframework.tests.sample.beans.TestBean; -import org.springframework.beans.factory.annotation.Configurable; - -/** - * @author Juergen Hoeller - */ -@Entity -@Configurable -public class ContextualPerson { - - @Id - @GeneratedValue(strategy=GenerationType.AUTO) - private Integer id; - - private transient TestBean testBean; - - // Lazy relationship to force use of instrumentation in JPA implementation. - @OneToOne(fetch=FetchType.LAZY, cascade=CascadeType.PERSIST) - @JoinColumn(name="DRIVERS_LICENSE_ID") - private DriversLicense driversLicense; - - private String first_name; - - @Basic(fetch=FetchType.LAZY) - private String last_name; - - @PersistenceContext - public transient EntityManager entityManager; - - - public Integer getId() { - return id; - } - - public void setTestBean(TestBean testBean) { - this.testBean = testBean; - } - - public TestBean getTestBean() { - return testBean; - } - - public void setFirstName(String firstName) { - this.first_name = firstName; - } - - public String getFirstName() { - return this.first_name; - } - - public void setLastName(String lastName) { - this.last_name = lastName; - } - - public String getLastName() { - return this.last_name; - } - - public void setDriversLicense(DriversLicense driversLicense) { - this.driversLicense = driversLicense; - } - - public DriversLicense getDriversLicense() { - return this.driversLicense; - } - - - @Override - public String toString() { - return getClass().getName() + ":(" + hashCode() + ") id=" + id + - "; firstName=" + first_name + "; lastName=" + last_name + "; testBean=" + testBean; - } - -} diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/domain/Person.java b/spring-orm/src/test/java/org/springframework/orm/jpa/domain/Person.java index cb850b1ab9..27dd1c8766 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/domain/Person.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/domain/Person.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 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. @@ -27,7 +27,6 @@ import javax.persistence.JoinColumn; import javax.persistence.OneToOne; import org.springframework.tests.sample.beans.TestBean; -import org.springframework.beans.factory.annotation.Configurable; /** * Simple JavaBean domain object representing an person. @@ -35,23 +34,22 @@ import org.springframework.beans.factory.annotation.Configurable; * @author Rod Johnson */ @Entity -@Configurable public class Person { @Id - @GeneratedValue(strategy=GenerationType.AUTO) + @GeneratedValue(strategy = GenerationType.AUTO) private Integer id; private transient TestBean testBean; // Lazy relationship to force use of instrumentation in JPA implementation. - @OneToOne(fetch=FetchType.LAZY, cascade=CascadeType.PERSIST) - @JoinColumn(name="DRIVERS_LICENSE_ID") + @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST) + @JoinColumn(name = "DRIVERS_LICENSE_ID") private DriversLicense driversLicense; private String first_name; - @Basic(fetch=FetchType.LAZY) + @Basic(fetch = FetchType.LAZY) private String last_name; @@ -91,11 +89,10 @@ public class Person { return this.driversLicense; } - @Override public String toString() { - return getClass().getName() + ":(" + hashCode() + ") id=" + id + - "; firstName=" + first_name + "; lastName=" + last_name + "; testBean=" + testBean; + return getClass().getName() + ":(" + hashCode() + ") id=" + id + "; firstName=" + first_name + "; lastName=" + + last_name + "; testBean=" + testBean; } } diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/domain/persistence-context.xml b/spring-orm/src/test/java/org/springframework/orm/jpa/domain/persistence-context.xml index b161b07f79..dda266f3b9 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/domain/persistence-context.xml +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/domain/persistence-context.xml @@ -1,13 +1,11 @@ - - + - org.springframework.orm.jpa.domain.ContextualPerson org.springframework.orm.jpa.domain.DriversLicense org.springframework.orm.jpa.domain.Person - + diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/domain/persistence-multi.xml b/spring-orm/src/test/java/org/springframework/orm/jpa/domain/persistence-multi.xml index d3c5739718..f1452fd77e 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/domain/persistence-multi.xml +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/domain/persistence-multi.xml @@ -1,17 +1,16 @@ - - + org.springframework.orm.jpa.domain.Person org.springframework.orm.jpa.domain.DriversLicense - + org.springframework.tests.sample.beans.TestBean - + diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/domain/persistence.xml b/spring-orm/src/test/java/org/springframework/orm/jpa/domain/persistence.xml index c75da3e4a5..01a1f08b11 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/domain/persistence.xml +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/domain/persistence.xml @@ -1,12 +1,11 @@ - - + org.springframework.orm.jpa.domain.Person org.springframework.orm.jpa.domain.DriversLicense - + diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/hibernate/HibernateEntityManagerFactoryIntegrationTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/hibernate/HibernateEntityManagerFactoryIntegrationTests.java index 55a612ecab..d5cc3cfeb2 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/hibernate/HibernateEntityManagerFactoryIntegrationTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/hibernate/HibernateEntityManagerFactoryIntegrationTests.java @@ -16,16 +16,10 @@ package org.springframework.orm.jpa.hibernate; -import java.util.List; - -import org.hibernate.Query; -import org.hibernate.SessionFactory; import org.hibernate.ejb.HibernateEntityManager; import org.hibernate.ejb.HibernateEntityManagerFactory; -import org.junit.Ignore; import org.springframework.orm.jpa.AbstractContainerEntityManagerFactoryIntegrationTests; import org.springframework.orm.jpa.EntityManagerFactoryInfo; -import org.springframework.orm.jpa.domain.Person; /** * Hibernate-specific JPA tests. @@ -33,25 +27,10 @@ import org.springframework.orm.jpa.domain.Person; * @author Juergen Hoeller * @author Rod Johnson */ -// TODO [SPR-11922] Decide what to do with HibernateEntityManagerFactoryIntegrationTests. -@Ignore("Disabled since AnnotationBeanConfigurerAspect cannot be found") -// The reason AnnotationBeanConfigurerAspect cannot be found is that it resides -// in the spring-aspects module which depends on this module (spring-orm). Thus, -// in order to overcome the cyclical dependency, this test could be moved to the -// root 'spring' module as a framework-level integration test, but the challenge -// with doing so is that this class depends on a test class hierarchy which is -// defined in this module. @SuppressWarnings("deprecation") public class HibernateEntityManagerFactoryIntegrationTests extends AbstractContainerEntityManagerFactoryIntegrationTests { - private SessionFactory sessionFactory; - - - public void setSessionFactory(SessionFactory sessionFactory) { - this.sessionFactory = sessionFactory; - } - @Override protected String[] getConfigLocations() { return HIBERNATE_CONFIG_LOCATIONS; @@ -68,22 +47,4 @@ public class HibernateEntityManagerFactoryIntegrationTests extends assertNotNull(hibernateEntityManager.getSession()); } - public void testWithHibernateSessionFactory() { - // Add with JDBC - String firstName = "Tony"; - insertPerson(firstName); - - Query q = this.sessionFactory.getCurrentSession().createQuery("select p from Person as p"); - List people = q.list(); - - assertEquals(1, people.size()); - assertEquals(firstName, people.get(0).getFirstName()); - } - - public void testConfigurablePerson() { - Query q = this.sessionFactory.getCurrentSession().createQuery("select p from ContextualPerson as p"); - assertEquals(0, q.list().size()); - // assertNotNull(new ContextualPerson().entityManager); TODO - } - } diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/hibernate/hibernate-manager.xml b/spring-orm/src/test/java/org/springframework/orm/jpa/hibernate/hibernate-manager.xml index 6779b221c3..2350190711 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/hibernate/hibernate-manager.xml +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/hibernate/hibernate-manager.xml @@ -1,41 +1,30 @@ - + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> - + - + - - - - - + + + - - - + + + org.hibernate.cache.HashtableCacheProvider - + - - - - -