When a test context fails to load, a `ContextLoadException` should
be thrown so that Framework can catch it and call any registered
`ApplicationContextFailureProcessor`s.
Closes gh-31793
Update `EventPublishingRunListener` to ensure that application event
listeners are always refreshed before multicasting initial events.
Prior to this commit, refreshing occurred after multicasting which
meant that listeners added by a different `SpringApplicationRunListener`
would not be picked up. This caused properties from tests that have
`UseMainMethod` set to `ALWAYS` or `WHEN_AVAILABLE` to be missing.
Fixes gh-32860
Refactor the way `ClientHttpRequestFactory` instances are created in
order to support setting read timeouts.
Prior to this commit, the reflection based approach would call
`setReadTimeout`. As of Spring Framework 6.0, the
`HttpComponentsClientHttpRequestFactory` class no longer supports this
approach. The timeout must be set on the `HttpClientConnectionManager`
used in the `HttpClient` which can be passed in to the constructor.
In order to support this approach, the `ClientHttpRequestFactory` can
now be created using a `Function` rather than a `Supplier`. The
function accepts a `ClientHttpRequestFactorySettings` which provides
the timeout settings to apply.
The `ClientHttpRequestFactories` utility class provides methods to
create `ClientHttpRequestFactory` instances that respect the settings.
Whenever possible, these are created without using reflection.
Fixes gh-32857
Co-authored-by: Phillip Webb <pwebb@vmware.com>
After AOT processing, a HttpGraphQlTester bean will be defined directly
so the context customizer that initiates its registration is not
needed.
Closes gh-32872
After AOT processing, a WebTestClient bean will be defined directly
so the context customizer that initiates its registration is not
needed.
Closes gh-32859
After AOT processing, a TestRestTemplate bean will be defined
directly so the context customizer that initiates its registration is
not needed. We'd already disabled the registrar but this is
insufficient in Graal 22.3 which fails fast when the customizer tries
to reference the registrar.
Fixes gh-32848
Update `OutputCapture` so that expensive build operations are only
performed when necessary. This update is especially important for Kotlin
users calling `"Expected String" in output` since this results in a call
to Kotlin's `CharSequence.contains` which calls the `length()` and
`charAt()` methods many times.
Closes gh-32033
This commit adapts the `TestRestTemplate` implementation to the
httpclient5 API since httpclient 4.x is now unsupported in Spring
Framework.
See gh-32461
As htttpclient 4.x is not supported anymore by `RestTemplate`, this
commit changes such dependencies to httpclient5 instead. In some cases,
the httpclient 4.x was transitively brought by a non-Spring dependency.
See gh-32461
This commit disables ContextCustomizer implementations that tune a
test configuration context at runtime. Previously, these ran again and
required additional hints to work properly.
Rather than contributing those hints, the customizer is skipped as its
impact is irrelevant in an AOT-optimized context: the context is fully
prepared and the updates on the MergedContextConfiguration are not taken
into account.
Closes gh-32422
Update `SpringBootContextLoader` so that it now implements the
`AotContextLoader` interface. The `ContextLoaderHook` will abandon
at `contextLoaded` if the test class is being AOT processed.
This commit also introduces a new `AotApplicationContextInitializer`
which allows us to plug-in an alternative AOT application context
listener when the `SpringApplication` is running in test mode.
Closes gh-31965
Add a new `useMainMethod` attribute to `SpringBootTest` which can be
used to determine how the test should run. The three available options
are:
- `ALWAYS`
- `NEVER`
- `WHEN_AVAILABLE`
The default is `WHEN_AVAILABLE` which will attempt to launch the test
using the `main` method if there is one.
The `SpringBootContextLoader` has been updated to use the new
`SpringApplicationHook` interface when the main method is being used.
Closes gh-22405
This commit adds the Spring for GraphQL auto-configuration back
into Spring Boot 3.0, now that a 1.1.0 release is scheduled with the
required baseline. This release also needs GraphQL Java 19.0 as a
baseline.
Closes gh-31809
Add `AbstractApplicationContextRunner.prepare` which can be used to
test an `ApplicationContext` that has been prepared but not refreshed.
Closes gh-31302
Previously, classes were registered first which meant that their
conditions were evaluated before any initializers and bean
registrations were applied. This prevented the bean registrations and
initializers from affecting the outcome of the condition evaluation.
This commit inverts the ordering so that classes are not registerd,
and therefore their conditions are not evaluated, until after the
bean registrations and initializers have been applied.
Closes gh-31280
As seen in spring-projects/spring-graphql#375, Spring Boot should also
use "application/json" as the default MIME type but remain compatible
with "application/graphql+json" still if clients POST content with this
type or explicitly accept it.
Closes gh-30860
Previously, if spring.main.web-application-type was configured in
application.properties to servlet or reactive, setting
webEnvironment=NONE on @SpringBootTest would not work correctly and
a servlet or reactive web application context would be created
based on the value of spring.main.web-application-type.
This commit updates the test context bootstapper to set
spring.main.web-application-type to none when webEnvironment has been
set to none. This is done in the merged context configuration's
property source properties which are applied to the environment in a
high-precedence test property source that will override configuration
in application.properties.
Closes gh-29695
Previously, SpringBootContextLoader would configure its
SpringApplication with an ApplicationContextFactory that ignores
the WebApplicationType with which its called and instead returns a
hard-coded type of context based on the type of the
MergedContextConfiguration. This hard-coding would result in the
wrong type of context being used if a subsequent change was made to
the application's WebApplicationType, for example due to binding of
the spring.main.web-application-type configuration property.
This commit updates SpringBootContextLoader to configure
SpringApplication with an ApplicationContextFactory that takes the
WebApplicationType with which it is called into consideration.
Fixes gh-29170
As seen in spring-projects/spring-graphql#108, the GraphQL HTTP spec now
requires the "application/graphql+json" media type and accepts
"application/json" for backwards compatibility.
This commit updates the `RouterFunction` definition for the GraphQL HTTP
endpoints so that both types are accepted.
Closes gh-30407