Commit Graph

2235 Commits

Author SHA1 Message Date
Sam Brannen a4956dfe26 Update copyright headers 2023-01-11 13:52:20 +01:00
Krzysztof Krason afb8a0d1b1 Use new Java features (switch expressions, text blocks, new JDK methods)
Closes gh-29747
2023-01-11 13:51:28 +01:00
rstoyanchev c702cd418e Polishing
See gh-29721
2023-01-06 16:50:19 +00:00
Simon Baslé 4bcc24372a Add ExecutingResponseCreator
This commit adds a new `ResponseCreator` implementation that uses a
`ClientHttpRequestFactory` to perform an actual request.

Closes gh-29721
2022-12-20 16:36:06 +01:00
Simon Baslé 74f58198fd
Add Kotlin DSL support for MockMVC andExpectAll (#29727)
As the DSL internally calls `ResultActions.andExpect`, this is done with
a trick where a synthetic `ResultActions` is provided at top level which
stores each `ResultMatcher` in a mutable list.

Once the DSL usage is done, the top level DSL `andExpectAll` turns that
list into a `vararg` passed down to the actual `actions.andExpectAll`.

Closes gh-27317
2023-01-03 18:26:26 +01:00
Sam Brannen d4623a393b Update copyright headers 2022-12-18 12:16:19 +01:00
Sam Brannen 2b6f3caff4 Remove dead code in MockClientHttpRequest 2022-12-09 15:57:35 -05:00
Sam Brannen 83eb8ac0ea Introduce additional constructors in MockClientHttp[Request|Response]
This commit introduces additional constructors in MockClientHttpRequest
and MockClientHttpResponse that were previously only present in the
internal "test fixtures" in spring-web.

This commit also aligns the mocks in spring-test with the test fixtures
in spring-web to simplify continued maintenance of the mocks and test
fixtures.

Closes gh-29670
2022-12-09 15:46:08 -05:00
Sam Brannen a1a140f7d5 Use URI#create instead of URI constructor where feasible in spring-test 2022-12-09 12:27:06 -05:00
Sam Brannen 4caf3c8ce0 Polish tests in spring-test 2022-12-09 12:26:38 -05:00
Sam Brannen 485c80fcf3 Apply 'instanceof pattern matching' in spring-test and Servlet mocks 2022-12-09 11:56:14 -05:00
Sam Brannen 69f47e7700 Polishing
- primarily automated "clean up" using Eclipse IDE
2022-12-09 00:56:00 -05:00
Sam Brannen 404661d5cb Polishing 2022-12-08 16:03:05 -05:00
Sam Brannen 7615762039 Update copyright headers 2022-12-07 12:11:45 -05:00
ShenFeng312 c79474d269
Polish var-args declarations
Closes gh-29640
2022-12-07 04:30:40 +01:00
Moritz Halbritter 752ef6f456 Fall back to JdkClientHttpConnector as ClientHttpConnector 2022-12-06 14:33:03 +01:00
Sam Brannen aa1f3d1681 Apply "instanceof pattern matching" 2022-12-03 16:06:58 -05:00
Johnny Lim 74ec10bf3a Polish
Closes gh-29619
2022-12-01 17:34:33 +01:00
Sam Brannen ad60164911 Update copyright headers for source code changed since August 2022
The changes in this commit were performed using the newly introduced
update_copyright_headers.sh script.
2022-11-29 19:38:42 +01:00
Sam Brannen 8e9a553517 Update Javadoc regarding JUnit versions 2022-11-26 16:48:03 +01:00
Sam Brannen 537d539b1d Use JUnit Jupiter annotations as examples in TestContextManager JavaDoc 2022-11-26 16:17:01 +01:00
Sam Brannen 476b9cfc99 Polish TestContextManager internals 2022-11-26 16:17:01 +01:00
Sam Brannen 352087a637 Forbid loading of test ApplicationContext in AOT mode if AOT processing failed
Prior to this commit, if AOT processing of a test's ApplicationContext
failed, the TestContext Framework (TCF) still attempted to load the
context via standard (JVM) mechanisms when running in AOT mode.

For example, if a test class uses Spring Boot's @MockBean, AOT
processing of that test's context will fail with a WARN log message,
and there will no mapping from that test class to an AOT-generated
ApplicationContextInitializer (ACI). Consequently, when the test suite
is run in AOT mode that particular test class will currently fail with
a confusing stack trace due to the fact that Spring Boot's
SpringApplication attempts to locate a "main" ACI instead of the
missing "test" ACI (missing because it was not generated during AOT
processing).

In general, the TCF should not attempt to load an ApplicationContext in
"JVM mode" while running in "AOT mode".

This commit therefore reworks the logic in
DefaultCacheAwareContextLoaderDelegate to fail fast (with a meaningful
error message) if an AOT-generated ACI cannot be found while running in
AOT mode. This avoids the aforementioned confusion when @MockBean tests
fail in AOT mode (on the JVM or within a native image), and it also
helps to diagnose build problems if AOT processing has not yet been
performed for the project's test suite.

Closes gh-29579
2022-11-26 15:32:16 +01:00
Sam Brannen 33d33802a8 Improve logging in TestContextManager 2022-11-26 15:30:50 +01:00
Sam Brannen 9ec937c843 Remove erroneous Javadoc link 2022-11-26 14:40:49 +01:00
Sam Brannen 7fcd1de8e3 Use AssertJ's isEmpty() instead of hasSize(0)
Achieved via global search-and-replace.
2022-11-22 17:11:50 +01:00
Sam Brannen d5b0b2b1a1 User AssertJ's hasSize() for arrays
Achieved via global search-and-replace.
2022-11-22 17:03:45 +01:00
Sam Brannen 36f7597f25 Use AssertJ's hasSize() for collections and maps
Achieved via a global search-and-replace.
2022-11-22 16:50:10 +01:00
Sam Brannen 43f8d9e084 Apply 'instanceof pattern matching' 2022-11-22 16:27:34 +01:00
Sam Brannen 917c41fd52 Use Set.of() for constant sets where appropriate 2022-11-21 16:49:07 +01:00
Sam Brannen 508d2c7a77 Fix Javadoc formatting issues for headings
Headings in method-level Javadoc must be h4 or higher in recent versions
of Java.
2022-11-16 14:09:42 +01:00
Sam Brannen bfc125105f Merge branch '5.3.x' 2022-11-15 14:47:21 +01:00
Sam Brannen 8e64701cb7 Fix Javadoc formatting issue in TestSocketUtils 2022-11-15 14:47:00 +01:00
Sam Brannen 2aa78889d2 Use consistent wording in precondition error messages 2022-11-15 12:31:01 +01:00
Sam Brannen 7d731ee754 Merge branch '5.3.x'
# Conflicts:
#	spring-core/src/test/java/org/springframework/util/SocketUtilsTests.java
2022-11-14 20:31:26 +01:00
Sam Brannen 698f8995f7 Revise TestSocketUtils and tests
Closes gh-29132
2022-11-14 20:26:58 +01:00
Chris Bono ee51dab1f3 Introduce TestSocketUtils as a replacement for SocketUtils
SocketUtils was officially deprecated in 5.3.16 (gh-28052) and removed
in 6.0 M3 (gh-28054); however, there is still need for a subset of this
functionality in integration tests for testing scenarios in which it is
not possible for the system under test to select its own random port
(or rely on the operating system to provide an ephemeral port).

This commit therefore introduces a scaled down version in the
spring-test module called TestSocketUtils which supports retrieval of a
single TCP port.

See gh-29132
2022-11-14 20:26:58 +01:00
Sam Brannen eb91d21ada Polishing 2022-11-13 18:21:56 +01:00
Sam Brannen ae3bec5d57 Allow test classes to provide runtime hints via declarative mechanisms
Prior to this commit, it was possible to register hints for individual
test classes programmatically via the
org.springframework.test.context.aot.TestRuntimeHintsRegistrar SPI;
however, that requires that a custom TestRuntimeHintsRegistrar be
registered via "META-INF/spring/aot.factories". In addition,
implementing a TestRuntimeHintsRegistrar is more cumbersome than using
the core mechanisms such as @Reflective, @ImportRuntimeHints, and
@RegisterReflectionForBinding.

This commit address this by introducing support for @Reflective and
@ImportRuntimeHints on test classes. @RegisterReflectionForBinding
support is available automatically since it is an extension of the
@Reflective mechanism.

Closes gh-29455
2022-11-12 14:41:09 +01:00
Juergen Hoeller d7d44c6c51 Polishing 2022-11-10 18:26:49 +01:00
Sam Brannen 69736af5fc Revise ContextLoadException constructor to accept a Throwable 2022-11-08 20:35:17 +01:00
Sam Brannen 7d68d0625c Polishing 2022-11-08 19:32:46 +01:00
Kulwant Singh debe78b7f9 Minor improvements in spring-test
- Remove final modifier from private method
- Use StandardCharsets
- Remove unnecessary toString calls
- Remove unnecessary static modifiers
- Refactor to use enhanced switch
- Replace concatenated strings with text blocks
- Rely on auto-boxing where appropriate
- Remove unnecessary code
- Fix imports in Kotlin test classes

Closes gh-29413
2022-11-08 19:32:46 +01:00
Sam Brannen 9d73f81e9c Avoid String allocations with Assert.notNull() 2022-11-08 14:23:22 +01:00
Sam Brannen 95f3337bb5 Revise contribution
This commit reverts changes to AbstractCacheManager since iterating
over the caches in a for-loop and a stream is duplicated effort.

This commit reverts changes to DefaultRenderingResponseBuilder,
RouterFunctions, and OriginHandshakeInterceptor since order matters for
those use cases: they were originally based on the semantics of
LinkedHashSet or LinkedHashMap; whereas, Set.copyOf() and Map.copyOf()
do not provide any guarantees regarding ordering.

This commit also applies analogous changes to "sibling" implementations
across Servlet mocks as well as Web MVC and WebFlux.

See gh-29321
2022-11-08 14:14:29 +01:00
divcon ba136dcf40 Replace use of Collections.unmodifiable*() methods where appropriate
Closes gh-29321
2022-11-08 13:51:31 +01:00
Juergen Hoeller 86d45578d9 Introduce findAllAnnotationsOnBean variant on ListableBeanFactory
Closes gh-29446
2022-11-08 13:29:33 +01:00
Sam Brannen 3438c47744 Polishing 2022-11-08 11:48:13 +01:00
Juergen Hoeller 19cf503534 Align with Servlet 6.0 and introduce support for Jakarta WebSocket 2.1
Includes corresponding build upgrade to Tomcat 10.1.1 and Undertow 2.3.0
(while retaining runtime compatibility with Tomcat 10.0 and Undertow 2.2)

Closes gh-29435
Closes gh-29436
2022-11-06 16:08:30 +01:00
Sam Brannen 82823517fa Merge branch '5.3.x'
# Conflicts:
#	build.gradle
#	spring-messaging/src/main/java/org/springframework/messaging/rsocket/DefaultRSocketRequesterBuilder.java
#	spring-messaging/src/main/java/org/springframework/messaging/rsocket/MetadataEncoder.java
#	spring-messaging/src/main/java/org/springframework/messaging/simp/broker/OrderedMessageChannelDecorator.java
#	spring-messaging/src/main/java/org/springframework/messaging/simp/user/DefaultUserDestinationResolver.java
#	spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java
#	spring-web/src/main/java/org/springframework/http/HttpRange.java
#	spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RedirectView.java
#	spring-webflux/src/main/java/org/springframework/web/reactive/socket/CloseStatus.java
#	spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/RedirectViewControllerRegistration.java
2022-11-05 14:50:18 +01:00