Commit Graph

317 Commits

Author SHA1 Message Date
Sebastien Deleuze 3922f6fc53 Update references to RFC 2616
Replace references to the old RFC 2616 (HTTP 1.1) with references
to the new RFCs 7230 to 7235.

This commit also deprecates:
 - HttpStatus.USE_PROXY
 - HttpStatus.REQUEST_ENTITY_TOO_LARGE in favor of HttpStatus.PAYLOAD_TOO_LARGE
 - HttpStatus.REQUEST_URI_TOO_LONG in favor of HttpStatus.URI_TOO_LONG

Issue: SPR-12067
2014-08-07 14:50:45 +02:00
Stephane Nicoll 3da68cfe21 Remove unused imports 2014-08-04 14:13:40 +02:00
Rossen Stoyanchev b5e1198bd2 Fix white spaces 2014-08-01 17:12:43 -04:00
Jakub Narloch a11b62540a Support HTTP HEAD method in MockMvcRequestBuilders
Surprisingly until now the MockMvcRequestBuilders did not have methods
for HTTP HEAD. This change adds such methods to the  API making it
consistent with other HTTP method types.

Issue: SPR-12055
2014-08-01 17:03:12 -04:00
Juergen Hoeller 8f484d382e Polishing 2014-07-29 11:42:37 +02:00
Juergen Hoeller 8cc0fa5ae1 Polishing 2014-07-28 22:05:40 +02:00
Sam Brannen 7971f6b638 Document that mock request doesn't support Accept-Language header
This commit updates the Javadoc for getLocale() and getLocales() in
MockHttpServletRequest to point out that the mock implementation does
not comply with the the Servlet specification with regard to the
Accept-Language header.

Issue: SPR-12043
2014-07-28 19:12:39 +03:00
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