Commit Graph

460 Commits

Author SHA1 Message Date
Sam Brannen 9bf73f3ab8 Document default locale in MockHttpServletRequest
This commit updates the class-level Javadoc for MockHttpServletRequest
with information regarding the default locale for the mocked server.

Issue: SPR-11701
2014-07-28 19:07:26 +03:00
Sam Brannen f862a009a7 Groovy loader should delegate to XML loader in the TCF
If a resource location in the MergedContextConfiguration has a ".xml"
extension, the GenericGroovyXmlContextLoader now delegates to a
dedicated XmlBeanDefinitionReader for loading bean definitions from that
resource, thus preserving XML validation for all XML resource locations.
For all other extensions (presumably only ".groovy"), the
GenericGroovyXmlContextLoader delegates to a GroovyBeanDefinitionReader.

Issue: SPR-11233
2014-07-28 17:55:57 +03:00
Sam Brannen 0ad5de3f77 Document default TELs in AbstTxTestNGSpringContextTests 2014-07-24 19:04:11 +02:00
Sam Brannen 5a483f347a Polishing 2014-07-24 19:02:10 +02:00
Sam Brannen d144e2918e Document default TELs in AbstTxJUnit4SpringContextTests 2014-07-24 18:58:59 +02:00
Sam Brannen 0d4526e050 Update Javadoc re: minimum JUnit 4.9 dependency 2014-07-24 18:54:13 +02:00
Sam Brannen 170d6c9fb9 Delete trailing whitespace in spring-test 2014-07-24 18:13:38 +02:00
Sam Brannen 35c372f200 Support Groovy scripts in the TCF
Spring Framework 4.0 introduced first-class support for a Groovy-based
DSL for defining the beans for an ApplicationContext. However, prior to
this commit, the Spring TestContext Framework (TCF) did not provide any
out-of-the-box support for using Groovy scripts as path-based resource
locations when loading an application context for tests.

This commit addresses this issue by introducing first-class support for
using Groovy scripts to load the ApplicationContext for integration
tests managed by the TCF. Specifically, the following changes have been
made in the TCF to support Groovy scripts.

 - Introduced getResourceSuffixes() in AbstractContextLoader in order
   to support multiple resource suffixes in the default detection
   process. This feature is used by the new Groovy/Xml context loaders.

 - Introduced GenericGroovyXmlContextLoader and
   GenericGroovyXmlWebContextLoader which support both Groovy scripts
   and XML config files for loading bean definitions. Furthermore,
   these loaders support "-context.xml" and "Context.groovy" as
   resource suffixes when detecting defaults. Note that a default XML
   config file will be detected before a default Groovy script.

 - DelegatingSmartContextLoader and WebDelegatingSmartContextLoader now
   use reflection to choose between using GenericGroovyXmlContextLoader
   and GenericGroovyXmlWebContextLoader vs. GenericXmlContextLoader and
   GenericXmlWebContextLoader as their XML loaders, depending on
   whether Groovy is present in the classpath.

 - Groovy scripts can be configured via the 'locations' or 'value'
   attributes of @ContextConfiguration and can be mixed seamlessly with
   XML config files.

Issue: SPR-11233
2014-07-24 17:04:40 +02:00
Sam Brannen b75eb60943 Clean up Spring MVC Test Framework code
- Formatting
 - Suppress warnings
 - Remove unused imports
2014-07-24 14:12:14 +02:00
Rossen Stoyanchev 71b63cd972 Update MockMvcConfigurer support
This is a follow-up on the commit introducing MockMvcConfigurer:
c2b0fac852

This commit refines the MockMvcConfigurer contract to use (the new)
ConfigurableMockMvcBuilder hence not requiring downcasting to
AbstractMockMvcBuilder.

The same also no longer passes the "default" RequestBuilder which would
also require a downcast, but rather allows a RequestPostProcessor to be
returned so that a 3rd party framework or application can modify any
property of every performed MockHttpServletRequest.

To make this possible the new SmartRequestBuilder interface separates
request building from request post processing while the new
ConfigurableSmartRequestBuilder allows adding a RequestPostProcessor
to a MockMvcBuilder.

Issue: SPR-11497
2014-07-22 13:41:22 -04:00
Sam Brannen 3013558e3d Update Javadoc for SqlScriptsTestExecutionListener 2014-07-20 22:03:31 +02:00
Sam Brannen a10537447e Polish Javadoc for TestTransaction 2014-07-19 10:59:10 +02:00
Sam Brannen 7d2ef69c6d Polish Javadoc for TransactionalTestExecutionListener 2014-07-19 10:52:46 +02:00
Sam Brannen 97dad7e2ea Polish Javadoc for TestExecutionListener 2014-07-19 10:45:53 +02:00
Sam Brannen b16e6cc44e Improve documentation for tx support in the TCF
Overhauled class-level Javadoc for TransactionalTestExecutionListener:

 - Reorganized content.
 - Added headings to paragraphs.
 - Documented TestTransaction support.

Issue: SPR-11941
2014-07-19 10:45:27 +02:00
Sam Brannen 526b4b647f Improve Javadoc for TransactionalTestExecutionListener 2014-07-18 17:50:12 +02:00
Juergen Hoeller 9d6c38bd54 Consistent bracket alignment 2014-07-18 17:21:58 +02:00
Sam Brannen 3e5946db37 Polish log statements for TransactionContext 2014-07-18 17:09:53 +02:00
Sam Brannen 7808996d71 Polishing 2014-07-18 17:02:45 +02:00
Sam Brannen 682e8fb3ad Reduce code duplication in MergedSqlConfig 2014-07-18 14:39:23 +02:00
Sam Brannen 2e75adb04c Improve transaction management for @Sql scripts
Prior to this commit, the support for SQL script execution via @Sql
provided an algorithm for looking up a required
PlatformTransactionManager to use to drive transactions. However, a
transaction manager is not actually required for all testing scenarios.

This commit improves the transaction management support for @Sql so
that SQL scripts can be executed without a transaction if a transaction
manger is not present in the ApplicationContext. The updated algorithm
now supports the following use cases.

 - If a transaction manager and data source are both present (i.e.,
   explicitly specified via the transactionManager and dataSource
   attributes of @SqlConfig or implicitly discovered in the
   ApplicationContext based on conventions), both will be used.

 - If a transaction manager is not explicitly specified and not
   implicitly discovered based on conventions, SQL scripts will be
   executed without a transaction but requiring the presence of a data
   source. If a data source is not present, an exception will be thrown.

 - If a data source is not explicitly specified and not implicitly
   discovered based on conventions, an attempt will be made to retrieve
   it by using reflection to invoke a public method named
   getDataSource() on the transaction manager. If this attempt fails,
   an exception will be thrown.

 - If a data source can be retrieved from the resolved transaction
   manager using reflection, an exception will be thrown if the
   resolved data source is not the data source associated with the
   resolved transaction manager. This helps to avoid possibly
   unintended configuration errors.

 - If @SqlConfig.transactionMode is set to ISOLATED, an exception will
   be thrown if a transaction manager is not present.

Issue: SPR-11911
2014-07-18 02:59:03 +02:00
Sam Brannen dfcb2a2875 Fix test broken by previous refactoring 2014-07-16 21:51:49 +02:00
Sam Brannen 91c9bad12e Rename test classes previously related only to ContextLoaderUtils 2014-07-16 21:49:29 +02:00
Sam Brannen c290839914 Investigate claim on SO regarding ctx cache in TCF
This commit introduces a test that investigates a claim made on Stack
Overflow regarding context caching in the TestContext Framework (TCF).
2014-07-16 21:34:43 +02:00
Sam Brannen da5b0b97d3 Update Javadoc in SqlScriptsTestExecutionListener 2014-07-16 18:19:49 +02:00
Sam Brannen 5cb046da3d Update Javadoc in SqlScriptsTestExecutionListener 2014-07-16 18:16:46 +02:00
Sam Brannen a488515097 Simplify logic in MergedSqlConfig 2014-07-16 18:12:59 +02:00
Sam Brannen 6d6f008faa Polish Javadoc for MergedSqlConfig 2014-07-16 17:54:23 +02:00
Sam Brannen c1a2f5efa4 Remove unnecessary warning suppression in ModelResultMatchers 2014-07-16 17:44:44 +02:00
Sam Brannen 628806e85b Introduce @SqlConfig for common SQL script config
Prior to this commit, @Sql provided attributes for configuring the
syntax of the referenced SQL scripts as well as exception handling and
transaction behavior; however, such configuration could not be reused
across @Sql declarations thus requiring developers to copy-and-paste
common configuration and resulting in unnecessary code duplication.

This commit addresses this issue by introducing a new @SqlConfig
annotation that can be used to declare common, global configuration for
SQL scripts that can be reused within a test class hierarchy.

 - Introduced top-level @SqlConfig annotation and extracted
   common configuration attributes from @Sql.

 - @SqlConfig can be used at the class level for common, global config
   or via the new 'config' attribute of @Sql for local config.

 - Introduced MergedSqlConfig as a holder for the merged values from
   local and global @SqlConfig instances. MergedSqlConfig also contains
   the logic for overriding global configuration with local
   configuration.

 - Refactored all attributes of @SqlConfig to be either of type String
   or custom enums in order to support overriding. Empty Strings or
   DEFAULT enum values imply the use of a default or inherited value.

Issue: SPR-11896
2014-07-16 17:21:15 +02:00
Rossen Stoyanchev c2b0fac852 Add extension point to pre-configure a MockMvcBuilder
Issue: SPR-11497
2014-07-15 22:59:25 -04:00
Rossen Stoyanchev 10a4c2cd81 Remove FreeMarker/Velocity/TilesConfigurer MVC config
After some further discussion:

The MVC config simplifies ViewResolver configuration especially where
content negotiation view resolution is involved.

The configuration of the underlying view technology however is kept
completely separate. In the case of the MVC namespace, dedicated
top-level freemarker, velocity, and tiles namespace elements are
provided. In the case of the MVC Java config, applications simply
declare FreeMarkerConfigurer, VelocityConfigurer, or TilesConfigurer
beans respectively.

Issue: SPR-7093
2014-07-15 14:27:01 -04:00
Rossen Stoyanchev f54cee47b0 Update ViewResolver registration classes
Following the separation of FreeMarker/Velocity/TilesConfigurer-related
configuration via separate interface, simplify and streamline the
view registration helper classes which no longer have much difference
(most are UrlBasedViewResolver's).

Updates to Javadoc and tests.

Issue: SPR-7093
2014-07-13 22:53:23 -04:00
Rossen Stoyanchev 5bc793768c Introduce Freemarker/Velocity/TilesWebMvcConfigurer
This change improves the support for auto-registration of FreeMarker,
Velocity, and Tiles configuration.

The configuration is now conditional not only based on the classpath
but also based on whether a FreeMarkerConfigurer for example is already
present in the configuration.

This change also introduces FreeMarker~, Velocity~, and
TilesWebMvcConfigurer interfaces for customizing each view technology.

The WebMvcConfigurer can still be used to configure all view resolvers
centrally (including FreeMarker, Velocity, and Tiles) without some
default conifguration, i.e. without the need to use the new
~WebMvcConfigurer interfaces until customizations are required.

Issue: SPR-7093
2014-07-12 17:23:47 -04:00
Sebastien Deleuze cc7e8f5558 Support Java and MVC namespace view resolution config
This commit improves and completes the initial MVC namespace
view resolution implementation. ContentNegotiatingViewResolver
registration is now also supported.

Java Config view resolution support has been added.
FreeMarker, Velocity and Tiles view configurers are registered
depending on the classpath thanks to an ImportSelector.

For both, a default configuration is provided and documented.

Issue: SPR-7093
2014-07-12 17:23:47 -04:00
Lea Farmer 85cdb9196e Added field error code matching to MockMvc
This change adds a method within the ModelResultMatcher that will allow
a user to assert whether the returned Model has an attribute with a
field that has a specific error associated with it.

Issue: SPR-11971
2014-07-11 09:36:09 -04:00
Juergen Hoeller 3c726aa6c1 Polishing 2014-07-09 21:24:59 +02:00
Sam Brannen 58955236ee Introduce tests for Spring Boot issue 885
This commit introduces unit tests that attempt to reproduce the problem
described in Spring Boot issue 885; however, the tests pass and
therefore do not confirm the reported problem.

See: https://github.com/spring-projects/spring-boot/issues/885
2014-07-04 16:11:28 +02:00
Sam Brannen 0d710f197e Polishing tests in spring-test 2014-07-03 19:33:20 +02:00
Sam Brannen bdceaa481b Introduce TestNG tests for programmatic tx mgmt in the TCF
Issue: SPR-5079
2014-07-02 23:14:42 +02:00
Sam Brannen f667e43ca2 Introduce programmatic tx mgmt in the TCF
Historically, Spring's JUnit 3.8 TestCase class hierarchy supported
programmatic transaction management of "test-managed transactions" via
the protected endTransaction() and startNewTransaction() methods in
AbstractTransactionalSpringContextTests.

The Spring TestContext Framework (TCF) was introduced in Spring 2.5 to
supersede the legacy JUnit 3.8 support classes; however, prior to this
commit the TCF has not provided support for programmatically starting
or stopping the test-managed transaction.

This commit introduces a TestTransaction class in the TCF that provides
static utility methods for programmatically interacting with
test-managed transactions. Specifically, the following features are
supported by TestTransaction and its collaborators.

 - End the current test-managed transaction.

 - Start a new test-managed transaction, using the default rollback
   semantics configured via @TransactionConfiguration and @Rollback.

 - Flag the current test-managed transaction to be committed.

 - Flag the current test-managed transaction to be rolled back.

Implementation Details:

 - TransactionContext is now a top-level, package private class.

 - The existing test transaction management logic has been extracted
   from TransactionalTestExecutionListener into TransactionContext.

 - The current TransactionContext is stored in a
   NamedInheritableThreadLocal that is managed by
   TransactionContextHolder.

 - TestTransaction defines the end-user API, interacting with the
   TransactionContextHolder behind the scenes.

 - TransactionalTestExecutionListener now delegates to
   TransactionContext completely for starting and ending transactions.

Issue: SPR-5079
2014-07-02 22:52:54 +02:00
Sebastien Deleuze 9e52004222 Add support for asserting JSON
Based on the JSONassert library.

Issue: SPR-10113
2014-07-01 22:47:02 -04:00
Sam Brannen 669386abac Organize imports in Spring MVC Test classes 2014-07-01 17:57:48 +02:00
Sam Brannen 49e960c151 Polish doc & imports for MockAsyncClientHttpRequest
Issue: SPR-11822
2014-07-01 16:36:48 +02:00
Rossen Stoyanchev 9aa53abdf9 Add AsyncRestTemplate support to client-side MockMvc
Issue: SPR-1822
2014-06-28 09:49:19 -04:00
Juergen Hoeller cc917de24d Polishing 2014-06-26 11:44:07 +02:00
Sam Brannen b4e16eacc5 Require JUnit 4.9 or higher in the TCF
Prior to this commit, the Spring TestContext Framework (TCF) was
compatible with JUnit 4.5 or higher.

This commit effectively raises the minimum version of JUnit that is
officially supported by the TCF to JUnit 4.9, thereby aligning with
similar upgrades made in the Spring Framework 4.0 release (i.e.,
upgrading minimum requirements on third-party libraries to versions
released mid 2010 or later).

Issue: SPR-11908
2014-06-25 10:10:25 +02:00
Sam Brannen f1517f03ff Delete remaining SimpleJdbcTemplate usage
This commit deletes all remaining usage of the deprecated
SimpleJdbcTemplate class within the framework itself.

Issue: SPR-11895
2014-06-22 15:40:41 +02:00
Sam Brannen 0c1249fe42 Introduce repeatable @Sql tests
This commit introduces explicit integration tests that verify Java 8's
@Repeatable support for the @Sql annotation.

Issue: SPR-7655
2014-06-20 14:37:45 +02:00
Sam Brannen abdb010fc8 Rename SQL script annotations in the TCF
Prior to this commit, SQL script annotations and related classes in the
TestContext framework (TCF) were named DatabaseInitializer*. However,
these annotations are not used only for initialization and are
therefore misleading when used for cleaning up the database.

This commit refines the names of annotations and related classes for
configuring SQL scripts to be executed for integration tests in the TCF
as follows:

- @DatabaseInitializer -> @Sql
- @DatabaseInitializers -> @SqlGroup
- DatabaseInitializerTestExecutionListener -> SqlScriptsTestExecutionListener

A special thanks goes out to the following attendees of the Zurich
Hackergarten meeting last night for their collective brainstorming:
@aalmiray, @atsticks, @ollin, @simkuenzi, @tangresh, @vyazelenko.

Issue: SPR-7655
2014-06-20 14:33:23 +02:00
Rossen Stoyanchev b214db3fc8 Rename HttpStatus 308 to Permanent Redirect
Issue: SPR-11854
2014-06-10 18:51:22 -04:00
Rossen Stoyanchev c269d27bde Improve no content handling in MockHttpServletRequest
Issue: SPR-11764
2014-06-06 11:25:15 -04:00
Sam Brannen f48bdafd52 Polish Javadoc for TestContextTransactionUtils 2014-06-05 21:09:29 +02:00
Sam Brannen 5fd6ebb548 Introduce annotation to execute SQL scripts in the TCF
Prior to this commit, it was possible to execute SQL scripts
programmatically via ResourceDatabasePopulator, JdbcTestUtils, and
ScriptUtils. Furthermore, it was also possible to execute SQL scripts
declaratively via the <jdbc> XML namespace. However, it was not
possible to execute SQL scripts declaratively on a per test class or
per test method basis.

This commit makes it possible to declaratively configure SQL scripts
for execution in integration tests via annotations that can be declared
at the class or method level. Details follow.

 - Introduced a repeatable @DatabaseInitializer annotation that can be
   used to configure SQL scripts at the class or method level with
   method-level overrides. @DatabaseInitializers serves as a container
   for @DatabaseInitializer.

 - Introduced a new DatabaseInitializerTestExecutionListener that is
   responsible for parsing @DatabaseInitializer and
   @DatabaseInitializers and executing SQL scripts.

 - DatabaseInitializerTestExecutionListener is registered by default in
   abstract base test classes as well as in TestContextBootstrapper
   implementations.

 - @DatabaseInitializer and @DatabaseInitializers may be used as
   meta-annotations; however, attribute overrides are not currently
   supported for repeatable annotations used as meta-annotations. This
   is a known limitation of Spring's AnnotationUtils.

 - The semantics for locating SQL script resources is consistent with
   @ContextConfiguration's semantics for locating XML configuration
   files. In addition, a default SQL script can be detected based
   either on the name of the annotated class or on the name of the
   annotated test method.

 - @DatabaseInitializer allows for specifying which DataSource and
   PlatformTransactionManager to use from the test's
   ApplicationContext, including default conventions consistent with
   TransactionalTestExecutionListener and @TransactionConfiguration.

 - @DatabaseInitializer supports all of the script configuration options
   currently supported by ResourceDatabasePopulator.

 - @DatabaseInitializer and DatabaseInitializerTestExecutionListener
   support execution phases for scripts that dictate when SQL scripts
   are executed (i.e., before or after a test method).

 - SQL scripts can be executed within the current test's transaction if
   present, outside of the current test's transaction if present, or
   always in a new transaction, depending on the value of the boolean
   requireNewTransaction flag in @DatabaseInitializer.

 - DatabaseInitializerTestExecutionListener delegates to
   ResourceDatabasePopulator#execute to actually execute the scripts.

Issue: SPR-7655
2014-06-05 20:06:11 +02:00
Juergen Hoeller 5eecb138f6 Unit tests for custom profile annotations on configuration classes
Issue: SPR-11808
2014-05-30 22:04:40 +02:00
Sam Brannen 4b291c665c Upgrade spring-test tests to Hibernate 4
This commit upgrades Hibernate-based integration tests in the
spring-test module to use Hibernate 4 instead of 3 and Hibernate
Validator 5 instead of 4. This streamlines and simplifies our
dependency management at the same time.

Issue: SPR-11834
2014-05-29 18:18:55 +02:00
Juergen Hoeller d9b39ad691 Consistent use of IllegalStateException instead of InternalError for UnsupportedEncodingException cause 2014-05-20 00:37:09 +02:00
Juergen Hoeller 1285467fe6 Consistently log Class.getName() instead of Class.toString(), avoiding double class term in log message
Issue: SPR-11804
2014-05-19 22:29:10 +02:00
Juergen Hoeller 2619955fc3 Consistently log Class.getName() instead of Class.toString(), avoiding double class term in log message
Issue: SPR-11804
2014-05-19 20:18:50 +02:00
Juergen Hoeller 41ed228450 Refined check for NoClassDefFoundError in getTestExecutionListeners()
Issue: SPR-11804
2014-05-19 16:31:23 +02:00
Rossen Stoyanchev 676282c66e Support ListenableFuture on @RequestMapping methods
Issue: SPR-11695
2014-05-01 12:28:59 -04:00
Juergen Hoeller 02aca9c754 Polishing 2014-04-30 00:01:07 +02:00
Juergen Hoeller 6cb45f714e General defensiveness about the bootstrap ClassLoader (i.e. null ClassLoader)
Issue: SPR-11721
(cherry picked from commit 59cef3c)
2014-04-28 00:47:21 +02:00
Alex Panchenko 09341b996e Add space separator in JsonPathExpectationsHelper 2014-04-25 18:04:54 +07:00
Stephane Nicoll 5559209233 Remove useless imports 2014-04-22 09:57:12 +02:00
Sam Brannen ba3c7e588f Polish Javadoc for SpringJUnit4ClassRunner 2014-04-10 18:28:36 +02:00
Sam Brannen 1bbc55d63c Polish Javadoc for TestContextBootstrapper 2014-04-10 01:09:51 +02:00
Sam Brannen 5df60a2bec Update ContextLoaderUtils Javadoc due to recent refactoring 2014-04-10 00:56:23 +02:00
Sam Brannen e1a1e1205f Simplify DefaultBootstrapContext.toString() 2014-04-10 00:44:14 +02:00
Sam Brannen a281bdbfc5 Introduce context bootstrap strategy in the TCF
Work done in conjunction with SPR-5243 and SPR-4588 introduced physical
package cycles in the spring-test module. The work performed in
conjunction with SPR-9924 uses reflection to resolve these physical
package cycles; however, prior to this commit the logical package
cycles still remain.

Furthermore, over time it has become apparent that the Spring
TestContext Framework (TCF) could better serve application developers
and especially third-party framework developers by providing a more
flexible mechanism for "bootstrapping" the TCF. For example, prior to
this commit, default TestExecutionListeners could only be registered by
subclassing TestContextManager (and SpringJUnit4ClassRunner if using
JUnit). Similarly, the default ContextLoader could only be set by
subclassing SpringJUnit4ClassRunner for JUnit and by copying and
modifying AbstractTestNGSpringContextTests for TestNG.

This commit addresses the aforementioned issues by introducing a
bootstrap strategy in the TestContext framework that is responsible for
determining default TestExecutionListeners and the default
ContextLoader in an extensible fashion. The new TestContextBootstrapper
SPI also provides a mechanism for supporting various types of
MergedContextConfiguration depending on the feature set of the context
loaders supported by the strategy.

The following provides an overview of the most significant changes in
this commit.

 - Introduced TestContextBootstrapper strategy SPI, BootstrapContext,
   and @BootstrapWith.

 - Introduced AbstractTestContextBootstrapper,
   DefaultTestContextBootstrapper, and WebTestContextBootstrapper
   implementations of the TestContextBootstrapper SPI and extracted
   related reflection code from ContextLoaderUtils & TestContextManager.

 - Introduced BootstrapUtils for retrieving the TestContextBootstrapper
   from @BootstrapWith, falling back to a default if @BootstrapWith is
   not present.

 - @WebAppConfiguration is now annotated with
   @BootstrapWith(WebTestContextBootstrapper.class).

 - CacheAwareContextLoaderDelegate is now an interface with a new
   DefaultCacheAwareContextLoaderDelegate implementation class.

 - Introduced closeContext(MergedContextConfiguration, HierarchyMode) in
   CacheAwareContextLoaderDelegate.

 - DefaultTestContext now uses CacheAwareContextLoaderDelegate instead
   of interacting directly with the ContextCache.

 - DefaultTestContext now delegates to a TestContextBootstrapper for
   building the MergedContextConfiguration.

 - TestContextManager now delegates to TestContextBootstrapper for
   retrieving TestExecutionListeners.

 - Deleted TestContextManager(Class, String) constructor and
   SpringJUnit4ClassRunner.getDefaultContextLoaderClassName(Class)
   method since default ContextLoader support is now implemented by
   TestContextBootstrappers.

 - Extracted ActiveProfilesUtils from ContextLoaderUtils.

 - Extracted ApplicationContextInitializerUtils from ContextLoaderUtils.

 - MetaAnnotationUtils is now a public utility class in the test.util
   package.

 - Removed restriction in @ActiveProfiles that a custom resolver cannot
   be used with the 'value' or 'profiles' attributes.

 - Introduced DefaultActiveProfilesResolver.

Issue: SPR-9955
2014-04-10 00:15:34 +02:00
Sam Brannen d53b498839 Don't encode '@' in {@code} tags 2014-04-08 15:01:54 +02:00
Sam Brannen a1486e46c8 Don't encode '@' in {@code} tags 2014-04-08 14:36:49 +02:00
Sam Brannen 4cd075bb96 Introduce test for PropertySource + ACI in the TCF
This commit introduces an explicit integration test to verify that a
PropertySource can be set via a custom ApplicationContextInitializer in
the Spring TestContext Framework.

Issue: SPR-11666
2014-04-06 20:09:22 +02:00
Sam Brannen 89a4c291c3 Remove trailing whitespace 2014-04-01 20:22:25 +02:00
Sam Brannen 1f017c4acb Support classes AND locations in @ContextConfiguration
Prior to this commit, the Spring TestContext Framework did not support
the declaration of both 'locations' and 'classes' within
@ContextConfiguration at the same time.

This commit addresses this in the following manner:

 - ContextConfigurationAttributes no longer throws an
   IllegalArgumentException if both 'locations' and 'classes' are
   supplied to its constructor.

 - Concrete SmartContextLoader implementations now validate the
   supplied MergedContextConfiguration before attempting to load the
   ApplicationContext. See validateMergedContextConfiguration().

 - Introduced tests for hybrid context loaders like the one used in
   Spring Boot. See HybridContextLoaderTests.

 - Updated the Testing chapter of the reference manual so that it no
   longer states that locations and classes cannot be used
   simultaneously, mentioning Spring Boot as well.

 - The Javadoc for @ContextConfiguration has been updated accordingly.

 - Added hasLocations(), hasClasses(), and hasResources() convenience
   methods to MergedContextConfiguration.

Issue: SPR-11634
2014-04-01 19:45:56 +02:00
Sam Brannen 5d049e0de8 Introduce execute(DataSource) in ResrcDbPopulator
To simplify common use cases, this commit introduces a new
execute(DataSource) method in ResourceDatabasePopulator that complements
the existing populate(Connection) method.

Issue: SPR-11629
2014-03-30 17:01:48 +02:00
Sam Brannen c38600762d Reinject Servlet mocks between TestNG test methods
Prior to this commit, if multiple test methods were executed in a
subclass of AbstractTestNGSpringContextTests annotated with
@WebAppConfiguration, then injected Servlet API mocks would only
reference the mocks created for the first test method. Subsequent test
methods could therefore never reference the current mocks, and there
was a discrepancy between the state of the injected mocks and the mock
set in the RequestContextHolder.

This commit addresses this issue by ensuring that dependencies
(including updated mocks) are injected into the test instance before
the next test method if the ServletTestExecutionListener resets the
request attributes in RequestContextHolder.

Issue: SPR-11626
2014-03-29 21:14:49 +01:00
Sam Brannen 5c577451f3 Polish Javadoc in abstract base test classes in the TCF 2014-03-27 14:49:26 +01:00
Juergen Hoeller dd7f54c3c0 Revised ResizableByteArrayOutputStream as an actual subclass of ByteArrayOutputStream, and consistently applied appropriate ByteArrayOutputStream initial capacities across the codebase
Issue: SPR-11594
2014-03-24 22:57:38 +01:00
Rossen Stoyanchev 05213c684c Give meaningful names to SprXxxTests in spring-test 2014-03-24 10:01:35 -04:00
Rossen Stoyanchev 9bda734e0a Improve method order in MockMvcRequestBuilders 2014-03-24 10:01:35 -04:00
Sebastien Deleuze 0b69a0ba4b Add URI based MockHttpServletRequestBuilder constructors
This commit adds new MockHttpServletRequestBuilder constructors
with an URI parameter in addition to the URL template + URL variables
existing ones.

It gives more control on how the URL is built, allowing for example to
use URL variables containing '/' character with proper encoding.

Issue: SPR-11441
2014-03-24 10:01:35 -04:00
Stephane Nicoll 4cd818b9e4 Harmonize log configuration
Prior to this commit, the codebase was using a mix of log4j.xml
and log4j.properties for test-related logging configuration. This
can be an issue as log4j takes the xml variant first when looking
for a default bootstrap configuration.

In practice, some modules declaring the properties variant were
taking the xml variant configuration from another module.

The general structure of the configuration has also been
harmonized to provide a standard console output as well as an
easy way to enable trace logs for the current module.
2014-03-20 09:43:29 -07:00
Sam Brannen 14a8f19670 Add links to class-level Javadoc in JdbcTestUtils 2014-03-16 17:44:11 +01:00
Sam Brannen 01b2f67f11 Introduce constructors in ResourceDatabasePopulator
Issue: SPR-9531
2014-03-13 13:45:05 +01:00
Sam Brannen a006ca2542 Remove trailing whitespace 2014-03-13 12:21:32 +01:00
Sam Brannen 2bfd6ddcf4 Refactor SQL script support
This commit continues the work in the previous commit as follows:

 - Introduced an exception hierarchy for exceptions related to SQL
   scripts, with ScriptException as the base.

 - CannotReadScriptException and ScriptStatementFailedException now
   extend ScriptException.

 - Introduced ScriptParseException, used by ScriptUtils.splitSqlScript().

 - DatabasePopulatorUtils.execute() now explicitly throws a
   DataAccessException.

 - Polished Javadoc in ResourceDatabasePopulator.

 - Overhauled Javadoc in ScriptUtils and documented all constants.

 - Added missing @author tags for original authors in ScriptUtils and
   ScriptUtilsTests.

 - ScriptUtils.splitSqlScript() now asserts preconditions.

 - Deleted superfluous methods in ScriptUtils and changed method
   visibility to private or package private as appropriate.

 - Deleted the ScriptStatementExecutor introduced in the previous
   commit; ScriptUtils.executeSqlScript() now accepts a JDBC Connection;
   JdbcTestUtils, AbstractTransactionalJUnit4SpringContextTests, and
   AbstractTransactionalTestNGSpringContextTests now use
   DatabasePopulatorUtils to execute a ResourceDatabasePopulator instead
   of executing a script directly via ScriptUtils.

 - Introduced JdbcTestUtilsIntegrationTests.

Issue: SPR-9531
2014-03-13 12:00:01 +01:00
cbaldwin74 e5c17560db Support multi-line comments in SQL scripts
Prior to this commit neither ResourceDatabasePopulator nor
JdbcTestUtils properly supported multi-line comments (e.g., /* ... */).
Secondarily there has developed a significant amount of code
duplication in these two classes that has led to maintenance issues
over the years.

This commit addresses these issues as follows:

 - Common code has been extracted from ResourceDatabasePopulator and
   JdbcTestUtils and moved to a new ScriptUtils class in the
   spring-jdbc module.

 - Relevant test cases have been migrated from JdbcTestUtilsTests to
   ScriptUtilsTests.

 - ScriptUtils.splitSqlScript() has been modified to ignore multi-line
   comments in scripts during processing.

 - ResourceDatabasePopulator supports configuration of the start and end
   delimiters for multi-line (block) comments.

 - A new test case was added to ScriptUtilsTests for the new multi-line
   comment support.

Issue: SPR-9531
2014-03-13 10:51:08 +01:00
Rossen Stoyanchev 6a4a2ec6a4 Fix expected and actual argument order
Issue: SPR-11424
2014-03-12 16:52:52 -04:00
Sam Brannen b364599278 Update links to Spring JIRA server 2014-03-10 12:26:29 +01:00
Sam Brannen 1d57a15e40 Delete unused imports in spring-test 2014-03-07 18:27:34 +01:00
Sam Brannen cb59d43a5f Fix typos in Javadoc in AssertThrows 2014-03-06 14:40:41 +01:00
Sam Brannen cf3b2b1a4d Simplify test includes & excludes in Gradle build
This commit aligns our include and exclude filters for test classes
with Gradle's standard patterns. Specifically, our patterns now end
with ".class" instead of ".*".

The aforementioned change makes the exclusion of inner classes
unnecessary. Thus, patterns for test classes ending with "TestCase" or
"TestSuite" have been deleted.

Furthermore, the include and exclude patterns previously used in the
spring-test module made it impossible for the
FailingBeforeAndAfterMethodsTests class in the 'testng' package to ever
be executed by the build. This has been addressed by renaming our JUnit
and TestNG variants of FailingBeforeAndAfterMethodsTests and moving the
TestNG variant into the 'junit' package so that it can be picked with
our standard include pattern for JUnit-based tests.
2014-03-06 00:06:50 +01:00
Rossen Stoyanchev 34924810fe Remove field no longer used after previous commit
Issue: SPR-11516
2014-03-05 14:50:16 -05:00
Rossen Stoyanchev 74de35df1e Refactor async result handling in Spring MVC Test
This change removes the use of a CountDownLatch to wait for the
asynchronously computed controller method return value. Instead we
check in a loop every 200 milliseconds if the result has been set.
If the result is not set within the specified amount of time to wait
an IllegalStateException is raised.

Additional changes:
 - Use AtomicReference to hold the async result
 - Remove @Ignore annotations on AsyncTests methods
 - Remove checks for the presence of Servlet 3

Issue: SPR-11516
2014-03-05 12:55:39 -05:00
Rossen Stoyanchev 705efc5bdf Fix timing issue with obtaining async result
Issue: SPR-11516
2014-03-04 21:38:42 -05:00
Rossen Stoyanchev c553d681f1 Add Servlet 3.1 methods to mock request
Issue: SPR-11492
2014-02-28 12:28:17 -05:00
Sam Brannen 979c483384 Do not inspect meta-annotations on Java annotations
This commit introduces a new isInJavaLangAnnotationPackage(Annotation)
method in AnnotationUtils. This method is now used in AnnotationUtils,
AnnotatedElementUtils, and MetaAnnotationUtils to ensure that search
algorithms do no search for meta-annotations on annotations in the
"java.lang.annotation" package.

The following are some empirical results from this change:

- The number of times that the findAnnotation(Class,Class,Set) method in
  AnnotationUtils is recursively invoked while executing
  AnnotationUtilsTests drops from 51 to 29.

- The number of times that the process(AnnotatedElement) method in
  AnnotationUtils.AnnotationCollector is recursively invoked while
  executing AnnotationUtilsTests.getRepeatableFromMethod() drops
  from 16 to 2.

- The number of times that the doProcess() method in
  AnnotatedElementUtils is recursively invoked while executing the
  "getAnnotationAttributes() On MetaCycleAnnotatedClass with missing
  target meta-annotation" test in AnnotatedElementUtilsTests drops
  from 23 to 5.

- The number of times that the findAnnotationDescriptor(Class,Set,Class)
  method in MetaAnnotationUtils is recursively invoked while executing
  the "findAnnotationDescriptor() on MetaCycleAnnotatedClass with
  missing target meta-annotation" test in MetaAnnotationUtilsTests drops
  from 16 to 8.

Issue: SPR-11483
2014-02-25 21:57:35 +01:00
Sam Brannen 78b69f5d77 Always supply test class to ContextLoaders in TCF
Prior to this commit, the following methods in ContextLoaderUtils
treated a composed @ContextConfiguration annotation (i.e., a custom
annotation that is meta-annotated with @ContextConfiguration) as the
"declaring class" instead of the actual test class.

- resolveContextConfigurationAttributes()
- resolveContextHierarchyAttributes()

As a consequence, if @ContextConfiguration is used as a
meta-annotation, the meta-annotated class is stored as the
"declaringClass" in ContextConfigurationAttributes. Thus, when a
ContextLoader (or SmartContextLoader) attempts to detect default
resource locations or configuration classes, it does so for the
composed annotation class instead of for the declaring test class.

This commit ensures that ContextLoaders are supplied the declaring test
class instead of the composed annotation class in such use cases.

Issue: SPR-11455
2014-02-25 15:27:31 +01:00
Sam Brannen f8950960f2 Support arbitrary meta-annotation levels in the TCF
Prior to this commit, the findAnnotationDescriptor() and
findAnnotationDescriptorForTypes() methods in MetaAnnotationUtils only
supported a single level of meta-annotations. In particular, this kept
the following annotations from being used as meta-annotations on
meta-annotations:

- @ContextConfiguration
- @ContextHierarchy
- @ActiveProfiles
- @TestExecutionListeners

This commit alters the search algorithms used in MetaAnnotationUtils so
that arbitrary levels of meta-annotations are now supported for the
aforementioned test-related annotations.

Issue: SPR-11470
2014-02-23 01:05:15 +01:00
Sam Brannen 2c8f25a14c Delete call to System.err in AbstractContextLoaderUtilsTests 2014-02-23 00:28:00 +01:00
Sam Brannen aa3e250ab6 @Ignore PrintingResultHandlerTests 2014-02-23 00:24:24 +01:00
Sam Brannen 3c511f00cc Simplify MetaAnnotationUtilsTests 2014-02-22 18:48:55 +01:00
Sam Brannen d9a2b3c2ba Deleted unused code in ContextLoaderUtilsActiveProfilesTests 2014-02-22 18:09:59 +01:00
Sam Brannen dc6eaad2e9 Update copyright date in ContextLoaderUtils 2014-02-22 18:06:37 +01:00
Sam Brannen 5f7d1758f8 Always pass test class to ActiveProfilesResolver
Prior to this commit, if @ActiveProfiles were used as a meta-annotation
on a composed annotation, then the composed annotation's class would be
passed to the ActiveProfilesResolver.resolve() method instead of the
test class, which breaks the contract for ActiveProfilesResolver.

This commit addresses this issue by ensuring that the actual test class
is always passed to ActiveProfilesResolver.resolve().

Issue: SPR-11467
2014-02-22 17:15:11 +01:00
Sam Brannen 34e90ba7f7 Simplify ContextLoaderUtilsActiveProfilesTests 2014-02-22 16:55:13 +01:00
Sam Brannen fe6a9826c5 Fix typo in AbstractDelegatingSmartContextLoader 2014-02-18 18:42:44 +01:00
Rossen Stoyanchev b1abe26b33 Add ResultMatchers for status code ranges
Issue: SPR-11424
2014-02-13 11:45:12 -05:00
Juergen Hoeller cead06a3d9 Polishing 2014-02-12 00:12:52 +01:00
Anton Bobov 1cf38a98a4 Fixed example in JavaDoc.
mimeType is not a valid method on ContentResultMatche.

I have signed and agree to the terms of the SpringSource Individual
Contributor License Agreement.
2014-02-10 14:23:10 +06:00
Sam Brannen c335e99e3f Remove trailing whitespace from source code 2014-02-08 17:30:39 +01:00
Sam Brannen 1f778530b5 Polish test classes
- Consistent importing of org.junit.Assert.*;
- Proper declaration of expected exceptions via @Test(expected).
- Renamed SpEL ExpressionTestCase to AbstractExpressionTests.
- Formatting and test method naming conventions.
2014-02-08 17:24:11 +01:00
Sam Brannen 08842f3fdf Delete legacy JUnit 3.8 test from spring-test 2014-02-08 15:50:04 +01:00
Sam Brannen 2d5c5fc18e Delete legacy JUnit 3.8 test from spring-test 2014-02-08 15:49:07 +01:00
Sam Brannen 522d136bbd Delete TODO that is now tracked in JIRA
Issue: SPR-11393
2014-02-06 14:12:03 +01:00
Sam Brannen b8ed2f4967 Ensure all tests are executed in the Gradle build
Prior to this commit several test classes named "*Test" were not
recognized as tests by the Gradle build. This is due to the configured
inclusion of '**/*Tests.*' which follows Spring's naming convention for
test classes.

This commit addresses this issue by:

 - Renaming real test classes consistently to "*Tests".
 - Renaming internal test classes to "*TestCase".
 - Renaming @WebTest to @WebTestStereotype.
 - Disabling broken tests in AnnoDrivenStaticEntityMockingControlTest.
 - Modifying the Gradle build configuration so that classes ending in
   either "*Tests" or "*Test" are considered test classes.

Issue: SPR-11384
2014-02-03 23:16:47 +01:00
Sam Brannen a521ef5cee Verify ServletCtxAware beans are processed in WAC tests
SPR-11145 claims that ServletContextAware beans declared in an
ApplicationContext loaded for an integration test by the TestContext
framework (TCF) do not have their setServletContext() methods invoked
if the tests are executed manually using JUnit 4.11.

This commit verifies that such ServletContextAware beans are processed
properly regardless of how the test was launched. Specifically:

 - A ServletContextAwareBean has been introduced.

 - BasicAnnotationConfigWacTests has been retrofitted with a
   ServletContextAwareBean in its context.

 - ServletContextAwareBeanWacTests has been introduced to execute
   BasicAnnotationConfigWacTests manually via JUnitCore.

Issue: SPR-11145
2014-02-01 02:08:21 +01:00
hupfis 0013a43237 Fixed code example in JavaDoc
equalTo is not a valid method on JsonPathResultMatchers

I have signed and agree to the terms of the SpringSource Individual Contributor License Agreement.
2014-01-24 09:26:09 +01:00
Sam Brannen fb12e234fc Handle NoClassDefFoundError consistently for TELs
Prior to this commit, a NoClassDefFoundError caught in
TestContextManager's retrieveTestExecutionListeners() method would be
handled differently for implicit default listeners (i.e., listeners not
declared via @TestExecutionListeners) and listeners explicitly declared
via @TestExecutionListeners. Specifically, a NoClassDefFoundError would
cause a test to fail for an explicitly declared TestExecutionListener
but not for an implicitly declared one.

This commit addresses this issue by:

 - Always swallowing a NoClassDefFoundError for both implicitly and
   explicitly declared TestExecutionListeners.
 - Changing the log level from DEBUG to INFO to make such situations
   more visible to the average end user.

Issue: SPR-11347
2014-01-22 23:28:36 +01:00
Sam Brannen 8105011368 Delete unnecessary redeclaration of test methods
This commit deletes methods in RollbackForRequiredEjbTxDaoTestNGTests
that were unnecessarily redeclared. The redeclaration is required for
JUnit's @FixMethodOrder support but not for TestNG's built-in support
for dependent methods.

Issue: SPR-6132
2014-01-22 17:44:13 +01:00
Sam Brannen c0eafa9ea1 Introduce EJB-based transactional tests in the TCF
This commit introduces transactional integration tests executing
against both JUnit and TestNG in the TestContext framework (TCF) using
@TransactionAttribute in EJBs instead of Spring’s @Transactional
annotation.

These tests disprove the claims raised in SPR-6132 by demonstrating that
transaction support in the TCF works as expected when a transactional
EJB method that is configured with TransactionAttribute.REQUIRES_NEW is
invoked. Specifically:

 - The transaction managed by the TCF is suspended while such an EJB
   method is invoked.
 - Any work performed within the new transaction for the EJB method is
   committed after the method invocation completes.
 - The transaction managed by the TCF is resumed and subsequently
   either rolled back or committed as necessary based on the
   configuration of @Rollback and @TransactionConfiguration.

The configuration for the JUnit-based tests is straightforward and self
explanatory; however, the configuration for the TestNG tests is less
intuitive.

In order for the TCF to function properly, the developer must ensure
that test methods within a given TestNG test (whether defined locally,
in a superclass, or somewhere else in the suite) are executed in the
proper order. In a stand-alone test class this is straightforward;
however, in a test class hierarchy (or test suite) with dependent
methods, it is necessary to configure TestNG so that all methods within
an individual test are executed in isolation from test methods in other
tests. This can be achieved by configuring a test class to run in its
own uniquely identified suite (e.g., by annotating each concrete
TestNG-based test class with @Test(suiteName = "< Some Unique Suite
Name >")).

For example, without specifying a unique suite name for the TestNG
tests introduced in this commit, test methods will be executed in the
following (incorrect) order:

 - CommitForRequiredEjbTxDaoTestNGTests.test1InitialState()
 - CommitForRequiresNewEjbTxDaoTestNGTests.test1InitialState()
 - RollbackForRequiresNewEjbTxDaoTestNGTests.test1InitialState()
 - RollbackForRequiredEjbTxDaoTestNGTests.test1InitialState()
 - CommitForRequiredEjbTxDaoTestNGTests.test2IncrementCount1()

The reason for this ordering is that test2IncrementCount1() depends on
test1InitialState(); however, the intention of the developer is that
the tests for an individual test class are independent of those in
other test classes. So by specifying unique suite names for each test
class, the following (correct) ordering is achieved:

 - RollbackForRequiresNewEjbTxDaoTestNGTests.test1InitialState()
 - RollbackForRequiresNewEjbTxDaoTestNGTests.test2IncrementCount1()
 - RollbackForRequiresNewEjbTxDaoTestNGTests.test3IncrementCount2()
 - CommitForRequiredEjbTxDaoTestNGTests.test1InitialState()
 - CommitForRequiredEjbTxDaoTestNGTests.test2IncrementCount1()
 - CommitForRequiredEjbTxDaoTestNGTests.test3IncrementCount2()
 - RollbackForRequiredEjbTxDaoTestNGTests.test1InitialState()
 - RollbackForRequiredEjbTxDaoTestNGTests.test2IncrementCount1()
 - RollbackForRequiredEjbTxDaoTestNGTests.test3IncrementCount2()
 - CommitForRequiresNewEjbTxDaoTestNGTests.test1InitialState()
 - CommitForRequiresNewEjbTxDaoTestNGTests.test2IncrementCount1()
 - CommitForRequiresNewEjbTxDaoTestNGTests.test3IncrementCount2()

See the JIRA issue for more detailed log output.

Furthermore, @DirtiesContext(classMode = ClassMode.AFTER_CLASS) has
been used in both the JUnit and TestNG tests introduced in this commit
in order to ensure that the in-memory database is reinitialized between
each test class.

Issue: SPR-6132
2014-01-22 12:56:07 +01:00
Sam Brannen 3370f8b1b1 Include ServletTEL in abstract base test classes
The ServletTestExecutionListener is now prepended to the set of default
listeners in AbstractJUnit4SpringContextTests and
AbstractTestNGSpringContextTests.

Issue: SPR-11340
2014-01-21 15:01:29 +01:00
Sam Brannen 6e30851328 Improve logging in TransactionalTEL
This commit makes the logging in TransactionalTestExecutionListener
consistent for both starting and ending transactions. Specifically,
the current TestContext is now included in the informational log
statement when starting a new transaction.

Issue: SPR-11323
2014-01-17 14:54:36 +01:00
Juergen Hoeller a5f9b29292 Polishing 2014-01-15 22:53:46 +01:00
Sam Brannen feb9d261ac Remove unused import in MockHttpServletRequestBuilderTests 2014-01-15 15:46:52 +01:00
Rossen Stoyanchev 8b35c3ff74 Recognize Content-Type as special header in MHSRB
When adding headers generically, MockHttpServletRequestBuilder now
recognizes Content-Type and updates the contentType field accordingly.

Issue: SPR-11308
2014-01-14 12:11:12 -05:00
Juergen Hoeller 26271fc30c Polishing 2014-01-13 23:45:54 +01:00
Juergen Hoeller 547646de6d Polishing 2014-01-13 22:25:34 +01:00
Juergen Hoeller f7fc2cbc3b Replaced reflection code with straight Servlet 3.0 setAsyncStarted call 2014-01-13 22:20:46 +01:00
Greg Turnquist 6b0d88721c Add method for HTTP PATCH in MockMvcRequestBuilders
Issue: SPR-11299

This is short to avoid having to use MockMvcRequestBuilders.request()
and instead have a simple patch(url, params...)
2014-01-13 14:17:16 -05:00
Sam Brannen a30cf3058e Remove unused imports in tests 2014-01-06 12:16:24 +01:00
Sam Brannen 27ab9332c1 Suppress deprecation warning for MHSR.setStatus()
Suppressing deprecation warnings for
MockHttpServletResponse.setStatus(int, String).
2014-01-06 12:15:52 +01:00
Brian Clozel 1c83e8653a Switch to Jackson 2 in unit tests
Prior to this commit, some unit tests were using
Spring's Jackson 1.x implementations. Now Jackson
2.x implementations are the default ones used in
unit tests.

Even if Jackson 1.x support is deprecated, Jackson 1.x
unit tests are kept.

Issue: SPR-11121
2014-01-03 09:50:43 +01:00
Rossen Stoyanchev 2e4f38f6af Introduce AbstractMockMvcBuilder class
This change splits out an abstract base class from DefaultMockMvcBuilder
with StandaloneMockMvcBuilder switching to extend the new abstract class
(rather than DefaultMockMvcBuilder).

Issue: SPR-11238
2013-12-23 21:40:27 -05:00
Sam Brannen a223e247c2 Document meta-annotation support in the TCF
- Completed Javadoc for MetaAnnotationUtils.
- Added Javadoc notes to multiple annotations in the TCF, pointing out
  which annotations can be used as meta-annotations.

Issue: SPR-11109
2013-12-11 14:43:10 +01:00
Sam Brannen da7ae4a63b Polish meta-annotation terminology in MetaAnnoUtils 2013-12-11 02:14:50 +01:00
Sam Brannen 800018a817 Do not repopulate RequestContextHolder in ServTEL
This commit fixes a bug introduced in the last commit.

ServletTestExecutionListener (STEL) now tracks whether it has already
populated the RequestContextHolder.

Issue: SPR-11144
2013-12-11 01:00:04 +01:00
Sam Brannen 099b10d23b Honor presence of @WebAppConfiguration in ServTEL
The previous commit for issue SPR-11144 revealed a bug in
ServletTestExecutionListener (STEL). Specifically, STEL acted on the
fact that the ApplicationContext for a given TestContext was an
instance of WebApplicationContext. This behavior could potentially
break test code from previous releases of the Spring Framework that
relied on a custom setup of the RequestAttributes in the
RequestContextHolder with a custom WebApplicationContext ContextLoader.

This commit addresses this issue by ensuring that STEL only comes into
play if the test class is annotated with @WebAppConfiguration (for
prepareTestInstance() and beforeTestMethod()) or if the TestContext
attribute named RESET_REQUEST_CONTEXT_HOLDER_ATTRIBUTE is set to
Boolean.TRUE (for afterTestMethod()).

Issue: SPR-11144
2013-12-10 23:49:58 +01:00
Sam Brannen a3b022aa48 Ensure ServTEL doesn't reset ReqAttrs by accident
Prior to this commit, the ServletTestExecutionListener did not
overwrite RequestAttributes in the RequestContextHolder if the
ApplicationContext associated with the given TestContext was not a
WebApplicationContext; however, the ServletTestExecutionListener would
clear the RequestAttributes after every test method execution,
regardless of whether the context was a WebApplicationContext or not.
This behavior breaks backwards compatibility with integration tests
that managed the RequestAttributes in RequestContextHolder themselves.

This commit addresses this issue by introducing a TestContext attribute
named RESET_REQUEST_CONTEXT_HOLDER_ATTRIBUTE in
ServletTestExecutionListener. This attribute is used internally within
ServletTestExecutionListener to ensure that the RequestContextHolder is
only cleared (i.e., reset) if the ServletTestExecutionListener actually
populated the RequestContextHolder.

Issue: SPR-11144
2013-12-09 15:35:54 +01:00
Sam Brannen 3e0b0f100c Delete unused import in MockAsyncContext 2013-12-05 21:48:49 +01:00
Phillip Webb 526555de85 Tweak times in TimedSpringRunnerTests 2013-12-02 22:47:01 -08:00
Juergen Hoeller f5a310ad57 Polishing (backported from 3.2.x) 2013-12-03 01:37:01 +01:00
Juergen Hoeller 2a52decbbc Polishing (including removal of javadoc imports that show as package cycles in IntelliJ) 2013-12-02 23:57:00 +01:00
Phillip Webb 043a41e382 Consistent whitespace after imports
Update code to have a consistent number of new-line characters after
import statements.
2013-11-26 15:14:43 -08:00
Phillip Webb 15698860e1 General polish of new 4.0 classes
Apply consistent styling to new classes introduced in Spring 4.0.

- Javadoc line wrapping, whitespace and formatting
- General code whitespace
- Consistent Assert.notNull messages
2013-11-26 15:11:18 -08:00
Phillip Webb a31ac882c5 Fix various javadoc warnings 2013-11-26 13:25:37 -08:00
Sam Brannen 64f593db8f Support meta-annotation attr overrides in the TCF
Prior to this commit, the Spring TestContext Framework (TCF) supported
the use of test-related annotations as meta-annotations for composing
custom test stereotype annotations; however, attributes in custom
stereotypes could not be used to override meta-annotation attributes.

This commit addresses this by allowing attributes from the following
annotations (when used as meta-annotations) to be overridden in custom
stereotypes.

- @ContextConfiguration
- @ActiveProfiles
- @DirtiesContext
- @TransactionConfiguration
- @Timed
- @TestExecutionListeners

This support depends on functionality provided by
AnnotatedElementUtils. See the 'Notes' below for further details and
ramifications.

Notes:

- AnnotatedElementUtils does not support overrides for the 'value'
  attribute of an annotation. It is therefore not possible or not
  feasible to support meta-annotation attribute overrides for some
  test-related annotations.
- @ContextHierarchy, @WebAppConfiguration, @Rollback, @Repeat, and
  @ProfileValueSourceConfiguration define single 'value' attributes
  which cannot be overridden via Spring's meta-annotation attribute
  support.
- Although @IfProfileValue has 'values' and 'name' attributes, the
  typical usage scenario involves the 'value' attribute which is not
  supported for meta-annotation attribute overrides. Furthermore,
  'name' and 'values' are so generic that it is deemed unfeasible to
  provide meta-annotation attribute override support for these.
- @BeforeTransaction and @AfterTransaction do not define any attributes
  that can be overridden.
- Support for meta-annotation attribute overrides for @Transactional is
  provided indirectly via SpringTransactionAnnotationParser.

Implementation Details:

- MetaAnnotationUtils.AnnotationDescriptor now provides access to the
  AnnotationAttributes for the described annotation.
- MetaAnnotationUtils.AnnotationDescriptor now provides access to the
  root declaring class as well as the declaring class.
- ContextLoaderUtils now retrieves AnnotationAttributes from
  AnnotationDescriptor to look up annotation attributes for
  @ContextConfiguration and @ActiveProfiles.
- ContextConfigurationAttributes now provides a constructor to have its
  attributes sourced from an instance of AnnotationAttributes.
- ContextLoaderUtils.resolveContextHierarchyAttributes() now throws an
  IllegalStateException if no class in the class hierarchy declares
  @ContextHierarchy.
- TransactionalTestExecutionListener now uses AnnotatedElementUtils to
  look up annotation attributes for @TransactionConfiguration.
- Implemented missing unit tests for @Rollback resolution in
  TransactionalTestExecutionListener.
- SpringJUnit4ClassRunner now uses AnnotatedElementUtils to look up
  annotation attributes for @Timed.
- TestContextManager now retrieves AnnotationAttributes from
  AnnotationDescriptor to look up annotation attributes for
  @TestExecutionListeners.
- DirtiesContextTestExecutionListener now uses AnnotatedElementUtils to
  look up annotation attributes for @DirtiesContext.

Issue: SPR-11038
2013-11-26 15:56:37 -05:00
Rossen Stoyanchev 119e793994 Fix concurrency issue in TestDispatcherServlet
This change fixes a timing issue in tests using Spring MVC Tests where
assertions on an async result may not wait long enough.

The fix involves the use of a new callback in  MockAsyncContext that
allows tests to detect when an async dispatch has been invoked.

Issue: SPR-10838
2013-11-25 21:51:08 -05:00
Sam Brannen a5d87fffd9 Polish Javadoc for @IfProfileValue 2013-11-25 21:22:54 -05:00
Sam Brannen 412f74f679 Provide meta-annotation support for @Rollback
@Rollback now supports ANNOTATION_TYPE as a target, allowing it to be
used as meta-annotation.

Note: this change was accidentally omitted from the original commit for
SPR-7827.

Issue: SPR-7827
2013-11-25 20:17:14 -05:00
Phillip Webb 59002f2456 Fix remaining compiler warnings
Fix remaining Java compiler warnings, mainly around missing
generics or deprecated code.

Also add the `-Werror` compiler option to ensure that any future
warnings will fail the build.

Issue: SPR-11064
2013-11-25 12:52:42 -08:00
Sam Brannen 665251fa2f Suppress deprecation warning in StatusResultMatchers 2013-11-22 12:55:12 +01:00
Sam Brannen 127bc07cda Delete unused package import 2013-11-22 12:49:25 +01:00
Phillip Webb d9c4470461 Upgrade to HSQLDB 2.3.1
Replace `hsqldb:hsqldb:1.8.0.10` with `org.hsqldb:hsqldb:2.3.1` and
fix breaking tests.

Issue: SPR-10947
2013-11-21 15:48:17 -08:00
Juergen Hoeller 6a9e116d78 Polishing 2013-11-20 14:50:59 +01:00
Juergen Hoeller 54571bf038 Introduced getBeanNamesForAnnotation method on ListableBeanFactory
Issue: SPR-11069
2013-11-15 16:04:11 +01:00
Rossen Stoyanchev 2e57cf8bfc Fold spring-test-mvc sources into spring-test
With spring-test compiling against Servlet 3.0 it is no longer required
to compile Spring MVC Test sources separately (from spring-test).
2013-11-05 11:44:13 -05:00
Sam Brannen 2e6c998168 Update Javadoc for mocks regarding Servlet 3.0
Commit deba32cad9 upgraded the Servlet API mocks to Servlet 3.0;
however, not all of the Javadoc was updated accordingly.

This commit updates the remaining Javadoc with regard to Servlet 3.0 as
the baseline for mocks in the spring-test module.

In addition, this commit syncs up the mocks used for internal testing in
the spring-web module with the most current versions from spring-test.

Issue: SPR-11049
2013-10-31 11:51:15 +01:00
Sam Brannen 180f41c4c5 Renamed @WebTests to @WebTest
@WebTests has been renamed to @WebTest so that the Gradle build does not
attempt to run it as a JUnit test.
2013-10-28 02:04:24 +01:00
Sam Brannen f9cadfe6f9 Relocate test class to src/test/java folder 2013-10-28 01:56:21 +01:00
Sam Brannen 5e7021f3f7 Provide meta-annotation support in the TCF
Spring 3.0 already allows component stereotypes to be used in a
meta-annotation fashion, for example by creating a custom
@TransactionalService stereotype annotation which combines
@Transactional and @Service in a single, reusable, application-specific
annotation. However, the Spring TestContext Framework (TCF) currently
does not provide any support for test-related annotations to be used as
meta-annotations.

This commit overhauls the TCF with regard to how annotations are
retrieved and adds explicit support for the following annotations to be
used as meta-annotations in conjunction with the TCF.

- @ContextConfiguration
- @ContextHierarchy
- @ActiveProfiles
- @DirtiesContext
- @IfProfileValue
- @ProfileValueSourceConfiguration
- @BeforeTransaction
- @AfterTransaction
- @TransactionConfiguration
- @Rollback
- @TestExecutionListeners
- @Repeat
- @Timed
- @WebAppConfiguration

Note that meta-annotation support for @Transactional was already
available prior to this commit.

The following is a summary of the major changes included in this commit.

- Now using AnnotationUtils.getAnnotation() instead of
  Class.getAnnotation() where appropriate in the TestContext Framework.
- Now using AnnotationUtils.findAnnotation() instead of
  Class.isAnnotationPresent() where appropriate in the TestContext
  Framework.
- Introduced findAnnotationPrefersInteracesOverLocalMetaAnnotations() in
  AnnotationUtilsTests in order to verify the status quo.
- AnnotationUtils.findAnnotationDeclaringClass() and
  AnnotationUtils.findAnnotationDeclaringClassForTypes() now support
  meta annotations.
- Introduced MetaAnnotationUtils and AnnotationDescriptor in the
  spring-test module.
- Introduced UntypedAnnotationDescriptor in MetaAnnotationUtils.
- Introduced findAnnotationDescriptorForTypes() in MetaAnnotationUtils.
- ContextLoaderUtils now uses MetaAnnotationUtils for looking up
  @ActiveProfiles as a potential meta-annotation.
- TestContextManager now uses MetaAnnotationUtils for looking up
  @TestExecutionListeners as a potential meta-annotation.
- DirtiesContextTestExecutionListener now uses AnnotationUtils for
  looking up @DirtiesContext as a potential meta-annotation.
- Introduced DirtiesContextTestExecutionListenerTests.
- ProfileValueUtils now uses AnnotationUtils for looking up
  @IfProfileValue and @ProfileValueSourceConfiguration as potential
  meta-annotations.
- @BeforeTransaction and @AfterTransaction now support ANNOTATION_TYPE
  as a target, allowing them to be used as meta-annotations.
- TransactionalTestExecutionListener now uses AnnotationUtils for
  looking up @BeforeTransaction, @AfterTransaction, @Rollback, and
  @TransactionConfiguration as potential meta-annotations.
- Introduced TransactionalTestExecutionListenerTests.
- @Repeat and @Timed now support ANNOTATION_TYPE as a target, allowing
  them to be used as meta-annotations.
- SpringJUnit4ClassRunner now uses AnnotationUtils for looking up
  @Repeat and @Timed as potential meta-annotations.
- Moved all remaining logic for building the MergedContextConfiguration
  from the DefaultTestContext constructor to
  ContextLoaderUtils.buildMergedContextConfiguration().
- Verified meta-annotation support for @WebAppConfiguration and
  @ContextConfiguration.

Issue: SPR-7827
2013-10-28 01:33:17 +01:00
Sam Brannen 88fe2e9b00 Convert TestContext to interface & default impl
Since the Spring TestContext Framework was introduced in Spring
Framework 2.5, the TestContext class has always been a public class
with package private constructors. The visibility of TestContext's
constructor and methods was intentionally limited in order to hide the
implementation details of the context cache, etc. However, this fact
has made it difficult (if not impossible) to unit test custom
TestExecutionListener implementations.

This commit addresses this issue by converting TestContext into a
public interface with a package private DefaultTestContext
implementation. This enables unit testing of any components that depend
on a TestContext (e.g., TestExecutionListeners) while at the same time
preserving the encapsulation of the inner workings of the TestContext
implementation with regard to context loading and caching.

Issue: SPR-7692
2013-10-26 21:20:12 +02:00
Sam Brannen 7658d856ca Assert context uniqueness against merged config
Prior to this commit, the uniqueness check for @ContextConfiguration
attributes within a @ContextHierarchy was performed at a single test
class level instead of against the merged configuration for all test
class levels in the test class hierarchy.

This commit addresses this issue by moving the uniqueness check
algorithm from resolveContextHierarchyAttributes() to
buildContextHierarchyMap() within ContextLoaderUtils.

Issue: SPR-10997
2013-10-21 19:33:04 +02:00
Brian Clozel e4479c8669 Fix MockHttpServletResponse HTTP status update
Prior to this commit, one could call the setStatus method on
this Mock object and update the response's status,
even though the sendError method had already been called.

According to the HttpServletResponse Javadoc, sendError() methods
commit the response; so the response can't be written after that.

This commit fixes MockHttpServletResponse's behavior; setStatus
methods do not update the status once the response has been
committed.

Issue: SPR-10414
2013-10-07 14:43:06 -04:00
Juergen Hoeller beaf6992b2 Fixed BadSqlGrammarException usage in transaction test suite
Issue: SPR-10902
(cherry picked from commit ef66708)
2013-09-25 14:11:10 +02:00
Sam Brannen ee5d6c8f83 Exclude null requestURI in MHSR.getRequestURL()
This commit undoes the changes made in ec5d81e78e and ensures that the
getRequestURL() method in MockHttpServletRequest does not include the
String "null" for a null requestURI by first checking if the requestURI
contains text before including it in the composed URL.

Issue: SPR-10643
2013-09-11 23:08:05 +02:00
Rossen Stoyanchev 0d5901ffb6 Polish Cookie abstraction in http packge of spring-web
A getCookies method is now available on ServerHttpRequest with one
ServletServerCookie implementation that wraps a Servlet cookie.

The SockJS service makes use of this to check for an existing session
cookie in the request.
2013-08-02 12:30:43 -04:00
Sam Brannen 8ad36ef812 Delete remaining JUnit 3.8 tests in spring-test
This commit deletes the remaining JUnit 3.8 tests in the spring-test
module that were still subclassing deprecated class hierarchies.

Issue: SPR-10499
2013-06-16 20:03:21 +02:00
Sam Brannen d25611dd40 Move MockMultHtServReqTests to correct package
This commit relocates MockMultipartHttpServletRequestTests to the
appropriate package.
2013-06-16 19:55:35 +02:00
Sam Brannen c06157acd3 @Ignore empty test methods in RootWacEarTests hierarchy 2013-06-16 19:47:18 +02:00
Sam Brannen 432f899b29 Reduce complexity in ContextLoaderUtilsTests
This commit refactors ContextLoaderUtilsTests into
AbstractContextLoaderUtilsTests and several specialized subclasses in
order to reduce to the growing complexity of ContextLoaderUtilsTests.
2013-06-16 17:54:55 +02:00
Sam Brannen d126620216 Remove superfluous not-null check in ContextLoaderUtils 2013-06-16 00:38:56 +02:00
Sam Brannen 044f51283b Introduce ActiveProfilesResolver in the TCF
Prior to this commit, the active bean definition profiles to use when
loading an ApplicationContext for tests could only be configured
declaratively (i.e., via hard-coded values supplied to the 'value' or
'profiles' attribute of @ActiveProfiles).

This commit makes it possible to programmatically configure active bean
definition profiles in tests via a new ActiveProfileResolver interface.
Custom resolvers can be registered via a new 'resolver' attribute
introduced in @ActiveProfiles.

Overview of changes:

 - Introduced a new ActiveProfilesResolver API.
 - Added a 'resolver' attribute to @ActiveProfiles.
 - Updated ContextLoaderUtils.resolveActiveProfiles() to support
   ActiveProfilesResolvers.
 - Documented these new features in the reference manual.
 - Added new content to the reference manual regarding the
   'inheritProfiles' attribute of @ActiveProfiles
 - Removed the use of <lineannotation> Docbook markup in the testing
   chapter of the reference manual for Java code examples in order to
   allow comments to have proper syntax highlighting in the generated
   HTML and PDF.

Issue: SPR-10338
2013-06-16 00:01:34 +02:00
Sam Brannen 51d828816d Throw ISEs in MockHttpSession for invalid session
The Javadoc for several methods in HttpSession specifies that an
IllegalStateException must be thrown if the method is called on an
invalidated session; however, Spring's MockHttpSession did not implement
this behavior consistently prior to this commit.

This commit therefore ensures that the following methods in
MockHttpSession properly throw an IllegalStateException as defined in
the Servlet specification.

 - long getCreationTime()
 - long getLastAccessedTime()
 - Object getAttribute(String)
 - Object getValue(String)
 - Enumeration<String> getAttributeNames()
 - String[] getValueNames()
 - void setAttribute(String, Object)
 - void putValue(String , Object)
 - void removeAttribute(String)
 - void removeValue(String)
 - void invalidate()
 - boolean isNew()

Issue: SPR-7659
2013-06-09 16:38:04 +02:00
Sam Brannen ec5d81e78e Ensure method & requestURI are non-null in MHSR
Prior to this commit it was possible for the method and requestURI
fields in MockHttpServletRequest to be set to null.

This commit ensures that the method and requestURI fields are internally
stored as empty strings if the user sets them to a null value.

Issue: SPR-10643
2013-06-09 12:42:00 +02:00
Sam Brannen 86591e5e5a Support implicit ports in MHSR.getRequestURL()
Prior to this commit, MockHttpServletRequest.getRequestURL() always
included the server port number in the reconstructed request URL, even
for implicit ports (i.e., 80 and 443) and negative ports.

MockHttpServletRequest.getRequestURL() now omits the port number when
reconstructing a URL that has an implicit or negative port.

Issue: SPR-9726
2013-06-09 11:55:24 +02:00
Sam Brannen b3a693e356 Add test to assess claim in SPR-10330
This commit verifies that JdbcTestUtils.readScript() properly handles
SQL comments prefixed by tab characters.

Issue: SPR-10330
2013-06-08 21:45:29 +02:00
Sam Brannen bc9e4ab106 Polish method names in JdbcTestUtilsTests 2013-06-08 21:05:16 +02:00
Sam Brannen 34e8ee94c4 Add deleteFromTableWhere() to base classes in TCF
This commit introduces a deleteFromTableWhere() convenience method in
AbstractTransactionalJUnit4SpringContextTests and
AbstractTransactionalTestNGSpringContextTests that delegates to the
recently introduced method of the same name in JdbcTestUtils.

Issue: SPR-10639
2013-06-08 21:03:45 +02:00
Rob Winch 9468548116 Add @Override to remaining source files
Issue: SPR-10130
2013-05-13 17:04:56 -05:00
Sam Brannen 6fa493908b Hoellereasymock --> Hoeller 2013-05-10 22:13:23 +02:00
Phillip Webb 8b904102ff Update ...DirtiesContextTests to get beans early
Change ContextHierarchyDirtiesContextTests to obtain beans whilst the
ApplicationContext is still open, rather than trying to obtain them
after the context has been closed.
2013-05-09 14:57:16 -07:00
Juergen Hoeller 2a44228b98 Consistent use of <pre class="code">
Issue: SPR-8108
2013-05-07 21:31:26 +02:00
Juergen Hoeller 1ca943c681 Fixed javadoc warnings
Issue: SPR-10373
2013-05-07 21:26:01 +02:00
Rossen Stoyanchev 59e6298c82 Merge remote-tracking branch 'upstream/master' 2013-05-06 16:44:35 -04:00
Sam Brannen d01d95118b Stop suppressing warnings for deleted deprecations
This commit removes the use of @SuppressWarnings("deprecation") for
code in the spring-test module that no longer references deprecated code.

Issue: SPR-10499
2013-05-06 21:29:49 +02:00
Rossen Stoyanchev e7f38e5b17 Merge branch 'websocket' 2013-05-06 14:46:29 -04:00
Sam Brannen 72d5a32104 Added schema version to test XML config file
This commit adds an explicit version to the updated XML configuration
file in order to avoid build errors in IntelliJ IDEA 12.
2013-05-05 21:50:34 +02:00
Sam Brannen 88e514bd56 Delete deprecated code in the TestContext framework
This commit deletes the deprecated SimpleJdbcTestUtils class as well as
remaining usage of SimpleJdbcTemplate within the TestContext framework
and its test suite.

Issue: SPR-10499
2013-04-28 19:10:53 +02:00
Sam Brannen 2685818e91 Delete deprecated code in the TestContext framework
This commit deletes the deprecated @ExpectedException and
@NotTransactional annotations, supporting code, and related Javadoc and
reference documentation.

Issue: SPR-10499
2013-04-28 17:31:54 +02:00
Sam Brannen eb65b2b083 Delete deprecated code in the TestContext framework
This commit deletes the deprecated JUnit 3.8 support in the TestContext
Framework.

Issue: SPR-10499
2013-04-28 16:05:49 +02:00
Sam Brannen 4525068f56 Remove JUnit 3.8 based test class hierarchy
This commit picks up where 74021b9 left off.
2013-04-28 13:00:09 +02:00
Rossen Stoyanchev 88447e503b Add first cut of SockJS server support 2013-04-15 11:03:24 -04:00
Sam Brannen 41737e827c Remove warning suppression in mocks
This commit removes the suppression of warnings in Servlet and Portlet
mocks since such suppression is no longer necessary with the upgrade to
version 3.0 of the Servlet specification.
2013-03-26 15:15:37 +01:00
Juergen Hoeller deba32cad9 Upgraded all Servlet API mocks to Servlet 3.0 (with a little bit of Servlet 3.1 support in MockHttpServletResponse) 2013-03-20 17:19:34 +01:00
Juergen Hoeller 74021b9e4a Removed JUnit 3.8 based test class hierarchy 2013-03-19 15:10:59 +01:00
Phillip Webb 4e1cab28df Merge branch '3.2.x'
* 3.2.x: (28 commits)
  Hide 'doc' changes from jdiff reports
  Document @Bean 'lite' mode vs @Configuration
  Final preparations for 3.2.2
  Remove Tiles 3 configuration method
  Polishing
  Extracted buildRequestAttributes template method from FrameworkServlet
  Added "beforeExistingAdvisors" flag to AbstractAdvisingBeanPostProcessor
  Minor refinements along the way of researching static CGLIB callbacks
  Compare Kind references before checking log levels
  Polish Javadoc in RequestAttributes
  Fix copy-n-paste errors in NativeWebRequest
  Fix issue with restoring included attributes
  Add additional test for daylight savings glitch
  Document context hierarchy support in the TCF
  Fix test for daylight savings glitch
  Make the methodParameter field of HandlerMethod final
  Disable AsyncTests in spring-test-mvc
  Reformat the testing chapter
  Document context hierarchy support in the TCF
  Document context hierarchy support in the TCF
  ...
2013-03-13 14:01:46 -07:00
Sam Brannen ccdb48210a Document context hierarchy support in the TCF
This commit polishes the Javadoc for @ContextHierarchy and
@ContextConfiguration.

Issue: SPR-10357
2013-03-10 14:26:19 +01:00
Sam Brannen 4e7098dc63 Document context hierarchy support in the TCF
This commit adds examples to the Javadoc for @ContextHierarchy and
updates the Javadoc for @ContextConfiguration accordingly.

Issue: SPR-10357
2013-03-10 01:39:14 +01:00