Commit Graph

726 Commits

Author SHA1 Message Date
Rossen Stoyanchev 1416c2a00e ContentRequestMatchers asserts request with form data
Issue: SPR-13044
2016-01-21 12:42:33 -05:00
Rossen Stoyanchev 952a3170e6 HeaderResultMatchers supports multi-value headers
Issue: SPR-10087
2016-01-21 11:19:43 -05:00
Rossen Stoyanchev ae224bed3e Polish HeaderResultMatchers 2016-01-21 10:20:04 -05:00
Rossen Stoyanchev df223eb118 Polish custom HTTP verb in Spring MVC Test
Issue: SPR-13719
2016-01-21 09:13:33 -05:00
Kamill Sokol 3554348919 Support custom HTTP verbs in Spring MVC Test
Prior to this commit, Spring MVC Test only supported HTTP methods GET,
POST, HEAD, OPTIONS, PUT, PATCH, DELETE, TRACE and multipart file
upload. This change adds generic methods to MockMvcRequestBuilders in
order to allow testing of arbitrary HTTP methods in a Spring MVC
application.

Issue: SPR-13719
2016-01-21 09:12:43 -05:00
Rossen Stoyanchev 4b1183582a Add methodCall option to HandlerResultMatchers
Issue: SPR-13736
2016-01-15 12:44:00 -05:00
Rossen Stoyanchev 1320da906b Polish HandlerResultMatchers 2016-01-15 12:44:00 -05:00
Stephane Nicoll 2fc2c29e9a Update copyright header 2016-01-15 10:51:11 +01:00
Rossen Stoyanchev 4818378c25 Better document client-side tests against MockMvc
Issue: SPR-13815
2016-01-14 15:15:07 -05:00
Brian Clozel 74d3bceb19 Add missing StatusResultMatcher for HTTP Status 451
Issue: SPR-13632
2015-12-29 21:23:09 +01:00
Juergen Hoeller 41ee25b1e7 Convenience constructors for common view prefix/suffix scenarios
Issue: SPR-13813
2015-12-22 12:00:49 +01:00
Sam Brannen 66562f2589 Require JUnit 4.12 or higher in the TestContext framework
Issue: SPR-13275
2015-12-19 18:43:59 +01:00
Sam Brannen 9eb713ae2c Mention DCBeforeModesTEL in TestExecutionListener Javadoc 2015-12-17 17:45:08 +01:00
Juergen Hoeller db05f43a75 Require JsonPath 1.1+
Issue: SPR-13729
2015-12-17 17:13:27 +01:00
Juergen Hoeller 935c0a463e Revised MockMvcResultHandlers logger initialization
Issue: SPR-13802
2015-12-16 21:49:48 +01:00
Juergen Hoeller 997278e3ed Polishing 2015-12-16 20:19:41 +01:00
Rossen Stoyanchev c8aa48faa9 Add params(MultiValueMap) to MockMvc
Issue: SPR-13801
2015-12-16 11:51:59 -05:00
Juergen Hoeller 11806b9215 Class identity comparisons wherever possible (and further polishing)
Issue: SPR-12926
2015-12-09 12:28:09 +01:00
Juergen Hoeller 4261f34b63 Consistent and lenient HttpMethod resolution across all web modules
Issue: SPR-13776
2015-12-09 12:26:44 +01:00
Juergen Hoeller 40cff5e340 Polishing 2015-12-07 17:30:25 +01:00
Juergen Hoeller a4f5c46fed MockHttpServletResponse.setIntHeader supports 'Content-Length' header as well
Issue: SPR-13752
2015-12-02 13:36:35 +01:00
Juergen Hoeller aef6b20626 Removed tests for invalid -1 index (for compatibility with JsonPath 2.1) 2015-11-27 14:11:40 +01:00
Juergen Hoeller dd647659b3 Rearranged cache test class names across several modules 2015-11-26 16:30:44 +01:00
Juergen Hoeller fd84262e71 Polishing 2015-11-25 23:09:24 +01:00
Stephane Nicoll bf1afdfdc9 Add cache tests for JCache 2015-11-24 10:15:09 +01:00
Stephane Nicoll 610b5a20ea Fix test name 2015-11-23 18:22:53 +01:00
Sam Brannen 59d60c60cf Polishing 2015-11-16 01:44:16 +01:00
Sam Brannen 4b682275c9 Clean up warnings in spring-test 2015-11-14 22:57:33 +01:00
Juergen Hoeller 5b901852e6 Upgrade to HtmlUnit 2.19
This upgrade includes AutoCloseable support for HtmlUnit WebConnections as introduced in 2.19, while remaining compatible with 2.18.

Issue: SPR-13686
2015-11-14 15:32:42 +01:00
Rossen Stoyanchev 8c127ad3c9 Property init HandlerMapping in standalone MockMvc
Issue: SPR-13637
2015-11-11 15:14:18 -05:00
Juergen Hoeller b057e503ef Adapted exception message expectations
Issue: SPR-13621
2015-11-05 18:06:14 +01:00
Hronom 1d60a6a6af Added strict compare mode for Json
Issue: SPR-13607
2015-10-29 17:05:37 +01:00
Rossen Stoyanchev 323fa8510d Call complete() on MockAsyncContext after dispatch
Issue: SPR-13615
2015-10-29 10:12:47 -04:00
Sam Brannen 1bf7249d59 Suppress deprecation warning in HtmlUnitRequestBuilderTests 2015-10-16 19:15:29 +02:00
Juergen Hoeller 66177dfd8c StreamUtils.emptyInput() for consistent empty InputStream exposure
Issue: SPR-13563
2015-10-12 22:25:40 +02:00
Sam Brannen 3db62d5494 Remove MimeTypeResolver since JAF is part of Java SE 6+
The inner MimeTypeResolver class is no longer necessary in the
MockServletContext since the Java Activation Framework (JAF) is a
standard part of Java SE since Java 6.
2015-10-06 15:56:00 +02:00
Sam Brannen 61a46db101 Treat query param w/o "=" as empty string in HtmlUnitRequestBuilder
Prior to this commit, HtmlUnitRequestBuilder stored empty query
parameters declared without an equals sign as null (i.e., query
parameters such as 'error' in 'http://example.com/login?error').

This commit addresses this issue by ensuring that
HtmlUnitRequestBuilder treats all empty query parameter values as empty
strings. Consequently, query strings such as '?error' and '?error=' now
both result in 'error' being stored as an empty string.

Issue: SPR-13524
2015-10-04 19:11:41 +02:00
Sam Brannen 283fc94572 Support null query param values in HtmlUnitRequestBuilder
Prior to this commit, HtmlUnitRequestBuilder would incorrectly attempt
to decode null values for query parameters (i.e., query parameters such
as 'error' in 'http://example.com/login?error') which resulted in a
NullPointerException since URLDecoder.decode() does not support null
values.

This commit fixes this issue by ensuring that HtmlUnitRequestBuilder
only attempts to decode non-null query parameter values.

Issue: SPR-13524
2015-09-30 21:48:14 +02:00
Sam Brannen d5b4685391 Polish HtmlUnitRequestBuilderTests 2015-09-30 21:48:13 +02:00
Juergen Hoeller a9fbbc55e6 Polishing 2015-09-28 22:11:10 +02:00
Sam Brannen d883efcb2a Throw meaningful exception if JUnit 4.9 is not present
SpringJUnit4ClassRunner, SpringClassRule, and SpringMethodRule now
throw an IllegalStateException with a meaningful message if JUnit 4.9
is not present in the classpath (specifically if
org.junit.runners.model.MultipleFailureException cannot be loaded).

Issue: SPR-13521
2015-09-28 20:15:40 +02:00
Sam Brannen d5ee787e1e Migrate JUnit 3 tests to JUnit 4
This commit migrates all remaining tests from JUnit 3 to JUnit 4, with
the exception of Spring's legacy JUnit 3.8 based testing framework that
is still in use in the spring-orm module.

Issue: SPR-13514
2015-09-27 21:17:51 +02:00
Rossen Stoyanchev df171ff5bb MockMvc request builder preserves double slashes
The MockHttpServletRequestBuilder now uses java.net.URI internally
rather than UriComponents.

This means that for the MockMvcRequestBuilders method variants that
accept a java.net.URI we can use it as is. The difference is almost
none but it does mean that you can create a URI with double slashes
(for testing purposes) and have it remain that way.

Issue: SPR-13435
2015-09-23 17:50:29 -04:00
Rossen Stoyanchev fb3e054a31 Update Javadoc
Issue: SPR-13479
2015-09-23 17:29:21 -04:00
Sam Brannen e2bfbdcfd1 Support attribute overrides with @ResponseStatus
This commit introduces support for attribute overrides for
@ResponseStatus when @ResponseStatus is used as a meta-annotation on
a custom composed annotation.

Specifically, this commit migrates all code that looks up
@ResponseStatus from using AnnotationUtils.findAnnotation() to using
AnnotatedElementUtils.findMergedAnnotation().

Issue: SPR-13441
2015-09-11 21:05:30 +02:00
Juergen Hoeller bc13cb2af5 Polishing 2015-09-10 14:05:06 +02:00
Sam Brannen ae8a341a55 Polishing 2015-09-08 18:34:47 +02:00
Juergen Hoeller 52fdfd59ab Polishing 2015-09-08 18:11:30 +02:00
Juergen Hoeller 667fc7e4a9 Polishing 2015-09-04 14:38:47 +02:00
Brian Clozel d3d81c2864 Add MockHttpServletResponse.getDateHeader
This change adds a new `getDateHeader` method that converts date header
Strings to long values - making tests more readable.

This feature is also documented in the "what's new section" for 4.2.
2015-09-03 16:03:46 +02:00
Sam Brannen 527b778bf9 Clean up warnings in spring-test 2015-08-27 22:12:14 +02:00
Juergen Hoeller 7d30017429 StubWebApplicationContext supports AutowireCapableBeanFactory operations (as far as possible)
This is generally worthwhile but in particular fixes a regression with our Jackson SpringHandlerInstantiator in standalone MVC tests.

Issue: SPR-13375
2015-08-25 21:52:49 +02:00
Rossen Stoyanchev 473dd5e9e8 Unwrap if necessary for MultipartHttpServletRequest
Before this commit RequestPartServletServerHttpRequest simply did an
instanceof check for MultipartHttpServletRequest. That hasn't failed
because request wrapping typically happens in filters before the
DispatcherServlet calls the MultipartResolver.

With Spring MVC Test and the Spring Security integraiton however,
this order is reversed since there we prepare the multipart request
upfront, i.e. there is no actual parsing.

The commit unwraps the request if necessary.

Issue: SPR-13317
2015-08-21 10:28:08 -04:00
Sam Brannen 0cd21aa55f Fix typo in Javadoc for TestContextBootstrapper 2015-08-19 20:52:36 +02:00
Sam Brannen 7a17abe448 Introduce empty & non-empty JsonPath matchers
This commit introduces new `isEmpty()` and `isNotEmpty()` methods in
`JsonPathResultMatchers` and `JsonPathRequestMatchers` which delegate
to the new `assertValueIsEmpty()` and `assertValueIsNotEmpty()` methods
in `JsonPathExpectationsHelper`, respectively.

Issue: SPR-13352
2015-08-15 19:28:09 +02:00
Sam Brannen 4799668a98 Introduce additional JsonPath RequestMatchers in Spring MVC Test
Commit fffdd1e9e9 introduced additional
JsonPath result matchers in JsonPathResultMatchers for server-side
testing of MVC controllers.

This commit introduces comparable methods in JsonPathRequestMatchers
for client-side testing with a RestTemplate.

- isString()
- isBoolean()
- isNumber()
- isMap()

Issue: SPR-13320
2015-08-15 14:56:57 +02:00
Sam Brannen e4f386ae1e Add regression test cases to JsonPathRequestMatchersTests 2015-08-15 14:15:13 +02:00
Sam Brannen 687af344de Polishing 2015-08-15 14:13:52 +02:00
Sam Brannen 5ee24c8482 Polish Javadoc for JsonPathRequestMatchers, etc. 2015-08-15 13:55:30 +02:00
Sam Brannen e7c95addeb Rename test classes to avoid confusion 2015-08-15 13:33:26 +02:00
Sam Brannen d4d5e5ce40 Polishing 2015-08-14 22:45:10 +02:00
Sam Brannen 07bb0378b9 Differentiate b/t (in)definite results in JsonPath assertions
Prior to this commit, the exists() method in JsonPathExpectationsHelper
correctly asserted that the evaluated JsonPath expression resulted in a
value (i.e., that a non-null value exists); however, if the value was
an empty array, the exists() method always threw an AssertionError.

The existing behavior makes sense if the JsonPath expression is
'indefinite' -- for example, if the expression uses a filter to select
results based on a predicate for which there is no match in the JSON
document, but the existing behavior is illogical and therefore invalid
if the JsonPath expression is 'definite' (i.e., directly references an
array in the JSON document that exists but happens to be empty). For
example, prior to this commit, the following threw an AssertionError.

    new JsonPathExpectationsHelper("$.arr").exists("{ 'arr': [] }");

Similar arguments can be made for the doesNotExist() method.

After thorough analysis of the status quo, it has become apparent that
the existing specialized treatment of arrays is a result of the fact
that the JsonPath library always returns an empty list if the path is
an 'indefinite' path that does not evaluate to a specific result.
Consult the discussion on "What is Returned When?" in the JsonPath
documentation for details:

    https://github.com/jayway/JsonPath#what-is-returned-when

This commit addresses these issues by ensuring that empty arrays are
considered existent if the JsonPath expression is definite but
nonexistent if the expression is indefinite.

Issue: SPR-13351
2015-08-14 22:07:03 +02:00
Sam Brannen d2503340e7 Polish assertion msgs in JsonPathExpectationsHelper 2015-08-14 20:38:50 +02:00
Sam Brannen af8d9eab59 Polish Javadoc for JsonPathExpectationsHelper 2015-08-14 17:59:12 +02:00
Sam Brannen 5a05cdbedb Consider empty arrays as existent in JsonPath assertions
Prior to this commit, a JsonPath assertion that a path expression
evaluated to an array in JsonPathExpectationsHelper (and therefore
indirectly in JsonPathResultMatchers in Spring MVC Test) would
incorrectly fail if the array was present in the JSON content but empty.

This commit fixes this issue by removing the "not empty" check for
arrays and lists.

Issue: SPR-13320
2015-08-14 17:20:07 +02:00
Sam Brannen 8afea1bc78 Add tests to JsonPathExpectationsHelperTests 2015-08-14 17:10:28 +02:00
Sam Brannen 0dbbbce8d5 Polish JsonPathResultMatchersTests 2015-08-14 17:07:23 +02:00
Sam Brannen ecb15ac58b Polish assertion msgs in JsonPathExpectationsHelper 2015-08-14 17:04:34 +02:00
Juergen Hoeller 3a5cc3df80 JCacheEhCache3Tests enforces EhCache 3.0's CachingProvider
Issue: SPR-13342
2015-08-12 23:09:16 +02:00
Juergen Hoeller d8794a1edc Test against EhCache 3.0 M2 (as a JCache provider)
Includes latest dependency updates (Jackson 2.6.1, Jetty 9.3.2, Undertow 1.2.10)

Issue: SPR-13342
2015-08-12 16:16:25 +02:00
Sam Brannen f3da7b810b Polish HtmlUnitRequestBuilder 2015-08-08 00:27:00 +02:00
Sam Brannen 93c07e76bc Return null instead of empty cookies array in Spring MVC Test
Prior to this commit, MockHttpServletRequestBuilder always supplied an
array of cookies to the MockHttpServletRequest that it built, even if
the array was empty.

However, this violates the contract of HttpServletRequest. According to
the Servlet API, the getCookies() method "returns null if no cookies
were sent."

This commit ensures that MockHttpServletRequestBuilder no longer
configures an empty array of cookies in the mock request that it builds.

Issue: SPR-13314
2015-08-07 01:00:12 +02:00
Craig Andrews fffdd1e9e9 Introduce additional JsonPath matchers in Spring MVC Test
This commit introduces the following methods in JsonPathResultMatchers
in the Spring MVC Test framework.

- isString()
- isBoolean()
- isNumber()
- isMap()

In addition, this commit overhauls the Javadoc in
JsonPathResultMatchers and JsonPathExpectationsHelper.

Issue: SPR-13320
2015-08-06 22:08:24 +02:00
Sam Brannen 725292081e Introduce 'value' alias for 'attribute' in @AliasFor
SPR-11512 introduced support for annotation attribute aliases via
@AliasFor, requiring the explicit declaration of the 'attribute'
attribute. However, for aliases within an annotation, this explicit
declaration is unnecessary.

This commit improves the readability of alias pairs declared within an
annotation by introducing a 'value' attribute in @AliasFor that is an
alias for the existing 'attribute' attribute. This allows annotations
such as @ContextConfiguration from the spring-test module to declare
aliases as follows.

public @interface ContextConfiguration {

     @AliasFor("locations")
     String[] value() default {};

     @AliasFor("value")
     String[] locations() default {};

    // ...
}

Issue: SPR-13289
2015-07-29 15:27:06 +02:00
Sam Brannen 6a59d00576 Fix references and typos in Spring MVC Test Javadoc
This commit fixes numerous references to 'legacy' packages within the
Javadoc for the Spring MVC Test framework.

In addition, this commit improves examples in Javadoc, adds links to
related classes where appropriate, and removes unnecessary imports for
types that are only referenced within documentation.

Issue: SPR-13284
2015-07-28 19:44:47 +02:00
Sam Brannen 29e6272c6b Polish 2015-07-27 22:44:42 +02:00
Sam Brannen 9023cf6ae0 Redesign MockMvcHtmlUnitDriverBuilder API
This commit introduces a dedicated build() method in
MockMvcHtmlUnitDriverBuilder to replace createDriver(). In addition,
the configureDriver() method has been renamed to withDelegate() and now
returns the builder for further customization.

This commit also overhauls the Javadoc for static factory methods and
the class-level Javadoc in MockMvcHtmlUnitDriverBuilder for greater
clarity to end users.

Issues SPR-13158
2015-07-27 22:41:22 +02:00
Sam Brannen 3b84a7e84d Redesign MockMvcWebClientBuilder API
This commit introduces a dedicated build() method in
MockMvcWebClientBuilder to replace createWebClient(). In addition, the
configureWebClient() method has been renamed to withDelegate() and now
returns the builder for further customization.

This commit also overhauls the constructor and class-level Javadoc in
MockMvcWebClientBuilder for greater clarity to end users.

Issues SPR-13158
2015-07-27 19:48:01 +02:00
Sam Brannen 3d6f465625 Polish Javadoc in HtmlUnit support 2015-07-27 19:47:43 +02:00
Sam Brannen 680936f4a2 Rename configureWebClient() to modifyWebClientInternal() in HtmlUnit support
This commit renames the configureWebClient() method in
WebConnectionHtmlUnitDriver to modifyWebClientInternal() in order to
better convey the relationship to HtmlUnitDriver#modifyWebClient().

Issues SPR-13158
2015-07-27 18:04:13 +02:00
Rob Winch 484ac5e242 Polish Javadoc
Issue: SPR-13158
2015-07-27 10:39:15 -05:00
Rob Winch e998c450e6 Add Assume PERFORMANCE to needed HtmlUnit Tests
Some of the HtmlUnit Tests required an internet connection. This
caused failures when running offline.

This commit adds Assume PERFORMANCE to those tests so they are
only ran when the PERFORMANCE group is selected.

Issue: SPR-13158
2015-07-27 10:29:30 -05:00
Sam Brannen 0b0a5a9ed4 Polish tests for HtmlUnit support 2015-07-27 14:30:46 +02:00
Sam Brannen 40ea9ffd63 Remove unnecessary imports 2015-07-27 13:06:54 +02:00
Sam Brannen d21ad29982 Polish MockMvc HtmlUnit Support
- formatting
- code style
- organized imports
- precondition assertions
- suppressed warnings
- Javadoc enhancements

Issue: SPR-13158
2015-07-27 12:03:21 +02:00
Rob Winch b73e39423c Introduce support for HtmlUnit in Spring MVC Test
This commit introduces integration between MockMvc and HtmlUnit, thus
simplifying end-to-end testing when using HTML-based views and enabling
developers to do the following.

 - Easily test HTML pages using tools such as HtmlUnit, WebDriver, & Geb
   without the need to deploy to a Servlet container

 - Test JavaScript within pages

 - Optionally test using mock services to speed up testing

 - Share logic between in-container, end-to-end tests and
   out-of-container integration tests

Issue: SPR-13158
2015-07-27 12:03:21 +02:00
Sam Brannen c5a037a5cf Delete unused Spring Security config file 2015-07-26 20:54:53 +02:00
Sam Brannen 5b8b1dd378 Clean up database tests in spring-test 2015-07-26 20:54:27 +02:00
Sam Brannen 47e1724d0e Deprecate TxConfigAttributes alongside @TxConfig
Since @TransactionConfiguration is now deprecated, this commit also
deprecates TransactionConfigurationAttributes with the intention of
completely removing TransactionConfigurationAttributes once
@TransactionConfiguration has been removed.

Issue: SPR-13277
2015-07-25 21:29:57 +02:00
Sam Brannen d6bdfcaa6e Introduce @Commit alias for @Rollback(false)
Due to common usage of @Rollback(false), this commit introduces a new
@Commit annotation that more clearly conveys the intent of the code
while retaining the run-time semantics.

@Commit is in fact meta-annotated with @Rollback(false).

Issue: SPR-13279
2015-07-25 21:09:32 +02:00
Sam Brannen baa66f7bfa Polishing 2015-07-25 18:43:47 +02:00
Sam Brannen c4bbc9df33 Migrate @TxConfig usage to @Rollback & @Transactional qualifiers
Issue: SPR-13276, SPR-13277
2015-07-25 18:41:50 +02:00
Sam Brannen 3f8b51283e Support @Rollback on classes & deprecate @TxConfig
Since Spring Framework 2.5, @Rollback has been supported on test
methods, with class-level rollback settings configured via
@TransactionConfiguration; however, allowing @Rollback to be declared
on test classes with method-level declarations overriding class-level
declarations would prove more intuitive than having to declare both
@TransactionConfiguration and @Rollback. Furthermore, the
transactionManager flag in @TransactionConfiguration was made
superfluous many years ago with the introduction of support for a
qualifier in @Transactional.

This commit enables @Rollback to be declared at the class level for
default rollback semantics within test class hierarchies and deprecates
@TransactionConfiguration in favor of @Rollback and @Transactional
qualifiers.

Issue: SPR-13276, SPR-13277
2015-07-25 18:22:26 +02:00
Juergen Hoeller efd7f9bf72 Polishing 2015-07-24 18:24:19 +02:00
Sam Brannen 24b1dc14d2 Reduce scope of suppressed deprecation warnings in SpringJUnit4ClassRunner 2015-07-24 16:51:41 +02:00
Sam Brannen dede31eeed Polish Javadoc in @Timed & @Repeat 2015-07-24 16:51:01 +02:00
Sam Brannen 2afbfb2c0d Polishing 2015-07-23 13:32:26 +02:00
Brian Clozel 43e36e2dee Improve DateHeaders in MockServletRequest/Response
Prior to this change, calling the `setDateHeader` method on a
Spring Test MockHttpServletResponse instance would just store the given
long value in a Map, not writing it as a formatted date String.
Also, calling `getDateHeader` on a MockHttpServletRequest would not
support date strings and could not parse those values.

This can be problematic when testing features related to date headers
such as "Expires", "If-Modified-Since", "Last-Modified", etc.

This commit adds formatting and parsing capabilities to Servlet Mocks
for date strings in HTTP headers.

When formatting dates to Strings, the date format used is the one
preferred by the HTTP RFC. When parsing date Strings, multiple date
formats are supported for better compatibility.

Issue: SPR-11912
2015-07-23 11:12:28 +02:00
Sam Brannen 3c799e6e05 Do not reuse mock requests in Spring MVC Test
SPR-13211 introduced support for reusing mock requests in Spring MVC
Test if the request was created by the the Spring TestContext
Framework. Unfortunately, that change makes it impossible for
MockMvc.perform() to be invoked multiple times within the same test
method without side effects. For example, session attributes and
request parameters are transparently and unexpectedly retained for
subsequent invocations of perform(), causing certain categories of
tests to fail.

This commit reverts the changes introduced in SPR-13211 and introduces
a new MockMvcReuseTests class to serve as regression tests within
Spring's test suite.

Issue: SPR-13260, SPR-13211
2015-07-22 17:50:05 +02:00
Sam Brannen 758a470d63 Include attribute/session name in assertions in RequestResultMatchers 2015-07-22 16:56:28 +02:00
Sam Brannen bb51447860 Fix typos in RequestResultMatchers 2015-07-22 16:46:13 +02:00
Brian Clozel cf2aed9d00 Add a dateValue HeaderResultMatcher
HTTP headers such as "Expires", "Last-Modified" all use date
strings like "Tue, 21 Jul 2015 10:00:00 GMT". Prior to this commit,
there was no way to match those header values, besides formatting dates
manually.

This commit introduces a new HeaderResultMatcher to test those date
headers using a long timestamp:

```
this.mockMvc.perform(get("/persons/1").header("If-Modified-Since", now))
  .andExpect(status().isNotModified())
  .andExpect(header().dateValue("Last-Modified", timestamp));
```

Issue: SPR-13263
2015-07-22 11:22:44 +02:00
Sam Brannen 420e8ca833 Sync Javadoc and reference manual regarding ReflectionTestUtils 2015-07-21 17:10:00 +02:00
Sam Brannen d8fb6c557d Delete unused imports in HeaderAssertionTests 2015-07-20 23:57:46 +02:00
Brian Clozel dba46c1358 Partial revert of SPR-13090
Use ServletHttpResponse.setDateHeader whenever possible and avoid using
SimpleDateFormat.
2015-07-20 22:48:20 +02:00
Sam Brannen 19fcb72d70 Polish Javadoc in the Spring MVC Test Framework 2015-07-20 22:41:30 +02:00
Sam Brannen bf06bf33ab Reuse mock request from the TCF in Spring MVC Test
Prior to this commit, the Spring MVC Test Framework always created a
new MockHttpServletRequest, disregarding any mock request already
present in Spring Web's RequestContextHolder -- for example, one
created by the ServletTestExecutionListener in the Spring TestContext
Framework (TCF).

This commit modifies MockHttpServletRequestBuilder so that it reuses a
mock request created by the TCF. However,
MockMultipartHttpServletRequestBuilder continues to always create a new
MockMultipartHttpServletRequest since a MockHttpServletRequest created
by the TCF is not directly compatible with a
MockMultipartHttpServletRequest. Furthermore, in order to avoid
unforeseen side effects, MockHttpServletRequestBuilder will always
create a new MockHttpServletRequest if a mock request is present in the
RequestContextHolder but not created by the TCF.

Issue: SPR-13211
2015-07-20 22:41:29 +02:00
Sam Brannen e9f64cf9ae Sync Servlet mocks between spring-test & spring-web 2015-07-19 20:23:51 +02:00
Juergen Hoeller aedef43a9a Exception fine-tuning and general polishing
Issue: SPR-13067
2015-07-17 15:24:04 +02:00
Juergen Hoeller 9f15f347bf Renamed 'name' attribute to 'scopeName' (in order to avoid common override conflicts)
Issue: SPR-13239
2015-07-17 15:23:47 +02:00
Michal Karolik 95fe5f9033 Fix package references
Closes gh-839
2015-07-16 11:28:12 +02:00
Juergen Hoeller ea2a1d33d9 Javadoc fixes plus additional polishing 2015-07-15 02:19:46 +02:00
Sam Brannen 9c46228a97 Populate RequestAttributes before invoking Filters in MockMvc
When using the Spring TestContext Framework (TCF) to load a
WebApplicationContext and the Spring MVC Test Framework (MockMvc) to
test a controller, two instances of MockHttpServletRequest will be
created. Due to an ordering issue with regard to population of the
RequestAttributes, it is therefore possible that a filter accesses the
mocked request managed by the TCF, while the controller accesses the
mocked request managed by MockMvc, and this leads to test failures if
the controller expects data from the filter to be present in the
request.

This commit fixes this bug by ensuring that the RequestAttributes
backed by the mocked request managed by MockMvc are stored in the
RequestContextHolder before any filters are invoked by MockMvc.

Issue: SPR-13217
2015-07-10 17:35:05 +03:00
Sam Brannen 3d951755fa Improve documentation for @IfProfileValue precedence
Issue: SPR-11902
2015-07-10 02:38:54 +03:00
Sam Brannen 3c2efeece4 Investigate claims raised in SPR-13211
This commit adds additional tests to RequestContextHolderTests that
verify proper support for the MockHttpServletRequest managed by Spring
MVC Test in the following scenarios:

- request-scoped service invoked by controller
- session-scoped service invoked by controller
- custom filter that sets request attributes

Issue: SPR-13211
2015-07-07 22:42:08 +02:00
Sam Brannen 5e24ee9b55 Update RequestContextHolderTests
This commit refactors RequestContextHolderTests in preparation for the
work to be done in SPR-13211.

Issue: SPR-13211
2015-07-07 21:37:46 +02:00
Sam Brannen ea0c37a535 Polishing 2015-07-03 18:38:20 +02:00
Sam Brannen 3c4ec9026a Introduce test for DeferredResult w/ delayed error in MVC Test
This commit introduces a test that verifies the fix introduced in
6842fd7fb9.

Issue: SPR-13079
2015-07-03 17:51:46 +02:00
Sam Brannen 0e70630ac4 Polish AsyncTests 2015-07-03 17:01:21 +02:00
Sam Brannen 0aac02d649 Introduce DirtiesContextBeforeModesTestExecutionListener
SPR-12429 introduced various `BEFORE_*` modes in `@DirtiesContext`. To
support these new modes, `DirtiesContextTestExecutionListener` (DCTEL)
was updated to support both `BEFORE_*` and `AFTER_*` modes. However,
there is a problem with having DCTEL support `BEFORE_*` modes since it
is typically configured to execute after the
`DependencyInjectionTestExecutionListener` (DITEL), and this leads to
several undesired side effects:

 - The test's `ApplicationContext` is closed by DCTEL *after*
   dependencies have been injected into the test instance.

 - Injected dependencies may therefore attempt to interact with an
   `ApplicationContext` that is no longer _active_.

 - If a test has its `ApplicationContext` injected as a dependency,
   interaction with the context will likely fail since the context has
   been closed.

 - Any `TestExecutionListeners` registered after DCTEL will get a _new_
   `ApplicationContext` if they invoke `getApplicationContext()` on the
   `TestContext`.

This commit fixes these issues by introducing a new
`DirtiesContextBeforeModesTestExecutionListener` (DCBMTEL) that is
registered by default before DITEL. The previous support for `BEFORE_*`
modes has been moved from DCTEL to DCBMTEL. In addition, an
`AbstractDirtiesContextTestExecutionListener` has been extracted from
DCTEL in order to avoid code duplication.

Issue: SPR-13180
2015-07-01 20:55:12 +02:00
Sam Brannen 63a1348c32 Polish LoggingResultHandler in Spring MVC Test
Issue: SPR-13171
2015-06-27 22:44:42 +02:00
Sam Brannen 693dcba867 Introduce LoggingResultHandler in Spring MVC Test
Prior to this commit, the Spring MVC Test framework only provided
support for printing debug information about the MvcResult to STDOUT.

This commit introduces support for logging `MvcResult` details at
`DEBUG` level via the Apache Commons Logging API. In addition, this
commit introduces additional `print(..)` variants for printing debug
information to custom output streams and writers.

Specifically, `MockMvcResultHandlers` has been augmented with the
following new static methods:

 - `log()`
 - `print(OutputStream)`
 - `print(Writer)`

Issue: SPR-13171
2015-06-27 21:53:19 +02:00
Sam Brannen 895d43a2b3 Print cookies in human-readable form in Spring MVC Test
Prior to this commit, when rendering cookies via `andDo(print())` in
Spring MVC Test, the output for the `MockHttpServletResponse` would
look something like the following:

  Cookies = [javax.servlet.http.Cookie@25084a1e]

The reason is that the Cookie class in javax.servlet-api-3.0.1.jar does
not implement toString(). Consequently, nothing about the cookie's
name, value, etc., is displayed, thereby making the debug output for
cookies next to useless.

This commit improves on this by implementing custom toString() logic
for cookies in debug output in Spring MVC Test. For example, the output
now looks like this (without the newlines):

  Cookies = [[Cookie@47faa49c name = 'enigma', value = '42', \\
            comment = [null], domain = [null], maxAge = -1, \\
            path = [null], secure = false, version = 0, \\
            httpOnly = false]]

In addition, this commit fixes a minor bug for FlashMap debug output if
the FlashMap is empty.

Issue: SPR-13168
2015-06-27 02:54:42 +02:00
Juergen Hoeller a2d3c27ed1 Allow MVC handler methods to return any CharSequence type as view name
Issue: SPR-13165
2015-06-26 22:17:53 +02:00
Rossen Stoyanchev 6842fd7fb9 Ensure result ready in asyncDispatch in MockMvc
Issue: SPR-13079
2015-06-25 09:25:21 -04:00
Sam Brannen 10a691bd51 Support inlined SQL statements in @Sql
Prior to this commit, it was only possible to declare SQL statements
via @Sql within external script resources (i.e., classpath or file
system resources); however, many developers have inquired about the
ability to inline SQL statements with @Sql analogous to the support for
inlined properties in @TestPropertySource.

This commit introduces support for declaring _inlined SQL statements_
in `@Sql` via a new `statements` attribute. Inlined statements are
executed after statements in scripts.

Issue: SPR-13159
2015-06-23 20:45:00 +02:00
Sam Brannen d0c0d9fc5a Synthesize annotation from defaults
This commit introduces a convenience method in AnnotationUtils for
synthesizing an annotation from its default attribute values.

TransactionalTestExecutionListener has been refactored to invoke this
new convenience method.

Issue: SPR-13087
2015-06-20 18:27:36 +02:00
Sam Brannen 27d1ce84a3 Polishing 2015-06-20 01:45:46 +02:00
Sam Brannen fb83e83e78 Honor contract of @Repeatable in AnnotationUtils
Prior to this commit, the implementation of getRepeatableAnnotation()
in Spring's AnnotationUtils complied neither with the contract of
getAnnotationsByType() nor with the contract of
getDeclaredAnnotationsByType() as defined in AnnotatedElement in Java 8.

Specifically, unexpected results can be encountered when using Spring's
support for @Repeatable annotations: either annotations show up in the
returned set in the wrong order, or annotations are returned in the set
that should not even be found based on the semantics of @Repeatable.

This commit remedies this problem by deprecating the existing
getRepeatableAnnotation() methods and replacing them with new
getRepeatableAnnotations() and getDeclaredRepeatableAnnotations()
methods that comply with the contracts of Java's getAnnotationsByType()
and getDeclaredAnnotationsByType(), respectively.

Issue: SPR-13068
2015-06-20 01:21:39 +02:00
Sam Brannen 23547a72f3 Clean up warnings and polish tests 2015-06-19 14:57:28 +01:00
Sam Brannen 37d61375e2 Fix typo 2015-06-19 14:39:50 +01:00
Sam Brannen ece12f9d37 Synthesize annotation from map w/ minimal attributes
The initial support for synthesizing an annotation from a Map (or
AnnotationAttributes) introduced in SPR-13067 required that the map
contain key-value pairs for every attribute defined by the supplied
annotationType. However, there are use cases that would benefit from
being able to supply a reduced set of attributes and still have the
annotation synthesized properly.

This commit refines the validation mechanism in
MapAnnotationAttributeExtractor so that a reduced set of attributes may
be supplied. Specifically, if an attribute is missing in the supplied
map the attribute will be set either to value of its alias (if an alias
value configured via @AliasFor exists) or to the value of the
attribute's default value (if defined), and otherwise an exception will
be thrown.

Furthermore, TransactionalTestExecutionListener has been refactored to
take advantage of this new feature by synthesizing an instance of
@TransactionConfiguration solely from the default values of its
declared attributes.

Issue: SPR-13087
2015-06-19 14:27:23 +01:00
Brian Clozel f988151163 Improve charset management in XpathResultMatchers
Prior to this change, `XpathResultMatchers` and more generally the
`MockHttpServletResponse` would default to ISO-8859-1 encoding even when
it's not supposed to. The Servlet/HTTP specs mention this encoding
for all `text/*` mime types when decoding bodies to Strings, but this
issue is about XML Parsers.

XML Parsers should use the encoding:

* defined in the `Content-Type` response header (if available)
* written in the XML declaration of the document
* "guessed" by a built-in auto-detection mechanism

This commit changes the following:

* XPathMatchers now feed the XML parser with byte arrays instead of
decoded Strings
* the response should be written to `MockHttpServletResponse` using
its OutputStream, and not a PrintWriter which defaults to ISO-8859-1

Issue: SPR-12676
2015-06-17 10:09:54 +02:00
Sam Brannen 68a704373d Retain order of active profiles in the TCF
Ever since @ActiveProfiles was introduced, the declared active profiles
for integration tests have been sorted in order to support unique cache
key generation; however, there are use cases for which the original
ordering should be retained.

For example, Spring Boot's ConfigFileApplicationListener loads
configuration files for active profiles in the order returned by
Environment.getActiveProfiles(), with the assumption that the ordering
matches the order in which the developer declared the active profiles.

This commit maintains the uniqueness of active profiles declared via
@ActiveProfiles but no longer sorts them.

Issue: SPR-12492
2015-06-15 14:25:06 +01:00
Sam Brannen ea9d7aa337 Polish Javadoc for @TransactionConfiguration 2015-06-14 15:24:20 +02:00
Sam Brannen 32c17bf540 Revise method and parameter names in annotation support
In AnnotatedElementUtils, all methods pertaining to merging annotation
attributes have been renamed to "getMerged*()" and "findMerged*()"
accordingly. Existing methods such as getAnnotationAttributes(..) have
been deprecated in favor of the more descriptive "merged" variants.
This aligns the naming conventions in AnnotatedElementUtils with those
already present in AnnotationReadingVisitorUtils.

The use of "annotationType" as a variable name for the fully qualified
class name of an annotation type has been replaced with
"annotationName" in order to improve the readability and intent of the
code base.

In MetaAnnotationUtils.AnnotationDescriptor, getMergedAnnotation() has
been renamed to synthesizeAnnotation(), and the method is now
overridden in UntypedAnnotationDescriptor to always throw an
UnsupportedOperationException in order to avoid potential run-time
ClassCastExceptions.

Issue: SPR-11511
2015-06-14 00:34:40 +02:00
Sam Brannen 6b7c1d72e8 Introduce alias for 'value' attribute in @Transactional
Issue: SPR-11393
2015-06-12 22:35:20 +02:00
Sam Brannen f6d2fe471a Proper support for Root WAC in Spring MVC Test
The modifications to DefaultMockMvcBuilder performed in conjunction
with SPR-12553 introduced a breaking change: the WebApplicationContext
supplied to DefaultMockMvcBuilder's constructor was *always* stored in
the ServletContext as the root WebApplicationContext, overwriting a
root WebApplicationContext that had been set by the user or by the
Spring TestContext Framework (TCF) -- for example, in
AbstractGenericWebContextLoader. Consequently, the changes in SPR-12553
cause tests that use @ContextHierarchy to fail if web components rely
on the correct WebApplicationContext being stored under the
WebApplicationContext#ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE key.

This commit reverts the breaking changes introduced in SPR-12553: if
the root WebApplicationContext has already been set in the
ServletContext of the WebApplicationContext supplied to
DefaultMockMvcBuilder, no action is taken.

Furthermore, this commit introduces new code to address the initial
intent of SPR-12553. Specifically, if the root WebApplicationContext
has NOT been set in the ServletContext of the WebApplicationContext
supplied to DefaultMockMvcBuilder, the application context hierarchy
will be traversed in search of the root WebApplicationContext, and the
root WebApplicationContext will then be stored under the
ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE key.

Issue: SPR-13075, SPR-12553
2015-06-11 19:54:25 +02:00
Brian Clozel e2c8d3762f Fix tests for SPR-13090 2015-06-11 16:34:33 +02:00
Esko Luontola 89c1674b89 Fix missing space in assertion message 2015-06-01 10:56:53 -04:00
Sam Brannen 6a5b2672e7 Introduce alias for 'value' attribute in @ResponseStatus
Issue: SPR-11393
2015-05-31 17:00:23 +02:00
Sam Brannen 8f233786ed Polishing 2015-05-29 02:05:44 +02:00
Sam Brannen e30c9b2ef3 Synthesize annotation from a map of attributes
Spring Framework 4.2 RC1 introduced support for synthesizing an
annotation from an existing annotation in order to provide additional
functionality above and beyond that provided by Java. Specifically,
such synthesized annotations provide support for @AliasFor semantics.
As luck would have it, the same principle can be used to synthesize an
annotation from any map of attributes, and in particular, from an
instance of AnnotationAttributes.

The following highlight the major changes in this commit toward
achieving this goal.

- Introduced AnnotationAttributeExtractor abstraction and refactored
  SynthesizedAnnotationInvocationHandler to delegate to an
  AnnotationAttributeExtractor.

- Extracted code from SynthesizedAnnotationInvocationHandler into new
  AbstractAliasAwareAnnotationAttributeExtractor and
  DefaultAnnotationAttributeExtractor implementation classes.

- Introduced MapAnnotationAttributeExtractor for synthesizing an
  annotation that is backed by a map or AnnotationAttributes instance.

- Introduced a variant of synthesizeAnnotation() in AnnotationUtils
  that accepts a map.

- Introduced findAnnotation(*) methods in AnnotatedElementUtils that
  synthesize merged AnnotationAttributes back into an annotation of the
  target type.

The following classes have been refactored to use the new support for
synthesizing AnnotationAttributes back into an annotation.

- ApplicationListenerMethodAdapter
- TestAnnotationUtils
- AbstractTestContextBootstrapper
- ActiveProfilesUtils
- ContextLoaderUtils
- DefaultActiveProfilesResolver
- DirtiesContextTestExecutionListener
- TestPropertySourceAttributes
- TestPropertySourceUtils
- TransactionalTestExecutionListener
- MetaAnnotationUtils
- MvcUriComponentsBuilder
- RequestMappingHandlerMapping

In addition, this commit also includes changes to ensure that arrays
returned by synthesized annotations are properly cloned first.

Issue: SPR-13067
2015-05-29 01:38:51 +02:00
Sam Brannen ca66e076d1 Support annotation attribute aliases and overrides via @AliasFor
This commit introduces first-class support for aliases for annotation
attributes. Specifically, this commit introduces a new @AliasFor
annotation that can be used to declare a pair of aliased attributes
within a single annotation or an alias from an attribute in a custom
composed annotation to an attribute in a meta-annotation.

To support @AliasFor within annotation instances, AnnotationUtils has
been overhauled to "synthesize" any annotations returned by "get" and
"find" searches. A SynthesizedAnnotation is an annotation that is
wrapped in a JDK dynamic proxy which provides run-time support for
@AliasFor semantics. SynthesizedAnnotationInvocationHandler is the
actual handler behind the proxy.

In addition, the contract for @AliasFor is fully validated, and an
AnnotationConfigurationException is thrown in case invalid
configuration is detected.

For example, @ContextConfiguration from the spring-test module is now
declared as follows:

    public @interface ContextConfiguration {

        @AliasFor(attribute = "locations")
        String[] value() default {};

        @AliasFor(attribute = "value")
        String[] locations() default {};

        // ...
    }

The following annotations and their related support classes have been
modified to use @AliasFor.

- @ManagedResource
- @ContextConfiguration
- @ActiveProfiles
- @TestExecutionListeners
- @TestPropertySource
- @Sql
- @ControllerAdvice
- @RequestMapping

Similarly, support for AnnotationAttributes has been reworked to
support @AliasFor as well. This allows for fine-grained control over
exactly which attributes are overridden within an annotation hierarchy.
In fact, it is now possible to declare an alias for the 'value'
attribute of a meta-annotation.

For example, given the revised declaration of @ContextConfiguration
above, one can now develop a composed annotation with a custom
attribute override as follows.

    @ContextConfiguration
    public @interface MyTestConfig {

        @AliasFor(
           annotation = ContextConfiguration.class,
           attribute = "locations"
        )
        String[] xmlFiles();

        // ...
    }

Consequently, the following are functionally equivalent.

- @MyTestConfig(xmlFiles = "test.xml")
- @ContextConfiguration("test.xml")
- @ContextConfiguration(locations = "test.xml").

Issue: SPR-11512, SPR-11513
2015-05-22 00:01:07 +02:00
Juergen Hoeller b4095c3e1d Class identity comparisons wherever possible
Issue: SPR-12926
2015-05-20 14:34:16 +02:00
Stephane Nicoll cf391f5ce1 polish
Remove unused imports
2015-05-19 08:49:01 +02:00
Sam Brannen 428499a384 Introduce SpringFailOnTimeout(Statement, Method) constructor 2015-05-18 00:43:41 +02:00
Sam Brannen f13f493551 Introduce TestAnnotationUtils to reduce code duplication 2015-05-17 22:24:29 +02:00
Sam Brannen 973582e7df Introduce TestContextManager cache in SpringClassRule
In order to simplify configuration of the SpringMethodRule and to ensure
that the correct TestContextManager is always retrieved for the
currently executing test class, this commit introduces a static
TestContextManager cache in SpringClassRule.

In addition, since it is not foreseen that SpringClassRule and
SpringMethodRule should be able to be subclassed, their internal methods
are now private instead of protected.

Issue: SPR-7731
2015-05-17 17:14:09 +02:00
Sam Brannen 68322fc42a Introduce JUnitTestingUtils to reduce code duplication 2015-05-17 15:47:39 +02:00
Sam Brannen d1b1c4f888 Introduce JUnit Rule alternative to SpringJUnit4ClassRunner
Since Spring Framework 2.5, support for integrating the Spring
TestContext Framework (TCF) into JUnit 4 based tests has been provided
via the SpringJUnit4ClassRunner, but this approach precludes the
ability for tests to be run with alternative runners like JUnit's
Parameterized or third-party runners such as the MockitoJUnitRunner.

This commit remedies this situation by introducing @ClassRule and @Rule
based alternatives to the SpringJUnit4ClassRunner. These rules are
independent of any Runner and can therefore be combined with
alternative runners.

Due to the limitations of JUnit's implementation of rules, as of JUnit
4.12 it is currently impossible to create a single rule that can be
applied both at the class level and at the method level (with access to
the test instance). Consequently, this commit introduces the following
two rules that must be used together.

 - SpringClassRule: a JUnit TestRule that provides the class-level
   functionality of the TCF to JUnit-based tests

 - SpringMethodRule: a JUnit MethodRule that provides the
   instance-level and method-level functionality of the TCF to
   JUnit-based tests

In addition, this commit also introduces the following new JUnit
Statements for use with rules:

 - RunPrepareTestInstanceCallbacks

 - ProfileValueChecker

Issue: SPR-7731
2015-05-16 20:25:12 +02:00
Sam Brannen bccd59e6c8 Use findAnnotationAttributes() where appropriate
This commit updates code that previously used getAnnotationAttributes()
in AnnotatedElementUtils to use findAnnotationAttributes(), where
appropriate.

Issue: SPR-12738
2015-05-14 03:49:59 +02:00
Sam Brannen 6422f7a0a1 Add TODO re: FailOnTimeout.builder() & JUnit 4.12 2015-05-11 18:13:45 +02:00
Sam Brannen d14e29a5c0 Polish SpringJUnit4ClassRunner and related support classes 2015-05-11 13:39:22 +02:00
Sam Brannen cf51f0c0aa Assert pre-conditions in AopTestUtils
Issue: SPR-13005
2015-05-09 21:02:40 +02:00
Sam Brannen efe3a35da8 Introduce AOP testing utilities
This commit introduces support in the spring-test module for obtaining a
reference to the underlying target object hidden behind one or more
proxies.

Specifically this commit introduces AopTestUtils with two methods:

 - getTargetObject(Object)

 - getUltimateTargetObject(Object)

Issue: SPR-13005
2015-05-09 20:32:28 +02:00
Sam Brannen 7a690df925 Remove trailing whitespace from Java source code 2015-05-06 20:08:42 +02:00
Sam Brannen 572cbb0821 Consistently supply test name to @Parameters 2015-05-05 14:07:00 +02:00
Sam Brannen e85e9768c5 Fail if multiple @BootstrapWith's are present
Prior to this commit it was possible for two @BootstrapWith annotations
to be 'present' on a test class -- for example, via competing custom
composed annotations. However, only one of the annotations will ever be
used to bootstrap the TestContext Framework. Thus, in such scenarios
one of the annotations will be silently ignored.

This commit introduces a check for such scenarios. BootstrapUtils'
resolveTestContextBootstrapper() method now throws an
IllegalStateException if more than one @BootstrapWith annotation is
'present' on a given test class.

Issue: SPR-12602
2015-04-26 02:58:07 +02:00
Rob Winch 1a6aeb17e1 Add merged RequestPostProcessor to front on merge
Previously MockHttpServletRequestBuilder merge method would append the
parent's (default) RequestPostProcessor implementations to the end. This
means that the default RequestPostProcessor implementations would override
values set by previous RequestPostProcessor implementations.

This commit ensures that the default RequestPostProcessor are preformed
first so that additional RequestPostProcessor implementations override
the defaults.

Issue: SPR-12945
2015-04-24 13:12:29 -04:00
Sam Brannen ad6bea1cda Support abstract, bridge, & interface methods in AnnotatedElementUtils
This commit introduces support for finding annotations on abstract,
bridge, and interface methods in AnnotatedElementUtils.

 - Introduced dedicated findAnnotationAttributes() methods in
   AnnotatedElementUtils that provide first-class support for
   processing methods, class hierarchies, interfaces, bridge methods,
   etc.

 - Introduced find/get search algorithm dichotomy in
   AnnotatedElementUtils which is visible in the public API as well as
   in the internal implementation. This was necessary in order to
   maintain backwards compatibility with the existing API (even though
   it was undocumented).

 - Reverted all recent changes made to the "get semantics" search
   algorithm in AnnotatedElementUtils in order to ensure backwards
   compatibility, and reverted recent changes to
   JtaTransactionAnnotationParser and SpringTransactionAnnotationParser
   accordingly.

 - Documented internal AnnotatedElementUtils.Processor<T> interface.

 - Enabled failing tests and introduced
   findAnnotationAttributesFromBridgeMethod() test in
   AnnotatedElementUtilsTests.

 - Refactored ApplicationListenerMethodAdapter.getCondition() and
   enabled failing test in TransactionalEventListenerTests.

 - AnnotationUtils.isInterfaceWithAnnotatedMethods() is now package
   private.

Issue: SPR-12738, SPR-11514, SPR-11598
2015-04-24 00:55:48 +02:00
Sam Brannen 69b0791926 Favor local, composed annotations in the TCF
Prior to this commit, AnnotationAttributes retrieved from
MetaAnnotationUtils's AnnotationDescriptor could contain attributes
from the wrong annotation if an inherited annotation shadowed a locally
declared composed annotation.

This commit addresses this issue by invoking the new
getAnnotationAttributes() method in AnnotatedElementUtils that provides
a flag to control whether superclasses should be searched -- which
coincidentally processes local annotations before searching the class
hierarchy.

Issue: SPR-12749, SPR-11598
2015-04-23 02:44:21 +02:00
Sam Brannen 5cbe4b948d Introduce dedicated 'cache' subpackage in the TCF
Since the ContextCache is now a published SPI, it and its collaborators
have been moved to a dedicated 'org.sfw.test.context.cache' subpackage.

Issue: SPR-12683
2015-04-20 21:48:30 +02:00
Sebastien Deleuze 5b0a0f4db5 Support CompletableFuture as alternative to DeferredResult in MVC
Issue: SPR-12597
2015-04-20 14:19:31 +02:00
Sam Brannen e829b2aa1d Polish Javadoc for ContextCache 2015-04-20 00:53:45 +02:00
Sam Brannen 93f403cbf6 Ensure that contexts loaded by the TCF are active
This commit adds an assertion to DefaultTestContext's
getApplicationContext() method to ensure that a context loaded by the
Spring TestContext Framework (TCF) or retrieved from the ContextCache
is still active. This extra check helps to avoid situations where
developers manually close a cached context instead of relying on the
@DirtiesContext support.

Issue: SPR-12932
2015-04-20 00:37:16 +02:00
Sam Brannen d66d160543 Use ConcurrentHashMaps in DefaultContextCache
The changes made in 0cb22fc8f3 would
result in contexts not being properly closed if evicted from the
ConcurrentReferenceHashMap by the Garbage Collector.

This commit reverts those changes and returns to using standard
ConcurrentHashMaps for the time being.

Issue: SPR-7687
2015-04-19 21:06:41 +02:00
Sam Brannen c52a0ccdfd Introduce TestContextManager(TestContextBootstrapper) constructor
Issue: SPR-12683
2015-04-19 20:09:03 +02:00
Sam Brannen 129488cb4f Improve extensibility of TestContext bootstrapping & context caching
- DefaultBootstrapContext and DefaultCacheAwareContextLoaderDelegate
   are now public classes in the 'support' subpackage.

 - Introduced getCacheAwareContextLoaderDelegate() in
   AbstractTestContextBootstrapper as an extension point for configuring
   custom ContextCache support.

 - Introduced reflection-based createBootstrapContext() utility method
   in BootstrapUtils; TestContextManager now delegates to BootstrapUtils
   in order to avoid package cycles.

 - Introduced logStatistics() method in the ContextCache API and defined
   statistics logging category as a constant.

 - DefaultCacheAwareContextLoaderDelegate now delegates to
   ContextCache.logStatistics().

Issue: SPR-12683
2015-04-19 19:23:56 +02:00
Sam Brannen e6c24f7167 Convert ContextCache to interface with default implementation
- ContextCache is now a public interface.

 - Introduced public DefaultContextCache implementation in the 'support'
   subpackage.

Issue: SPR-12683
2015-04-19 19:23:42 +02:00
Sam Brannen c9d597f519 Introduce createBootstrapContext() extension in TestContextManager
Issue: SPR-12683
2015-04-18 23:47:11 +02:00
Sam Brannen 0b054f9fbd Improve Javadoc for TestContextBootstrapper 2015-04-18 23:45:34 +02:00
Sam Brannen 186abcb054 Introduce buildTestContext() in TestContextBootstrapper
This commit moves the responsibility of building a TestContext from the
TestContextManager to a TestContextBootstrapper.

In addition, DefaultTestContext is now a public class residing in the
"support" subpackage.

Issue: SPR-12683
2015-04-18 23:15:30 +02:00
Sam Brannen 0392a88c69 Move static ContextCache to DefaultCacheAwareContextLoaderDelegate
Issue: SPR-12683
2015-04-18 20:23:24 +02:00
Sam Brannen 0e287c1a90 Introduce resetContextCache() in ContextCacheTestUtils 2015-04-18 19:16:59 +02:00
Sam Brannen dc345dcb3d Polish TestContextManager 2015-04-18 18:50:37 +02:00
Sam Brannen 0cb22fc8f3 Use SoftReferences for context caching in the TCF
Prior to this commit, the ContextCache in the Spring TestContext
Framework (TCF) cached ApplicationContexts in a ConcurrentHashMap using
strong references. This practice can occasionally lead to
OutOfMemoryErrors when running a large number of tests in a test suite
with varying context configuration since the context cache becomes
overpopulated over time.

This commit addresses this issue by using Spring's
ConcurrentReferenceHashMap which uses SoftReferences for both the keys
(i.e., MergedContextConfiguration instances) and values (i.e.,
ApplicationContexts) stored in the map that backs the ContextCache.

Issue: SPR-7687
2015-04-18 17:36:39 +02:00
Sam Brannen 2a4f4cd258 Introduce reset() method in ContextCache 2015-04-17 22:51:04 +02:00
Sam Brannen 3c5a9b4e1d Introduce class-level @DirtiesContext tests for TestNG
Prior to this commit, ClassLevelDirtiesContextTests existed for
verifying the expected behavior of @DirtiesContext declared at the
class level in conjunction with JUnit and SpringJUnit4ClassRunner.

This commit introduces analogous tests for TestNG in the new
ClassLevelDirtiesContextTestNGTests class.

Furthermore, ContextCacheTestUtils and TrackingTestNGTestListener have
been introduced to reduce code duplication across the test suite.

Issue: SPR-12918
2015-04-17 17:26:38 +02:00
Sam Brannen c006b74e91 Make AbsTstCtxBootstrapper.resolveContextLoader protected
This commit increases the extensibility of
AbstractTestContextBootstrapper by making the resolveContextLoader()
and resolveExplicitContextLoaderClass() methods protected instead of
private.

Furthermore, resolveContextLoader() now throws an IllegalStateException
if getDefaultContextLoaderClass() returns null.

Issue: SPR-12682
2015-04-15 00:37:43 +02:00
Sam Brannen 063ef240c1 Support static fields in ReflectionTestUtils
Prior to this commit it was possible to set or get a static field using
ReflectionTestUtils but only if an instance of the target class was
available.

This commit introduces dedicated support for setting and getting static
fields in ReflectionTestUtils when only the target class is available.

Furthermore, this commit increases the robustness of
ReflectionTestUtilsTests regarding expected exceptions and simplifies
the Javadoc for ReflectionTestUtils.

Issue: SPR-6792
2015-04-08 22:32:00 -04:00
Rossen Stoyanchev 0b8554f94a Leave query un-encoded in MockMvc request builder
Issue: SPR-12880
2015-04-06 22:43:25 -04:00
Juergen Hoeller 4e1af7d195 Deprecated MatcherAssertionErrors in favor of the original org.hamcrest.MatcherAssert (v1.3)
As of JUnit 4.9 / Hamcrest 1.3, there is no real need for a custom copy of that class anymore.
2015-03-25 00:04:47 +01:00
Juergen Hoeller b2308926bc Restored isTypeMatch null behavior and refined typeToMatch parameter name
Issue: SPR-12147
2015-03-23 21:57:03 +01:00
Brian Clozel 7f845f7b5e Fix failing HeaderAssertionTests
Since SPR-11792, Last-Modified and ETag headers are also written in
`HTTP 304 Not Modified` responses. This is expected as per
https://tools.ietf.org/html/rfc7232#section-4.1 .

Those tests expected "Last-Modified" to be missing in case of HTTP 304
responses, which is not the case anymore since 953608ec .

Issue: SPR-11792
2015-03-23 18:50:32 +01:00
Sam Brannen e086a637d5 Introduce BEFORE METHOD/CLASS modes in @DirtiesContext
Prior to this commit, @DirtiesContext could only be used to close a
test ApplicationContext after an entire test class or after a test
method; however, there are some use cases for which it would be
beneficial to close a test ApplicationContext before a given test class
or test method -- for example, if some rogue (i.e., yet to be
determined) test within a large test suite has corrupted the original
configuration for the ApplicationContext.

This commit provides a solution to such testing challenges by
introducing the following modes for @DirtiesContext.

 - MethodMode.BEFORE_METHOD: configured via the new methodMode attribute

 - ClassMode.BEFORE_CLASS and ClassMode.BEFORE_EACH_TEST_METHOD: both
   configured via the existing classMode attribute

Issue: SPR-12429
2015-03-22 21:33:20 +01:00
Sam Brannen 6028a64444 Polish Javadoc for TestContext 2015-03-22 21:33:06 +01:00
Sam Brannen 3d2bde7156 Add tests that use the new generate-name attribute
This commit updates the Spr8849Tests test suite to include XML
configuration that guarantees that a unique database name is always
automatically generated (via the new 'generate-name' attribute that was
introduced in SPR-8849) while reusing the same bean name (i.e.,
'dataSource').

Issue: SPR-8849
2015-03-21 00:39:54 +01:00
Rossen Stoyanchev f06dffb714 Improve MockHttpServletRequest/Response charset parsing
Issue: SPR-12677
2015-03-20 16:12:46 -04:00
Sam Brannen ab771dfd97 Refactor tests to use the new database-name attribute
This commit refactors the XML configuration used by the tests in the
Spr8849Tests test suite so that a unique database name is always
generated (via the new 'database-name' attribute that was introduced in
SPR-12835) while reusing the same bean name (i.e., 'dataSource').

This is a much more robust alternative to the previous work-around
since the name of the DataSource does not randomly change across
application contexts, thus allowing proper autowiring by name and bean
referencing within XML configuration.

Issue: SPR-8849
2015-03-20 17:11:52 +01:00
Juergen Hoeller 778a01943b ResolvableType-based type matching at the BeanFactory API level
Issue: SPR-12147
2015-03-18 23:05:13 +01:00
Juergen Hoeller bc6a98c144 Polishing (in particular updating javadoc references to Apache Commons) 2015-03-13 18:19:10 +01:00
Sam Brannen e24a7ded62 Simplify Groovy ContextLoaders in the TCF
This commit simplifies the implementations of loadBeanDefinitions() in
GenericGroovyXmlContextLoader and GenericGroovyXmlWebContextLoader.

Due to the recent bug fix for GroovyBeanDefinitionReader regarding full
support for XML config files, these Groovy context loaders can now
simply use a GroovyBeanDefinitionReader instead of a
GroovyBeanDefinitionReader plus an XmlBeanDefinitionReader.

Issue: SPR-12769
2015-02-28 23:28:55 +01:00
Sam Brannen 2ba1151b7f Support XML config fully in web integration tests
Prior to this commit, it was impossible to use all features of XML
configuration (e.g., the <qualifier> tag) in web-based integration
tests (loaded using @WebAppConfiguration, @ContextConfiguration, etc.)
if the Groovy library was on the classpath. The reason is that the
GroovyBeanDefinitionReader used internally by
GenericGroovyXmlWebContextLoader disables XML validation for its
internal XmlBeanDefinitionReader, and this prevents some XML
configuration features from working properly. For example, the default
value for the 'type' attribute (defined in the spring-beans XSD) of the
<qualifier> tag gets ignored, resulting in an exception when the
application context is loaded.

This commit addresses this issue by refactoring the implementation of
loadBeanDefinitions() in GenericGroovyXmlWebContextLoader to use an
XmlBeanDefinitionReader or GroovyBeanDefinitionReader depending on the
file extension of the resource location from which bean definitions
should be loaded. This aligns the functionality of
GenericGroovyXmlWebContextLoader with the existing functionality of
GenericGroovyXmlContextLoader.

Issue: SPR-12768
2015-02-28 19:06:40 +01:00
Sam Brannen fa5ea38210 Delete unused import in AsyncTests 2015-02-28 19:05:37 +01:00
Stephane Nicoll babbf6e871 Harmonize resources location
Issue: SPR-12766
2015-02-28 10:32:40 +01:00
Rossen Stoyanchev c48858c972 Prevent ISE in the MockMvc PrintingResultHandler
Issue: SPR-12735
2015-02-27 11:30:12 -05:00
Rossen Stoyanchev e13c300b53 Fix white space issues 2015-02-27 10:53:34 -05:00
Rossen Stoyanchev 2beca4d75e Update javadoc 2015-02-26 11:45:50 -05:00
Rossen Stoyanchev 2dd5875964 Support @ControllerAdvice in StandaloneMockMvcBuilder
Issue: SPR-12751
2015-02-25 16:57:58 -05:00