Commit Graph

420 Commits

Author SHA1 Message Date
Sam Brannen
8748ba4c4b Suppress warning in SpringFailOnTimeoutTests 2018-04-14 16:46:57 +02:00
Sam Brannen
fecbcd4e93 Expand scope of SpringFailOnTimeoutTests
Issue: SPR-16716
2018-04-12 10:58:21 +02:00
Igor Suhorukov
59396e1a6f Throw exception from user code in SpringFailOnTimeout even if a timeout occurs
Issue: SPR-16717
2018-04-12 10:58:21 +02:00
Rossen Stoyanchev
6deee3e818 TestDispatcherServlet unwraps to find mock request
Issue: SPR-16695
2018-04-06 11:21:25 -04:00
Rossen Stoyanchev
6e4bbac6f7 MvcResult returns asyncResult after asyncDispatch
Issue: SPR-16648
2018-03-28 22:27:30 -04:00
Sam Brannen
68463e2018 Support target type in JsonPath assertions for MockMvc results
This commit picks up where SPR-14498 left off by adding support for an
explicit target type when using JsonPath to perform an assertion against
the response content using a Hamcrest Matcher.

Specifically, there is a new overloaded value(Matcher<T>, Class<T>)
method in JsonPathResultMatchers for use with Hamcrest matchers where
the target type (i.e., Class<T>) can be specified.

Issue: SPR-16587
2018-03-13 16:06:39 +01:00
Juergen Hoeller
bd6b7b08f3 Concurrency and exception message refinements for test transactions
(cherry picked from commit a0cc800)
2018-03-05 13:40:13 +01:00
Juergen Hoeller
073e78b68d Polishing 2018-02-25 15:04:19 +01:00
Juergen Hoeller
722cb36e01 Consistent Class array vs vararg declarations (and related polishing)
(cherry picked from commit 3b810f3)
2018-02-14 16:38:28 +01:00
Rossen Stoyanchev
fe4472dbeb MockHttpServletRequestBuilder decodes pathInfo
Previously MockHttpServletRequestBuilder calculated the pathInfo from the
provided URL without decoding the value. This meant that the pathInfo
incorrectly included URL encoded values.

Now MockHttpServletRequestBuilder properly decodes the pathInfo.

Backport of #0cd427bdd35e668dda6332ae2885d94c222d9c49.

Fixes: SPR-16453
2018-02-02 15:17:58 -05:00
Rossen Stoyanchev
0a30b71dc3 Fix failing tests caused by previous commit 2018-01-12 12:36:24 -05:00
Juergen Hoeller
a88c47a120 Properly handle follow-up request after failure
Issue: SPR-16132
2017-11-14 12:30:04 +01:00
Juergen Hoeller
dc0a934c99 MockHttpServletResponse.getDateHeader returns -1 for non-existent header
Includes consistent getDateHeader results in both MockHttpServletResponse variants (spring-test and spring-web)

Issue: SPR-16160

(cherry picked from commit 80a0cf7)
2017-11-14 12:26:32 +01:00
Juergen Hoeller
9ca4de1ccf MockHttpServletRequest.getRequestURL aligns with getServerName/Port
Issue: SPR-16138

(cherry picked from commit 0edf4d6)
2017-11-14 12:25:55 +01:00
Juergen Hoeller
fa2c377405 Downgrade to AspectJ 1.8.9 and merge EhCache 3 tests into spring-context-support
Includes latest applicable updates (Jackson 2.8.10, OkHttp 3.8.1, Undertow 1.3.31, Netty 4.1.15)

Issue: SPR-15836
Issue: SPR-15880
2017-09-08 19:41:27 +02:00
Rossen Stoyanchev
8d743181da Fix MockMvc + HttpPutFormContentFilter issue
Issue: SPR-15753
2017-07-11 12:03:07 +02:00
Juergen Hoeller
a17255a2e3 SimpleRequestExpectationManager properly handles sequential requests with different count
Issue: SPR-15672
(cherry picked from commit efb735a)
2017-06-30 16:06:39 +02:00
Juergen Hoeller
9b647021f7 Allow for HttpOnly cookie result matcher
Issue: SPR-15488
(cherry picked from commit 04f0f13)
2017-05-04 14:00:37 +02:00
Juergen Hoeller
38089d8e66 Correct attributeHasNoErrors message in ModelResultMatchers
Includes consistent name quoting.

Issue: SPR-15487
(cherry picked from commit 0479dc9)
2017-05-04 14:00:15 +02:00
Juergen Hoeller
21ac764e5c Polishing 2017-03-24 13:41:34 +01:00
Juergen Hoeller
98dbc17591 Polishing 2017-03-07 10:33:48 +01:00
Juergen Hoeller
eff285eb3b MockHttpServletRequest exposes "HTTP/1.1" as default protocol
Issue: SPR-15232
(cherry picked from commit ed85337)
2017-02-10 11:46:42 +01:00
Juergen Hoeller
28849e0987 Revisit Assert to avoid single-arg assert methods (with refined messages)
Issue: SPR-15196
(cherry picked from commit 1b2dc36)
2017-01-31 10:28:46 +01:00
Rossen Stoyanchev
c8b0ff2fca Add ExpectedCount#never()
Issue: SPR-15168
2017-01-20 17:11:09 -05:00
Juergen Hoeller
c5500b2332 MockHttpServletRequestBuilder supports multiple locales
Includes revised content type handling.

Issue: SPR-15116
(cherry picked from commit 02d727f)
2017-01-12 22:50:50 +01:00
Rossen Stoyanchev
b14d189db9 MockRestRequestMatchers can match query params
Issue: SPR-14995
2016-12-13 16:07:19 -05:00
Rossen Stoyanchev
872d6ef55a HtmlUnitRequestBuilder detects form encoding type
Issue: SPR-14916
2016-11-28 18:08:44 -05:00
Juergen Hoeller
7e7504f5ea Polishing 2016-11-03 23:20:33 +01:00
Stephane Nicoll
1e3012cb49 Allow to customize TestDispatcherServlet
This commit introduces the `DispatcherServletCustomizer` callback
interface that can be used to customize the `DispatcherServlet` that a
`MockMvc` is using.

Previously, only the `dispatchOptions` flag can be customized. This
commit allows to customize any property of `DispatcherServlet` before it
is initialized.

Issue: SPR-14277
2016-10-29 11:09:48 +02:00
Juergen Hoeller
430180aa96 Polishing 2016-08-26 18:33:13 +02:00
Rossen Stoyanchev
d09b0fe83a Support target type in JsonPath assertions
This change adds support for a target type in JsonPath assertions in
Spring MVC Test.

The existing assertValue(String expression, Object expectedValue)
transparently falls back on using an alternative JsonPath API that
allows specifying the target type to coerce to.

There is also a new overloaded method
assertValue(String expression, Matcher<T> matcher, Class<T> targetType)
for use with Hamcrest matchers where the target type can be specified.

Issue: SPR-14498
(cherry picked from commit 7fdb892)
2016-08-26 17:28:37 +02:00
Juergen Hoeller
2a82b8fed9 Consistent use of Charset.forName over JDK 7 StandardCharsets in 4.x line 2016-08-26 13:11:39 +02:00
Rob Winch
43faabd4cc Fix HtmlUnitRequestBuilder merge
Previously invoking HtmlUnitRequestBuilder merge caused the pathInfo of
the parent to be corrupted. This could additional invocations with the
same parent.

This fix ensures that the parent is no longer directly used. Instead,
we create a copy of the parent by merging the parent that was passed in
with the copy.

Fixes SPR-14584
2016-08-12 20:49:48 -05:00
Juergen Hoeller
67f0b1986c Consistent spelling for StandaloneMockMvcBuilder's addPlaceholderValue
(cherry picked from commit a4b6682)
2016-08-10 14:57:43 +02:00
Juergen Hoeller
4627545a3b Polishing
(cherry picked from commit eae079a)
2016-08-09 11:03:51 +02:00
Vladimir L
df556333a8 Add StreamingResponseBody MockMvc sample tests
Issue: SPR-14456
(cherry picked from 7da63c)
2016-07-19 10:48:29 -04:00
Juergen Hoeller
3c14911401 Polishing 2016-07-06 17:59:49 +02:00
Sam Brannen
f7dd757593 Support WebSocket ServletServerContainerFB in the TCF
Prior to this commit, any attempt to include a bean of type
ServletServerContainerFactoryBean in the WebApplicationContext for an
integration test class annotated with @WebAppConfiguration in
conjunction the Spring TestContext Framework (TCF) would have resulted
in an IllegalStateException stating that "A ServletContext is required
to access the javax.websocket.server.ServerContainer instance."

In such scenarios, the MockServletContext was in fact present in the
WebApplicationContext; however there was no WebSocket ServerContainer
stored in the ServletContext.

This commit addresses this issue by introducing the following.

- MockServerContainer: a private mock implementation of the
  javax.websocket.server.ServerContainer interface.

- MockServerContainerContextCustomizer: a ContextCustomizer that
  instantiates a new MockServerContainer and stores it in the
  ServletContext under the attribute named
  "javax.websocket.server.ServerContainer".

- MockServerContainerContextCustomizerFactory: a
  ContextCustomizerFactory which creates a
  MockServerContainerContextCustomizer if WebSocket support is present
  in the classpath and the test class is annotated with
  @WebAppConfiguration. This factory is registered by default via the
  spring.factories mechanism.

Issue: SPR-14367
2016-06-22 22:10:16 +02:00
nkjackzhang
981a748dcc Fix ambiguous static import in TestPropertySourceUtilsTests 2016-06-17 17:18:36 +02:00
Sam Brannen
045ee52232 Invoke target.toString() safely in ReflectionTestUtils
ReflectionTestUtils invokes toString() on target objects in order to
build exception and logging messages, and prior to this commit problems
could occur if the invocation of toString() threw an exception.

This commit addresses this issue by ensuring that all invocations of
toString() on target objects within ReflectionTestUtils are performed
safely within try-catch blocks.

Issue: SPR-14363
2016-06-14 20:08:26 +02:00
Sam Brannen
eaa9511921 Avoid ClassCastException in HandlerResultMatchers.methodCall() 2016-06-07 16:13:42 +02:00
Sam Brannen
5a0100111e Polish HandlerAssertionTests 2016-06-07 16:13:42 +02:00
Sam Brannen
c19740a020 Clean up warnings in spring-test 2016-06-06 18:54:16 +02:00
Rossen Stoyanchev
998b83ce8c Fix hardcoded value MockRestServiceServerBuilder 2016-06-06 08:46:50 -04:00
Rob Winch
54f84cbd97 MockMvcWebConnection stores cookies from response
Previously MockMvcWebConnection did not update the cookie manager with the
cookies from MockHttpServletResponse. This meant that newly added cookies
are not saved to the cookie manager and thus are not presented in the next
request.

This commit ensures that MockMvcWebConnection stores the response cookies
in the cookie manager.

Issue: SPR-14265
2016-05-31 12:43:58 -04:00
Juergen Hoeller
822e40e24f AssertionErrors.assertEquals exposes readable array representation
Issue: SPR-14281
2016-05-30 17:16:03 +02:00
Sam Brannen
31a93792b2 Delete unused imports 2016-05-27 16:33:43 +02:00
Rossen Stoyanchev
4e8754ea87 Add reset() to MockRestServiceServer
Issue: SPR-14306
2016-05-26 11:44:40 -04:00
Rossen Stoyanchev
f4ab6d8d52 MockRestServiceServerBuilder can be re-used
Issue: SPR-14306
2016-05-26 09:48:16 -04:00
Sam Brannen
a1a87679da Support test annotations on interfaces
Prior to Java 8 it never really made much sense to author integration
tests using interfaces. Consequently, the Spring TestContext Framework
has never supported finding test-related annotations on interfaces in
its search algorithms.

However, Java 8's support for interface default methods introduces new
testing use cases for which it makes sense to declare test
configuration (e.g., @ContextConfiguration, etc.) on an interface
containing default methods instead of on an abstract base class.

This commit ensures that all non-repeatable, class-level test
annotations in the Spring TestContext Framework can now be declared on
test interfaces. The only test annotations that cannot be declared on
interfaces are therefore @Sql and @SqlGroup.

Issue: SPR-14184
2016-05-05 19:54:44 +02:00