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 718f3d6e8e..9c8c13be35 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 @@ -28,10 +28,8 @@ import javax.persistence.Query; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.orm.jpa.domain.DriversLicense; import org.springframework.orm.jpa.domain.Person; -import org.springframework.test.annotation.ExpectedException; -import org.springframework.test.annotation.NotTransactional; -import org.springframework.test.annotation.Repeat; -import org.springframework.test.annotation.Timed; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.SerializationTestUtils; /** @@ -42,39 +40,40 @@ import org.springframework.util.SerializationTestUtils; * @author Juergen Hoeller */ @SuppressWarnings("deprecation") -public abstract class AbstractContainerEntityManagerFactoryIntegrationTests - extends AbstractEntityManagerFactoryIntegrationTests { +public abstract class AbstractContainerEntityManagerFactoryIntegrationTests extends + AbstractEntityManagerFactoryIntegrationTests { - @NotTransactional + @Transactional(propagation = Propagation.NOT_SUPPORTED) public void testEntityManagerFactoryImplementsEntityManagerFactoryInfo() { assertTrue(Proxy.isProxyClass(entityManagerFactory.getClass())); - assertTrue("Must have introduced config interface", - entityManagerFactory instanceof EntityManagerFactoryInfo); + assertTrue("Must have introduced config interface", entityManagerFactory instanceof EntityManagerFactoryInfo); EntityManagerFactoryInfo emfi = (EntityManagerFactoryInfo) entityManagerFactory; - //assertEquals("Person", emfi.getPersistenceUnitName()); + // assertEquals("Person", emfi.getPersistenceUnitName()); assertNotNull("PersistenceUnitInfo must be available", emfi.getPersistenceUnitInfo()); assertNotNull("Raw EntityManagerFactory must be available", emfi.getNativeEntityManagerFactory()); } public void testStateClean() { - assertEquals("Should be no people from previous transactions", - 0, countRowsInTable("person")); + assertEquals("Should be no people from previous transactions", 0, countRowsInTable("person")); + } + + public void testJdbcTx1_1() { + testJdbcTx2(); + } + + public void testJdbcTx1_2() { + testJdbcTx2(); } - @Repeat(5) - public void testJdbcTx1() throws Exception { + public void testJdbcTx1_3() { testJdbcTx2(); } - @Timed(millis=273) - public void testJdbcTx2() throws InterruptedException { - //Thread.sleep(2000); + public void testJdbcTx2() { assertEquals("Any previous tx must have been rolled back", 0, countRowsInTable("person")); - //insertPerson("foo"); executeSqlScript("/org/springframework/orm/jpa/insertPerson.sql", false); } - //@NotTransactional @SuppressWarnings({ "unused", "unchecked" }) public void testEntityManagerProxyIsProxy() { assertTrue(Proxy.isProxyClass(sharedEntityManager.getClass())); @@ -86,21 +85,31 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests assertTrue("Close should have been silently ignored", sharedEntityManager.isOpen()); } - @ExpectedException(RuntimeException.class) public void testBogusQuery() { - Query query = sharedEntityManager.createQuery("It's raining toads"); - // required in OpenJPA case - query.executeUpdate(); + try { + Query query = sharedEntityManager.createQuery("It's raining toads"); + // required in OpenJPA case + query.executeUpdate(); + fail("Should have thrown a RuntimeException"); + } + catch (RuntimeException e) { + /* expected */ + } } - @ExpectedException(EntityNotFoundException.class) public void testGetReferenceWhenNoRow() { - Person notThere = sharedEntityManager.getReference(Person.class, 666); + try { + Person notThere = sharedEntityManager.getReference(Person.class, 666); - // We may get here (as with Hibernate). - // Either behaviour is valid: throw exception on first access - // or on getReference itself. - notThere.getFirstName(); + // We may get here (as with Hibernate). + // Either behaviour is valid: throw exception on first access + // or on getReference itself. + notThere.getFirstName(); + fail("Should have thrown an EntityNotFoundException"); + } + catch (EntityNotFoundException e) { + /* expected */ + } } public void testLazyLoading() { @@ -125,7 +134,6 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests } finally { deleteFromTables(new String[] { "person", "drivers_license" }); - //setComplete(); } } @@ -157,12 +165,12 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests } } -// public void testAspectJInjectionOfConfigurableEntity() { -// Person p = new Person(); -// System.err.println(p); -// assertNotNull("Was injected", p.getTestBean()); -// assertEquals("Ramnivas", p.getTestBean().getName()); -// } + // public void testAspectJInjectionOfConfigurableEntity() { + // Person p = new Person(); + // System.err.println(p); + // assertNotNull("Was injected", p.getTestBean()); + // assertEquals("Ramnivas", p.getTestBean().getName()); + // } public void testInstantiateAndSaveWithSharedEmProxy() { testInstantiateAndSave(sharedEntityManager); @@ -194,7 +202,7 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests } } - @NotTransactional + @Transactional(propagation = Propagation.NOT_SUPPORTED) @SuppressWarnings("unchecked") public void testQueryNoPersonsNotTransactional() { EntityManager em = entityManagerFactory.createEntityManager(); @@ -225,7 +233,7 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests } } - @NotTransactional + @Transactional(propagation = Propagation.NOT_SUPPORTED) @SuppressWarnings("unchecked") public void testQueryNoPersonsSharedNotTransactional() { EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(entityManagerFactory); @@ -238,7 +246,9 @@ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests fail("Should have thrown IllegalStateException"); } catch (Exception ex) { - // IllegalStateException expected, but PersistenceException thrown by Hibernate + // IllegalStateException expected, but PersistenceException thrown by + // Hibernate + System.err.println(ex); assertTrue(ex.getMessage().indexOf("closed") != -1); } q = em.createQuery("select p from Person as p"); diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/ApplicationManagedEntityManagerIntegrationTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/ApplicationManagedEntityManagerIntegrationTests.java index 2593604cb9..bc05a5a5a2 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/ApplicationManagedEntityManagerIntegrationTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/ApplicationManagedEntityManagerIntegrationTests.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. @@ -16,16 +16,15 @@ package org.springframework.orm.jpa; -import java.util.List; import java.lang.reflect.Proxy; +import java.util.List; import javax.persistence.EntityManager; import javax.persistence.Query; import javax.persistence.TransactionRequiredException; import org.springframework.orm.jpa.domain.Person; -import org.springframework.orm.jpa.AbstractEntityManagerFactoryIntegrationTests; -import org.springframework.test.annotation.NotTransactional; +import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; /** @@ -38,7 +37,7 @@ import org.springframework.transaction.annotation.Transactional; @SuppressWarnings("deprecation") public class ApplicationManagedEntityManagerIntegrationTests extends AbstractEntityManagerFactoryIntegrationTests { - @NotTransactional + @Transactional(propagation = Propagation.NOT_SUPPORTED) public void testEntityManagerIsProxy() { assertTrue("EntityManagerFactory is proxied", Proxy.isProxyClass(entityManagerFactory.getClass())); } diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/ContainerManagedEntityManagerIntegrationTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/ContainerManagedEntityManagerIntegrationTests.java index 51f5de0b33..edd7ac2712 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/ContainerManagedEntityManagerIntegrationTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/ContainerManagedEntityManagerIntegrationTests.java @@ -16,8 +16,8 @@ package org.springframework.orm.jpa; -import java.util.List; import java.lang.reflect.Proxy; +import java.util.List; import javax.persistence.EntityManager; import javax.persistence.PersistenceException; @@ -27,8 +27,8 @@ import javax.persistence.TransactionRequiredException; import org.springframework.dao.DataAccessException; import org.springframework.dao.support.PersistenceExceptionTranslator; import org.springframework.orm.jpa.domain.Person; -import org.springframework.test.annotation.ExpectedException; -import org.springframework.test.annotation.NotTransactional; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; /** * Integration tests using in-memory database for container-managed JPA @@ -39,12 +39,12 @@ import org.springframework.test.annotation.NotTransactional; @SuppressWarnings("deprecation") public class ContainerManagedEntityManagerIntegrationTests extends AbstractEntityManagerFactoryIntegrationTests { - @NotTransactional + @Transactional(propagation = Propagation.NOT_SUPPORTED) public void testExceptionTranslationWithDialectFoundOnIntroducedEntityManagerInfo() throws Exception { doTestExceptionTranslationWithDialectFound(((EntityManagerFactoryInfo) entityManagerFactory).getJpaDialect()); } - @NotTransactional + @Transactional(propagation = Propagation.NOT_SUPPORTED) public void testExceptionTranslationWithDialectFoundOnEntityManagerFactoryBean() throws Exception { AbstractEntityManagerFactoryBean aefb = (AbstractEntityManagerFactoryBean) applicationContext.getBean("&entityManagerFactory"); @@ -80,9 +80,14 @@ public class ContainerManagedEntityManagerIntegrationTests extends AbstractEntit } // This would be legal, at least if not actually _starting_ a tx - @ExpectedException(IllegalStateException.class) public void testEntityManagerProxyRejectsProgrammaticTxManagement() { - createContainerManagedEntityManager().getTransaction(); + try { + createContainerManagedEntityManager().getTransaction(); + fail("Should have thrown an IllegalStateException"); + } + catch (IllegalStateException e) { + /* expected */ + } } /* @@ -93,10 +98,15 @@ public class ContainerManagedEntityManagerIntegrationTests extends AbstractEntit createContainerManagedEntityManager().joinTransaction(); } - @NotTransactional - @ExpectedException(TransactionRequiredException.class) + @Transactional(propagation = Propagation.NOT_SUPPORTED) public void testContainerEntityManagerProxyRejectsJoinTransactionWithoutTransaction() { - createContainerManagedEntityManager().joinTransaction(); + try { + createContainerManagedEntityManager().joinTransaction(); + fail("Should have thrown a TransactionRequiredException"); + } + catch (TransactionRequiredException e) { + /* expected */ + } } public void testInstantiateAndSave() { 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 daf5b26e00..10bdc0723a 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 @@ -25,7 +25,6 @@ import org.hibernate.ejb.HibernateEntityManagerFactory; import org.springframework.orm.jpa.AbstractContainerEntityManagerFactoryIntegrationTests; import org.springframework.orm.jpa.EntityManagerFactoryInfo; import org.springframework.orm.jpa.domain.Person; -import org.springframework.test.annotation.IfProfileValue; /** * Hibernate-specific JPA tests. @@ -33,8 +32,8 @@ import org.springframework.test.annotation.IfProfileValue; * @author Juergen Hoeller * @author Rod Johnson */ -// Essentially @Ignore-d since AnnotationBeanConfigurerAspect cannot be found -@IfProfileValue(name="test-group", value="broken") +// TODO Decide what to do with broken HibernateEntityManagerFactoryIntegrationTests. +// See isDisabledInThisEnvironment() for details. @SuppressWarnings("deprecation") public class HibernateEntityManagerFactoryIntegrationTests extends AbstractContainerEntityManagerFactoryIntegrationTests { @@ -42,6 +41,15 @@ public class HibernateEntityManagerFactoryIntegrationTests extends private SessionFactory sessionFactory; + /** + * Always returns {@code true}, thereby disabling this entire test class + * since AnnotationBeanConfigurerAspect cannot be found. + */ + @Override + protected boolean isDisabledInThisEnvironment(String testMethodName) { + return true; + } + public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } @@ -51,7 +59,6 @@ public class HibernateEntityManagerFactoryIntegrationTests extends return HIBERNATE_CONFIG_LOCATIONS; } - public void testCanCastNativeEntityManagerFactoryToHibernateEntityManagerFactoryImpl() { EntityManagerFactoryInfo emfi = (EntityManagerFactoryInfo) entityManagerFactory; assertTrue(emfi.getNativeEntityManagerFactory() instanceof HibernateEntityManagerFactory); @@ -78,7 +85,7 @@ public class HibernateEntityManagerFactoryIntegrationTests extends 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 + // assertNotNull(new ContextualPerson().entityManager); TODO } } diff --git a/spring-orm/src/test/java/org/springframework/test/AbstractDependencyInjectionSpringContextTests.java b/spring-orm/src/test/java/org/springframework/test/AbstractDependencyInjectionSpringContextTests.java index ec2b9499e5..5137c64b42 100644 --- a/spring-orm/src/test/java/org/springframework/test/AbstractDependencyInjectionSpringContextTests.java +++ b/spring-orm/src/test/java/org/springframework/test/AbstractDependencyInjectionSpringContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 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,6 +27,8 @@ import org.springframework.context.ApplicationContext; import org.springframework.util.Assert; /** + * This class is only used within tests in the spring-orm module. + * *

* Convenient superclass for JUnit 3.8 based tests depending on a Spring * context. The test instance itself is populated by Dependency Injection. diff --git a/spring-orm/src/test/java/org/springframework/test/AbstractSingleSpringContextTests.java b/spring-orm/src/test/java/org/springframework/test/AbstractSingleSpringContextTests.java index c71e846dcd..4c3ea02e11 100644 --- a/spring-orm/src/test/java/org/springframework/test/AbstractSingleSpringContextTests.java +++ b/spring-orm/src/test/java/org/springframework/test/AbstractSingleSpringContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 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. @@ -26,6 +26,8 @@ import org.springframework.util.ResourceUtils; import org.springframework.util.StringUtils; /** + * This class is only used within tests in the spring-orm module. + * *

* Abstract JUnit 3.8 test class that holds and exposes a single Spring * {@link org.springframework.context.ApplicationContext ApplicationContext}. diff --git a/spring-orm/src/test/java/org/springframework/test/AbstractSpringContextTests.java b/spring-orm/src/test/java/org/springframework/test/AbstractSpringContextTests.java index 696b9b79cf..bbb0dd2693 100644 --- a/spring-orm/src/test/java/org/springframework/test/AbstractSpringContextTests.java +++ b/spring-orm/src/test/java/org/springframework/test/AbstractSpringContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 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. @@ -25,6 +25,8 @@ import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; /** + * This class is only used within tests in the spring-orm module. + * *

* Superclass for JUnit 3.8 test cases using Spring * {@link org.springframework.context.ApplicationContext ApplicationContexts}. diff --git a/spring-orm/src/test/java/org/springframework/test/AbstractTransactionalDataSourceSpringContextTests.java b/spring-orm/src/test/java/org/springframework/test/AbstractTransactionalDataSourceSpringContextTests.java index dcd60ae78c..be52d90888 100644 --- a/spring-orm/src/test/java/org/springframework/test/AbstractTransactionalDataSourceSpringContextTests.java +++ b/spring-orm/src/test/java/org/springframework/test/AbstractTransactionalDataSourceSpringContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 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. @@ -31,7 +31,9 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.jdbc.JdbcTestUtils; /** - * Subclass of AbstractTransactionalSpringContextTests that adds some convenience + * This class is only used within tests in the spring-orm module. + * + *

Subclass of AbstractTransactionalSpringContextTests that adds some convenience * functionality for JDBC access. Expects a {@link javax.sql.DataSource} bean * to be defined in the Spring application context. * diff --git a/spring-orm/src/test/java/org/springframework/test/AbstractTransactionalSpringContextTests.java b/spring-orm/src/test/java/org/springframework/test/AbstractTransactionalSpringContextTests.java index 637aa5b794..9759601d88 100644 --- a/spring-orm/src/test/java/org/springframework/test/AbstractTransactionalSpringContextTests.java +++ b/spring-orm/src/test/java/org/springframework/test/AbstractTransactionalSpringContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 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. @@ -23,7 +23,9 @@ import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.DefaultTransactionDefinition; /** - * Convenient base class for JUnit 3.8 based tests that should occur in a + * This class is only used within tests in the spring-orm module. + * + *

Convenient base class for JUnit 3.8 based tests that should occur in a * transaction, but normally will roll the transaction back on the completion of * each test. * diff --git a/spring-orm/src/test/java/org/springframework/test/ConditionalTestCase.java b/spring-orm/src/test/java/org/springframework/test/ConditionalTestCase.java index f2403b649a..50e6553d4a 100644 --- a/spring-orm/src/test/java/org/springframework/test/ConditionalTestCase.java +++ b/spring-orm/src/test/java/org/springframework/test/ConditionalTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 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. @@ -21,7 +21,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** - * Superclass for JUnit 3.8 based tests that allows conditional test execution + * This class is only used within tests in the spring-orm module. + * + *

Superclass for JUnit 3.8 based tests that allows conditional test execution * at the individual test method level. The * {@link #isDisabledInThisEnvironment(String) isDisabledInThisEnvironment()} * method is invoked before the execution of each test method. Subclasses can diff --git a/spring-orm/src/test/java/org/springframework/test/annotation/AbstractAnnotationAwareTransactionalTests.java b/spring-orm/src/test/java/org/springframework/test/annotation/AbstractAnnotationAwareTransactionalTests.java index d1808d9449..4824c5136d 100644 --- a/spring-orm/src/test/java/org/springframework/test/annotation/AbstractAnnotationAwareTransactionalTests.java +++ b/spring-orm/src/test/java/org/springframework/test/annotation/AbstractAnnotationAwareTransactionalTests.java @@ -18,54 +18,30 @@ package org.springframework.test.annotation; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.util.Map; -import junit.framework.AssertionFailedError; - -import org.springframework.context.ApplicationContext; import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.annotation.AnnotationTransactionAttributeSource; import org.springframework.transaction.interceptor.TransactionAttributeSource; -import org.springframework.util.Assert; /** - *

- * Java 5 specific subclass of + * This class is only used within tests in the spring-orm module. + * + *

Java 5 specific subclass of * {@link AbstractTransactionalDataSourceSpringContextTests}, obeying annotations * for transaction control. - *

- *

- * For example, test methods can be annotated with the regular Spring + * + *

For example, test methods can be annotated with the regular Spring * {@link org.springframework.transaction.annotation.Transactional @Transactional} - * annotation (e.g., to force execution in a read-only transaction) or with the - * {@link NotTransactional @NotTransactional} annotation to prevent any - * transaction being created at all. In addition, individual test methods can be - * annotated with {@link Rollback @Rollback} to override the - * {@link #isDefaultRollback() default rollback} settings. - *

- *

- * The following list constitutes all annotations currently supported by - * AbstractAnnotationAwareTransactionalTests: - *

- * + * annotation — for example, to force execution in a read-only transaction + * or to prevent any transaction from being created at all by setting the propagation + * level to {@code NOT_SUPPORTED}. * * @author Rod Johnson * @author Sam Brannen * @author Juergen Hoeller * @since 2.0 - * @deprecated as of Spring 3.0, in favor of using the listener-based test context framework - * ({@link org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests}) + * @deprecated as of Spring 3.0, in favor of using the listener-based TestContext framework */ @Deprecated public abstract class AbstractAnnotationAwareTransactionalTests extends @@ -73,15 +49,6 @@ public abstract class AbstractAnnotationAwareTransactionalTests extends private final TransactionAttributeSource transactionAttributeSource = new AnnotationTransactionAttributeSource(); - /** - * {@link ProfileValueSource} available to subclasses but primarily intended - * for use in {@link #isDisabledInThisEnvironment(Method)}. - *

Set to {@link SystemProfileValueSource} by default for backwards - * compatibility; however, the value may be changed in the - * {@link #AbstractAnnotationAwareTransactionalTests(String)} constructor. - */ - protected ProfileValueSource profileValueSource = SystemProfileValueSource.getInstance(); - /** * Default constructor for AbstractAnnotationAwareTransactionalTests, which @@ -93,37 +60,11 @@ public abstract class AbstractAnnotationAwareTransactionalTests extends /** * Constructs a new AbstractAnnotationAwareTransactionalTests instance with - * the specified JUnit {@code name} and retrieves the configured (or - * default) {@link ProfileValueSource}. + * the specified JUnit {@code name}. * @param name the name of the current test - * @see ProfileValueUtils#retrieveProfileValueSource(Class) */ public AbstractAnnotationAwareTransactionalTests(String name) { super(name); - this.profileValueSource = ProfileValueUtils.retrieveProfileValueSource(getClass()); - } - - - /** - * Search for a unique {@link ProfileValueSource} in the supplied - * {@link ApplicationContext}. If found, the - * {@code profileValueSource} for this test will be set to the unique - * {@link ProfileValueSource}. - * @param applicationContext the ApplicationContext in which to search for - * the ProfileValueSource; may not be {@code null} - * @deprecated Use {@link ProfileValueSourceConfiguration @ProfileValueSourceConfiguration} instead. - */ - @Deprecated - protected void findUniqueProfileValueSourceFromContext(ApplicationContext applicationContext) { - Assert.notNull(applicationContext, "Can not search for a ProfileValueSource in a null ApplicationContext."); - ProfileValueSource uniqueProfileValueSource = null; - Map beans = applicationContext.getBeansOfType(ProfileValueSource.class); - if (beans.size() == 1) { - uniqueProfileValueSource = (ProfileValueSource) beans.values().iterator().next(); - } - if (uniqueProfileValueSource != null) { - this.profileValueSource = uniqueProfileValueSource; - } } /** @@ -140,55 +81,19 @@ public abstract class AbstractAnnotationAwareTransactionalTests extends final Method testMethod = getTestMethod(); - if (isDisabledInThisEnvironment(testMethod)) { - recordDisabled(); - this.logger.info("**** " + getClass().getName() + "." + getName() + " is disabled in this environment: " - + "Total disabled tests=" + getDisabledTestCount()); - return; - } - - TransactionDefinition explicitTransactionDefinition = - this.transactionAttributeSource.getTransactionAttribute(testMethod, getClass()); + TransactionDefinition explicitTransactionDefinition = this.transactionAttributeSource.getTransactionAttribute( + testMethod, getClass()); if (explicitTransactionDefinition != null) { this.logger.info("Custom transaction definition [" + explicitTransactionDefinition + "] for test method [" + getName() + "]."); setTransactionDefinition(explicitTransactionDefinition); } - else if (testMethod.isAnnotationPresent(NotTransactional.class)) { - // Don't have any transaction... + + if (this.transactionDefinition.getPropagationBehavior() == TransactionDefinition.PROPAGATION_NOT_SUPPORTED) { preventTransaction(); } - // Let JUnit handle execution. We're just changing the state of the test class first. - runTestTimed(new TestExecutionCallback() { - @Override - public void run() throws Throwable { - try { - AbstractAnnotationAwareTransactionalTests.super.runBare(); - } - finally { - // Mark the context to be blown away if the test was - // annotated to result in setDirty being invoked - // automatically. - if (testMethod.isAnnotationPresent(DirtiesContext.class)) { - AbstractAnnotationAwareTransactionalTests.this.setDirty(); - } - } - } - }, testMethod); - } - - /** - * Determine if the test for the supplied {@code testMethod} should - * run in the current environment. - *

The default implementation is based on - * {@link IfProfileValue @IfProfileValue} semantics. - * @param testMethod the test method - * @return {@code true} if the test is disabled in the current environment - * @see ProfileValueUtils#isTestEnabledInThisEnvironment - */ - protected boolean isDisabledInThisEnvironment(Method testMethod) { - return !ProfileValueUtils.isTestEnabledInThisEnvironment(this.profileValueSource, testMethod, getClass()); + super.runBare(); } /** @@ -213,89 +118,17 @@ public abstract class AbstractAnnotationAwareTransactionalTests extends } /** - * Determine whether or not to rollback transactions for the current test - * by taking into consideration the - * {@link #isDefaultRollback() default rollback} flag and a possible - * method-level override via the {@link Rollback @Rollback} annotation. + * Determine whether or not to roll back transactions for the current test. + *

The default implementation simply delegates to {@link #isDefaultRollback()}. * @return the rollback flag for the current test */ @Override protected boolean isRollback() { boolean rollback = isDefaultRollback(); - Rollback rollbackAnnotation = getTestMethod().getAnnotation(Rollback.class); - if (rollbackAnnotation != null) { - boolean rollbackOverride = rollbackAnnotation.value(); - if (this.logger.isDebugEnabled()) { - this.logger.debug("Method-level @Rollback(" + rollbackOverride + ") overrides default rollback [" - + rollback + "] for test [" + getName() + "]."); - } - rollback = rollbackOverride; - } - else { - if (this.logger.isDebugEnabled()) { - this.logger.debug("No method-level @Rollback override: using default rollback [" + rollback - + "] for test [" + getName() + "]."); - } + if (this.logger.isDebugEnabled()) { + this.logger.debug("Using default rollback [" + rollback + "] for test [" + getName() + "]."); } return rollback; } - private void runTestTimed(TestExecutionCallback tec, Method testMethod) throws Throwable { - Timed timed = testMethod.getAnnotation(Timed.class); - if (timed == null) { - runTest(tec, testMethod); - } - else { - long startTime = System.currentTimeMillis(); - try { - runTest(tec, testMethod); - } - finally { - long elapsed = System.currentTimeMillis() - startTime; - if (elapsed > timed.millis()) { - fail("Took " + elapsed + " ms; limit was " + timed.millis()); - } - } - } - } - - private void runTest(TestExecutionCallback tec, Method testMethod) throws Throwable { - ExpectedException expectedExceptionAnnotation = testMethod.getAnnotation(ExpectedException.class); - boolean exceptionIsExpected = (expectedExceptionAnnotation != null && expectedExceptionAnnotation.value() != null); - Class expectedException = (exceptionIsExpected ? expectedExceptionAnnotation.value() : null); - - Repeat repeat = testMethod.getAnnotation(Repeat.class); - int runs = ((repeat != null) && (repeat.value() > 1)) ? repeat.value() : 1; - - for (int i = 0; i < runs; i++) { - try { - if (runs > 1 && this.logger != null && this.logger.isInfoEnabled()) { - this.logger.info("Repetition " + (i + 1) + " of test " + testMethod.getName()); - } - tec.run(); - if (exceptionIsExpected) { - fail("Expected exception: " + expectedException.getName()); - } - } - catch (Throwable t) { - if (!exceptionIsExpected) { - throw t; - } - if (!expectedException.isAssignableFrom(t.getClass())) { - // Wrap the unexpected throwable with an explicit message. - AssertionFailedError assertionError = new AssertionFailedError("Unexpected exception, expected<" + - expectedException.getName() + "> but was<" + t.getClass().getName() + ">"); - assertionError.initCause(t); - throw assertionError; - } - } - } - } - - - private static interface TestExecutionCallback { - - void run() throws Throwable; - } - } diff --git a/spring-orm/src/test/java/org/springframework/test/annotation/DirtiesContext.java b/spring-orm/src/test/java/org/springframework/test/annotation/DirtiesContext.java deleted file mode 100644 index 51a4177881..0000000000 --- a/spring-orm/src/test/java/org/springframework/test/annotation/DirtiesContext.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2002-2012 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.test.annotation; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - *

- * Test annotation to indicate that a test method dirties the context - * for the current test. - *

- *

- * Using this annotation in conjunction with - * {@link AbstractAnnotationAwareTransactionalTests} is less error-prone than - * calling - * {@link org.springframework.test.AbstractSingleSpringContextTests#setDirty() setDirty()} - * explicitly because the call to {@code setDirty()} is guaranteed to - * occur, even if the test failed. If only a particular code path in the test - * dirties the context, prefer calling {@code setDirty()} explicitly -- - * and take care! - *

- * - * @author Rod Johnson - * @author Sam Brannen - * @since 2.0 - * @see org.springframework.test.AbstractSingleSpringContextTests - */ -@Target( { ElementType.METHOD }) -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface DirtiesContext { - -} diff --git a/spring-orm/src/test/java/org/springframework/test/annotation/ExpectedException.java b/spring-orm/src/test/java/org/springframework/test/annotation/ExpectedException.java deleted file mode 100644 index 22faabb2b4..0000000000 --- a/spring-orm/src/test/java/org/springframework/test/annotation/ExpectedException.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2002-2007 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.test.annotation; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Test annotation to indicate that a test method is required to throw the - * specified exception. - * - * @author Rod Johnson - * @author Sam Brannen - * @since 2.0 - */ -@Target( { ElementType.METHOD }) -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface ExpectedException { - - Class value(); - -} diff --git a/spring-orm/src/test/java/org/springframework/test/annotation/IfProfileValue.java b/spring-orm/src/test/java/org/springframework/test/annotation/IfProfileValue.java deleted file mode 100644 index 662eb69d51..0000000000 --- a/spring-orm/src/test/java/org/springframework/test/annotation/IfProfileValue.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2002-2012 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.test.annotation; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Inherited; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - *

- * Test annotation to indicate that a test is enabled for a specific testing - * profile or environment. If the configured {@link ProfileValueSource} returns - * a matching {@link #value() value} for the provided {@link #name() name}, the - * test will be enabled. - *

- *

- * Note: {@link IfProfileValue @IfProfileValue} can be applied at either the - * class or method level. - *

- *

- * Examples: when using {@link SystemProfileValueSource} as the - * {@link ProfileValueSource} implementation, you can configure a test method to - * run only on Java VMs from Sun Microsystems as follows: - *

- * - *
- * {@link IfProfileValue @IfProfileValue}(name="java.vendor", value="Sun Microsystems Inc.")
- * testSomething() {
- *     // ...
- * }
- * 
- * - *

- * You can alternatively configure {@link IfProfileValue @IfProfileValue} with - * OR semantics for multiple {@link #values() values} as follows - * (assuming a {@link ProfileValueSource} has been appropriately configured for - * the "test-groups" name): - *

- * - *
- * {@link IfProfileValue @IfProfileValue}(name="test-groups", values={"unit-tests", "integration-tests"})
- *  public void testWhichRunsForUnitOrIntegrationTestGroups() {
- *      // ...
- *  }
- * 
- * - * @author Rod Johnson - * @author Sam Brannen - * @since 2.0 - * @see ProfileValueSource - * @see ProfileValueSourceConfiguration - * @see ProfileValueUtils - * @see AbstractAnnotationAwareTransactionalTests - * @see org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests - * @see org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests - * @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner - */ -@Target({ElementType.TYPE, ElementType.METHOD}) -@Retention(RetentionPolicy.RUNTIME) -@Inherited -@Documented -public @interface IfProfileValue { - - /** - * The {@code name} of the profile value against which to test. - */ - String name(); - - /** - * A single, permissible {@code value} of the profile value - * for the given {@link #name() name}. - *

Note: Assigning values to both {@link #value()} and {@link #values()} - * will lead to a configuration conflict. - */ - String value() default ""; - - /** - * A list of all permissible {@code values} of the - * profile value for the given {@link #name() name}. - *

Note: Assigning values to both {@link #value()} and {@link #values()} - * will lead to a configuration conflict. - */ - String[] values() default {}; - -} diff --git a/spring-orm/src/test/java/org/springframework/test/annotation/NotTransactional.java b/spring-orm/src/test/java/org/springframework/test/annotation/NotTransactional.java deleted file mode 100644 index 9b3df71806..0000000000 --- a/spring-orm/src/test/java/org/springframework/test/annotation/NotTransactional.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2002-2007 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.test.annotation; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Test annotation to indicate that a method is not transactional. - * - * @author Rod Johnson - * @author Sam Brannen - * @since 2.0 - */ -@Target( { ElementType.METHOD }) -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface NotTransactional { - -} diff --git a/spring-orm/src/test/java/org/springframework/test/annotation/ProfileValueSource.java b/spring-orm/src/test/java/org/springframework/test/annotation/ProfileValueSource.java deleted file mode 100644 index 05ee407f5f..0000000000 --- a/spring-orm/src/test/java/org/springframework/test/annotation/ProfileValueSource.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2002-2012 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.test.annotation; - -/** - *

- * Strategy interface for retrieving profile values for a given - * testing environment. - *

- *

- * Concrete implementations must provide a {@code public} no-args - * constructor. - *

- *

- * Spring provides the following out-of-the-box implementations: - *

- * - * - * @author Rod Johnson - * @author Sam Brannen - * @since 2.0 - * @see ProfileValueSourceConfiguration - * @see IfProfileValue - * @see ProfileValueUtils - */ -public interface ProfileValueSource { - - /** - * Get the profile value indicated by the specified key. - * @param key the name of the profile value - * @return the String value of the profile value, or {@code null} - * if there is no profile value with that key - */ - String get(String key); - -} diff --git a/spring-orm/src/test/java/org/springframework/test/annotation/ProfileValueSourceConfiguration.java b/spring-orm/src/test/java/org/springframework/test/annotation/ProfileValueSourceConfiguration.java deleted file mode 100644 index dafbe4f1a1..0000000000 --- a/spring-orm/src/test/java/org/springframework/test/annotation/ProfileValueSourceConfiguration.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2002-2007 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.test.annotation; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Inherited; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - *

- * ProfileValueSourceConfiguration is a class-level annotation which is used to - * specify what type of {@link ProfileValueSource} to use when retrieving - * profile values configured via the - * {@link IfProfileValue @IfProfileValue} annotation. - *

- * - * @author Sam Brannen - * @since 2.5 - * @see ProfileValueSource - * @see IfProfileValue - * @see ProfileValueUtils - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -@Inherited -@Documented -public @interface ProfileValueSourceConfiguration { - - /** - *

- * The type of {@link ProfileValueSource} to use when retrieving - * profile values. - *

- * - * @see SystemProfileValueSource - */ - Class value() default SystemProfileValueSource.class; - -} diff --git a/spring-orm/src/test/java/org/springframework/test/annotation/ProfileValueUtils.java b/spring-orm/src/test/java/org/springframework/test/annotation/ProfileValueUtils.java deleted file mode 100644 index 75cb9c1423..0000000000 --- a/spring-orm/src/test/java/org/springframework/test/annotation/ProfileValueUtils.java +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright 2002-2012 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.test.annotation; - -import java.lang.reflect.Method; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.springframework.core.annotation.AnnotationUtils; -import org.springframework.util.Assert; -import org.springframework.util.ObjectUtils; -import org.springframework.util.StringUtils; - -/** - * General utility methods for working with profile values. - * - * @author Sam Brannen - * @author Juergen Hoeller - * @since 2.5 - * @see ProfileValueSource - * @see ProfileValueSourceConfiguration - * @see IfProfileValue - */ -public abstract class ProfileValueUtils { - - private static final Log logger = LogFactory.getLog(ProfileValueUtils.class); - - - /** - * Retrieves the {@link ProfileValueSource} type for the specified - * {@link Class test class} as configured via the - * {@link ProfileValueSourceConfiguration @ProfileValueSourceConfiguration} - * annotation and instantiates a new instance of that type. - *

- * If - * {@link ProfileValueSourceConfiguration @ProfileValueSourceConfiguration} - * is not present on the specified class or if a custom - * {@link ProfileValueSource} is not declared, the default - * {@link SystemProfileValueSource} will be returned instead. - * - * @param testClass The test class for which the ProfileValueSource should - * be retrieved - * @return the configured (or default) ProfileValueSource for the specified - * class - * @see SystemProfileValueSource - */ - @SuppressWarnings("unchecked") - public static ProfileValueSource retrieveProfileValueSource(Class testClass) { - Assert.notNull(testClass, "testClass must not be null"); - - Class annotationType = ProfileValueSourceConfiguration.class; - ProfileValueSourceConfiguration config = testClass.getAnnotation(annotationType); - if (logger.isDebugEnabled()) { - logger.debug("Retrieved @ProfileValueSourceConfiguration [" + config + "] for test class [" - + testClass.getName() + "]"); - } - - Class profileValueSourceType; - if (config != null) { - profileValueSourceType = config.value(); - } - else { - profileValueSourceType = (Class) AnnotationUtils.getDefaultValue(annotationType); - } - if (logger.isDebugEnabled()) { - logger.debug("Retrieved ProfileValueSource type [" + profileValueSourceType + "] for class [" - + testClass.getName() + "]"); - } - - ProfileValueSource profileValueSource; - if (SystemProfileValueSource.class.equals(profileValueSourceType)) { - profileValueSource = SystemProfileValueSource.getInstance(); - } - else { - try { - profileValueSource = profileValueSourceType.newInstance(); - } - catch (Exception e) { - if (logger.isWarnEnabled()) { - logger.warn("Could not instantiate a ProfileValueSource of type [" + profileValueSourceType - + "] for class [" + testClass.getName() + "]: using default.", e); - } - profileValueSource = SystemProfileValueSource.getInstance(); - } - } - - return profileValueSource; - } - - /** - * Determine if the supplied {@code testClass} is enabled - * in the current environment, as specified by the - * {@link IfProfileValue @IfProfileValue} annotation at the class level. - *

- * Defaults to {@code true} if no - * {@link IfProfileValue @IfProfileValue} annotation is declared. - * - * @param testClass the test class - * @return {@code true} if the test is enabled in the - * current environment - */ - public static boolean isTestEnabledInThisEnvironment(Class testClass) { - IfProfileValue ifProfileValue = testClass.getAnnotation(IfProfileValue.class); - if (ifProfileValue == null) { - return true; - } - ProfileValueSource profileValueSource = retrieveProfileValueSource(testClass); - return isTestEnabledInThisEnvironment(profileValueSource, ifProfileValue); - } - - /** - * Determine if the supplied {@code testMethod} is enabled - * in the current environment, as specified by the - * {@link IfProfileValue @IfProfileValue} annotation, which may be declared - * on the test method itself or at the class level. - *

- * Defaults to {@code true} if no - * {@link IfProfileValue @IfProfileValue} annotation is declared. - * - * @param testMethod the test method - * @param testClass the test class - * @return {@code true} if the test is enabled in the - * current environment - */ - public static boolean isTestEnabledInThisEnvironment(Method testMethod, Class testClass) { - IfProfileValue ifProfileValue = testMethod.getAnnotation(IfProfileValue.class); - if (ifProfileValue == null) { - ifProfileValue = testClass.getAnnotation(IfProfileValue.class); - if (ifProfileValue == null) { - return true; - } - } - ProfileValueSource profileValueSource = retrieveProfileValueSource(testClass); - return isTestEnabledInThisEnvironment(profileValueSource, ifProfileValue); - } - - /** - * Determine if the supplied {@code testMethod} is enabled - * in the current environment, as specified by the - * {@link IfProfileValue @IfProfileValue} annotation, which may be declared - * on the test method itself or at the class level. - *

- * Defaults to {@code true} if no - * {@link IfProfileValue @IfProfileValue} annotation is declared. - * - * @param profileValueSource the ProfileValueSource to use to determine if - * the test is enabled - * @param testMethod the test method - * @param testClass the test class - * @return {@code true} if the test is enabled in the - * current environment - */ - public static boolean isTestEnabledInThisEnvironment(ProfileValueSource profileValueSource, Method testMethod, - Class testClass) { - - IfProfileValue ifProfileValue = testMethod.getAnnotation(IfProfileValue.class); - if (ifProfileValue == null) { - ifProfileValue = testClass.getAnnotation(IfProfileValue.class); - if (ifProfileValue == null) { - return true; - } - } - return isTestEnabledInThisEnvironment(profileValueSource, ifProfileValue); - } - - /** - * Determine if the {@code value} (or one of the {@code values}) - * in the supplied {@link IfProfileValue @IfProfileValue} annotation is - * enabled in the current environment. - * - * @param profileValueSource the ProfileValueSource to use to determine if - * the test is enabled - * @param ifProfileValue the annotation to introspect - * @return {@code true} if the test is enabled in the - * current environment - */ - private static boolean isTestEnabledInThisEnvironment(ProfileValueSource profileValueSource, - IfProfileValue ifProfileValue) { - - String environmentValue = profileValueSource.get(ifProfileValue.name()); - String[] annotatedValues = ifProfileValue.values(); - if (StringUtils.hasLength(ifProfileValue.value())) { - if (annotatedValues.length > 0) { - throw new IllegalArgumentException("Setting both the 'value' and 'values' attributes " - + "of @IfProfileValue is not allowed: choose one or the other."); - } - annotatedValues = new String[] { ifProfileValue.value() }; - } - - for (String value : annotatedValues) { - if (ObjectUtils.nullSafeEquals(value, environmentValue)) { - return true; - } - } - return false; - } - -} diff --git a/spring-orm/src/test/java/org/springframework/test/annotation/Repeat.java b/spring-orm/src/test/java/org/springframework/test/annotation/Repeat.java deleted file mode 100644 index b2e832fac3..0000000000 --- a/spring-orm/src/test/java/org/springframework/test/annotation/Repeat.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2002-2008 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.test.annotation; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Test annotation to indicate that a test method should be invoked repeatedly. - *

- * Note that the scope of execution to be repeated includes execution of the - * test method itself as well as any set up or tear down - * of the test fixture. - * - * @author Rod Johnson - * @author Sam Brannen - * @since 2.0 - */ -@Target( { ElementType.METHOD }) -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface Repeat { - - int value() default 1; - -} diff --git a/spring-orm/src/test/java/org/springframework/test/annotation/Rollback.java b/spring-orm/src/test/java/org/springframework/test/annotation/Rollback.java deleted file mode 100644 index 754888cc14..0000000000 --- a/spring-orm/src/test/java/org/springframework/test/annotation/Rollback.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2002-2012 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.test.annotation; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Test annotation to indicate whether or not the transaction for the annotated - * test method should be rolled back after the test method has - * completed. If {@code true}, the transaction will be rolled back; - * otherwise, the transaction will be committed. - * - * @author Sam Brannen - * @since 2.5 - */ -@Target( { ElementType.METHOD }) -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface Rollback { - - /** - *

- * Whether or not the transaction for the annotated method should be rolled - * back after the method has completed. - *

- */ - boolean value() default true; - -} diff --git a/spring-orm/src/test/java/org/springframework/test/annotation/SystemProfileValueSource.java b/spring-orm/src/test/java/org/springframework/test/annotation/SystemProfileValueSource.java deleted file mode 100644 index 5a39918a77..0000000000 --- a/spring-orm/src/test/java/org/springframework/test/annotation/SystemProfileValueSource.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2002-2012 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.test.annotation; - -import org.springframework.util.Assert; - -/** - * Implementation of {@link ProfileValueSource} which uses system properties as - * the underlying source. - * - * @author Rod Johnson - * @author Sam Brannen - * @since 2.0 - */ -public class SystemProfileValueSource implements ProfileValueSource { - - private static final SystemProfileValueSource INSTANCE = new SystemProfileValueSource(); - - - /** - * Obtain the canonical instance of this ProfileValueSource. - */ - public static final SystemProfileValueSource getInstance() { - return INSTANCE; - } - - - /** - * Private constructor, enforcing the singleton pattern. - */ - private SystemProfileValueSource() { - } - - /** - * Get the profile value indicated by the specified key from the - * system properties. - * @see System#getProperty(String) - */ - @Override - public String get(String key) { - Assert.hasText(key, "'key' must not be empty"); - return System.getProperty(key); - } - -} diff --git a/spring-orm/src/test/java/org/springframework/test/annotation/Timed.java b/spring-orm/src/test/java/org/springframework/test/annotation/Timed.java deleted file mode 100644 index aaba1d92cd..0000000000 --- a/spring-orm/src/test/java/org/springframework/test/annotation/Timed.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2002-2008 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.test.annotation; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - *

- * Test-specific annotation to indicate that a test method has to finish - * execution in a {@link #millis() specified time period}. - *

- *

- * If the text execution takes longer than the specified time period, then the - * test is to be considered failed. - *

- *

- * Note that the time period includes execution of the test method itself, any - * {@link Repeat repetitions} of the test, and any set up or - * tear down of the test fixture. - *

- * - * @author Rod Johnson - * @author Sam Brannen - * @since 2.0 - * @see Repeat - * @see AbstractAnnotationAwareTransactionalTests - */ -@Target({ElementType.METHOD}) -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface Timed { - - /** - * The maximum amount of time (in milliseconds) that a test execution can - * take without being marked as failed due to taking too long. - */ - long millis(); - -} diff --git a/spring-orm/src/test/java/org/springframework/test/jpa/AbstractJpaTests.java b/spring-orm/src/test/java/org/springframework/test/jpa/AbstractJpaTests.java index bcd5704c80..968c288117 100644 --- a/spring-orm/src/test/java/org/springframework/test/jpa/AbstractJpaTests.java +++ b/spring-orm/src/test/java/org/springframework/test/jpa/AbstractJpaTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 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. @@ -50,7 +50,9 @@ import org.springframework.test.annotation.AbstractAnnotationAwareTransactionalT import org.springframework.util.StringUtils; /** - * Convenient support class for JPA-related tests. Offers the same contract as + * This class is only used within tests in the spring-orm module. + * + *

Convenient support class for JPA-related tests. Offers the same contract as * AbstractTransactionalDataSourceSpringContextTests and equally good performance, * even when performing the instrumentation required by the JPA specification. * @@ -171,15 +173,6 @@ public abstract class AbstractJpaTests extends AbstractAnnotationAwareTransactio return; } - final Method testMethod = getTestMethod(); - - if (isDisabledInThisEnvironment(testMethod)) { - recordDisabled(); - this.logger.info("**** " + getClass().getName() + "." + getName() + " is disabled in this environment: " - + "Total disabled tests=" + getDisabledTestCount()); - return; - } - if (!shouldUseShadowLoader()) { super.runBare(); return;