Commit Graph

836 Commits

Author SHA1 Message Date
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
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
9b0729007f Polish MockHttpServletResponseTests 2020-08-01 12:26:38 +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
27e0febacf Polish MockHttpServletResponseTests 2020-07-26 09:57:25 +02:00
Rossen Stoyanchev
b16f6fa456 Shared static instance of DefaultDataBufferFactory 2020-06-24 16:12:56 +01:00
Sam Brannen
9d5881e0ad Suppress warnings, remove unused code, etc. 2020-06-20 17:15:35 +02:00
Rossen Stoyanchev
de0a043739 Add contains form data RequestMatcher
See gh-23671
2020-06-18 07:49:27 +01:00
Rossen Stoyanchev
bc33ae3f8b Update multipart RequestMatcher
See gh-23772
2020-06-18 07:49:27 +01:00
vspac
e01160db31 Multipart RequestMatcher's
See gh-23772
2020-06-18 07:49:27 +01:00
Sam Brannen
adc76a1d8f Suppress warnings in ResponseCreatorsTests 2020-06-14 19:45:51 +02:00
Rossen Stoyanchev
8d449471c7 Polishing contribution
See gh-25148
2020-05-29 17:37:43 +01:00
Mihai Dumitrescu
b31b8ce6c1 Polishing in MockServerHttpRequest
Closes gh-25109
2020-05-29 16:31:19 +01:00
Rossen Stoyanchev
875e7f8630 Match multiple values in HeaderAssertions
Closes gh-23878
2020-05-13 12:31:19 +01:00
Sam Brannen
715e8c9ef6 Align TransactionManagementConfigurer support in TCF with production
This commit picks up where 613bd3be1d
left off by ensuring that a transaction manager configured via the
TransactionManagementConfigurer API takes precedence over any
transaction manager configured as a bean in the ApplicationContext
unless @Transactional is configured with a qualifier for the explicit
transaction manager to use in tests.

Closes gh-24869
2020-05-11 13:59:34 +02:00
Sam Brannen
613bd3be1d Honor TxMgmtConfigurer when @Primary tx mgr is present in TCF
Prior to this commit, the Spring TestContext Framework (TCF) favored a
@Primary transaction manger over one configured via the
TransactionManagementConfigurer API, and this contradicts the behavior
in production Spring applications.

This commit aligns the transaction manger lookup within the TCF so that
a transaction manger configured via the TransactionManagementConfigurer
API is properly favored over a @Primary transaction manager.

Closes gh-24869
2020-05-09 20:09:27 +02:00
Sam Brannen
745cfcb161 Upgrade tests to TestNG 7.1
See gh-24298
2020-05-09 17:36:34 +02:00
Sam Brannen
12e05280ad Upgrade to AssertJ 3.16 2020-05-06 15:22:23 +02:00
Rossen Stoyanchev
5883ea2721 Polishing contribution
See gh-24926
2020-05-06 10:53:25 +01:00
Evgenii Koba
e15ed44a68 Make HtmlUnitRequestBuilder handle form data file properly
See gh-18551
2020-05-06 10:53:25 +01:00
Sam Brannen
1b4b4c3302 Support @TestConstructor config via JUnit Platform config param
This commit introduces support for setting the
spring.test.constructor.autowire.mode property via a JUnit Platform
configuration parameter -- for example, via the
junit-platform.properties file.

Closes gh-24285
2020-05-03 19:02:44 +02:00
Sam Brannen
6b410df45b Retain brackets for IPV6 address in MockHttpServletRequest
According to the Javadoc for ServletRequest's getServerName() method,
when the `Host` header is set, the server name is "the value of the
part before ':' in the Host header value ...". For a value representing
an IPV6 address such as `[::ffff:abcd:abcd]`, the enclosing square
brackets should therefore not be stripped from the enclosed IPV6
address.

However, the changes made in conjunction with gh-16704 introduced a
regression in Spring Framework 4.1 for the getServerName() method in
MockHttpServletRequest by stripping the enclosing brackets from the
IPV6 address in the `Host` header. Similarly, the changes made in
conjunction with gh-20686 introduced a regression in Spring Framework
4.3.13 and 5.0.2 in the getRequestURL() method in
MockHttpServletRequest by delegating to the getServerName() method
which strips the enclosing brackets.

This commit fixes the implementation of getServerName() so that the
enclosing brackets are no longer stripped from an IPV6 address in the
`Host` header. The implementation of getRequestURL() is therefore also
fixed.

In addition, in order to avoid a NullPointerException, the
implementations of getServerName() and getServerPort() now assert that
an IPV6 address present in the `Host` header correctly contains an
opening and closing bracket and throw an IllegalStateException if that
is not the case.

Closes gh-24916
2020-04-17 15:01:35 +02:00
Sam Brannen
0017256968 Test that @TestConstructor can be used as a meta-annotation 2020-04-17 13:29:33 +02:00
Sam Brannen
a5498ba2ad Test status quo for @Primary + TransactionManagementConfigurer in TCF
This commit introduces an integration test for the status quo in the
Spring TestContext Framework (TCF) for multiple transaction managers
registered as @Primary and via the TransactionManagementConfigurer API.

In Spring Framework 5.3 we will revise the transaction manager lookup in
TestContextTransactionUtils so that the transaction manager configured
via the TransactionManagementConfigurer API is favored over a @Primary
transaction manager.

See gh-24869
2020-04-06 19:11:53 +02:00
Sam Brannen
a42944d364 Consolidate TxMgr lookup tests in the TCF
This commit consolidates TransactionManager lookup tests in the Spring
TestContext Framework (TCF), migrates some to JUnit Jupiter, simplifies
their implementations, and removes duplicated test cases.
2020-04-06 18:21:48 +02:00
Sam Brannen
a842434bff Document precedence for @DynamicPropertySource
Closes gh-24837
2020-04-01 18:09:31 +02:00
陈其苗
13970ae528 Use autoboxing instead of explicit wrapping in tests
Closes gh-24801
2020-04-01 14:34:20 +02:00
Rossen Stoyanchev
a606fb4b21 Fix checkstyle errors 2020-03-26 22:02:32 +00:00
Rossen Stoyanchev
3175f0771e Remove dumpString from DataBufferTestUtils
See gh-24786
2020-03-26 21:42:12 +00:00
Sam Brannen
cf7daa36c8 Add @DynamicPropertySource support in TestContext framework
This commit introduces a @DynamicPropertySource annotation that can be
used on methods in test classes that want to add properties to the
Environment with a dynamically supplied value.

This new feature can be used in conjunction with Testcontainers and
other frameworks that manage resources outside the lifecycle of a
test's ApplicationContext.

Closes gh-24540

Co-authored-by: Phillip Webb <pwebb@pivotal.io>
2020-03-23 17:10:18 +01:00
Qimiao Chen
09b36380cd Fix typos in source files
Closes gh-24746
2020-03-20 20:06:52 +01:00
Rossen Stoyanchev
a134e92e7f Improve checks on URI string in MockMvc request builder
Closes gh-24556
2020-02-20 15:07:40 +00:00
Sam Brannen
05301d24c1 Upgrade to JUnit Jupiter 5.6
Closes gh-24299
2020-02-13 15:44:58 +01:00
Rossen Stoyanchev
009dfbfafc MockRestServiceServer clears failed requests map
Closes gh-24486
2020-02-10 15:01:47 +00:00
Sam Brannen
cbb037bc68 Suppress deprecation warning in spring-test 2020-01-31 14:37:40 +01:00
Sam Brannen
7b6d83a106 Use Gradle test fixture support for spring-web
See gh-23550
2020-01-02 16:01:35 +01:00
Sam Brannen
5581f3b77b Use Gradle test fixture support for spring-tx
See gh-23550
2020-01-02 16:01:35 +01:00
Sam Brannen
7cd4ddf5fc Rename test fixture package in spring-beans
See gh-23550
2020-01-02 16:01:35 +01:00
Sam Brannen
4260c34b47 Rename test fixture package in spring-core
See gh-23550
2020-01-02 16:01:34 +01:00
Sam Brannen
61d4ee594d Use Gradle test fixture support for spring-beans and spring-context
See gh-23550
2020-01-02 16:01:34 +01:00