Commit Graph

1733 Commits

Author SHA1 Message Date
Sam Brannen 31316a11fd Polishing 2020-09-11 16:37:11 +02:00
Arjen Poutsma d550d344d5 Respect context path in WebMvc.fn & WebFlux.fn
This commit makes several changes in both WebMvc.fn as well as
WebFlux.fn.

 - ServerRequest now exposes a RequestPath through requestPath(), and
   pathContainer() has been deprecated.

 - The PathPredicate and PathResourceLookupFunction now respects this
   RequestPath's pathInApplication() in their path-related
   functionality.

 - When nesting, the PathPredicate now appends the matched part of the
   path to the current context path, instead of removing the matched
   part (which was done previously). This has the same result: the
   matched part is gone, but now the full path stays the same.

Closes gh-25270
2020-09-03 15:10:56 +02:00
Rossen Stoyanchev 25165f552d Remove erroneously committed change 2020-09-01 09:42:38 +01:00
Rossen Stoyanchev e34c800467 More updates to Web testing section
See gh-19647
2020-09-01 08:56:57 +01:00
Rossen Stoyanchev 9b6476c0a1 Rename MockMvcTestClient to MockMvcWebTestClient
Closes gh-19647
2020-08-31 21:15:17 +01:00
Сергей Цыпанов 1f3e52d932 gh-25650 Replace remaining usage of LinkedList with ArrayList in tests 2020-08-31 14:33:14 +02:00
Juergen Hoeller 0f2cc53be7 Merge branch '5.2.x'
# Conflicts:
#	build.gradle
2020-08-27 17:32:20 +02:00
Juergen Hoeller 71e70aed14 Polishing 2020-08-27 17:13:33 +02:00
Rossen Stoyanchev 568b44eb9d Consistent generics in spring-test Matcher declarations
Closes gh-25610
2020-08-27 10:50:30 +01:00
Juergen Hoeller 874574513c Replace remaining usage of LinkedList with ArrayList/ArrayDeque
Closes gh-25650
2020-08-26 18:32:08 +02:00
Juergen Hoeller 7324140d20 Merge branch '5.2.x' 2020-08-25 16:21:00 +02:00
Juergen Hoeller 6f0461c569 Polishing 2020-08-25 16:17:22 +02:00
Juergen Hoeller 04df9b8f49 Efficient checks for empty strings and single character matches
Closes gh-25552
Closes gh-25553
2020-08-25 16:17:12 +02:00
Rossen Stoyanchev 7adeb461e0 WebClient exposes API for access to native request
Closes gh-25115, gh-25493
2020-08-24 07:58:35 +01:00
Rossen Stoyanchev 3426e6274c Add MockMvcTestClient
See gh-19647
2020-08-19 21:15:20 +01:00
Rossen Stoyanchev 128acaff8a WebTestClient cookie assertion support
See gh-19647
2020-08-19 21:15:20 +01:00
Rossen Stoyanchev 6e8bb6c4a9 WebTestClient header assertion improvements
Provides parity with similar options in MockMvc:
 - compare header using a long value
 - compare header using a date/time value
 - dedicated method for "Location" header (redirect)
 - let Hamcrest assert a header even when missing

See gh-19647
2020-08-19 21:14:13 +01:00
Rossen Stoyanchev f500ab0f9b Add mechanism to expose mock server results
WebTestClient is an actual client and generally it's only possible
to assert the client response (i.e. what goes over HTTP). However,
in a mock server scenario technically we have access to the server
request and response and can make those available for further
assertions.

This will be helpful for the WebTestClient integration with MockMvc
where many more assertions can be performed on the server request
and response when needed.

See gh-19647
2020-08-19 21:14:13 +01:00
Rossen Stoyanchev cb02b0e776 WebTestClient releases body on returnResult(Void.class)
The original behavior was to ignore the body which came with odd
warnings in the Javadoc and potential leaks that could be reported
from tests causing unnecessary concern.

This change causes the body to be released and effectively still
ignores it but minus the potential leaks.

See gh-19647
2020-08-19 21:14:13 +01:00
Rossen Stoyanchev dd7369df48 WiretapConnector.Info is private
The claimRequest method was not intended to be public and couldn't
have been used since the Info type it returned was package private.
This change completely hides the Info.

See gh-19647
2020-08-19 21:14:13 +01:00
Rossen Stoyanchev 4116e6dd18 Pull up method to ConfiugrableMockMvcBuilder
See gh-19647
2020-08-19 21:13:17 +01:00
Rossen Stoyanchev 443e9ee618 MockMvc applies StandardMultipartHttpServletRequest wrapper
This is necessary to correctly process multipart requests and resolve
@RequestPart arguments and MultipartFile arguments.

Closes gh-25602
2020-08-19 09:06:20 +01:00
Sam Brannen 50b20c2bb7 Merge branch '5.2.x' 2020-08-17 16:01:32 +02:00
Sam Brannen d939016a09 Polish contribution
See gh-25600
2020-08-17 15:53:45 +02:00
Maciej Miklas a83529c844 Introduce createContext() factory method in AbstractGenericContextLoader
Prior to this commit it was possible to configure the
DefaultListableBeanFactory used by the GenericApplicationContext
created by AbstractGenericContextLoader, but it was not possible to
completely replace the bean factory.

This commit introduces a new createContext() factory method in
AbstractGenericContextLoader which indirectly allows subclasses to
supply a custom DefaultListableBeanFactory implementation to the
GenericApplicationContext.

Closes gh-25600
2020-08-17 15:38:24 +02:00
Sam Brannen 32e851617e Fix Javadoc formatting in GenericGroovyXmlContextLoader 2020-08-17 15:37:51 +02:00
Sam Brannen 13183c89ce Update tests due to deprecations in Reactor 2020-08-12 13:46:32 +02:00
Sam Brannen c558391e2c Declare interfaces as @FunctionalInterface where feasible
This commit declares each of the following public interfaces as a
@FunctionalInterface.

- org.springframework.context.ApplicationContextInitializer
- org.springframework.test.web.servlet.DispatcherServletCustomizer
- org.springframework.validation.MessageCodeFormatter
- org.springframework.util.IdGenerator
- org.springframework.beans.factory.config.YamlProcessor.MatchCallback
- org.springframework.beans.factory.config.YamlProcessor.DocumentMatcher

Closes gh-25580
2020-08-11 17:01:03 +02:00
Sam Brannen 5de549d7d4 Update contentType property via MockHttpServletResponse::setCharacterEncoding()
Prior to this commit, MockHttpServletResponse's setCharacterEncoding()
method did not update the contentType property, which violates the
Servlet 2.4 Javadoc for getContentType() and setCharacterEncoding().

This commit addresses this issue; however, some existing tests may have
to be updated as a result of this change.

For example, note how some of the tests in this commit have been
refactored to use MediaType##isCompatibleWith() instead of asserting
exact matches for the value returned by MockHttpServletResponse's
getContentType() method.

Closes gh-25536
2020-08-10 16:05:18 +02:00
Sam Brannen c5bb5d6c03 Polish ViewResolutionTests 2020-08-10 15:31:51 +02:00
Brian Clozel 617ec359bd Update after MonoProcessor deprecation in Reactor
This commit adapts the usage of `MonoProcessor` after deprecations
introduced in reactor/reactor-core#1053
2020-08-07 18:59:21 +02:00
Juergen Hoeller b345019415 Introduce getBeanProvider variants with allowEagerInit flag
Closes gh-25559
2020-08-07 12:07:13 +02:00
Sam Brannen dded51fa80 Merge branch '5.2.x' 2020-08-05 17:47:44 +02:00
Sam Brannen 96da1ff9ea Support @RestControllerAdvice in Standalone MockMvc again
Since Spring Framework 5.2, @RestControllerAdvice registered with
MockMvc when using MockMvcBuilders.standaloneSetup() has no longer been
properly supported if annotation attributes were declared in the
@RestControllerAdvice annotation. Prior to 5.2, this was not an issue.

The cause for this regression is two-fold.

1. Commit 50c257794f refactored
   DefaultListableBeanFactory so that findAnnotationOnBean() supports
   merged annotations; however, that commit did not refactor
   StaticListableBeanFactory#findAnnotationOnBean() to support merged
   annotations.

2. Commit 978adbdae7 refactored
   ControllerAdviceBean so that a merged @ControllerAdvice annotation
   is only looked up via ApplicationContext#findAnnotationOnBean().

The latter relies on the fact that findAnnotationOnBean() supports
merged annotations (e.g., @RestControllerAdvice as a merged instance of
@ControllerAdvice). Behind the scenes, MockMvcBuilders.standaloneSetup()
creates a StubWebApplicationContext which internally uses a
StubBeanFactory which extends StaticListableBeanFactory. Consequently,
since the implementation of findAnnotationOnBean() in
StaticListableBeanFactory was not updated to support merged annotations
like it was in DefaultListableBeanFactory, we only see this regression
with the standalone MockMvc support and not with MockMvc support for an
existing WebApplicationContext or with standard Spring applications
using an ApplicationContext that uses DefaultListableBeanFactory.

This commit fixes this regression by supporting merged annotations in
StaticListableBeanFactory#findAnnotationOnBean() as well.

Closes gh-25520
2020-08-05 17:40:16 +02:00
Sam Brannen 40fc472c70 Polish ExceptionHandlerTests 2020-08-05 17:24:45 +02:00
Sam Brannen d646e602d9 Merge branch '5.2.x' 2020-08-03 12:19:49 +02:00
Sam Brannen 969aa8ad47 Update copyright date 2020-08-03 12:19:21 +02:00
Sam Brannen d8554c498c Merge branch '5.2.x' 2020-08-01 16:42:31 +02:00
Sam Brannen 482adb9478 Fix error message for type mismatch in jsonPath().value()
Prior to this commit, if a value existed at the specified JSON path but
had an incompatible type, the AssertionError thrown contained a message
stating that the value did not exist (i.e., "No Value at JSON Path"),
which was not only misleading but also technically incorrect.

This commit fixes the error message for such use cases. For example, the
AssertionError thrown in such use cases now resembles the following.

  At JSON path "$.name", value <Lisa> of type <java.lang.String> cannot
  be converted to type <byte[]>

Closes gh-25480
2020-08-01 16:35:54 +02:00
Sam Brannen 5a12e7b2c5 Fix typo in test method names 2020-08-01 16:30:12 +02:00
Sam Brannen 58412affaa Merge branch '5.2.x' 2020-08-01 14:02:22 +02:00
Sam Brannen 5576321b04 Reset charset field in MockHttpServletResponse
Prior to this commit, calling reset() on MockHttpServletResponse did not
reset the `charset` field to `false` which could result in the
"Content-Type" header containing `;charset=null` which in turn would
result in errors when parsing the "Content-Type" header.

This commit resets the charset field to `false` in
MockHttpServletResponse's reset() method to avoid such errors.

Closes gh-25501
2020-08-01 14:01:39 +02:00
Sam Brannen 89bb9cb749 Polish Javadoc 2020-08-01 12:26:56 +02:00
Sam Brannen 9b0729007f Polish MockHttpServletResponseTests 2020-08-01 12:26:38 +02:00
Brian Clozel 9aae5ed3fa Update Reactor Netty modules
Since reactor/reactor-netty#739, the `reactor-netty` module is now split
into two: `reactor-netty-core` and `reactor-netty-http`.

This commit updates the Spring Framework build accordingly.
2020-08-01 11:49:15 +02:00
Sam Brannen 86c52a842f Support multiple Content-Language values in MockHttpServletResponse
Prior to this commit, if the user supplied a comma-separated list such
as "en, it" as the Content-Language header value to
MockHttpServletResponse's setHeader() method, only the first language
was actually set in the response's Content-Language header (e.g., "en").

This commit ensures that all supplied content languages are set in the
response's Content-Language header.

Closes gh-25281
2020-07-27 17:47:46 +02:00
Sam Brannen d2db43a900 Polish Javadoc 2020-07-27 14:38:24 +02:00
Sam Brannen 27e0febacf Polish MockHttpServletResponseTests 2020-07-26 09:57:25 +02:00
XenoAmess ab859fcc96 Refine use of substring operations
Closes gh-25445
2020-07-22 17:26:42 +02:00
XenoAmess edfc6c0293 Refine use of substring operations
Closes gh-25445
2020-07-22 16:28:58 +02:00