Skip to content

Commit 502022a

Browse files
committed
Delete test annotations in spring-orm
This commit deletes all test annotations from the spring-orm module in order to reduce unnecessary confusion between these "copies" and the real, current versions of such classes in the spring-test module. Furthermore, the legacy abstract JUnit 3.8 base classes and test cases have been refactored accordingly.
1 parent 6ad79e0 commit 502022a

23 files changed

+129
-1022
lines changed

spring-orm/src/test/java/org/springframework/orm/jpa/AbstractContainerEntityManagerFactoryIntegrationTests.java

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@
2828
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
2929
import org.springframework.orm.jpa.domain.DriversLicense;
3030
import org.springframework.orm.jpa.domain.Person;
31-
import org.springframework.test.annotation.ExpectedException;
32-
import org.springframework.test.annotation.NotTransactional;
33-
import org.springframework.test.annotation.Repeat;
34-
import org.springframework.test.annotation.Timed;
31+
import org.springframework.transaction.annotation.Propagation;
32+
import org.springframework.transaction.annotation.Transactional;
3533
import org.springframework.util.SerializationTestUtils;
3634

3735
/**
@@ -42,39 +40,40 @@
4240
* @author Juergen Hoeller
4341
*/
4442
@SuppressWarnings("deprecation")
45-
public abstract class AbstractContainerEntityManagerFactoryIntegrationTests
46-
extends AbstractEntityManagerFactoryIntegrationTests {
43+
public abstract class AbstractContainerEntityManagerFactoryIntegrationTests extends
44+
AbstractEntityManagerFactoryIntegrationTests {
4745

48-
@NotTransactional
46+
@Transactional(propagation = Propagation.NOT_SUPPORTED)
4947
public void testEntityManagerFactoryImplementsEntityManagerFactoryInfo() {
5048
assertTrue(Proxy.isProxyClass(entityManagerFactory.getClass()));
51-
assertTrue("Must have introduced config interface",
52-
entityManagerFactory instanceof EntityManagerFactoryInfo);
49+
assertTrue("Must have introduced config interface", entityManagerFactory instanceof EntityManagerFactoryInfo);
5350
EntityManagerFactoryInfo emfi = (EntityManagerFactoryInfo) entityManagerFactory;
54-
//assertEquals("Person", emfi.getPersistenceUnitName());
51+
// assertEquals("Person", emfi.getPersistenceUnitName());
5552
assertNotNull("PersistenceUnitInfo must be available", emfi.getPersistenceUnitInfo());
5653
assertNotNull("Raw EntityManagerFactory must be available", emfi.getNativeEntityManagerFactory());
5754
}
5855

5956
public void testStateClean() {
60-
assertEquals("Should be no people from previous transactions",
61-
0, countRowsInTable("person"));
57+
assertEquals("Should be no people from previous transactions", 0, countRowsInTable("person"));
58+
}
59+
60+
public void testJdbcTx1_1() {
61+
testJdbcTx2();
62+
}
63+
64+
public void testJdbcTx1_2() {
65+
testJdbcTx2();
6266
}
6367

64-
@Repeat(5)
65-
public void testJdbcTx1() throws Exception {
68+
public void testJdbcTx1_3() {
6669
testJdbcTx2();
6770
}
6871

69-
@Timed(millis=273)
70-
public void testJdbcTx2() throws InterruptedException {
71-
//Thread.sleep(2000);
72+
public void testJdbcTx2() {
7273
assertEquals("Any previous tx must have been rolled back", 0, countRowsInTable("person"));
73-
//insertPerson("foo");
7474
executeSqlScript("/org/springframework/orm/jpa/insertPerson.sql", false);
7575
}
7676

77-
//@NotTransactional
7877
@SuppressWarnings({ "unused", "unchecked" })
7978
public void testEntityManagerProxyIsProxy() {
8079
assertTrue(Proxy.isProxyClass(sharedEntityManager.getClass()));
@@ -86,21 +85,31 @@ public void testEntityManagerProxyIsProxy() {
8685
assertTrue("Close should have been silently ignored", sharedEntityManager.isOpen());
8786
}
8887

89-
@ExpectedException(RuntimeException.class)
9088
public void testBogusQuery() {
91-
Query query = sharedEntityManager.createQuery("It's raining toads");
92-
// required in OpenJPA case
93-
query.executeUpdate();
89+
try {
90+
Query query = sharedEntityManager.createQuery("It's raining toads");
91+
// required in OpenJPA case
92+
query.executeUpdate();
93+
fail("Should have thrown a RuntimeException");
94+
}
95+
catch (RuntimeException e) {
96+
/* expected */
97+
}
9498
}
9599

96-
@ExpectedException(EntityNotFoundException.class)
97100
public void testGetReferenceWhenNoRow() {
98-
Person notThere = sharedEntityManager.getReference(Person.class, 666);
101+
try {
102+
Person notThere = sharedEntityManager.getReference(Person.class, 666);
99103

100-
// We may get here (as with Hibernate).
101-
// Either behaviour is valid: throw exception on first access
102-
// or on getReference itself.
103-
notThere.getFirstName();
104+
// We may get here (as with Hibernate).
105+
// Either behaviour is valid: throw exception on first access
106+
// or on getReference itself.
107+
notThere.getFirstName();
108+
fail("Should have thrown an EntityNotFoundException");
109+
}
110+
catch (EntityNotFoundException e) {
111+
/* expected */
112+
}
104113
}
105114

106115
public void testLazyLoading() {
@@ -125,7 +134,6 @@ public void testLazyLoading() {
125134
}
126135
finally {
127136
deleteFromTables(new String[] { "person", "drivers_license" });
128-
//setComplete();
129137
}
130138
}
131139

@@ -157,12 +165,12 @@ public void testEntityManagerProxyRejectsProgrammaticTxManagement() {
157165
}
158166
}
159167

160-
// public void testAspectJInjectionOfConfigurableEntity() {
161-
// Person p = new Person();
162-
// System.err.println(p);
163-
// assertNotNull("Was injected", p.getTestBean());
164-
// assertEquals("Ramnivas", p.getTestBean().getName());
165-
// }
168+
// public void testAspectJInjectionOfConfigurableEntity() {
169+
// Person p = new Person();
170+
// System.err.println(p);
171+
// assertNotNull("Was injected", p.getTestBean());
172+
// assertEquals("Ramnivas", p.getTestBean().getName());
173+
// }
166174

167175
public void testInstantiateAndSaveWithSharedEmProxy() {
168176
testInstantiateAndSave(sharedEntityManager);
@@ -194,7 +202,7 @@ public void testQueryNoPersons() {
194202
}
195203
}
196204

197-
@NotTransactional
205+
@Transactional(propagation = Propagation.NOT_SUPPORTED)
198206
@SuppressWarnings("unchecked")
199207
public void testQueryNoPersonsNotTransactional() {
200208
EntityManager em = entityManagerFactory.createEntityManager();
@@ -225,7 +233,7 @@ public void testQueryNoPersonsShared() {
225233
}
226234
}
227235

228-
@NotTransactional
236+
@Transactional(propagation = Propagation.NOT_SUPPORTED)
229237
@SuppressWarnings("unchecked")
230238
public void testQueryNoPersonsSharedNotTransactional() {
231239
EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(entityManagerFactory);
@@ -238,7 +246,9 @@ public void testQueryNoPersonsSharedNotTransactional() {
238246
fail("Should have thrown IllegalStateException");
239247
}
240248
catch (Exception ex) {
241-
// IllegalStateException expected, but PersistenceException thrown by Hibernate
249+
// IllegalStateException expected, but PersistenceException thrown by
250+
// Hibernate
251+
System.err.println(ex);
242252
assertTrue(ex.getMessage().indexOf("closed") != -1);
243253
}
244254
q = em.createQuery("select p from Person as p");

spring-orm/src/test/java/org/springframework/orm/jpa/ApplicationManagedEntityManagerIntegrationTests.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,16 +16,15 @@
1616

1717
package org.springframework.orm.jpa;
1818

19-
import java.util.List;
2019
import java.lang.reflect.Proxy;
20+
import java.util.List;
2121

2222
import javax.persistence.EntityManager;
2323
import javax.persistence.Query;
2424
import javax.persistence.TransactionRequiredException;
2525

2626
import org.springframework.orm.jpa.domain.Person;
27-
import org.springframework.orm.jpa.AbstractEntityManagerFactoryIntegrationTests;
28-
import org.springframework.test.annotation.NotTransactional;
27+
import org.springframework.transaction.annotation.Propagation;
2928
import org.springframework.transaction.annotation.Transactional;
3029

3130
/**
@@ -38,7 +37,7 @@
3837
@SuppressWarnings("deprecation")
3938
public class ApplicationManagedEntityManagerIntegrationTests extends AbstractEntityManagerFactoryIntegrationTests {
4039

41-
@NotTransactional
40+
@Transactional(propagation = Propagation.NOT_SUPPORTED)
4241
public void testEntityManagerIsProxy() {
4342
assertTrue("EntityManagerFactory is proxied", Proxy.isProxyClass(entityManagerFactory.getClass()));
4443
}

spring-orm/src/test/java/org/springframework/orm/jpa/ContainerManagedEntityManagerIntegrationTests.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
package org.springframework.orm.jpa;
1818

19-
import java.util.List;
2019
import java.lang.reflect.Proxy;
20+
import java.util.List;
2121

2222
import javax.persistence.EntityManager;
2323
import javax.persistence.PersistenceException;
@@ -27,8 +27,8 @@
2727
import org.springframework.dao.DataAccessException;
2828
import org.springframework.dao.support.PersistenceExceptionTranslator;
2929
import org.springframework.orm.jpa.domain.Person;
30-
import org.springframework.test.annotation.ExpectedException;
31-
import org.springframework.test.annotation.NotTransactional;
30+
import org.springframework.transaction.annotation.Propagation;
31+
import org.springframework.transaction.annotation.Transactional;
3232

3333
/**
3434
* Integration tests using in-memory database for container-managed JPA
@@ -39,12 +39,12 @@
3939
@SuppressWarnings("deprecation")
4040
public class ContainerManagedEntityManagerIntegrationTests extends AbstractEntityManagerFactoryIntegrationTests {
4141

42-
@NotTransactional
42+
@Transactional(propagation = Propagation.NOT_SUPPORTED)
4343
public void testExceptionTranslationWithDialectFoundOnIntroducedEntityManagerInfo() throws Exception {
4444
doTestExceptionTranslationWithDialectFound(((EntityManagerFactoryInfo) entityManagerFactory).getJpaDialect());
4545
}
4646

47-
@NotTransactional
47+
@Transactional(propagation = Propagation.NOT_SUPPORTED)
4848
public void testExceptionTranslationWithDialectFoundOnEntityManagerFactoryBean() throws Exception {
4949
AbstractEntityManagerFactoryBean aefb =
5050
(AbstractEntityManagerFactoryBean) applicationContext.getBean("&entityManagerFactory");
@@ -80,9 +80,14 @@ public void testEntityManagerProxyIsProxy() {
8080
}
8181

8282
// This would be legal, at least if not actually _starting_ a tx
83-
@ExpectedException(IllegalStateException.class)
8483
public void testEntityManagerProxyRejectsProgrammaticTxManagement() {
85-
createContainerManagedEntityManager().getTransaction();
84+
try {
85+
createContainerManagedEntityManager().getTransaction();
86+
fail("Should have thrown an IllegalStateException");
87+
}
88+
catch (IllegalStateException e) {
89+
/* expected */
90+
}
8691
}
8792

8893
/*
@@ -93,10 +98,15 @@ public void testContainerEntityManagerProxyAllowsJoinTransactionInTransaction()
9398
createContainerManagedEntityManager().joinTransaction();
9499
}
95100

96-
@NotTransactional
97-
@ExpectedException(TransactionRequiredException.class)
101+
@Transactional(propagation = Propagation.NOT_SUPPORTED)
98102
public void testContainerEntityManagerProxyRejectsJoinTransactionWithoutTransaction() {
99-
createContainerManagedEntityManager().joinTransaction();
103+
try {
104+
createContainerManagedEntityManager().joinTransaction();
105+
fail("Should have thrown a TransactionRequiredException");
106+
}
107+
catch (TransactionRequiredException e) {
108+
/* expected */
109+
}
100110
}
101111

102112
public void testInstantiateAndSave() {

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,31 @@
2525
import org.springframework.orm.jpa.AbstractContainerEntityManagerFactoryIntegrationTests;
2626
import org.springframework.orm.jpa.EntityManagerFactoryInfo;
2727
import org.springframework.orm.jpa.domain.Person;
28-
import org.springframework.test.annotation.IfProfileValue;
2928

3029
/**
3130
* Hibernate-specific JPA tests.
3231
*
3332
* @author Juergen Hoeller
3433
* @author Rod Johnson
3534
*/
36-
// Essentially @Ignore-d since AnnotationBeanConfigurerAspect cannot be found
37-
@IfProfileValue(name="test-group", value="broken")
35+
// TODO Decide what to do with broken HibernateEntityManagerFactoryIntegrationTests.
36+
// See isDisabledInThisEnvironment() for details.
3837
@SuppressWarnings("deprecation")
3938
public class HibernateEntityManagerFactoryIntegrationTests extends
4039
AbstractContainerEntityManagerFactoryIntegrationTests {
4140

4241
private SessionFactory sessionFactory;
4342

4443

44+
/**
45+
* Always returns {@code true}, thereby disabling this entire test class
46+
* since AnnotationBeanConfigurerAspect cannot be found.
47+
*/
48+
@Override
49+
protected boolean isDisabledInThisEnvironment(String testMethodName) {
50+
return true;
51+
}
52+
4553
public void setSessionFactory(SessionFactory sessionFactory) {
4654
this.sessionFactory = sessionFactory;
4755
}
@@ -51,7 +59,6 @@ protected String[] getConfigLocations() {
5159
return HIBERNATE_CONFIG_LOCATIONS;
5260
}
5361

54-
5562
public void testCanCastNativeEntityManagerFactoryToHibernateEntityManagerFactoryImpl() {
5663
EntityManagerFactoryInfo emfi = (EntityManagerFactoryInfo) entityManagerFactory;
5764
assertTrue(emfi.getNativeEntityManagerFactory() instanceof HibernateEntityManagerFactory);
@@ -78,7 +85,7 @@ public void testWithHibernateSessionFactory() {
7885
public void testConfigurablePerson() {
7986
Query q = this.sessionFactory.getCurrentSession().createQuery("select p from ContextualPerson as p");
8087
assertEquals(0, q.list().size());
81-
//assertNotNull(new ContextualPerson().entityManager); TODO
88+
// assertNotNull(new ContextualPerson().entityManager); TODO
8289
}
8390

8491
}

spring-orm/src/test/java/org/springframework/test/AbstractDependencyInjectionSpringContextTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,6 +27,8 @@
2727
import org.springframework.util.Assert;
2828

2929
/**
30+
* This class is only used within tests in the spring-orm module.
31+
*
3032
* <p>
3133
* Convenient superclass for JUnit 3.8 based tests depending on a Spring
3234
* context. The test instance itself is populated by Dependency Injection.

spring-orm/src/test/java/org/springframework/test/AbstractSingleSpringContextTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,6 +26,8 @@
2626
import org.springframework.util.StringUtils;
2727

2828
/**
29+
* This class is only used within tests in the spring-orm module.
30+
*
2931
* <p>
3032
* Abstract JUnit 3.8 test class that holds and exposes a single Spring
3133
* {@link org.springframework.context.ApplicationContext ApplicationContext}.

spring-orm/src/test/java/org/springframework/test/AbstractSpringContextTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,6 +25,8 @@
2525
import org.springframework.util.StringUtils;
2626

2727
/**
28+
* This class is only used within tests in the spring-orm module.
29+
*
2830
* <p>
2931
* Superclass for JUnit 3.8 test cases using Spring
3032
* {@link org.springframework.context.ApplicationContext ApplicationContexts}.

spring-orm/src/test/java/org/springframework/test/AbstractTransactionalDataSourceSpringContextTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,7 +31,9 @@
3131
import org.springframework.test.jdbc.JdbcTestUtils;
3232

3333
/**
34-
* Subclass of AbstractTransactionalSpringContextTests that adds some convenience
34+
* This class is only used within tests in the spring-orm module.
35+
*
36+
* <p>Subclass of AbstractTransactionalSpringContextTests that adds some convenience
3537
* functionality for JDBC access. Expects a {@link javax.sql.DataSource} bean
3638
* to be defined in the Spring application context.
3739
*

0 commit comments

Comments
 (0)