Prior to this commit, active profiles were being added to the Spring Boot
application environment by setting the `spring.profiles.active` property.
This could result in profiles getting parsed differently than other uses of `@ActiveProfiles`.
Setting the profiles directly in the `Environment` prevents this parsing.
See gh-19556
Previously, Maven's default behaviour was relied up which resulted
in the artifact ID being appended to each URL as it was inherited.
This behaviour can only be disabled in Maven 3.6 and later, a version
that we cannot use due to an incompatibility with the Flatten Plugin.
This commit works around Maven's default behaviour by defining
properties for the SCM URL, connection, and developer connection and
then explicitly defining the settings in each pom using these
properties. The explicit definition of the properties in each pom
prevents them being inherited from the parent, thereby disabling the
unwanted appending of the artifact ID to the URL.
Fixes gh-18328
Previously, when spying on a scoped bean the creation of the spy
would be performed using the scoped proxy. This would result in
the spy being unable to spy on any of the target bean's methods as
the scoped proxy's implementations of those methods would be final.
This commit updates MockitoPostProcessor so that the creation of the
spy and injection of the @SpyBean-annotated field is performed using
the scoped target. The scoped target has not be proxied so this
allows Mockito to spy on all of its methods.
Closes gh-17817
Extend `JsonContentAssert` with `hasJsonPath` and `doesNotHaveJsonPath`
methods which can be used to check the path regardless of the value it
may or may not contain.
Prior to this commit there wasn't an easy way to assert that the
Jackson `@JsonInclude(JsonInclude.Include.NON_NULL)` annotation was
applied since `assertDoesNotHavePathValue` would pass for both
`{"name" : null}` and `{}`.
Closes gh-17608
Meta-annotate `ClassPathExclusions` and `ClassPathOverrides` with
so that the `ModifiedClassPathExtension` no longer needs to be
used directly.
See gh-17491
Apply checkstyle rule to ensure that private and package private
classes do not have unnecessary public methods. Test classes have
also been unified as much as possible to use default scoped
inner-classes.
Closes gh-7316
Broaden the scope of customizer support so that instead of focusing
just on headers, we can now customize any outgoing `HttpClientRequest`.
Also update auto-configuration to automatically add any
`RestTemplateRequestCustomizer` beans to the builder.
See gh-17091
Update `RestTemplateBuilder` so that it is easier to apply custom
headers to the outgoing request. The update is particularly useful
for setting the `User-Agent` header, for example so that a GitHub
username can be used when calling `api.github.com`.
See gh-17091
Reduce the surface area of the public API by making the
`BasicAuthentication` and `BasicAuthenticationClientHttpRequestFactory`
class package private.
This commit also attempts to simplify `TestRestTemplate` by keeping
the `RestTemplateBuilder` and reusing it, rather than needing to deal
only with a `RestTemplate` instance.
See gh-17010
Update `RestTemplateBuilder` to use a custom request factory to add
authentication headers rather than an interceptor.
Prior to this commit, the use of the `BasicAuthenticationInterceptor`
interceptor could cause `OutOfMemoryError` whenever a large file is
uploaded.
See gh-17010
Split the JUnit 5 `OutputCapture` class into separate `OutputExtension`
and `CapturedOutput` classes. The JUnit 5 callback methods are now
contained only in the `OutputExtension` class so no longer pollute the
public API that users will interact with.
The `CapturedOutput` class has also been updated to capture System.err
and System.out separately to allow distinct assertions if required.
Closes gh-17029
Previously, due to a quirk in Spring Framework, it was necessary to use bean method
proxying in @Configuration classes that define one or more FactoryBeans. This quirk has
now been addressed so this commit disables bean method proxying where it is now no longer
needed.
Closes gh-16533
The `spring-boot-test` module has a dependency to TestNG to validate
some part of the test infrastructure but no tests are actually written
using TestNG. The presence of TestNG is a trigger for the maven surefire
plugin and it attempts to run tests using it.
This commit defines the explicit provider to use (JUnit 4)
Closes gh-16735
Polish contribution to use a factory method in `AbstractJsonMarshalTester`
rather than additional constructor arguments.
Also change the `JsonContent` tests so that the `Configuration` constructor
is package private. This keeps JsonPath classes out of our public API, at
the expense of limiting custom JsonPath configurations to just our code.
See gh-16629
Update `JacksonTester` so that the JsonPath instance is explicitly configured
with both a `JacksonJsonProvider` and a `JacksonMappingProvider`.
Prior to this commit, the handling of special characters was not symmetrical
between the serialization (handled via the JacksonTester) and the parsing (handled
via JsonPath) due to the fact that JsonPath used `SimpleJson` as its parser.
See gh-16629
Rework `AbstractApplicationContextRunner.withBean` methods to
align signatures as much as possible with those provided by
the `ApplicationContext`.
Also update the implementation to use a dedicate member
variable rather than adding initializers.
Closes gh-16011
This commit adds `withBean` methods to the `ApplicationContextRunner`
abstraction so that simple beans can be registered inline. This is a
nice alternative for cases where a inner configuration class has to be
defined for the purpose of creating a simple bean.
Closes gh-16011
This commit migrates `AnnotationConfigReactiveWebApplicationContext`
parent to the `GenericApplicationContext` abstraction. Any use of
`AnnotationConfigWebApplicationContext` is also removed as it also
inherits from the `AbstractRefreshableApplicationContext` outdated
hierarchy.
A new `AnnotationConfigServletWebApplicationContext` context is
introduced instead, extending from `GenericApplicationContext` and
providing the counter part of the reactive context for the Servlet-based
web app tests.
See gh-16096
Until Spring Framework 5.1.15, a FactoryBean with a non-default constructor
defined via component scanning would cause an error. This behavior has changed
as of https://github.com/spring-projects/spring-framework/issues/22409.
Regardless of this change we want to ensure that we avoid triggering eager
initialisation. `SimpleFactoryBean` has been written this way so that the tests
fail if early initialization is triggered regardless of the Spring Framework version.
Fixes gh-15898
This commit updates the behavior of withBasicAuth on TestRestTemplate
by trying to use the same request factory type as the underlying restTemplate.
If creation of a new instance of the configured request factory class fails,
it falls back to the `ClientHttpRequestFactorySupplier`.
See gh-15982
It's part of TestRestTemplate's contract that it's fault tolerant. This
commit aligns the behavior of `withBasicAuth` with that expectation.
Closes gh-15780
Update `ApplicationContextAssert.getBean` so that multiple beans are
supported as long as one of them is primary. This aligns better with
the way that the standard `ApplicationContext.getBean` method works.
Closes gh-14874
Update `Assertable*ApplicationContext` interfaces so that they also
extend the appropriate `Configurable*ApplicationContext` interface.
Closes gh-14650
The SpringBootContextLoader still checked if tests were annotated with
@IntegrationTest or @WebIntegrationTest. Those classes have been
removed in Spring Boot 1.5 and been deprecated since 1.4.
This commit removes the check on the annotations as well as the static
list of names.
See gh-14592
This commit changes @SpringBootTest(randomPort = true) to
generate a random port for the actuator endpoints if the
management server runs on a different port from the main
server.
Closes gh-4424
Update `MockitoPostProcessor` so that `@MockBean` and `@SpyBean`
work consistently when combined with `@Primary`.
See gh-11077
Co-authored-by: Andreas Neiser <andreas.neiser@gmail.com>
As of Spring Framework 5.1, we're depending on the Reactor Californium
release train.
Reactor Netty is now at version 0.8 and changed its artifact
coordinates, package names and broke several APIs. Spring Framework is
now up-to-date with those changes and this commit does the same for
Spring Boot.
Note that in that process, the `NettyServerCustomizer` has been changed
since the former `HttpServerOptions.Builder` API is now gone from
Reactor Netty, and we're now relying on immutable server instances
instead of a stateful builder pattern.
See gh-13321
This commit changes invocations to immediately return the expression
instead of assigning it to a temporary variable. The method name should
be sufficient for callers to know exactly what will be returned.
Closes gh-12211
This commit fixes two issues in `TestRestTemplate`:
* it improves the detection of the underlying request factory, using
reflection to look inside the intercepting request factory if
interceptors were configured
* it avoids reusing the same request factory when creating a new
`TestRestTemplate` with `withBasicAuth`. Sharing the same instance would
result in sharing authentication state (HTTP cookies). Since the
original request factory can't be detected consistently, a new one is
selected automatically
See gh-8697
Previously `TestRestTemplate` would override the configured
`ClientHttpRequestFactory` if the Apache HTTP client library was on
classpath.
This commit fixes two issues:
1. The existing `ClientHttpRequestFactory` is overridden *only* if it is
using the Apache HTTP client variant, in order to wrap it with the
`TestRestTemplate` custom support
2. Calling `withBasicAuth` will no longer directly use the request
factory returned by the internal `RestTemplate`; if client interceptors
are configured, the request factory is wrapped with an
`InterceptingClientHttpRequestFactory`. If we don't unwrap it,
interceptors are copied/applied twice in the newly created
`TestRestTemplate` instance. For that, we need to use reflection as the
underlying request factory is not accessible directly.
Closes gh-8697
Update `ApplicationContextAssert` with support for scopes. Allows
tests to consider the all ancestors, or limit assertions to just the
current context.
Fixes gh-12015
As discussed in gh-11872, `TestRestTemplate` constructor variants taking
a `RestTemplate` argument are confusing since the main goal of that
class is to mutate `RestTemplate`.
This commit removes all those constructor variants and replaces them
with `RestTemplateBuilder` arguments when possible.
Closes gh-11872