Commit Graph

526 Commits

Author SHA1 Message Date
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