Commit Graph

2025 Commits

Author SHA1 Message Date
Henning Poettker ed4e2289cd Support H2 1.4 & 2.0 in H2SequenceMaxValueIncrementer
Prior to this commit, H2SequenceMaxValueIncrementer only supported H2
database 1.4.

This commit updates H2SequenceMaxValueIncrementer's getSequenceQuery()
method so that the syntax used supports version 1.4 and 2.0 of the H2
database.

This commit also updates several test schemas so that they work with H2
1.4 and 2.0 as well as HSQL.

Closes gh-27870
2022-01-07 10:09:27 +01:00
Sam Brannen 61c3d7a989 Merge branch '5.3.x' 2022-01-04 14:09:02 +01:00
Sam Brannen 03668f9c10 Replace remaining use of StringBuffer with StringBuilder
Although this commit only applies to test classes, it serves to reduce
the noise when searching for undesirable usage of StringBuffer in
production code.
2022-01-04 14:06:13 +01:00
Sam Brannen 97625e3658 Additional changes because HttpMethod changed from enum to class
See gh-27697
2022-01-03 16:12:14 +01:00
Juergen Hoeller bfdb93b406 Merge branch '5.3.x'
# Conflicts:
#	build.gradle
#	src/docs/asciidoc/integration.adoc
2021-12-14 16:51:00 +01:00
Juergen Hoeller ca84559588 Provide findAnnotationOnBean variant with allowFactoryBeanInit flag
Closes gh-27796
2021-12-14 16:47:12 +01:00
Stephane Nicoll 8d93dc4abb Merge branch '5.3.x' 2021-12-14 14:05:18 +01:00
Stephane Nicoll b06d267232 Remove references to AsyncConfigurerSupport
Closes gh-27812
2021-12-14 13:59:05 +01:00
Juergen Hoeller 7f43128a0e Merge branch '5.3.x'
# Conflicts:
#	build.gradle
#	spring-web/src/main/java/org/springframework/web/server/MediaTypeNotSupportedStatusException.java
#	spring-web/src/main/java/org/springframework/web/util/ContentCachingRequestWrapper.java
#	spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java
2021-12-03 22:42:05 +01:00
Juergen Hoeller 14f24f43d7 Polishing 2021-12-03 22:36:31 +01:00
Arjen Poutsma 7a4207cd7b Changes because HttpMethod changed to class
This commit contains changes made because HttpMethod changed from enum
to class.

See gh-27697
2021-11-30 13:44:36 +01:00
Sam Brannen 44950bb862 Merge branch '5.3.x' 2021-11-30 12:27:41 +01:00
Sam Brannen 40d2058b97 Upgrade to JUnit 5.8.2
Closes gh-27744
2021-11-30 12:22:31 +01:00
김보배(Bobae Kim)/Platform Engineering팀/11ST 804b343cab Use parseInt without substring method 2021-11-25 16:14:59 +01:00
Sam Brannen 2be80b8fc8 Merge branch '5.3.x' 2021-11-18 19:23:49 +01:00
Sam Brannen c37d6c30a0 Fix nullability declarations in MergedContextConfiguration 2021-11-18 19:23:28 +01:00
Juergen Hoeller 4750a9430c Early removal of 5.x-deprecated code
Closes gh-27686
2021-11-18 09:18:06 +01:00
Christoph Dreis 5c972fcc54 Use Charset variants of URLEncoder and URLDecoder methods 2021-11-10 16:12:11 +01:00
SungMin 32af39d6e6
Use 'toString(Charset)' instead of 'toString(String)' for encodings (#27646)
Co-authored-by: 홍성민(SungMin Hong)/Platform Engineering팀/11ST <devmonster@11stcorp.com>
2021-11-10 15:11:33 +01:00
Juergen Hoeller 75036fa0ad Merge branch '5.3.x' 2021-11-10 14:22:58 +01:00
Juergen Hoeller 15a6373fed Avoid nullability warnings 2021-11-10 14:22:06 +01:00
Sam Brannen 32c14a2b42 Update Javadoc regarding repeatable annotation support 2021-10-29 11:04:01 +02:00
Sam Brannen d9e9a33b66 Merge branch '5.3.x' 2021-10-22 15:29:37 +02:00
xxpain 66826ac960 Fix typo in Javadoc in HeaderAssertions
Closes gh-27589
2021-10-22 15:28:27 +02:00
Sam Brannen b8fc79543d Polish tests and test fixtures in spring-test 2021-10-14 22:12:23 +02:00
Sam Brannen fba92c0120 Update copyright date 2021-10-14 16:03:39 +02:00
Sam Brannen 940a37f9ce Apply "final fields" Eclipse clean-up in spring-test
This has only been applied to `src/main/java`.
2021-10-14 15:53:54 +02:00
Sam Brannen 7e4870577d Apply "instanceof pattern matching" Eclipse clean-up in spring-test
This has only been applied to `src/main/java`.
2021-10-14 15:50:36 +02:00
Sam Brannen 373b90d263 Simplify JsonPathExpectationsHelperTests with text blocks 2021-10-13 20:43:13 +02:00
Sam Brannen 1ef47fa369 Use instanceof pattern matching in select classes in spring-test 2021-10-13 20:41:49 +02:00
Koen Punt 50b92118a9 Include correct keyword in CookieAssertions failure messages
Closes gh-27550
2021-10-13 14:02:55 +02:00
Koen Punt daf10d6c45
Include correct keyword in CookieAssertions failure messages
Closes gh-27550
2021-10-13 14:00:29 +02:00
Sam Brannen f479668938 Merge branch '5.3.x' 2021-10-11 15:00:00 +02:00
Sam Brannen 63fac1b7c8 Allow default CacheAwareContextLoaderDelegate configuration via system property
Prior to this commit, the default CacheAwareContextLoaderDelegate could
be configured by extending AbstractTestContextBootstrapper and
overriding getCacheAwareContextLoaderDelegate(); however, this required
that the user configure the custom TestContextBootstrapper via
@BootstrapWith.

This commit introduces a new
"spring.test.context.default.CacheAwareContextLoaderDelegate" property
that can be configured via a JVM system property or via the
SpringProperties mechanism. BootstrapUtils uses this new property to
load the default CacheAwareContextLoaderDelegate. If the property is
not defined, BootstrapUtils will fall back to creating a
DefaultCacheAwareContextLoaderDelegate as it did previously.

This allows third parties to configure the default
CacheAwareContextLoaderDelegate transparently for the user -- for
example, to intercept context loading in order to load the context in a
different manner -- for example, to make use of ahead of time (AOT)
techniques for implementing a different type of ApplicationContext at
build time.

Closes gh-27540
2021-10-11 14:59:09 +02:00
Rossen Stoyanchev e3b48c23dd Remove AsyncRestTemplate and related types 2021-10-08 17:59:53 +01:00
Sam Brannen 2d1e0d5e38 Merge branch '5.3.x' 2021-10-06 12:13:21 +02:00
Sam Brannen 41ae9632d1 Upgrade to Checkstyle 9.0 and spring-javaformat 0.0.29
This commit upgrades the Gradle build to use Checkstyle 9.0 and
spring-javaformat 0.0.29 (which internally uses Checkstyle 8.45.1).

Closes gh-27520
2021-10-06 12:11:19 +02:00
Sam Brannen cb9246e481 Merge branch '5.3.x' 2021-10-01 10:36:28 +02:00
Sam Brannen f0aa4f4857 Escape closing curly braces in regular expressions for Android support
PR gh-24470 introduced a regression for Android users by no longer
escaping closing curly braces in regular expressions.

This commit therefore partially reverts the changes made in 273812f9c5
for closing curly braces (`}`).

Closes gh27467
2021-10-01 10:35:28 +02:00
Juergen Hoeller dc5807ea51 Merge branch '5.3.x'
# Conflicts:
#	spring-core/src/main/java/org/springframework/cglib/core/ReflectUtils.java
2021-09-30 17:37:28 +02:00
Juergen Hoeller 4f44ae3f28 Polishing 2021-09-30 17:34:22 +02:00
Sam Brannen 030ba52805 Merge branch '5.3.x' 2021-09-29 16:56:33 +02:00
Sam Brannen 96e4d3a530 Fail Gradle build for Javadoc warnings
In order to catch Javadoc errors in the build, we now enable the
`Xwerror` flag for the `javadoc` tool. In addition, we now use
`Xdoclint:syntax` instead of `Xdoclint:none` in order to validate
syntax within our Javadoc.

This commit fixes all resulting Javadoc errors and warnings.

This commit also upgrades to Undertow 2.2.12.Final and fixes the
artifact names for exclusions for the Servlet and annotations APIs.

The incorrect exclusion of the Servlet API resulted in the Servlet API
being on the classpath twice for the javadoc task, which resulted in the
following warnings in previous builds.

javadoc: warning - Multiple sources of package comments found for package "javax.servlet"
javadoc: warning - Multiple sources of package comments found for package "javax.servlet.http"
javadoc: warning - Multiple sources of package comments found for package "javax.servlet.descriptor"
javadoc: warning - Multiple sources of package comments found for package "javax.servlet.annotation"

Closes gh-27480
2021-09-29 14:02:37 +02:00
Sam Brannen 16bf39ea1b Merge branch '5.3.x' 2021-09-28 10:35:18 +02:00
Sam Brannen 2567b20949 Upgrade to spring-javaformat 0.0.28 and downgrade to Checkstyle 8.41
In order to be able to use text blocks and other new Java language
features, we are upgrading to a recent version of Checkstyle.

The latest version of spring-javaformat-checkstyle (0.0.28) is built
against Checkstyle 8.32 which does not include support for language
features such as text blocks. Support for text blocks was added in
Checkstyle 8.36.

In addition, there is a binary compatibility issue between
spring-javaformat-checkstyle 0.0.28 and Checkstyle 8.42. Thus we cannot
use Checkstyle 8.42 or higher.

In this commit, we therefore upgrade to spring-javaformat-checkstyle
0.0.28 and downgrade to Checkstyle 8.41.

This change is being applied to `5.3.x` as well as `main` in order to
benefit from the enhanced checking provided in more recent versions of
Checkstyle.

Closes gh-27481
2021-09-28 10:29:31 +02:00
Sam Brannen a247b83cd9 Ensure projects can be imported into Eclipse IDE with JDK 17
Prior to this commit, the Spring Framework projects could not be
imported into Eclipse IDE when using JDK 17 to build the projects.

The primary obstacle is the fact that Eclipse enforces a strict
"no split packages between the unnamed module and a system module" rule
when building with a "modular JDK" (such as JDK 17).

Resources:

- https://bugs.eclipse.org/bugs/show_bug.cgi?id=536928
- https://bugs.openjdk.java.net/browse/JDK-8215739
- http://mail.openjdk.java.net/pipermail/jigsaw-dev/2018-December/014077.html
- https://stackoverflow.com/questions/51094274/eclipse-cant-find-xml-related-classes-after-switching-build-path-to-jdk-10/53824670#53824670

Since the bug (JDK-8215739) has not been fixed in OpenJDK, the strict
"no split packages" rule does not apply to the Java compiler used in
Spring Framework's Gradle build or the compiler in IntelliJ IDEA. Hence,
this issue only arrises when building the framework in Eclipse IDE.

This commit addresses this issue in the following affected projects.

- spring-oxm: removal of the dependency on XPP3 which publishes
    javax.xml.namespace.QName as part of the JAR. The QName type is
    also published by the java.xml JDK 17 system module. To make the
    tests pass, we have switched to using the DomDriver instead of the
    XppDriver in our XStream tests.

- spring-test: HtmlUnit has a transitive dependency on xml-apis which
    publishes several packages also published by java.xml JDK 17 system
    module. Thus, we have explicitly excluded the transitive dependency
    on xml-apis for our `optional` configuration.

See gh-27407
2021-09-22 16:22:27 +02:00
Sam Brannen b808b53bcc Remove unnecessary cast in ContentRequestMatchers 2021-09-22 16:06:58 +02:00
Sam Brannen 69a46a7296 Merge branch '5.3.x' 2021-09-21 10:49:31 +02:00
Sam Brannen 28496059bc Make TestNG test methods public due to bug in TestNG TestEngine
This commit makes all test methods in our TestNG test classes public
due to the following bug in the TestNG engine for the JUnit Platform.

https://github.com/junit-team/testng-engine/issues/16

See gh-27407
2021-09-21 10:35:34 +02:00
Sam Brannen 40c51efee8 Introduce @Suite for TestNG tests
In order to allow developers to execute TestNG tests in Eclipse IDE
without installing the TestNG plugin for Eclipse, this commit introduces
a JUnit Platform @Suite class that can be executed within the IDE.

See gh-27407
2021-09-21 10:33:25 +02:00
Sam Brannen cf46384887 Merge branch '5.3.x' 2021-09-20 14:44:36 +02:00
Marc Philipp e29867b96e Exclude TestCase classes in spring-test build
When not excluded, TestNG will pick up nested TestCase classes and run
them.

This commit therefore filters out `*TestCase` test classes from the
build since these are not intended to be executed with the build.

See gh-27406
2021-09-20 14:02:06 +02:00
Sam Brannen 0b552a3534 Migrate to TestNG Engine for the JUnit Platform in spring-test
Prior to this commit, we had configured separate test tasks for JUnit
and TestNG. In addition, we configured a standard `test` task that
depended on the `junit` and `testNG` tasks, and we had an additional
`aggregateTestReports` task that aggregated the reports from the JUnit
and TestNG test tasks.

Thanks to the introduction of the "TestNG Engine for the JUnit
Platform", this commit simplifies our Gradle build in the spring-test
module by running JUnit 4, JUnit Jupiter, and TestNG tests on the JUnit
Platform in a single Gradle `test` task.

See gh-27406
2021-09-20 14:02:06 +02:00
Juergen Hoeller d84ca2ba90 Jakarta EE 9 migration
Upgrades many dependency declarations; removes old EJB 2.x support and outdated Servlet-based integrations (Commons FileUpload, FreeMarker JSP support, Tiles).

Closes gh-22093
Closes gh-25354
Closes gh-26185
Closes gh-27423
See gh-27424
2021-09-17 09:14:07 +02:00
Sam Brannen d55cbf8b4d Avoid use of deprecated API in aggregateTestReports task
See gh-26870
2021-09-13 16:52:00 +02:00
Sam Brannen 04e6b233ca Upgrade to JUnit 5.8
Closes gh-27392
2021-09-13 16:38:30 +02:00
Brian Clozel cecc0849a8 Upgrade to Gradle 7.2
This commit upgrades Gradle to 7.2.
Gradle configuration names are updated accordingly.
This also upgrades Gradle build plugins.

See gh-26870
2021-09-13 09:37:35 +02:00
Sam Brannen 19283c9245 Avoid accidental dependency on older version of Byte Buddy
This commit allows Mockito-based tests in spring-test to work again
in Eclipse IDE.

This problem was uncovered while fixing gh-27365
2021-09-07 11:33:32 +02:00
Sam Brannen d1a00b4301 Polishing
See gh-27230
2021-09-06 16:58:32 +02:00
Sam Brannen 87d3d1bbd1 Throw UnsupportedOperationException in defaultResponseCharacterEncoding()
This commit updates the defaultResponseCharacterEncoding() `default`
method in ConfigurableMockMvcBuilder so that it throws an
UnsupportedOperationException instead of silently ignoring the user's
request to set the default response character encoding.

Note, however, that AbstractMockMvcBuilder already overrides the
default method with a concrete implementation which is used by default
in MockMvc.

See gh-27230
2021-09-06 16:55:11 +02:00
Rossen Stoyanchev 1b3fd9edff Ensure one time logging for request details
Closes gh-26969
2021-09-06 13:56:54 +01:00
Rossen Stoyanchev 5ea7592d70 Polishing in ExchangeResult 2021-09-06 13:56:54 +01:00
Leeseojune 434cbab6a7
Update copyright date in tests in spring-test
Closes gh-27354
2021-09-03 10:50:50 +02:00
Sam Brannen 3c2dfebf4e Polish soft assertion support for WebTestClient
See gh-26969
2021-08-23 19:09:34 +02:00
Michal Rowicki 25dca40413 Introduce soft assertions for WebTestClient
It happens very often that WebTestClient is used in heavyweight
integration tests, and it's a hindrance to developer productivity to
fix one failed assertion after another. Soft assertions help a lot by
checking all conditions at once even if one of them fails.

This commit introduces a new expectAllSoftly(..) method in
WebTestClient to address this issue.

client.get().uri("/hello")
	.exchange()
	.expectAllSoftly(
		spec -> spec.expectStatus().isOk(),
		spec -> spec.expectBody(String.class).isEqualTo("Hello, World")
	);

Closes gh-26969
2021-08-23 19:09:23 +02:00
Sam Brannen dd9b99e13d Introduce ResultActions.andExpectAll() for soft assertions in MockMvc
Closes gh-26917
2021-08-23 15:27:07 +02:00
Sam Brannen cd078eaad8 Use ExceptionCollector for soft assertions in MockMvc
See gh-26917
2021-08-23 15:22:54 +02:00
Sam Brannen 5f47d3be22 Polish soft assertions for MockMvc
See gh-26917
2021-08-23 15:22:44 +02:00
Michal Rowicki 35bec8102b Introduce soft assertions for MockMvc
It happens very often that MockMvc is used in heavyweight integration
tests. It's no use to waste time to check if another condition has been
fixed or not. Soft assertions help a lot by checking all conditions at
once even if one of them fails.

See gh-26917

Co-authored-by: Sach Nguyen <sachnbbkhn@gmail.com>
2021-08-23 15:22:35 +02:00
Sam Brannen 4c153b80ee Make ExceptionCollector.Executable public
See gh-27316
2021-08-23 11:57:54 +02:00
Sam Brannen 81a6ba42a3 Introduce ExceptionCollector testing utility
This commit introduces a new ExceptionCollector testing utility in order
to support "soft assertion" use cases.

Closes gh-27316
2021-08-23 11:44:25 +02:00
Sam Brannen 8a7c4fc10d Support HtmlFileInput.setData() with HtmlUnit and MockMvc
Prior to this commit, if the user tested file upload support with
HtmlUnit and MockMvc by invoking HtmlFileInput.setData() instead of
HtmlFileInput.setFiles(), the in-memory file data was simply ignored.

This commit addresses this issue by creating a MockPart from the
in-memory data in HtmlUnitRequestBuilder.

Closes gh-27199
2021-08-22 17:44:14 +02:00
Sam Brannen 7da7a976e6 Document when prepareTestInstance() is invoked by the SpringMethodRule
Closes gh-27305
2021-08-22 15:56:58 +02:00
izeye 86ef0236e6 Polish printMvcResultsToWriterWithFailingGlobalResultMatcher()
See gh-27238
2021-08-04 08:29:26 +02:00
Sam Brannen bd1f5bd9fc Support Charset for character encoding in MockMvc
To improve the developer experience and avoid the use of String
literals, this commit provides overloaded support via Charset for
character encoding in MockHttpServletRequestBuilder and
ContentResultMatchers.

Closes gh-27231
2021-07-30 15:24:47 +02:00
Sam Brannen 4d115eef91 Polishing 2021-07-30 15:20:44 +02:00
Sam Brannen 0f421f9f86 Support default character encoding for response in MockMvc
Commit e4b9b1fadb introduced support for setting the default character
encoding in MockHttpServletResponse.

This commit introduces support for configuring the default character
encoding in the underlying MockHttpServletResponse used in MockMvc.

Closes gh-27230
2021-07-30 14:42:45 +02:00
Sam Brannen 41fa199178 Polish PrintingResultHandler 2021-07-29 19:43:54 +02:00
Sam Brannen 881fa889fc Apply global ResultHandlers before ResultMatchers in MockMvc
Prior to this commit, MockMvc applied global ResultMatchers before
global ResultHandlers. This lead to unexpected scenarios where a
failing matcher would prevent a handler from being applied.

One concrete use case is `alwaysDo(print(System.err))` which should
print out MockMvc results for debugging purposes. However, if MockMvc is
configured with something like `alwaysExpect(content().string("?"))`
and the expectation fails, the user will never see the expected debug
output to help diagnose the problem.

This commit addresses this issue by applying global ResultHandlers
before ResultMatchers in MockMvc.

Closes gh-27225
2021-07-29 19:18:18 +02:00
Sam Brannen e4b9b1fadb Introduce setDefaultCharacterEncoding() in MockHttpServletResponse
Prior to this commit, it was possible to set the character encoding
in MockHttpServletResponse via setCharacterEncoding() or
setContentType(); however, those methods append "charset=..." to the
Content-Type header which may not be an acceptable side effect.

This commit addresses this shortcoming by introducing a new
setDefaultCharacterEncoding() in MockHttpServletResponse which allows
one to override the previously hard coded value of "ISO-8859-1". In
addition, setDefaultCharacterEncoding() does not modify the Content-Type
header.

The reset() method has also been updated to reset the character encoding
to the configured default character encoding.

Closes gh-27214
2021-07-29 16:02:58 +02:00
Sam Brannen 5b3f11c543 Add @Nullable to setLocale in MockHttpServletResponse
See gh-26493
2021-07-29 14:47:31 +02:00
Sam Brannen 96ee8a3bc7 Ensure characterEncoding in MockHttpServletResponse is non-null
Closes gh-27219
2021-07-29 14:40:01 +02:00
Sam Brannen 403e04c0b4 Polish MockHttpServletResponse 2021-07-28 11:27:56 +02:00
Juergen Hoeller acb2aec3dd Compatibility with HtmlUnit 2.51
Includes upgrade to Tomcat 9.0.50, Jetty 9.4.43, Jackson 2.12.4.

Closes gh-27147
2021-07-09 13:22:34 +02:00
Sam Brannen a2ef6badc4 Use StringBuilder.append(char) where possible
To slightly improve performance, this commit switches to
StringBuilder.append(char) instead of StringBuilder.append(String)
whenever we append a single character to a StringBuilder.

Closes gh-27098
2021-06-25 10:44:28 +02:00
Sam Brannen 000b6a7e95 Polish @ResponseStatus javadoc and StatusAssertionTests 2021-06-08 18:55:05 +02:00
Rossen Stoyanchev cc2b980e5c Update MockMvc default for suffixPattern matching
Closes gh-27030
2021-06-08 17:41:04 +01:00
Sam Brannen cd9cad31f9 Increase the likelihood that timed tests pass on CI server 2021-05-11 16:16:18 +02:00
Juergen Hoeller 5f5cd8a7c4 Log resource path resolution failure at debug level (instead of warn)
Closes gh-26828
2021-05-11 15:46:21 +02:00
Sam Brannen d79e33b5a0 Handle empty file input in HtmlUnitRequestBuilder
This commit revises the fix submitted in 959e6d1745 by ensuring that
empty file input is converted to a MockPart with the supplied name, an
empty filename, "application/octet-stream" as the content type, and
empty content.

This aligns with the behavior of Servlet containers, as tested with the
interaction between Firefox and a standard Servlet running in a Jetty
Servlet container.

Closes gh-26799
2021-05-07 16:00:09 +02:00
Sam Brannen 959e6d1745 Handle empty file input in HtmlUnitRequestBuilder
Prior to this commit, when using HtmlUnit with empty file input,
MockMvc's HtmlUnitRequestBuilder would throw a NullPointerException
when attempting to create a MockPart based on the null File.

This commit ensures that empty file input is converted to a MockPart
with a valid name but with a null filename, a null content type, and
empty content.

Closes gh-26799
2021-05-05 18:11:15 +02:00
Johnny Lim 98770b15e7
Polishing
Closes gh-26878
2021-04-29 16:53:53 +02:00
Sam Brannen e4f753e3e3 Honor class-level @DirtiesContext if test class is disabled via SpEL
Prior to this commit, if a test class annotated with @DirtiesContext
and @EnabledIf/@DisabledIf with `loadContext = true` was disabled due
to the evaluated SpEL expression, the ApplicationContext would not be
marked as dirty and closed.

The reason is that @EnabledIf/@DisabledIf are implemented via JUnit
Jupiter's ExecutionCondition extension API which results in the entire
test class (as well as any associated extension callbacks) being
skipped if the condition evaluates to `disabled`. This effectively
prevents any of Spring's TestExecutionListener APIs from being invoked.
Consequently, the DirtiesContextTestExecutionListener does not get a
chance to honor the class-level @DirtiesContext declaration.

This commit fixes this by implementing part of the logic of
DirtiesContextTestExecutionListener in
AbstractExpressionEvaluatingCondition (i.e., the base class for
@EnabledIf/@DisabledIf support). Specifically, if the test class for an
eagerly loaded ApplicationContext is disabled,
AbstractExpressionEvaluatingCondition will now mark the test
ApplicationContext as dirty if the test class is annotated with
@DirtiesContext.

Closes gh-26694
2021-03-18 13:51:32 +01:00
Rossen Stoyanchev 4982b5fcb9 Improve docs on SSE tests for Spring MVC
Closes gh-26687
2021-03-16 17:55:43 +00:00
Rebwon fd17738f76 Polish TestContextAnnotationsUtilsTests
Closes gh-26684
2021-03-16 12:15:00 +01:00
Juergen Hoeller 4f14291e2f Add since tag
See gh-19647
2021-03-15 18:00:54 +01:00
Rebwon 7f422f206c Polishing
Closes gh-26682
2021-03-15 13:47:13 +01:00
Rossen Stoyanchev 6e264f9bdd Add test for global Consumer<ExchangeResult> in WebTestClient
See gh-26662
2021-03-15 10:01:41 +00:00
Rossen Stoyanchev c6b271f1b6 Support global Consumer<ExchangeResult> in WebTestClient
Closes gh-26662
2021-03-15 09:56:17 +00:00
Juergen Hoeller c1b1940dd2 Polishing 2021-03-12 11:02:35 +01:00
Juergen Hoeller 97b3aa4b13 Polishing 2021-03-12 00:14:04 +01:00
Michal Stehlik 79b5710386 StatusAssertion value methods fail when used with custom status code 2021-03-11 15:57:32 +01:00
Sam Brannen 5593e95e89 Do not assert thread count in ParallelApplicationEventsIntegrationTests 2021-03-11 10:14:39 +01:00
Johnny Lim cf4e77907f
Fix MockHttpServletRequest reference in Javadoc
Closes gh-26592
2021-02-23 10:43:38 +01:00
Rossen Stoyanchev 274db2f7a9 Undo HttpServletMapping support in MockHttpServletRequest
Closes gh-26555
2021-02-19 12:07:05 +00:00
Sam Brannen 49ccd7ad9c Polish MockHttpServletResponseTests
See gh-26558
2021-02-17 14:32:39 +01:00
Koos Gadellaa 40661d62c1 Support cookie w/ only Expires attribute in MockHttpServletResponse
Prior to this commit, MockHttpServletResponse only included the Expires
attribute in the generated Cookie header if the Max-Age attribute had
also been set.

This commit supports including the Expires attribute in the generated
Cookie Header even when the Max-Age attribute has not been set.

Closes gh-26558
2021-02-17 14:32:39 +01:00
Sam Brannen e17ca9a4e9 Implement toString() in MockCookie 2021-02-17 14:32:38 +01:00
Juergen Hoeller ca8261cbf8 Polishing 2021-02-15 17:18:01 +01:00
Juergen Hoeller df977a2fd2 Nullability refinements and related polishing 2021-02-14 17:57:32 +01:00
Sam Brannen 5d70aaacef Improve diagnostics for flaky ParallelApplicationEventsIntegrationTests 2021-02-12 12:02:37 +01:00
Sam Brannen bc90512309 Fix Checkstyle violation 2021-02-10 14:03:33 +01:00
Sam Brannen edd15646af Check available processors in ParallelApplicationEventsIntegrationTests
This commit changes the condition in the if-block to check the number of
available processors instead of currently active threads with the hope
that doing so will prove more reliable on the CI server.
2021-02-10 12:02:32 +01:00
Sam Brannen 836976d732 Increase fudge factor 2021-02-04 13:41:47 +01:00
Rossen Stoyanchev c52526ad42 Fix in MockMultipartHttpServletRequest#getMultipartHeaders
Previously this method returned headers only when a Content-Type part header
was present. Now it is guaranteed to return headers (possibly empty) as long
as there is a MultipartFile or Part with the given name.

Closes gh-26501
2021-02-03 21:55:42 +00:00
Sam Brannen 1a3ff83157 Remove obsolete code in HeaderValueHolder 2021-02-02 11:28:32 +01:00
Sam Brannen c19b2851f1 Ignore null Locale in MockHttpServletResponse
Prior to this commit, calls to setLocale() MockHttpServletResponse
would result in a NullPointerException if the supplied Locale was null.

Although the Javadoc for setLocale(Locale) and addHeader(String, String)
in javax.servlet.ServletResponse does not specify how a null
Locale should be handled, both Tomcat and Jetty simply ignore a null
value.

This commit therefore updates MockHttpServletResponse to silently
ignore a null Locale passed to setLocale().

Closes gh-26493
2021-02-02 11:18:34 +01:00
Sam Brannen 3b4a3431d4 Ignore null header value in MockHttpServletResponse
Prior to this commit, calls to setHeader() and addHeader() in
MockHttpServletResponse would result in an IllegalArgumentException or
NullPointerException if the supplied header value was null.

Although the Javadoc for setHeader(String, String) and
addHeader(String, String) in javax.servlet.http.HttpServletResponse
does not specify how a null header value should be handled, both Tomcat
and Jetty simply ignore a null value. Furthermore,
org.springframework.http.HttpHeaders.add(String, String) declares the
headerValue parameter as @Nullable.

This commit therefore updates MockHttpServletResponse to silently
ignore null header values passed to setHeader() and addHeader().

Closes gh-26488
2021-02-02 11:18:34 +01:00
Rossen Stoyanchev f22e2ac578 Add HttpServletMapping support to MockHttpServletRequest
See gh-26428
2021-01-26 17:30:16 +00:00
Sam Brannen cd9d562129 Check thread count in ParallelApplicationEventsIntegrationTests 2021-01-25 11:02:36 +01:00
Sam Brannen 4a7a2258f9 Unwrap proxied DataSources in SqlScriptsTestExecutionListener
Prior to this commit, if the DataSource in the
DataSourceFromTransactionManager was wrapped in a proxy implementing
InfrastructureProxy, SqlScriptsTestExecutionListener would throw an
exception stating that the DataSource in the ApplicationContext and the
DataSource in the DataSourceFromTransactionManager were not the same.

This commit unwraps both data sources and compares the underlying
target instances to check for equality.

In addition, this commit makes the unwrapResourceIfNecessary() method in
TransactionSynchronizationUtils public.

Closes gh-26422
2021-01-22 18:22:00 +01:00
Rossen Stoyanchev 584dabbb39 Add all non-file parts as request parameters
Closes gh-26400
2021-01-19 20:49:59 +00:00
Rossen Stoyanchev 35225e5794 Add verify(Duration) to MockRestServiceServer
Closes gh-22618
2021-01-13 17:50:01 +00:00
Rossen Stoyanchev a1cf6bbc37 Avoid wrapping of AssertionError in ExchangeResult
Closes gh-26303
2021-01-06 21:56:14 +00:00
Rossen Stoyanchev fb2e53276c Assert WebFlux present for WebTestClient
Closes gh-26308
2021-01-06 21:56:14 +00:00
Sam Brannen ee41ebc1ab Polish MockMvcReuseTests 2020-12-28 16:03:16 +01:00
Sam Brannen 885f6dbab9 Ensure ParallelApplicationEventsIntegrationTests passes on CI server
See gh-25616
2020-12-23 10:16:13 +01:00
Sam Brannen 1565f4b83e Introduce ApplicationEvents to assert events published during tests
This commit introduces a new feature in the Spring TestContext
Framework (TCF) that provides support for recording application events
published in the ApplicationContext so that assertions can be performed
against those events within tests. All events published during the
execution of a single test are made available via the ApplicationEvents
API which allows one to process the events as a java.util.Stream.

The following example demonstrates usage of this new feature.

@SpringJUnitConfig(/* ... */)
@RecordApplicationEvents
class OrderServiceTests {

    @Autowired
    OrderService orderService;

    @Autowired
    ApplicationEvents events;

    @Test
    void submitOrder() {
        // Invoke method in OrderService that publishes an event
        orderService.submitOrder(new Order(/* ... */));
        // Verify that an OrderSubmitted event was published
        int numEvents = events.stream(OrderSubmitted.class).count();
        assertThat(numEvents).isEqualTo(1);
    }
}

To enable the feature, a test class must be annotated or meta-annotated
with @RecordApplicationEvents. Behind the scenes, a new
ApplicationEventsTestExecutionListener manages the registration of
ApplicationEvents for the current thread at various points within the
test execution lifecycle and makes the current instance of
ApplicationEvents available to tests via an @Autowired field in the
test class. The latter is made possible by a custom ObjectFactory that
is registered as a "resolvable dependency". Thanks to the magic of
ObjectFactoryDelegatingInvocationHandler in the spring-beans module,
the ApplicationEvents instance injected into test classes is
effectively a scoped-proxy that always accesses the ApplicationEvents
managed for the current test.

The current ApplicationEvents instance is stored in a ThreadLocal
variable which is made available in the ApplicationEventsHolder.
Although this class is public, it is only intended for use within the
TCF or in the implementation of third-party extensions.

ApplicationEventsApplicationListener is responsible for listening to
all application events and recording them in the current
ApplicationEvents instance. A single
ApplicationEventsApplicationListener is registered with the test's
ApplicationContext by the ApplicationEventsTestExecutionListener.

The SpringExtension has also been updated to support parameters of type
ApplicationEvents via the JUnit Jupiter ParameterResolver extension
API. This allows JUnit Jupiter based tests to receive access to the
current ApplicationEvents via test and lifecycle method parameters as
an alternative to @Autowired fields in the test class.

Closes gh-25616
2020-12-20 23:46:19 +01:00
Juergen Hoeller fbd2ffdd23 Consistent declarations and assertions in MockMultipartFile
See gh-26261
2020-12-16 22:27:33 +01:00
Sam Brannen b3a47c76f8 Introduce TestContextAnnotationUtils.hasAnnotation() 2020-12-15 22:48:33 +01:00
Sam Brannen 1292947f78 Introduce computeAttribute() in AttributeAccessor
This commit introduces computeAttribute() as an interface default method
in the AttributeAccessor API. This serves as a convenience analogous to
the computeIfAbsent() method in java.util.Map.

Closes gh-26281
2020-12-15 22:47:02 +01:00
Rossen Stoyanchev bcfbde9848 Parse parts in MockMultipartHttpServletRequestBuilder
Closes gh-26261
2020-12-14 21:13:29 +00:00
Rossen Stoyanchev d82cb15439 Ensure both mock files and parts can be provided
Closes gh-26166
2020-12-03 17:53:26 +00:00
Sébastien Deleuze 0fd6c100a6 Polishing
See gh-24103
2020-11-16 14:33:21 +01:00
Sam Brannen 0819a9fcc9 Discover @DynamicPropertySource methods on enclosing test classes
gh-19930 introduced support for finding class-level test configuration
annotations on enclosing classes when using JUnit Jupiter @Nested test
classes, but support for @DynamicPropertySource methods got overlooked
since they are method-level annotations.

This commit addresses this shortcoming by introducing full support for
@NestedTestConfiguration semantics for @DynamicPropertySource methods
on enclosing classes.

Closes gh-26091
2020-11-15 20:59:15 +01:00
Sam Brannen 1b0be5862d Polishing 2020-11-12 15:32:41 +01:00
Sam Brannen 48af36c6fa Ensure test() conditions in JUnit TestKit match method names
Prior to this commit, the test("test") conditions used in
AutowiredConfigurationErrorsIntegrationTests inadvertently asserted
that the invoked test methods reside in an org.springframework.test
subpackage, which is always the case for any test method in the
`spring-test` module. In other words, "test" is always a substring of
"org.springframework.test...", which is not a meaningful assertion.

This commit ensures that the JUnit Platform Test Kit is asserting the
actual names of test methods.
2020-11-12 15:11:54 +01:00
Sam Brannen 3851b291da Use MethodFilter.and() in TransactionalTestExecutionListener 2020-11-11 11:11:34 +01:00
Sam Brannen fc5e3c335f Introduce and() methods in MethodFilter & FieldFilter for composition
This commit introduces `and()` default methods in the MethodFilter and
FieldFilter functional interfaces in ReflectionUtils in order to simplify
uses cases that need to compose filter logic.

Closes gh-26063
2020-11-10 18:00:24 +01:00
Sam Brannen b019f30a15 Validate that test & lifecycle methods are not @Autowired
Prior to this commit, a developer may have accidentally annotated a
JUnit Jupiter test method or lifecycle method with @Autowired, and that
would have potentially resulted in an exception that was hard to
understand. This is because the Spring container considers any
@Autowired method to be a "configuration method" when autowiring the
test class instance. Consequently, such an @Autowired method would be
invoked twice: once by Spring while attempting to autowire the test
instance and another time by JUnit Jupiter when invoking the test or
lifecycle method. The autowiring invocation of the method often leads
to an exception, either because Spring cannot satisfy a dependency (such
as JUnit Jupiter's TestInfo) or because the body of the method fails due
to test setup that has not yet been invoked.

This commit introduces validation for @Autowired test and lifecycle
methods in the SpringExtension that will throw an IllegalStateException
if any @Autowired method in a test class is also annotated with any of
the following JUnit Jupiter annotations.

- @Test
- @TestFactory
- @TestTemplate
- @RepeatedTest
- @ParameterizedTest
- @BeforeAll
- @AfterAll
- @BeforeEach
- @AfterEach

Closes gh-25966
2020-11-10 15:28:34 +01:00
Juergen Hoeller bd2640a9d6 Strict nullability for field assignment 2020-11-09 21:33:32 +01:00
Sam Brannen b077e4cd85 Use MergedAnnotationCollectors again in TestContextAnnotationUtils
See gh-26031
2020-11-04 14:42:19 +01:00
Sam Brannen 68934f1b79 Use TYPE_HIERARCHY strategy in AnnoDescr.findAllLocalMergedAnnotations()
Prior to this commit, the findAllLocalMergedAnnotations() method in
AnnotationDescriptor altered between the use of TYPE_HIERARCHY and
TYPE_HIERARCHY_AND_ENCLOSING_CLASSES for the SearchStrategy, depending
on @NestedTestConfiguration semantics; however, when searching for
"local" annotations, there is no need to search the enclosing class
hierarchy since AnnotationDescriptor#next() handles that use case.

This commit therefore switches to using only the TYPE_HIERARCHY
strategy.

This commit also discontinues the use of
MergedAnnotationCollectors.toAnnotationSet() in order to avoid the
unnecessary creation of a temporary List when collecting synthesized
annotations in a LinkedHashSet.

Closes gh-25985
2020-11-03 16:17:15 +01:00
Sam Brannen 5628c8cd63 Polish ActiveProfilesUtils 2020-11-03 14:46:17 +01:00
Sam Brannen acbbf61be8 Preserve registration order in @ActiveProfiles
With this commit, bean definition profiles declared via @ActiveProfiles
are once again stored in registration order, in order to support use
cases in Spring Boot and other frameworks that depend on the
registration order.

This effectively reverts the changes made in conjunction with gh-25973.

Closes gh-26004
2020-11-02 16:39:59 +01:00
Sam Brannen 9c2fd0bd05 Document @DynamicPropertySource use cases that require @DirtiesContext
Closes gh-25850
2020-10-27 14:26:40 +01:00
Sam Brannen fc9650a9a6 Finalize API for TestContextAnnotationUtils 2020-10-27 00:22:03 +01:00
Sam Brannen 82fa3f3fc1 Reinstate tests for deprecated MetaAnnotationUtils 2020-10-27 00:18:25 +01:00
Juergen Hoeller 0aa3205e38 Fix nullability warnings 2020-10-26 22:19:26 +01:00
Sébastien Deleuze d04c5f8b2c Support multiple matchers in MockMvc Kotlin DSL
Previous incarnation of MockMvc Kotlin DSL tried to reuse directly
Java APIs like ModelResultMatchers or StatusResultMatchers, but
when using multiple matchers in DSL blocks like model { } or
status { }, only the last statement was taken in account which
was very confusing.

This refactoring provides dedicated Kotlin DSLs for matchers.

The main API breaking changes is that functions like isOk() need to be
invoked with the parenthesis, isOk is not supported anymore (on purpose).

Closes gh-24103
2020-10-26 18:13:55 +01:00