Commit Graph

2374 Commits

Author SHA1 Message Date
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
Sam Brannen 5f02323b9c Avoid String allocations with Assert.isTrue() 2022-11-05 14:40:45 +01:00
Sam Brannen d849f9816a Merge branch '5.3.x'
# Conflicts:
#	build.gradle
#	spring-webflux/src/test/java/org/springframework/web/reactive/result/view/script/ScriptTemplateViewTests.java
#	spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateView.java
#	spring-webmvc/src/test/java/org/springframework/web/servlet/view/script/ScriptTemplateViewTests.java
2022-11-04 16:29:54 +01:00
Sam Brannen a281d8c3fd Polishing 2022-11-04 16:24:59 +01:00
Sam Brannen c21bd6659d Introduce TestContextSpringFactoriesUtils to reduce code duplication 2022-10-27 15:19:44 +02:00
Sam Brannen a4d36a8b83 Polish ApplicationContextFailureProcessor support
See gh-29387
2022-10-27 14:29:04 +02:00
Sam Brannen a13cb01b99 Load ApplicationContextFailureProcessors from spring.factories
At the request of the Spring Boot team, ApplicationContextFailureProcessor
implementations are now loaded via the spring.factories mechanism
instead of supporting a single processor registered via subclasses of
AbstractTestContextBootstrapper.

This makes the retrieval and handling of processors internal to
DefaultCacheAwareContextLoaderDelegate, while simultaneously supporting
multiple processors that can be registered by anyone (i.e., not
limited to projects that implement custom TestContextBootstrappers).

See gh-28826
Closes gh-29387
2022-10-26 19:00:32 +02:00
Sam Brannen 273e38c2b4 Make TestAotProcessor more easily extensible 2022-10-26 14:20:46 +02:00
Sam Brannen 997dd3ee65 Revise logging in the TestContext framework
For a Spring Boot test, Logback logs at DEBUG level by default until
Spring Boot's logging infrastructure has a chance to take control, and
this can result in a considerable amount of INFO and DEBUG output.

It's not the number of lines that causes an issue. Rather, it's the
amount of information in each line that can become overwhelming,
especially when the MergedContextConfiguration is complex.

The main reason for lengthy DEBUG logging in a Spring Boot test is that
Spring Boot's ImportsContextCustomizer implements toString() which
results in logging of the fully qualified class names of all imported
configuration classes. In an example using @WebMvcTest, this resulted
in logging of 27 imported classes twice. However, the lists of
registered TestExecutionListener, ContextCustomizerFactory, and
ContextCustomizer implementations are also logged separately, and that
adds quite a bit of noise at DEBUG level.

This commit addresses these issues and simultaneously completely
revises logging within the Spring TestContext Framework (TCF).

- Numerous log statements are now logged at TRACE level instead of
  DEBUG.

- Numerous log statements now have two modes. When logging at TRACE
  level, fully qualified class names (or the results of invoking
  toString() on related components) are included. When logging at DEBUG
  level, simple names of classes are logged and the results of invoking
  toString() on related components are omitted.

- toString() implementations in TCF components are now based on the
  newly introduced SimpleValueStyler for ToStringCreator.

The combination of the above changes greatly reduces the amount of
DEBUG logging output in the TCF, but users can still access complete
details by switching to TRACE level logging.

Closes gh-29229
2022-10-25 17:43:07 +02:00
Stephane Nicoll 82a0154bd1 Expose a system property when AOT processing is running
This commit exposes a "spring.aot.processing" system property when the
AOT engine is running. This can be used by code that need to react
differently when the application is being refreshed for AOT processing.

Closes gh-29340
2022-10-18 18:18:43 +02:00
Sam Brannen eadb003a8d Introduce builder API for AOT processor Settings
Closes gh-29341
2022-10-18 16:33:16 +02:00
Sam Brannen 6bdf0bcc4a Introduce ApplicationContextFailureProcessor SPI in the TCF
This commit introduces an ApplicationContextFailureProcessor SPI in the
Spring TestContext Framework that allows third parties to process
failures that occur while a SmartContextLoader attempts to load an
ApplicationContext.

SmartContextLoader implementations must introduce a try-catch block
around the loading code and throw a ContextLoadException that wraps
the failed ApplicationContext and the cause of the failure.

Extensions of AbstractTestContextBootstrapper can configure an
ApplicationContextFailureProcessor by overriding the new protected
getApplicationContextFailureProcessor() method.

DefaultCacheAwareContextLoaderDelegate unwraps any ContextLoadException
and delegates to the configured ApplicationContextFailureProcessor for
processing.

Closes gh-28826
2022-10-18 14:40:35 +02:00
Arjen Poutsma ce03980fb4 Mark HttpRequest::getMethodValue and ClientHttpResponse::getRawStatusCode for removal 2022-10-12 16:29:14 +02:00
Juergen Hoeller 0f8ca805e1 Move hints to dedicated top-level package (avoiding aot<->support cycle)
See gh-29026, gh-29069
2022-10-11 15:34:30 +02:00
Sam Brannen f00e4b230f Support method chaining in AbstractAotProcessor.Settings
See gh-29266
2022-10-10 19:09:41 +02:00
Sam Brannen cad7444afa Introduce Settings container in AbstractAotProcessor
See gh-29266
2022-10-10 18:58:27 +02:00
Sam Brannen de609e5d45 Polishing 2022-10-10 16:52:22 +02:00
Sam Brannen b2b3163fae Redesign AOT processors for consistency and simplification
There's currently a considerable amount of overlap between the
implementations of AotProcessor and TestAotProcessor. In addition
AotProcessor is abstract and does not include a main() method; whereas,
TestAotProcessor is concrete and does include a main() method.

To address these issues, this commit:

- Introduces an AbstractAotProcessor base class that AotProcessor and
  TestAotProcessor now both extend

- Moves common properties/functionality to AbstractAotProcessor

- Renames AotProcessor to ContextAotProcessor

- Makes TestAotProcessor abstract like ContextAotProcessor

- Removes the main() method from TestAotProcessor

Closes gh-29266
2022-10-10 16:27:04 +02:00
Sam Brannen bca35dc0a2 Generate direct mappings from AOT initializers to test classes
See gh-29289
2022-10-10 12:09:17 +02:00
Sam Brannen be70b675c6 Polishing 2022-10-10 11:01:04 +02:00
Sam Brannen 69e4cc5576 Ensure context caching works properly during AOT runtime in the TCF
Prior to this commit, the AOT runtime support in the Spring TestContext
Framework (TCF) relied on the MergedContextConfiguration for a given
test class being the same as during the AOT processing phase. However,
this is not always the case. For example, Spring Boot "disables"
selected `ContextCustomizer` implementations during AOT runtime
execution.

See 0f325f98b5

To address that, this commit ensures that context caching works
properly during AOT runtime execution even if the
MergedContextConfiguration differs from what was produced during the
AOT processing phase. Specifically, this commit introduces
AotMergedContextConfiguration which is a MergedContextConfiguration
implementation based on an AOT-generated ApplicationContextInitializer.

AotMergedContextConfiguration wraps the MergedContextConfiguration
built during AOT runtime execution.

Interactions with the ContextCache are performed using the
AotMergedContextConfiguration; whereas, the ApplicationContext is
loaded using the original MergedContextConfiguration.

This commit also introduces a ContextCustomizerFactory that emulates
the ImportsContextCustomizerFactory in Spring Boot's testing support.
BasicSpringJupiterImportedConfigTests uses @Import to verify that the
context customizer works, and AotIntegrationTests has been updated to
execute BasicSpringJupiterImportedConfigTests after test classes whose
MergedContextConfiguration is identical during AOT runtime execution.
Without the fix in this commit, BasicSpringJupiterImportedConfigTests
would fail in AOT runtime mode since its ApplicationContext would be
pulled from the cache using an inappropriate cache key.

Closes gh-29289
2022-10-09 16:17:43 +02:00
Sam Brannen cfa95c793b Ensure MergedContextConfigurationRuntimeHints is invoked once per config 2022-10-09 15:16:42 +02:00
Sam Brannen d4a5565340 Enable default TestExecutionListeners in JUnit 4 and TestNG base test classes
Prior to this commit, the abstract base test classes for JUnit 4 and
TestNG registered explicit sets of TestExecutionListeners. This
configuration was useful in the early years of the Spring TestContext
Framework. However, since the introduction of support for automatic
registration of "default" listeners in Spring Framework 4.1, these
predefined sets of TestExecutionListeners have become a hindrance to
using Spring's testing support with default listeners from Spring
portfolio projects (such as Spring Boot and Spring Security) as well as
third-party or project-specific default listeners.

To address this issue, the four abstract base test classes for JUnit 4
and TestNG no longer declare listeners via @TestExecutionListeners and
instead now rely on registration of default listeners.

Closes gh-29149
2022-10-08 16:30:07 +02:00
Sam Brannen 3061a81b0f Merge branch '5.3.x' 2022-10-08 16:21:30 +02:00
Sam Brannen b71d95df71 Document how to switch to the default set of TestExecutionListeners
Closes gh-29281
2022-10-08 16:20:55 +02:00
Sam Brannen afd0443204 Merge branch '5.3.x'
# Conflicts:
#	spring-test/src/main/java/org/springframework/test/web/reactive/server/ExchangeResult.java
2022-10-08 16:03:52 +02:00
Sam Brannen b20de758b2 Support custom status code in ExchangeResult for WebTestClient
Prior to this commit, ExchangeResult.assertWithDiagnostics() threw an
IllegalArgumentException for a custom HTTP status code since toString()
invoked getStatus() without a try-catch block.

This commit addresses this issue by introducing a formatStatus() method
that defensively formats the response status, initially trying to
format the HttpStatus and falling back to formatting the raw integer
status code.

Closes gh-29283
2022-10-08 15:45:24 +02:00
Sam Brannen ae368a20b8 Merge branch '5.3.x'
# Conflicts:
#	spring-web/src/test/kotlin/org/springframework/http/codec/json/KotlinSerializationJsonDecoderTests.kt
#	spring-web/src/test/kotlin/org/springframework/http/codec/json/KotlinSerializationJsonEncoderTests.kt
2022-10-08 14:06:41 +02:00
Johnny Lim 1c1a0afbed Use AssertJ static imports consistently in 5.3.x
Closes gh-29282
2022-10-08 13:57:21 +02:00
Sam Brannen b3afafbf5a Merge branch '5.3.x' 2022-10-07 18:02:25 +02:00
Sam Brannen a599601dd9 Document how to switch to the default set of TestExecutionListeners
Closes gh-29281
2022-10-07 17:58:22 +02:00
Sam Brannen 64412907f7 Merge branch '5.3.x'
# Conflicts:
#	spring-test/src/main/java/org/springframework/test/util/AopTestUtils.java
2022-10-07 16:12:21 +02:00
Sam Brannen 5eee4673c1 Document limitation of AopTestUtils.getUltimateTargetObject() regarding non-static TargetSource
Closes gh-29276
2022-10-07 16:09:39 +02:00
rstoyanchev b6c2e8de23 Support context propagation for Spring MVC controllers
Closes gh-29056
2022-10-06 12:43:54 +01:00
Juergen Hoeller 326335f903 Upgrade to Tomcat 10.1
Includes Jetty 11.0.12, Hibernate ORM 5.6.12, HtmlUnit 2.65
2022-10-06 12:09:05 +02:00
Juergen Hoeller b45a48461f Polishing 2022-10-06 12:03:25 +02:00
Sam Brannen 61cc7c0a93 Prepare TestAotProcessor to make it abstract and remove the main() method
See gh-29266
2022-10-05 20:03:52 +02:00
Sam Brannen 647e811e47 Restructure AopTestUtilsTests 2022-10-05 19:13:51 +02:00
Sam Brannen 66395502db Polishing 2022-10-05 19:06:15 +02:00
Sam Brannen 26e485ce40 Make TestClassScanner package private again
TestClassScanner was made public with the assumption that Spring Boot's
AOT testing support might need to work directly with that class; however,
it turns out that Spring Boot does not currently have such a need.

In light of that, this commit restores TestClassScanner's visibility to
package private.
2022-10-05 19:06:15 +02:00
Sam Brannen 98801f8a5b Consistently declare RuntimeHints parameter 1st in test AOT APIs 2022-10-05 19:06:15 +02:00
Sam Brannen 935265048a Simplify TestRuntimeHintsRegistrar API
Prior to this commit, the TestRuntimeHintsRegistrar API combined
processing of MergedContextConfiguration and test classes. However, it
appears that only spring-test internals have a need for registering
hints based on the MergedContextConfiguration. For example, Spring
Boot's AOT testing support has not had such a need, and it is assumed
that third parties likely will not have such a need.

In light of that, this commit simplifies the TestRuntimeHintsRegistrar
API so that it focuses on processing of a single test class.

In addition, this commit moves the hint registration code specific to
MergedContextConfiguration to an internal mechanism.

Closes gh-29264
2022-10-05 18:37:06 +02:00
Stephane Nicoll 2f20d6322b Enable cglib proxy for configuration classes if necessary
This commit updates code generation to customize the instantiation of
a configuration class that requires a proxy. Rather than instantiating
the raw class, the proxy is used.

Closes gh-29107
2022-10-04 16:54:44 +02:00
rstoyanchev b1ee44f12e Polishing contribution
Closes gh-27280
2022-09-27 17:08:52 +01:00
Ashley Scopes d14477eb84 Add methods to DefaultResponseCreator & MockRestResponseCreators
New methods in DefaultResponseCreator for adding headers and cookies,
for specifying the character encoding when setting a string body on
a response, which is useful when working in environments that do not
automatically assume UTF-8, such as integrating with legacy
applications from a new Spring one.

New methods in MockRestResponseCreators support extra commonly used
HTTP status codes, including some that occur when working in AWS,
CloudFlare, or when using gateways such as Kong, where resilient
applications should be able to respond to ratelimits, gateway errors,
and gateway timeouts that may occur if a remote service is down.

Added test cases for any changes made.

See gh-27280
2022-09-27 15:58:44 +01:00
Stephane Nicoll 8ef850ff91 Update ClassNameGenerator to work with a ClassName target
This commit updates ClassNameGenerator so that it uses a ClassName for
its default target. This makes sure that a target that has been
generated can be used.

See gh-29027
2022-09-27 10:33:13 +02:00
Adam Ostrožlík 0ccb64fe10 Replace Collectors.toList with Stream.toList
Closes gh-29203
2022-09-26 18:32:01 +02:00
Phillip Webb 6802665177 Refactor GeneratedFilesTestCompilerUtils to CompilerFiles
See gh-29175
2022-09-20 11:00:56 -07:00
Stephane Nicoll 4625e92eb8 Break dependency between TestCompiler and AOT
This commit improves `TestCompiler` with a `with` function that allows
to customize a test compiler instance. Rather than `TestCompiler`
knowing about `TestGenerationContext`, the latter implements the
function so that it can be passed as is.

See gh-29175
2022-09-20 15:07:51 +02:00
Sam Brannen 321092ce6f Consistent use of @Deprecated(since = "6.0") 2022-09-20 14:34:24 +02:00
Sam Brannen f140464c12 Remove unused variable in test
See gh-28324
2022-09-20 13:51:39 +02:00
Phillip Webb 52bffbff76 Move `TestCompiler` and related classes to `core.test.tools` package
Closes gh-29175
2022-09-19 22:29:40 -07:00
Phillip Webb cc7552ec61 Rename @CompileWithTargetClassAccess
Rename `@CompileWithTargetClassAccess` to
`@CompileWithForkedClassLoaderClassLoader`.

Closes gh-29173
2022-09-19 22:29:40 -07:00
Stephane Nicoll b44eb63d29 Workaround LinkageError with TestCompiler
See gh-29159
2022-09-15 16:00:25 +02:00
rstoyanchev f3c082abac Deprecate ignoreDefaultModelOnRedirect property
Closes gh-28324
2022-09-14 18:14:04 +01:00
Sam Brannen b87d48b99b Merge branch '5.3.x' 2022-09-14 17:18:00 +02:00
Marc Wrobel ce49068ff9 Fix links in Javadoc and reference docs
- Fix broken links (by using a new URL, an alternative URL, or a
  Wayback Machine link)

- Use HTTPS where possible

- Remove https://issuetracker.springsource.com/browse/EBR-349: this
  link is dead and is also mentioned in
  https://jira.spring.io/browse/SPR-8093

- Clean up nohttp allowlist.lines

Closes gh-28876
2022-09-14 17:00:11 +02:00
Sam Brannen af2481f6da Merge branch '5.3.x' 2022-09-14 15:54:34 +02:00
Johnny Lim 5f5d383eeb Fix Javadoc since tag for AbstractGenericWebContextLoader.createContext()
See gh-28983
Closes gh-29154
2022-09-14 15:53:18 +02:00
Sam Brannen 948c9b85a0 Revise internals of AOT testing support 2022-09-13 13:06:33 +02:00
Sam Brannen e7a297a948 Rename TestAotMappings to AotTestContextInitializers
- for consistency with AotTestAttributes and similar classes

See gh-28205, gh-28204
2022-09-13 12:07:30 +02:00
Sam Brannen a3b6b41bd7 Polish BootstrapUtils 2022-09-13 11:28:57 +02:00
Sam Brannen 1e2541a0a3 Remove support for setting default CacheAwareContextLoaderDelegate
The ability to set a system property to change the default
CacheAwareContextLoaderDelegate was only needed by the Spring Native
project in the Spring Framework 5.3.x line and should not be used by
other projects.

This commit therefore reverts the changes made in conjunction with
gh-27540.

Closes gh-29061
2022-09-13 11:14:51 +02:00
Sam Brannen b0ee513db6 Introduce AotTestAttributes mechanism in the TestContext framework
For certain use cases it is beneficial to be able to compute something
during AOT build-time processing and then retrieve the result of that
computation during AOT run-time execution, without having to deal with
code generation on your own.

To support such use cases, this commit introduces an AotTestAttributes
mechanism in the Spring TestContext Framework with the following
feature set.

- conceptually similar to org.springframework.core.AttributeAccessor in
  the sense that attributes are generic metadata

- allows an AOT-aware test component to contribute a key-value pair
  during the AOT build-time processing phase, where the key is a String
  and the value is a String

- provides convenience methods for storing and retrieving attributes as
  boolean values

- generates the necessary source code during the AOT build-time
  processing phase in the TestContext framework to create a persistent
  map of the attributes

- provides a mechanism for accessing the stored attributes during AOT
  run-time execution

Closes gh-29100
2022-09-12 20:32:36 +02:00
Sam Brannen d3822a2eb9 Revert workaround for Java 8 compiler bug 2022-09-12 18:24:00 +02:00
Sam Brannen a085a1b6b6 Polishing 2022-09-12 12:37:46 +02:00
rstoyanchev 2f4c39ba2a Add classpath detection for Reactor Netty 2
See gh-28847
2022-09-12 09:37:11 +01:00
Brian Clozel 0770d86936 Deprecate StreamUtils.emptyInput()
Closes gh-29125
2022-09-12 10:21:50 +02:00
Sam Brannen 7605ed7862 Improve tips for using endToEndTestsForEntireSpringTestModule()
See gh-29122
2022-09-10 20:09:47 +02:00
Sam Brannen 6d83a959fb Rename registerResourceIfNecessary to registerResource
This commit renames registerResourceIfNecessary() to registerResource()
and throws an exception if the class path resource does not exist.

Closes gh-29083
2022-09-10 19:49:56 +02:00
Sam Brannen d883c8fbb3 Polishing 2022-09-10 19:24:34 +02:00
Sam Brannen b429d6b5a6 Filter AOT end-to-end tests like in the actual build 2022-09-10 19:24:34 +02:00
Brian Clozel 2b5ca63339 Fix serialization compiler warnings with Java 18
As of Java 18, the serial lint warning in javac has been expanded to
check for class fields that are not marked as `Serializable`.
See https://www.oracle.com/java/technologies/javase/18all-relnotes.html#JDK-8202056

In the Spring Framework codebase, this can happen with `Map`, `Set` or
`List` attributes which are often assigned with an unmodifiable
implementation variant. Such implementations are `Serializable` but
cannot be used as field types.

This commit ensures that the following changes are applied:
* fields are marked as transient if they can't be serialized
* classes are marked as `Serializable` if this was missing
* `@SuppressWarnings("serial")` is applied where relevant
2022-09-09 20:24:26 +02:00
Sam Brannen 1228f1cb58 Polishing 2022-09-09 18:32:38 +02:00
Sam Brannen ae864eb642 Introduce @Disabled end-to-end AOT tests for the spring-test module
This commit introduces endToEndTestsForEntireSpringTestModule() in
AotIntegrationTests to allow us to periodically check on our AOT
support.

Status quo:

- several test classes cannot be processed for AOT due to exceptions
  thrown during processing
- some generated classes fail to compile
- some tests fail

See gh-29122
2022-09-09 17:42:18 +02:00
Sam Brannen 94ff519072 Test JUnit 4, JUnit Jupiter, & TestNG in AotIntegrationTests
With this commit we also now assert the number of successfully
executed tests.
2022-09-09 17:15:54 +02:00
Sam Brannen 4e9fad7514 Revise TestAotProcessorTests to rely on Path APIs
Instead of String comparisons, assertions are now based on Path
comparisons.

See gh-29103
2022-09-09 16:57:01 +02:00
Sam Brannen d21d7fd6d0 Polishing 2022-09-09 16:08:19 +02:00
Nheyll 058109315d Deprecate support for theme
As seen in gh-28868, the support for Themes is now deprecated as of
Spring Framework 6.0 and will be removed in a future release.

Closes gh-29114
2022-09-09 11:22:21 +02:00
Sam Brannen f5bc182ba7 Rename AotTestMappings to TestAotMappings
This provides consistency with other classes in the aot package,
leaving only extended core interfaces starting with the `Aot` prefix.
2022-09-08 13:04:29 +02:00
Sam Brannen 3f288eea17 Fix TestAotProcessorTests on MS Windows
Closes gh-29103
2022-09-08 11:50:25 +02:00
Sébastien Deleuze 9cfe79186d Stop using RuntimeHintsUtils
Due to gh-29053, we can stop using RuntimeHintsUtils to
register SynthesizedAnnotation proxies.

Closes gh-29059
2022-09-07 10:10:07 +02:00
Sébastien Deleuze b8c1fc9202 Revert "Remove RuntimeHintsUtils"
This reverts commit 3e327f5641.
2022-09-06 18:21:34 +02:00
Sébastien Deleuze 3e327f5641 Remove RuntimeHintsUtils
Due to gh-29053, we can stop using RuntimeHintsUtils to
register SynthesizedAnnotation proxies.

Closes gh-29058
Closes gh-29059
2022-09-06 15:31:02 +02:00
Sam Brannen 8fbd2141b7 Move registerResourceIfNecessary() to ResourceHints
See gh-29083
2022-09-06 15:22:18 +02:00
Sam Brannen 28c492cbdd Introduce RuntimeHintsUtils.registerResourceIfNecessary
This commit introduces a new registerResourceIfNecessary() method in
RuntimeHintsUtils that simplifies the registration of hints for
`classpath:` resources.

Closes gh-29083
2022-09-06 14:36:28 +02:00
Brian Clozel dd1e6b9412 Revisit request parameters access with HtmlUnit
Prior to this commit, the `HtmlUnitRequestBuilder` would "translate"
HtmlUnit web requests into Servlet requests using APIs that were not
clearly defined and meant for internal usage.

HtmlUnit 2.64.0 introduced a new `.getParameters()` API for collecting
`NameValuePair` parsed from the request URI or request body, depending
on the nature of the request. This arrangement is much more stable and
in line with HtmlUnit's expectations.

This commit uses this new API and makes HtmlUnit 2.64.0 a new minimum
requirement for using HtmlUnit integration with Spring Framework.
This also removes tests that were previously testing HtmlUnit's behavior
and using the API now marked as internal.

Closes gh-28240
2022-09-06 13:40:28 +02:00
Sam Brannen 6902ff77d9 Fix resource registration hints in the TestContext framework
Resource patterns registered for inclusion in a GraalVM native image
must not start with a leading slash.
2022-09-05 18:38:38 +02:00
Stephane Nicoll 6e93f1187c Move TestCompiler from generator to generate
This commit harmonizes the package space by moving the TestCompiler
infrastructure from the now outdated "generator" package to "generate".

Closes gh-29082
2022-09-05 16:30:19 +02:00
Stephane Nicoll 58b0251af1 Relocate TestGenerationContext to spring-core-test
This commit moves the test implementation for GenerationContext in
spring-core-test. This also removes the copy we had in testfixtures

See gh-28877
2022-09-05 16:21:17 +02:00
Sam Brannen e57b5f1dfc Register runtime hints for @Sql scripts
SqlScriptsTestExecutionListener now implements AotTestExecutionListener
in order to register run-time hints for SQL scripts used by test
classes and test methods annotated with @Sql if the configured or
detected SQL scripts are classpath resources.

Closes gh-29027
2022-09-05 14:15:19 +02:00
Sam Brannen e85e769f1c Introduce @Sql tests for AOT processing 2022-09-05 12:54:55 +02:00
Sam Brannen 35bbe9f99d Polishing 2022-09-05 12:51:14 +02:00
Sam Brannen ea132388c5 Introduce AotTestExecutionListener API in the TestContext framework
This commit introduces an AotTestExecutionListener API that extends
TestExecutionListener and allows a TestExecutionListener to opt in for
AOT processing support, analogous to what the AotContextLoader API does
for a SmartContextLoader.

Closes gh-29070
2022-09-05 12:10:29 +02:00
Sam Brannen c2dd6667f1 Revise method signature in TestRuntimeHintsRegistrar 2022-09-05 12:10:29 +02:00
Sam Brannen b0e723dbbb Delete obsolete test code
We no longer register reflection run-time hints for the SpringExtension
since that is covered by the JupiterConfigProvider in the GraalVM Native
Build Tools project.
2022-09-04 19:50:41 +02:00
Sam Brannen a68d4ae25c Register runtime hints for ActiveProfilesResolvers
This commit introduces automatic registration of runtime hints for
custom ActiveProfilesResolver implementations configured via the
`resolver` attribute in @ActiveProfiles.

Closes gh-29022
2022-09-04 18:59:12 +02:00
Sam Brannen 8d6d3f2698 Polishing 2022-09-04 17:51:48 +02:00
Sam Brannen afff849992 Add missing package-info.java file 2022-09-04 17:50:45 +02:00
Sam Brannen cbb30153fb Introduce StandardTestRuntimeHints in the TestContext framework
This commit introduces StandardTestRuntimeHints and migrates existing
hint registration from TestContextAotGenerator to this new class.

In addition, this commit removes a package cycle between context.aot and
context.web that was introduced in commit dc7c7ac22a.

See gh-29026, gh-29069
2022-09-04 17:44:19 +02:00
Sam Brannen bf0ac84a05 Introduce TestRuntimeHintsRegistrar in the TestContext framework
Although RuntimeHintsRegistrar can be implemented to register general
hints that should be applied for all testing infrastructure, certain
use cases require access to test classes and the
MergedContextConfiguration in order to register appropriate hints.

To address that, this commit introduces TestRuntimeHintsRegistrar as a
companion to the core RuntimeHintsRegistrar.

Closes gh-29069
2022-09-04 17:14:24 +02:00
Sam Brannen dc7c7ac22a Register runtime hint for @WebAppConfiguration's resource path
This commit introduces automatic registration of a runtime hint for
classpath resources configured via the `value` attribute in
@WebAppConfiguration.

Closes gh-29026
2022-09-04 16:45:06 +02:00
Sam Brannen ef7784f85e Register runtime hints for @TestPropertySource#locations
This commit introduces automatic registration of runtime hints for
classpath resources configured via the `locations` attribute in
@TestPropertySource as well as for detected default properties files.

Closes gh-29025
2022-09-04 15:19:56 +02:00
Sam Brannen dcf160e427 Consistently include leading slash for classpath: resources in the TCF 2022-09-04 15:19:56 +02:00
Sam Brannen 920fbb34c8 Register runtime hints for @ContextConfiguration#locations
This commit introduces automatic registration of runtime hints for
classpath resources configured via the `locations` attribute in
@ContextConfiguration.

Closes gh-29021
2022-09-03 17:25:46 +02:00
Sam Brannen c0040b9024 Polishing 2022-09-03 17:25:00 +02:00
Sam Brannen 36a2a62294 Polishing 2022-09-03 16:55:28 +02:00
Sam Brannen cced3cba09 Register runtime hints for @TestExecutionListeners
Closes gh-29024
2022-09-02 14:53:49 +02:00
Sam Brannen 34635d7751 Register runtime hints for TestContextBootstrappers
This commit automatically registers runtime hints for
TestContextBootstrapper classes, including default bootstrappers as
well as any bootstrapper configured via @BootstrapWith.

Closes gh-29023
2022-09-02 14:40:09 +02:00
Sam Brannen 1cae054cf5 Polishing 2022-09-02 14:27:58 +02:00
Sam Brannen 549f4e7933 Register runtime hints for ApplicationContextInitializers in the TCF
This commit introduces automatic registration of runtime hints for
ApplicationContextInitializers configured via the `initializers`
attribute in @ContextConfiguration.

See gh-29021
2022-09-02 14:20:22 +02:00
Sam Brannen 51daeac86b Register runtime hints for ContextLoaders automatically in the TCF
This commit moves the registration of runtime hints for ContextLoaders
from TestContextRuntimeHints to TestContextAotGenerator.

This allows for automatic registration of any ContextLoader used,
including custom loaders declared via the `loader` attribute in
@ContextConfiguration.

See gh-29021
2022-09-02 14:20:11 +02:00
Sam Brannen 41b6f4e351 Commit changes to test 2022-09-02 13:17:48 +02:00
Sam Brannen 52712cecce Document reasons for hint registration in the TestContext framework 2022-09-02 13:15:32 +02:00
Sam Brannen dadfdb91d9 Stop registering SynthesizedAnnotation proxies in spring-test
See gh-29059
2022-09-02 13:10:18 +02:00
Sam Brannen 69f23095b8 Deprecate SynthesizedAnnotation and related methods
Since Spring no longer adds the SynthesizedAnnotation interface to the
JDK dynamic proxy used to synthesize an annotation, this commit
officially deprecates SynthesizedAnnotation and related methods in
RuntimeHintsUtils.

See gh-29041, gh-29054
Closes gh-29053
2022-09-02 12:04:17 +02:00
Sam Brannen 73abd58202 Polishing 2022-09-02 10:23:53 +02:00
Phillip Webb 505da5c602 Migrate hint registration to shortcuts
Migrate code to make use of the `MemberCategory` and `FieldMode`
shortcuts.

See gh-29011
2022-09-01 17:26:06 -07:00
Sam Brannen b22d01f5f3 Polish TestContextRuntimeHints 2022-08-31 16:35:13 +02:00
Sam Brannen 40647bdaf6 Register hints for test execution event annotations in the TCF
See gh-29044
2022-08-31 16:35:13 +02:00
Sam Brannen 2d35bbd74e Move TestContextRuntimeHints to aot.hint package 2022-08-31 16:35:13 +02:00
Sam Brannen 98c74059e0 Polish Javadoc 2022-08-31 16:35:13 +02:00
Andy Wilkinson a5fb55fd6d Replace dependency management plugin with built-in platform support 2022-08-30 17:03:24 +01:00
Sam Brannen 741ee960e2 Register runtime hints for TestContext framework classes and annotations
This commit introduces TestContextRuntimeHints which is a
RuntimeHintsRegistrar implementation that makes core types and
annotations from the Spring TestContext Framework available at runtime
within a GraalVM native image.

TestContextRuntimeHints is registered automatically via the
"META-INF/spring/aot.factories" file in spring-test.

This commit also modifies TestContextAotGeneratorTests to assert the
expected runtime hints registered by TestContextRuntimeHints as well as
runtime hints for TestExecutionListener and ContextCustomizerFactory
implementations registered by SpringFactoriesLoaderRuntimeHints.

Closes gh-29028
Closes gh-29044
2022-08-30 15:31:02 +02:00
Sam Brannen 0ebc86c1af Merge branch '5.3.x'
# Conflicts:
#	spring-test/src/main/java/org/springframework/test/context/web/socket/MockServerContainerContextCustomizerFactory.java
#	spring-test/src/test/java/org/springframework/test/context/web/socket/WebSocketServletServerContainerFactoryBeanTests.java
2022-08-28 18:48:21 +02:00
Sam Brannen 2c75eb8745 Support @Nested tests in MockServerContainerContextCustomizerFactory
Prior to this commit, MockServerContainerContextCustomizerFactory did
not find @WebAppConfiguration on an enclosing class and therefore
failed to create a MockServerContainerContextCustomizer for a @Nested
test class.

This commit addresses this by using TestContextAnnotationUtils to
determine if the test class is "annotated" with @WebAppConfiguration.

Closes gh-29037
2022-08-28 18:41:27 +02:00
Sam Brannen c24e98e51b Avoid reflection for instantiating MockServerContainerContextCustomizer
Since MockServerContainerContextCustomizerFactory already has a
`webSocketPresent` check, there should be no need to instantiate
MockServerContainerContextCustomizer via reflection.

See gh-29028
Closes gh-29035
2022-08-28 18:09:05 +02:00
Sam Brannen 92b582701e Skip ContextCustomizerFactory that cannot be loaded
With this commit, if a ContextCustomizerFactory cannot be loaded due to
a ClassNotFoundException or NoClassDefFoundError, we skip it and log a
DEBUG message.

This aligns with the "skipping" logic already in place for
TestExecutionListeners.

Closes gh-29034
2022-08-28 18:09:05 +02:00
Sam Brannen ab20a189c5 Consistent logging for skipped TestExecutionListeners
With this commit we now log an identical message (without a stack
trace) for a TestExecutionListener skipped due to a
ClassNotFoundException like we already do for a listener skipped due to
a NoClassDefFoundError.
2022-08-28 18:09:05 +02:00
Sam Brannen 7f88f315a4 Introduce logging for ContextCustomizer[Factory] to improve diagnostics
Prior to this commit, we logged which default TestExecutionListeners
were discovered and which listeners were used, but we did not log
anything for ContextCustomizerFactory and ContextCustomizer.

This commit therefore introduces similar logging for
ContextCustomizerFactory and ContextCustomizer to improve diagnostics.

Closes gh-29036
2022-08-28 18:08:12 +02:00
Sam Brannen aa7ef79478 Apply "instanceof pattern matching" in spring-test 2022-08-28 17:51:52 +02:00
Sam Brannen b50415062b Clean up warnings and polish tests
This commit also modifies ResourceWebHandlerTests.getResourceFromFileSystem()
so that it passes in the IDE.
2022-08-26 15:20:16 +02:00
Sam Brannen e53c7ae6f5 Polish Javadoc and internals of the TestContext framework 2022-08-26 13:53:10 +02:00
Sam Brannen c32ff17821 Revise @Nullable declarations in the TestContext framework 2022-08-26 12:21:47 +02:00
Sam Brannen 7671d29899 Add missing @Nullable declaration in AotTestMappings 2022-08-25 16:53:54 +02:00
Sam Brannen d467db4b9e Make TestClassScanner and TestContextAotGenerator public
This commit makes TestClassScanner and TestContextAotGenerator public so
that the Spring Boot team can take over implementation of the
TestAotProcessor to integrate it into the AOT and native build plugins.
2022-08-25 12:03:11 +02:00
Arjen Poutsma 9c33d2707a Introduce support for Netty 5 Buffer
This commit introduces support for Netty 5's Buffer, in the form of
Netty5DataBuffer. Because of the new API offered by Buffer, several
changes have been made to the DataBuffer API:

- CloseableDataBuffer is a simpler alternative to PooledDataBuffer, and
  implemented by Netty5DataBuffer. DataBufferUtils::release can now
  handle CloseableDataBuffer as well as PooledDataBuffer.
- PooledDataBuffer::touch has been moved into a separate interface:
  TouchableDataBuffer, which is implemented by Netty5DataBuffer.
- The capacity of DataBuffers can no longer be reduced, they can only
  grow larger. As a consequence, DataBuffer::capacity(int) has been
  deprecated, but ensureWritable (formally ensureCapacity) still exists.
- DataBuffer::slice and retainedSlice have been deprecated in favor of
  split, a new method that ensures that memory regions do not overlap.
- DataBuffer::asByteBuffer has been deprecated in favor of toByteBuffer,
  a new method that returns a copy, instead of shared data.
- DataBufferFactory::allocateBuffer has been deprecated in favor of
  allocateBuffer(int).

Closes gh-28874
2022-08-25 11:00:22 +02:00
Sam Brannen 019785a72e Introduce CLI for triggering AOT test context processing
This commit introduces TestAotProcessor which replaces
ProcessTestsAheadOfTimeCommand, removes the dependency on picocli, and
aligns with the implementation of the AotProcessor in Spring Boot.

TestAotProcessor is a command-line application (CLI) that scans the
provided classpath roots for Spring integration test classes and then
generates AOT artifacts for those test classes in the provided output
directories.

This CLI is only intended to be used by build tools.

Closes gh-28825
2022-08-24 17:12:34 +02:00
Sam Brannen 5115deb5e3 Introduce CLI for triggering AOT test context processing
This commit introduces ProcessTestsAheadOfTimeCommand, a command-line
application (CLI) that scans the provided classpath roots for Spring
integration test classes and then generates AOT artifacts for those
test classes in the provided output directories.

This CLI is only intended to be used by build tools.

Closes gh-28825
2022-08-23 16:39:59 +02:00
Sam Brannen feb2a30910 Improve precondition checks in TestClassScanner 2022-08-23 16:03:06 +02:00
Sam Brannen 8a6c1ba198 Introduce AOT run-time support in the TestContext framework
This commit introduces initial AOT run-time support in the Spring
TestContext Framework.

- DefaultCacheAwareContextLoaderDelegate: when running in AOT mode, now
  loads a test's ApplicationContext via the AotContextLoader SPI
  instead of via the standard SmartContextLoader and ContextLoader SPIs.

- DependencyInjectionTestExecutionListener: when running in AOT mode,
  now injects dependencies into a test instance using a local instance
  of AutowiredAnnotationBeanPostProcessor instead of relying on
  AutowireCapableBeanFactory support.

Closes gh-28205
2022-08-23 13:41:24 +02:00
Sam Brannen ada0880f3c Introduce AotTestMappings and AotTestMappingsCodeGenerator
TestContextAotGenerator now uses AotTestMappingsCodeGenerator to
generate a AotTestMappings__Generated.java class which is loaded in
AotTestMappings via reflection in order to retrieve access to
ApplicationContextIntializers generated during AOT processing.

Furthermore, the processAheadOfTimeAndGenerateAotTestMappings() method
in TestContextAotGeneratorTests now performs a rather extensive test
including:

- emulating TestClassScanner to find test classes
- processing all test classes and generating ApplicationContextIntializers
- generating mappings for AotTestMappings
- compiling all generated code
- loading AotTestMappings
- using AotTestMappings to instantiate the generated ApplicationContextIntializer
- using the AotContextLoader API to load the AOT-optimized ApplicationContext
- asserting the behavior of the loaded ApplicationContext

See gh-28205
Closes gh-28204
2022-08-23 13:41:16 +02:00
Sam Brannen b0d65709ac Test XML, Web, & @TestPropertySource AOT support
See gh-28204, gh-28205
2022-08-23 13:41:07 +02:00
Sam Brannen 84c377965c Introduce AotContextLoader SPI in the TestContext framework
This commit introduces a dedicated AotContextLoader extension of
SmartContextLoader and reverts the recent changes to the existing
contract for SmartContextLoader. This allows existing
SmartContextLoader implementations to continue working unaffected by
AOT support unless they opt into AOT support by explicitly implementing
the new AotContextLoader contract.

In addition, existing SmartContextLoader implementations in the
spring-test module have been modified to implement AotContextLoader
instead of SmartContextLoader. This allows the core framework to
provide built-in AOT support in the TestContext framework, and it also
allows third-party extensions to built-in SmartContextLoaders to
participate in AOT processing and run-time support transparently (or at
least as transparent as possible).

Closes gh-28906
2022-08-23 13:40:58 +02:00
Sam Brannen c1a6bfc701 Introduce initial support for processing test contexts ahead-of-time
This commit introduces TestContextAotGenerator for processing Spring
integration test classes and generating AOT artifacts. Specifically,
this class performs the following.

- bootstraps the TCF for a given test class
- builds the MergedContextConfiguration for each test class and tracks
  all test classes that share the same MergedContextConfiguration
- loads each test ApplicationContext without refreshing it
- passes the test ApplicationContext to ApplicationContextAotGenerator
  to generate the AOT optimized ApplicationContextInitializer
  - The GenerationContext passed to ApplicationContextAotGenerator uses
    a feature name of the form "TestContext###_", where "###" is a
    3-digit sequence ID left padded with zeros.

This commit also includes tests using the TestCompiler to verify that
each generated ApplicationContextInitializer can be used to populate a
GenericApplicationContext as expected.

See gh-28204
2022-08-23 13:40:48 +02:00
Sam Brannen a9466437c8 Merge branch '5.3.x'
# Conflicts:
#	spring-test/src/main/java/org/springframework/test/context/cache/DefaultCacheAwareContextLoaderDelegate.java
2022-08-21 15:23:33 +02:00
Sam Brannen 711820ec70 Introduce createContext() factory method in AbstractWebGenericContextLoader
Prior to this commit it was possible to configure the
DefaultListableBeanFactory used by the GenericWebApplicationContext
created by AbstractWebGenericContextLoader, but it was not possible to
completely replace the bean factory.

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

See gh-25600
Closes gh-28983
2022-08-21 15:05:23 +02:00
Sam Brannen 69d87f16ee Reorganize internals of DefaultCacheAwareContextLoaderDelegate 2022-08-21 15:02:28 +02:00
Sam Brannen 409ee9234d Merge branch '5.3.x' 2022-08-19 16:06:14 +02:00
Sam Brannen 38f94799f4 Use andExpectAll() in example in MockMvc Javadoc 2022-08-19 16:05:31 +02:00
Sam Brannen 4264d0becd Fix example in MockMvc Javadoc 2022-08-19 16:02:10 +02:00
Sam Brannen ef7ab768e7 Polishing 2022-08-17 12:03:10 +02:00
Sam Brannen 8fe6a9f537 Handle NoClassDefFoundError consistently for skipped TestExecutionListener
Commit d1b65f6d3e introduced a regression for the handling of
NoClassDefFoundError when skipping a TestExecutionListener that cannot
be loaded. Specifically, the DEBUG log message changed and included the
stack trace; whereas, it previously did not include the stack trace.

This commit consistently handles NoClassDefFoundError for a skipped
TestExecutionListener, whether a default listener or a listener
registered via @TestExecutionListeners and aligns with the previous
behavior by omitting the stack trace for a NoClassDefFoundError.

Closes gh-28962
2022-08-17 11:25:51 +02:00
Sam Brannen 36fa8bd26b Remove unused constructors in TestGenerationContext 2022-08-16 12:06:40 +02:00
Juergen Hoeller 38c9e7f629 Polishing 2022-08-10 23:30:27 +02:00
Sam Brannen 0944c9a99c Remove `throws IOException` from DefaultGenerationContext.writeGeneratedContent()
The `throws` declaration is unnecessary since writeGeneratedContent()
will never throw an IOException.
2022-08-06 14:34:04 +03:00
Sam Brannen a466179bc8 Polish and sync TestGenerationContext implementations
- new constructor for providing InMemoryGeneratedFiles
- writeGeneratedContent() now throws UncheckedIOException
2022-08-06 14:08:49 +03:00
Sam Brannen 843221b448 Fix broken Javadoc links
See gh-28906
2022-08-04 11:51:56 +03:00
Sam Brannen 855a3e5221 Polish ContextLoader support 2022-08-03 18:37:54 +03:00
Sam Brannen e3f4d810f6 Revise configurable refresh support in SmartContextLoader SPI
This commit revises 903e9f2a02 based on feedback from the Spring Boot
team.

- The original loadContext(MergedContextConfiguration) method is no
  longer deprecated.

- loadContext(MergedContextConfiguration, boolean) has been replaced by
  loadContextForAotProcessing(MergedContextConfiguration) which is
  implemented as a `default` method that throws an
  UnsupportedOperationException.

- Affected code has been refactored to adjust to these changes.

See gh-28906
2022-08-03 16:54:32 +03:00
Sam Brannen 903e9f2a02 Introduce configurable refresh support in SmartContextLoader SPI
Prior to this commit, the contract of the loadContext() method in the
SmartContextLoader SPI required that the ApplicationContext be returned
in a fully refreshed state with a JVM shutdown hook registered for it.

However, in order to support AOT processing within the Spring
TestContext Framework (TCF), we need a way to signal to
SmartContextLoader implementations that they should load the test's
ApplicationContext without refreshing it or registering a JVM shutdown
hook.

To address this issue, this commit:

- Introduces a new loadContext(MergedContextConfiguration, boolean)
  method. The boolean `refresh` flag controls whether the returned
  ApplicationContext should be refreshed and have a JVM shutdown hook
  registered for it.

- Deprecates the existing loadContext(MergedContextConfiguration)
  method in favor of loadContext(MergedContextConfiguration, boolean).

- Removes all use of the deprecated method within the spring-test
  module, excluding the exception mentioned below.

Note that loadContext(MergedContextConfiguration, boolean) is
implemented as an interface `default` method which delegates to the
deprecated loadContext(MergedContextConfiguration) method for backward
compatibility. When migrating a SmartContextLoader to Spring Framework
6.0, implementations that directly implement the SmartContextLoader SPI
(instead of extending AbstractGenericContextLoader or
AbstractGenericWebContextLoader) will need to override the new
loadContext(MergedContextConfiguration, boolean) method in order to
honor the `refresh` flag for AOT processing support. See the
implementation in AbstractGenericContextLoader for an example of how
this can be achieved.

Closes gh-28906
2022-08-03 13:10:35 +03:00
Sam Brannen abd06768a3 Avoid dependence on deprecated ContextLoader API within AbstractContextLoader
See gh-28905
2022-08-02 15:29:04 +03:00