Commit Graph

359 Commits

Author SHA1 Message Date
Brian Clozel f2e77e46cd Auto-configure codecs in WebTestClient
This commit applies what's been done in gh-9166 for WebFlux client and
server, but for the `WebTestClient` auto-configuration.

`WebTestClient` can be configured for mock or integration tests and this
change applies `CodecCustomizer` beans to the client being built.

Closes gh-9577
2017-07-03 11:23:06 +02:00
Stephane Nicoll 0fcf6a0e51 Allow to specify multiple auto-configs in autoConfigFirst 2017-06-30 14:52:31 +02:00
Stephane Nicoll 5ecdee0e1b Polish 2017-06-29 16:15:35 +02:00
Stephane Nicoll 18ba414000 Add test helper to manipulate the ApplicationContext
This commit adds ContextLoader, a test helper that configures an
ApplicationContext that is meant to simulate a particular
auto-configuration scenario.

The auto-configuration, user configuration and environment can be
customized. The loader invokes a ContextConsumer to assert the context
and automatically close the context once it is done.

Concretely, tests can create a shared field instance of that helper with
the shared configuration to increase its visibility and tune the context
further in each test.

If the context is expected to fail, `loadAndFail` allows to optionally
assert the root exception and consume it for further assertions.

This commit also migrates some tests to illustrate the practical use of
the helper

Closes gh-9634
2017-06-29 15:34:10 +02:00
Andy Wilkinson 991314c63d Merge branch '1.5.x' 2017-06-16 09:13:42 +01:00
Phillip Webb b94bb00fa1 Remove need for attached test-jar artifacts
Remove test-jar artifacts from Maven projects and relocate classes. The
majority of utilities now live in the `spring-boot-testsupport` module.

This update will help us to deploy artifacts using the standard Maven
deploy plugin in the future (which doesn't support the filtering of
individual artifacts).

Fixes gh-9493
2017-06-12 21:11:35 -07:00
Spring Buildmaster 05d4d0281c Next Development Version 2017-06-08 12:47:16 +00:00
Andy Wilkinson 563c9dc58c Merge branch '1.5.x' 2017-06-06 22:24:31 +01:00
Andy Wilkinson 84721666c5 Stop DuplicateJsonObjectContextCustomizer breaking context caching
See gh-9248
2017-06-06 22:23:43 +01:00
Andy Wilkinson 61a1798296 Merge branch '1.5.x' 2017-06-06 21:39:09 +01:00
Andy Wilkinson 21a5ab7875 Log a warning during tests when multiple JSONOjects on the class path
Closes gh-9248
2017-06-06 21:35:33 +01:00
Phillip Webb 2c7dd9f519 Polish 2017-06-02 16:00:39 -07:00
Stephane Nicoll 9332a3a4ae Merge branch '1.5.x' 2017-05-28 17:46:00 +02:00
Stephane Nicoll b5709fd618 Polish
See gh-9330
2017-05-28 17:44:58 +02:00
Madhura Bhave d745b69630 Replace usages of EnvironmentTestUtils 2017-05-24 14:59:04 -07:00
Madhura Bhave 05254fe322 Deprecate EnvironmentTestUtils in favor of TestPropertyValues
Fixes gh-9253
2017-05-24 14:58:40 -07:00
Phillip Webb 889d43ddc4 Refine SpringApplication source types
Update `SpringApplication` so that the `run` methods and constructors
now require `Class<?>` arguments, rather than `Objects`. String based
sources can still be loaded, but must now be set on the `getSources()`
collections. `Package` and `Resource` types are no longer directly
supported.

This change should help IDEs offer better content assist, and will
help integrations with alternative languages such as Ceylon.

Users currently passing in Class references or using the
`spring.main.sources` property should not be affected by this change. If
an XML resource is being used, some refactoring may be required (see the
changes to `SampleSpringXmlApplication` in this commit).

Fixes gh-9170
2017-05-15 20:35:29 -07:00
Stephane Nicoll e007f20725 Merge branch '1.5.x' 2017-05-12 17:27:46 +02:00
Stephane Nicoll a22b3d9515 Merge branch '1.4.x' into 1.5.x 2017-05-12 17:27:28 +02:00
Stevo Slavić 6e1d99aa10 Fix typo in javadoc
Closes gh-9212
2017-05-12 17:26:26 +02:00
Andy Wilkinson b71daac58a Remove redundant logic for uninstalling Tomcat's URL stream handler factory
Closes gh-8622
2017-05-11 17:22:15 +01:00
Phillip Webb fa4de13519 Rework ConfigurationPropertySources
Rework the ConfigurationPropertySources and related adapter classes to
help with performance. The ConfigurationPropertySources class now only
monitors for updates when `.attach` is used. The `.get` methods now
return the adapted version, but no longer checks to see if sources have
been added or removed on each call.

This commit also fixes a few caching issues and makes both the
`PropertyMapper` implementations true static singletons.

See gh-9000
2017-05-09 22:09:40 -07:00
Phillip Webb 931ce15d7f Update copyright header dates 2017-05-09 21:43:52 -07:00
Madhura Bhave c0d4a771c9 Use new configuration properties in spring-boot-test
Update `spring-boot-test` to use the new configuration properties
support.

See gh-9000
2017-04-27 13:59:25 -07:00
Phillip Webb 06558675bb Polish 2017-04-25 09:45:14 -07:00
Spring Buildmaster 9768b0a8c2 Next Development Version 2017-04-21 08:32:01 +00:00
Spring Buildmaster d719d2cbbc Next Development Version 2017-04-20 12:46:19 +00:00
Phillip Webb 81fef71fcb Merge branch '1.5.x' 2017-04-19 22:48:46 -07:00
Phillip Webb 5abc050a96 Support detection and with test initializers
Relax `SpringBootTestContextBootstrapper` rules so that a test can
specify an `ApplicationContextInitializer` and still have
`@SpringBootConfiguration` detected.

Prior to this commit detection would not occur because it's possible
that an initializer _could_ register configuration. This scenario is
actually quite unlikely to occur, certainly less likely than wanting to
use an initializer in combination with auto-detection.

Fixes gh-8483
2017-04-19 22:18:12 -07:00
Phillip Webb 850517a8db Fix merge issue 2017-04-18 21:57:33 -07:00
Phillip Webb 94209e2883 Merge branch '1.5.x' 2017-04-18 15:06:43 -07:00
Phillip Webb 393c17b68b Support @SpringBootTest with @ContextHierarchy
Update SpringBootTestContextBootstrapper to detect `@ContextHierarchy`
annotations so that only the last child creates a
`WebApplicationContext`.

Prior to this commit a context hierarchy would start two embedded web
servers which is inconsistent with the `SpringApplicationBuilder`
behavior.

Fixes gh-8311
2017-04-18 14:56:12 -07:00
Phillip Webb 8eb79b3c0f Polish 2017-04-18 11:13:12 -07:00
Phillip Webb 383640d5ec Merge branch '1.5.x' 2017-04-17 22:15:33 -07:00
Phillip Webb f46d799f31 Polish 2017-04-17 22:08:51 -07:00
Madhura Bhave ed072abaef Merge branch '1.5.x' 2017-04-17 11:42:02 -07:00
Madhura Bhave 9e2d54feae Support json view with JacksonTester
Closes gh-8672
2017-04-17 11:14:26 -07:00
Phillip Webb 700f0ea93c Fix WebClientTest calls
Update calls to WebClientTest following upstream changes.
2017-04-14 16:26:01 -07:00
dreis f3bbbc4530 Use JDK hashCode() variants for primitives
See gh-8768
2017-04-12 15:22:14 +02:00
Andy Wilkinson ef72c22563 Update HtmlUnitDriver tests to align with HtmlUnit 2.26
See gh-8853 and cb34189c66
2017-04-07 12:10:39 +01:00
Stephane Nicoll 6d6d76ca06 Polish
See gh-8543
2017-03-16 09:54:06 +01:00
Madhura Bhave 0b1d32e762 Add tests for TestRestTemplate in reactive env
Closes gh-8543
2017-03-15 14:46:44 -07:00
Phillip Webb b76ca0bf8f Restructure web auto-configuration
Restructure `org.springframework.boot.autoconfigure.web` to better align
with the new package structure in `spring-boot`.

Auto-configuration is now split into client, servlet and reactive
sub-packages. In addition a new `http` package now handles common
HTTP concerns.

Fixes gh-8616
2017-03-14 22:06:28 -07:00
Phillip Webb 33e54ed723 Relocate `org.springframework.boot.web.support`
Move `org.springframework.boot.web.support` under the `servlet` package.

Fixes gh-8557
2017-03-14 22:03:03 -07:00
Phillip Webb b1c689b9b2 Unify WebServerFactory implementations
Unify common for from the abstract `ServletWebServerFactory` and
`ReactiveWebServerFactory` classes. Common code is now located in
`AbstractConfigurableWebServerFactory`.

Fixes gh-8631
2017-03-14 21:52:40 -07:00
Phillip Webb 67556ba8ea Restructure embedded web server packages
Rework `org.springframework.boot.context.embedded` to relocate classes
to `org.springframework.boot.web`. Packages are now organized around
the following areas:

Packages for shared concerns, for example the `WebServer` interface
to start/stop a server and the common configuration elements:
- org.springframework.boot.web.context
- org.springframework.boot.web.server

Servlet specific packages:
- org.springframework.boot.web.servlet.server
- org.springframework.boot.web.servlet.context
- org.springframework.boot.web.servlet.filter

Reactive specific packages:
- org.springframework.boot.web.reactive.context
- org.springframework.boot.web.reactive.server

Embedded server implementations (both reactive and servlet):
- org.springframework.boot.web.embedded

In addition:

- Rename `EmbeddedServletContainerFactory` to `ServletWebServerFactory`
  to align with the `ReactiveWebServerFactory`.
- Rename `EmbeddedWebApplicationContext` to
  `ServletWebServerApplicationContext` and
- Rename `EmbeddedReactiveWebApplicationContext` to
  `ReactiveWebServerApplicationContext`.
- Add checkstyle rules to restrict imports.
- Fixup all affected code to use the correct imports and local names.

Fixes gh-8532
2017-03-12 21:08:25 -07:00
Andy Wilkinson 62de505e43 Update tests to align with slight change in HtmlUnit's behaviour
See gh-8515
2017-03-10 09:45:10 +00:00
Stephane Nicoll 361ad69a4b Merge branch '1.5.x' 2017-03-10 09:55:11 +01:00
Stephane Nicoll c8ac94b75d Polish contribution
Closes gh-8490
2017-03-10 09:51:35 +01:00
Roland Weisleder a6f0da8cc6 Introduce reset method to OutputCapture
Closes gh-8390
2017-03-10 09:48:36 +01:00
Phillip Webb d8f827d224 Cleanup and format code 2017-03-06 17:08:09 -08:00
Phillip Webb 425dbc3e52 Update copyright header for edited files 2017-03-06 15:04:07 -08:00
Phillip Webb 2a592103f0 Polish formatting 2017-03-06 15:03:43 -08:00
Spring Buildmaster d23fa24340 Next Development Version 2017-03-03 16:18:26 +00:00
Spring Buildmaster 2a83e80a9b Next Development Version 2017-03-03 14:39:21 +00:00
Stephane Nicoll f143ec52a6 Fix Javadoc of `WebEnvironment`
Closes gh-8469
2017-03-03 13:52:53 +01:00
Andy Wilkinson e20219aac9 Merge branch '1.5.x' 2017-02-28 15:58:22 +00:00
Andy Wilkinson 545b29552d Merge branch '1.4.x' into 1.5.x 2017-02-28 15:58:08 +00:00
Andy Wilkinson 98cf35d48e Polish "Ignore spock.lang annotations when creating test context cache key"
See gh-8252
2017-02-28 15:55:55 +00:00
erlholmq 8f18df8a9c Ignore spock.lang annotations when creating test context cache key
See gh-7524
Closes gh-8252
2017-02-28 15:49:35 +00:00
Phillip Webb a4bcd20b64 Merge branch '1.5.x' 2017-02-27 20:43:18 -08:00
Phillip Webb ca1540cefe Update header copyright for changed files 2017-02-27 20:41:18 -08:00
Phillip Webb 5867cd6175 Polish 2017-02-27 20:41:18 -08:00
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
2017-02-27 15:05:34 +01:00
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
2017-02-24 13:50:58 +01:00
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
2017-02-24 13:03:12 +01:00
Andy Wilkinson fcd1eb79fc Fix forward merge of new SpyBean test to use correct Mockito 2 API 2017-02-21 20:48:58 +00:00
Andy Wilkinson 1e806bbbd2 Merge branch '1.5.x' 2017-02-21 20:20:36 +00:00
Andy Wilkinson 8318177b0d Merge branch '1.4.x' into 1.5.x 2017-02-21 20:20:26 +00:00
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
2017-02-21 20:19:50 +00:00
Andy Wilkinson 13791cad53 Use DefaultUriBuilderFactory instead of DefaultUriTemplateHandler
Closes gh-8247
2017-02-09 14:00:53 +00:00
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
2017-02-07 16:48:22 +01:00
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
2017-02-06 14:43:16 +01:00
Stephane Nicoll cfdc75d384 Merge branch '1.5.x' 2017-02-06 10:38:16 +01:00
Johnny Lim 0adab8a2be Use logical 'and' instead of bitwise 'and'
Closes gh-8198
2017-02-06 10:35:13 +01:00
Andy Wilkinson aa19cad770 Merge branch '1.5.x' 2017-02-02 13:48:30 +00:00
Andy Wilkinson b9b0cdb342 Merge branch '1.4.x' into 1.5.x 2017-02-02 13:48:19 +00:00
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
2017-02-02 13:28:52 +00:00
Andy Wilkinson 95f659f4f9 Add new WebApplicationType enum to pave the way for Web Flux support
Closes gh-8077
2017-01-30 20:26:24 +00:00
Spring Buildmaster 5c12500366 Next Development Version 2017-01-30 20:10:13 +00:00
Spring Buildmaster a2696bf873 Next Development Version 2017-01-30 11:40:24 +00:00
Andy Wilkinson 15639d39b0 Merge branch '1.5.x' 2017-01-30 10:02:27 +00:00
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
2017-01-30 09:59:11 +00:00
Phillip Webb 8747e039ee Merge branch '1.5.x' 2017-01-27 17:50:01 -08:00
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
2017-01-27 17:19:52 -08:00
Andy Wilkinson 31b0e81765 Add @FunctionalInterface to remaining public and protected interfaces
See gh-6857
2017-01-27 16:41:09 +00:00
Spring Buildmaster ed1ce140c0 Next Development Version 2017-01-26 14:20:39 +00:00
Stephane Nicoll 661fd848eb Merge branch '1.5.x' 2017-01-25 11:02:32 +01:00
Stephane Nicoll 505e7f75ea Polish contribution
Closes gh-8089
2017-01-25 11:01:53 +01:00
dreis d58f38f6f6 Use String.replace() with single char if possible
See gh-8089
2017-01-25 11:01:52 +01:00
Andy Wilkinson fd677af868 Merge branch '1.5.x' 2017-01-20 16:25:14 +00:00
Andy Wilkinson b71baf2c38 Support @ContextHierarchy when using @SpringBootTest
Closes gh-8000
2017-01-20 16:24:42 +00:00
Andy Wilkinson 973b7a118c Merge branch '1.5.x' 2017-01-19 11:03:38 +00:00
Andy Wilkinson c31a2d8101 Merge branch '1.4.x' into 1.5.x 2017-01-19 11:03:33 +00:00
Andy Wilkinson 80a1e1ae64 Polishing 2017-01-19 11:03:18 +00:00
Andy Wilkinson 84583d2b8f Merge branch '1.5.x' 2017-01-19 10:58:43 +00:00
Andy Wilkinson 4e70cd2934 Merge branch '1.4.x' into 1.5.x 2017-01-19 10:58:34 +00:00
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
2017-01-19 10:39:02 +00:00
Andy Wilkinson d2201d5284 Correct copyright dates and enforce that starting year is 2012
Closes gh-7923
2017-01-13 18:43:30 -05:00
Phillip Webb 0fca9aaccb Polish Mockito 2.0 support 2017-01-05 16:42:12 -08:00