Commit Graph

347 Commits (2d79d63a9d553d98cefefeb3fc944341be2bce56)

Author SHA1 Message Date
Phillip Webb 5867cd6175 Polish 8 years ago
Stephane Nicoll c5595f296c Add support for Mock test with WebFlux
This commit add mock support for WebFlux with an infrastructure similar
to what `WebMvcTest` provides. `@WebFluxTest` can be used to test
controllers with a narrowed classpath that is relevant to WebFlux. Also,
`@SpringBootTest` now starts WebFlux in "mock" mode by default and
`@AutoConfigureWebTestClient` can be used to inject a `WebTestClient`
connected to the `ApplicationContext`.

To make that happen, a `ReactiveWebApplicationContext` interface has been
introduced to mirror what `WebApplicationContext` currently does. Things
are still a bit volatile at this point and that infra may move to Spring
Framework at some point.

Closes gh-8401
8 years ago
Stephane Nicoll 12397edbd4 Expose a WebTestClient with `@SpringBootTest`
This commit exposes a `WebTestClient` automatically in a reactive
integration test that uses an embedded web server. This is similar to
what we do with `TestRestTemplate` for servlet based integration tests.

Closes gh-8399
8 years ago
Stephane Nicoll 54939e8e3c Start a reactive web application if necessary
This commit makes sure that `@SpringBootTest` with a reactive setup
starts a web application if necessary.

If both a servlet and a reactive environment are available, a servlet
environment is bootstraped. This commit also adds a way to force a
reactive environment by specifying the `spring.main.web-application-type`
property of the test (e.g. `@TestPropertySource`).

Closes gh-8383
8 years ago
Andy Wilkinson fcd1eb79fc Fix forward merge of new SpyBean test to use correct Mockito 2 API 8 years ago
Andy Wilkinson 1e806bbbd2 Merge branch '1.5.x' 8 years ago
Andy Wilkinson 8318177b0d Merge branch '1.4.x' into 1.5.x 8 years ago
Andy Wilkinson 70e802fba5 Use name from @SpyBean to disambiguate multiple candidates
Previously, @SpyBean's name attribute was not used when determining
the name of the bean to spy upon. When there were multiple candidates,
none of which were primary, this would lead to a failure to find the
bean to spy upon. This behaviour is also inconsistent with @MockBean
which does use the name attribute to identify the bean to mock.

This commit updates MockitoPostProcessor to use the name attribute,
when set, to identify the bean that should be spied upon. For
consistency with @MockBean it is always used when set. When not set
the previous logic will continue to be used.

Closes gh-8315
8 years ago
Andy Wilkinson 13791cad53 Use DefaultUriBuilderFactory instead of DefaultUriTemplateHandler
Closes gh-8247
8 years ago
Brian Clozel 12d883f6b9 Introduce "server.servlet" configuration prefix
This commit refactors the `ServerProperties` property keys and
introduces a separate "server.servlet" namespace to isolate
servlet-specific properties from the rest.

Closes gh-8066
8 years ago
Brian Clozel 250a1601d7 Add WebApplicationType.REACTIVE type
This commit introduces a new variant of web applications: there are now
Servlet based and Reactive web applications.
The mere presence of `Servlet` and `ConfigurableWebApplicationContext`
classes is not enough to make a difference between those variants.
This is why the decision process is now the following:

* if `DispatcherHandler` is present but not `DispatcherServlet`, the
WebApplicationType is detected as REACTIVE
* if `DispatcherHandler` is present and `DispatcherServlet`, this is a
case where we consider that developers are using Spring MVC in
combination with the reactive web client. So WebApplicationType is
detected as SERVLET
* if `Servlet` and `ConfigurableWebApplicationContext` are present,
WebApplicationType is detected as SERVLET
* if none of the above match, WebApplicationType is NONE

Fixes gh-8017
8 years ago
Stephane Nicoll cfdc75d384 Merge branch '1.5.x' 8 years ago
Johnny Lim 0adab8a2be Use logical 'and' instead of bitwise 'and'
Closes gh-8198
8 years ago
Andy Wilkinson aa19cad770 Merge branch '1.5.x' 8 years ago
Andy Wilkinson b9b0cdb342 Merge branch '1.4.x' into 1.5.x 8 years ago
Andy Wilkinson 2f50d515a1 Apply root to URIs directly rather than relying on expansion
Previously, TestRestTemplate applied the root URI to URIs by
converting them to a String and then passing the String to the
RestTemplate delegate. Being a String, meant that the URI passed
through RestTemplate's standard URI template expansion processing
using the configured UriTemplateHandler. While this caused the root
URI to be applied, it also had the unwanted side-effect of
encoding the URI for a second time.

This commit updates TestRestTemplate so that, when configured with a
RootUriTemplateHandler, it applies the root URI directly and then
passes a modified URI to the RestTemplate delegate. Being a URI means
that no template expansion is performed and the possible double
encoding is avoided.

Closes gh-8163
8 years ago
Andy Wilkinson 95f659f4f9 Add new WebApplicationType enum to pave the way for Web Flux support
Closes gh-8077
8 years ago
Spring Buildmaster 5c12500366 Next Development Version 8 years ago
Spring Buildmaster a2696bf873 Next Development Version 8 years ago
Andy Wilkinson 15639d39b0 Merge branch '1.5.x' 8 years ago
Andy Wilkinson dd4051686b Remove empty test
The caching behaviour when using ImportAutoConfiguration is covered
by tests in spring-boot-test-auto-configuration, specifically by
ImportsContextCustomizerFactoryWithAutoConfigurationTests.

See gh-7953
8 years ago
Phillip Webb 8747e039ee Merge branch '1.5.x' 8 years ago
Phillip Webb fa6a138598 Refine ImportsContextCustomizer cache logic
Update `ImportsContextCustomizer` so that whenever possible a more
specific cache key is used.

Prior to this commit the customizer would generate a key based on *all*
annotations on the test class. This has repeatedly caused issues where
test classes that should have the same cache key did not due to
unrelated annotations.

A new `DeterminableImports` interface has been added that can be
implemented by `ImportSelector` and `ImportBeanDefinitionRegistrar`
implementations that are able to determine their imports early. The
existing `ImportAutoConfigurationImportSelector` and
`AutoConfigurationPackages` classes have been retrofitted with
this interface.

Fixes gh-7953
8 years ago
Andy Wilkinson 31b0e81765 Add @FunctionalInterface to remaining public and protected interfaces
See gh-6857
8 years ago
Spring Buildmaster ed1ce140c0 Next Development Version 8 years ago
Stephane Nicoll 661fd848eb Merge branch '1.5.x' 8 years ago
Stephane Nicoll 505e7f75ea Polish contribution
Closes gh-8089
8 years ago
dreis d58f38f6f6 Use String.replace() with single char if possible
See gh-8089
8 years ago
Andy Wilkinson fd677af868 Merge branch '1.5.x' 8 years ago
Andy Wilkinson b71baf2c38 Support @ContextHierarchy when using @SpringBootTest
Closes gh-8000
8 years ago
Andy Wilkinson 973b7a118c Merge branch '1.5.x' 8 years ago
Andy Wilkinson c31a2d8101 Merge branch '1.4.x' into 1.5.x 8 years ago
Andy Wilkinson 80a1e1ae64 Polishing 8 years ago
Andy Wilkinson 84583d2b8f Merge branch '1.5.x' 8 years ago
Andy Wilkinson 4e70cd2934 Merge branch '1.4.x' into 1.5.x 8 years ago
Andy Wilkinson b7a02e7237 Update TestRestTemplate to apply template handler to URIs
Previously, TestRestTemplate would only apply the UriTemplateHandler
to Strings and not to URIs. When using the auto-configured
TestRestTemplate, this prevented relative URIs from being
made absolute using LocalHostUriTemplateHandler.

The commit updates TestRestTemplate to turn URIs into Strings before
passing them to the delegate RestTemplate. Turning them into Strings
ensures that the delegate calls the UriTemplateHandler.

Closes gh-7891
8 years ago
Andy Wilkinson d2201d5284 Correct copyright dates and enforce that starting year is 2012
Closes gh-7923
8 years ago
Phillip Webb 0fca9aaccb Polish Mockito 2.0 support 8 years ago
Phillip Webb 962313d0e1 Merge branch '1.5.x' 8 years ago
Phillip Webb abb8e3663a Polish Mockito 2.0 support 8 years ago
Phillip Webb c4779a10ac Fix Mockito 2 support
See gh-7770
8 years ago
Phillip Webb 77f9bb09ca Further Polish Mockito 2 support
See gh-7770
8 years ago
Phillip Webb 1169f69390 Polish MockitoApi 8 years ago
Phillip Webb 9048c97572 Polish Mockito 2 support
gh-7770
8 years ago
Phillip Webb 0cc313f224 Polish 8 years ago
Stephane Nicoll fab43f343d Merge branch '1.5.x' 8 years ago
Stephane Nicoll 6293033e1b Remove useless dependency 8 years ago
Stephane Nicoll c28ff4314c Upgrade to Mockito 2
Closes gh-7770
8 years ago
Phillip Webb ad2ff27208 Merge branch '1.5.x' 8 years ago
Phillip Webb fac6b8da47 Upgrade to JSONassert 1.4.0
Closes gh-7846
8 years ago
Stephane Nicoll 506f6497c0 Merge branch '1.5.x' 8 years ago
Johnny Lim f915ae197a Polish 8 years ago
Phillip Webb b1cb8bb3d9 Merge branch '1.5.x' 8 years ago
Phillip Webb 8ccd4db513 Merge branch '1.4.x' into 1.5.x 8 years ago
Phillip Webb 556ce14f2d Fix TestRestTemplate.withBasicAuth interceptors
Update `TestRestTemplate` to handle `BasicAuthorizationInterceptor`s
correctly. Prior to this commit the `BasicAuthorizationInterceptor`
was added directly to the `ClientHttpRequestFactory` rather than
to the `RestTemplate`. This meant that it could not easily be removed
when `TestRestTemplate.withBasicAuth` was invoked.

The `TestRestTemplate` now sets the interceptor on `RestTemplate`
directly and relies on the logic in `InterceptingHttpAccessor` to
add it to the `ClientHttpRequestFactory`.

Fixes gh-7812
8 years ago
Phillip Webb 519f9c6c54 Merge branch '1.5.x' 8 years ago
Phillip Webb 8b69856fc9 Polish 8 years ago
Stephane Nicoll 576d5dd58f Merge branch '1.5.x' 8 years ago
Stephane Nicoll 25bd0e0455 Do not reset server.port if a custom inline property is set
This commit allows to define `server.port` in a non-embedded web
environment. Previously, `server.port` would have been set to `-1`
regardless.

Closes gh-7353
8 years ago
Phillip Webb a2c50a9828 Merge branch '1.5.x' 8 years ago
Phillip Webb 884c9ef11e Remove accidentally committed file 8 years ago
Phillip Webb 49fa702708 Merge branch '1.5.x' 8 years ago
Phillip Webb e0541d0f74 Polish 8 years ago
Stephane Nicoll ec15607bad Merge branch '1.5.x' 8 years ago
Stephane Nicoll 37519ecfef Merge branch '1.4.x' into 1.5.x 8 years ago
Stephane Nicoll 062104f1d6 Fix TestRestTemplate#patchFor methods visibility
Closes gh-7742
8 years ago
Spring Buildmaster 9057f9ae1f Next development version 8 years ago
Phillip Webb 6e02fe59f7 Merge branch '1.5.x' 8 years ago
Phillip Webb 765fd1dca0 Merge branch '1.4.x' into 1.5.x 8 years ago
Phillip Webb 138b96cf5f Use unique `testRestTemplate` bean name
Update `SpringBootTestContextCustomizer` to use the full qualified
TestRestTemplate as the registered bean name. Prior to this commit it
was possible that the customizer would replace the relatively common
bean name `testRestTemplate`.

Fixes gh-7711
8 years ago
Phillip Webb 571544d1b3 Merge branch '1.5.x' 8 years ago
Phillip Webb 73a45797c0 Merge branch '1.4.x' into 1.5.x 8 years ago
Phillip Webb 7824171413 Allow @SpyBean to work with @Primary beans
Update `MockitoPostProcessor` so that `@SpyBean` will automatically
pick the `@Primary` bean when multiple candidates exist.

Fixes gh-7621
8 years ago
Phillip Webb 87547f208a Add test for @SpyBean for generic bean definition
Add an integration test to check that @SpyBean can be used with on a
bean definition that returns a generic type.

Closes gh-7625
8 years ago
Phillip Webb 1f417997f3 Merge branch '1.5.x' 8 years ago
Phillip Webb 4b9cba351b Merge branch '1.4.x' into 1.5.x 8 years ago
Phillip Webb bd74c3d327 Polish formatting 8 years ago
Stephane Nicoll b000e182a2 Merge branch '1.5.x' 8 years ago
Stephane Nicoll 28e86272e8 Merge branch '1.4.x' into 1.5.x 8 years ago
Stephane Nicoll 863f97dc11 Polish since version
Closes gh-7412
8 years ago
Andy Wilkinson 367de7bf71 Add support for new PATCH methods to TestRestTemplate
Closes gh-7412
8 years ago
Phillip Webb 263d444d4e Merge branch '1.5.x' 8 years ago
Phillip Webb f6b0652369 Merge branch '1.4.x' into 1.5.x 8 years ago
Phillip Webb e430583eaf Polish 8 years ago
Stephane Nicoll 816c236e5b Merge branch '1.5.x' 8 years ago
Stephane Nicoll ee72e788ed Rename `spring-boot-junit-runners` to `spring-boot-test-support`
Closes gh-7421
8 years ago
Andy Wilkinson 304fff1bee Merge branch '1.5.x' 8 years ago
Andy Wilkinson 3ac22e7cdf Merge branch '1.4.x' into 1.5.x 8 years ago
Andy Wilkinson d9b8fc960c Correct the scope of the spock-core dependency in spring-boot-test
See gh-7524
8 years ago
Andy Wilkinson 881eaab601 Merge branch '1.5.x' 8 years ago
Andy Wilkinson 1d476b375f Merge branch '1.4.x' into 1.5.x 8 years ago
Andy Wilkinson 45d672f5b3 Ignore Spock annotations when creating test context cache key
Closes gh-7524
8 years ago
Andy Wilkinson e5e22af73e Merge branch '1.5.x' 8 years ago
Andy Wilkinson 3dcb2d5316 Merge branch '1.4.x' into 1.5.x 8 years ago
Andy Wilkinson 46e8cf4a43 Test that a broken factory bean does not break resetting of mocks
Previously, ResetMocksTestExecutionListener used getBean(name) to
retrieve each instantiated singleton. When the instantiated singleton
was a factory bean, this would cause getObject on the factory bean to
be called. If the factory bean was unable to produce its object, for
example due to test slicing excluding something, an exception would
be thrown.

The previous commit updated ResetMocksTestsExecutionListener to
use getSingleton(name) rather than getBean(name).  This will retrieve
the factory bean itself rather than causing the factory bean to
attempt to create an object. This commit updates the tests to verify
the new behaviour.

Closes gh-7270
8 years ago
Aleksander Bartnikiewicz eb927f1b29 Prevent a broken factory bean from breaking the resetting of mocks
Closes gh-7271
8 years ago
Phillip Webb e0dfff2b23 Merge branch '1.5.x' 8 years ago
Phillip Webb 88c84ce234 Merge branch '1.4.x' into 1.5.x 8 years ago
Phillip Webb a3b79be6b3 Support @MockBean on FactoryBeans
Update @MockBean support so that FactoryBean classes can be mocked.

Fixes gh-7439
8 years ago
Phillip Webb 1452d3cd51 Ensure withBasicAuth keeps error handler
Fix `TestRestTemplate` so that any custom `ErrorHandler` isn't lost
when calling `withBasicAuth`.

Fixes gh-7441
8 years ago
Phillip Webb 20d7dd5747 Merge branch '1.5.x' 8 years ago
Phillip Webb 1657120286 Move ModifiedClassPathRunner to its own module
Migrate `ModifiedClassPathRunner` from `spring-boot` test source to
its own module.

Fixes gh-7420
8 years ago
Andy Wilkinson 9ec38dc8c1 Merge branch '1.5.x' 8 years ago
Andy Wilkinson f35fa87366 Fix problems in SpringBootMockUtil reported by Checkstyle 8 years ago
Andy Wilkinson 9273b1789b Merge branch '1.5.x' 8 years ago
Andy Wilkinson 1cd781b242 Make spring-boot-test compatible with Mockito 2.1 and 2.2
We use some internal Mockito classes and some  breaking API changes
have been made to them in Mockito 2. This commit introduces a utility
class, SpringBootMockUtil, to shield our code from these differences.
Mockito 1 is called directly and Mockito 2 is called via reflection.

To allow these changes to be tested, FilteredClassPathRunner has been
enhanced to also support overriding a dependency on the class path.
As a result it has been renamed to ModifiedClassPathRunner. The new
ClassPathOverrides annotation can be used to provide the Maven
coordinates of one or more dependencies that should be resolved and
added to the class path. Such additions are added to the start of
the class path so that they override any existing dependency that
contains the same classes.

Closes gh-6520
8 years ago
Andy Wilkinson 6361a6728a Add support for new PATCH methods to TestRestTemplate
Closes gh-7412
8 years ago
Phillip Webb cb7c0b5031 Merge branch '1.5.x' 8 years ago
Phillip Webb 7daf69a393 Upgrade to HTMLUnit 2.23 (+selenium module 2.23.2)
Fixes gh-7232
8 years ago
Spring Buildmaster e712a9ba8c Next Development Version 8 years ago
Stephane Nicoll e509278580 Merge branch '1.5.x' 8 years ago
Stephane Nicoll eddb10e4c9 Merge branch '1.4.x' into 1.5.x 8 years ago
Stephane Nicoll 4603d8259a Make MockitoTestExecutionListener public
Closes gh-7016
8 years ago
Andy Wilkinson 86034e5c5c Merge branch '1.5.x' 8 years ago
Andy Wilkinson 3ea09d2e04 Merge branch '1.4.x' into 1.5.x 8 years ago
Andy Wilkinson 02e89acd1e Add managed version for kotlin-runtime to spring-boot-parent
See gh-7101
8 years ago
Andy Wilkinson b1026db330 Merge branch '1.5.x' 8 years ago
Andy Wilkinson f942fe4947 Merge branch '1.4.x' into 1.5.x 8 years ago
Andy Wilkinson 64d32191cf Ignore Kotlin annotations when creating test context cache key
Every classes that's compiled by Kotlin is annotated with
kotlin.Metadata. The attributes of this annotation always differ so
if they are used in the cache key, context caching will effectively
be disabled.

This commit updates the key used by ImportsContextCustomizer to
ignore the kotlin.Metadata annotation. Additionally, to align with
with Java where annotations in java.lang.annotation are ignored,
annotations in kotlin.annotation are also ignored.

Closes gh-7101
8 years ago
Phillip Webb 01900c8342 Merge branch '1.5.x' 8 years ago
Phillip Webb d3e06c4627 Merge branch '1.4.x' into 1.5.x 8 years ago
Phillip Webb db3f488d5a Polish 8 years ago
Phillip Webb 53f50eda39 Merge branch '1.5.x' 8 years ago
Phillip Webb f2b0fa284e Merge branch '1.4.x' into 1.5.x 8 years ago
Madhura Bhave 16fe332f51 Fix NoClassDefFoundError when Mockito is missing
Update MockReset class to check for the presence of the MockUtil class
before attempting to use it.

Fixes gh-7065
8 years ago
Phillip Webb 3326841a97 Formatting 8 years ago
Phillip Webb f59cc25e2b Fix eclipse warnings 8 years ago
Stephane Nicoll b95b57dbf5 Merge branch '1.5.x' 8 years ago
Stephane Nicoll e643fc5bd1 Merge branch '1.4.x' into 1.5.x 8 years ago
Johnny Lim 503d735fdd Polish
Closes gh-7081
8 years ago
Stephane Nicoll 49a606fa91 Merge branch '1.5.x' 8 years ago
Stephane Nicoll cdd59707fc Merge branch '1.4.x' into 1.5.x 8 years ago
Johnny Lim 30a677646f Polish
Closes gh-7030
8 years ago
Andy Wilkinson 0cdbbd49b5 Address warnings caused by deprecations in Spring Framework 5
See gh-6977
8 years ago
Stephane Nicoll 6643ec3713 Next development version 8 years ago
Stephane Nicoll ce1e41dce3 Remove deprecated code
This code removes code deprecated in 1.4 with the exception of code that
requires an update to Spring Framework 5.

Closes gh-6971
8 years ago
Stephane Nicoll 6bd670edbc Initiate 1.4.x branch 8 years ago
Spring Buildmaster 7e9ed5e1a7 Next Development Version 8 years ago
Stephane Nicoll 111743275f Polish 8 years ago
Johnny Lim a994b11a73 Polish 8 years ago
Eddú Meléndez bc55b6e0d4 Add contextPath LocalHostUriTemplateHandler URIs
Update `LocalHostUriTemplateHandler` so that the `server.context-path`
property is also considered when building the URL.

Fixes gh-6904
Closes gh-6919
8 years ago
Phillip Webb aad40093ff Make Mock/Spy qualifiers part of context cache key
Refine @MockBean/@SpyBean qualifier support so that qualifiers form part
of the context cache key. Prior to this commit is was possible that two
different tests could accidentally share the same context if they
defined the same @Mock but with different @Qualifiers.

See gh-6753
8 years ago
Phillip Webb 04448d6bd9 Polish 8 years ago
Stephane Nicoll 3f236dc951 Support Qualifiers on MockBean and SpyBean
Previously, if an injection point used a qualifier, `MockBean` and
`SpyBean` couldn't be used to mock/spy it as there was no way to
specify that qualifier information.

This commit now detects qualifier information on the injection point
and associate it with the created `BeanDefintion`. If one wants to
mock a bean that is qualified with `@Qualifier("foo")`, the definition
of the mock should be as follows:

```
public class MyTest {

	@MockBean
	@Qualifier("foo")
	private ExampleService service;
}
```

As a side effect, it is now possible to mock a service by type even if
there are multiple instances of that type in the application context. The
provided qualifier information is used to determine the right candidate
and the proper bean definition is replaced accordingly.

Closes gh-6753
8 years ago
Phillip Webb 25c4e261e9 Fix failing tests
See gh-6897
8 years ago
Phillip Webb 5f7897ba41 Refine inner-class test @Configuration detection
Update detection logic to also consider `@Rules` classes. Also make the
documentation a little clearer.

Fixes gh-6768
8 years ago
Phillip Webb ebb08c3655 Generate property meta-data for test projects
Add annotation processor to `spring-boot-test` and
`spring-boot-test-autoconfigure`.

Fixes gh-6893
8 years ago
Andy Wilkinson 7b3382e332 Fail fast if @WebAppConfiguration is used with a non-mock web environement
@WebAppConfiguration expects a mock web environment. If it is used
in conjuction with @SpringBootTest configured with a RANDOM_PORT or
DEFINED_PORT web environment a null pointer exception occurs as an
assumption that's made by MockServerContainerContextCustomizer doesn't
hold true in a non-mock web environment.

This commit updates SpringBootTestContextBootstrap to detect the
illegal configuration combination and fail fast, advising the user
to remove @WebAppConfiguration or reconfigure @SpringBootTest.

Closes gh-6795
8 years ago
Phillip Webb 7134586310 Ensure test @PostConstructs are only called once
Rename AutoConfigureReportTestExecutionListener to
SpringBootDependencyInjectionTestExecutionListener and ensure that it
replaces any existing DependencyInjectionTestExecutionListener.

Prior to this commit the registration of two DependencyInjection
listeners would cause @PostConstruct methods on tests to be called
twice.

In order to allow the standard DependencyInjectionTestExecutionListener
to be removed a new DefaultTestExecutionListenersPostProcessor interface
has been introduced.

Fixes gh-6874
8 years ago
Andy Wilkinson 21a25ce855 Revert "Fail fast if @WebAppConfiguration and @SpringBootTest are used together"
This reverts commit c54cdd6735.
8 years ago