Commit Graph

176 Commits

Author SHA1 Message Date
Phillip Webb 655fa59db0 Merge branch '1.4.x' into 1.5.x 2017-01-19 12:33:42 -08:00
Phillip Webb b05bdbfe4f Polish 2017-01-19 12:31:43 -08:00
Stephane Nicoll e44b595c0d Fix merge issue 2017-01-19 16:36:00 +01:00
Stephane Nicoll d2299555d2 Merge branch '1.4.x' into 1.5.x 2017-01-19 16:14:44 +01:00
Stephane Nicoll ffa6d6d6e0 Improve error message used in TestDatabaseAutoConfiguration
By default, `@DataJpaTest` (and `@AutoConfigureTestDatabase`) attempt to
replace any existing `DataSource` by an embedded one. Previously, if
there is was no embedded database on the classpath, the exception message
did not provide that context in the error message.

This commit clarifies the error message to conduct
`TestDatabaseAutoConfiguration` (that is replacing the existing
`DataSource`).

Closes gh-7797
2017-01-19 16:13:49 +01:00
Phillip Webb 0a6456a748 Always use `prefix` config annotation attribute
Update use of `@ConfigurationProperties` to prefer the more explicit
`prefix` attribute, rather than `value`.

See gh-7579
2017-01-18 20:49:53 -08:00
Stephane Nicoll 7a75fb0f38 Fix test-specific configuration metadata
Most of the config keys defined by the `spring-boot-test-autoconfigure`
module can't be overridden because they are mapped with `@PropertyMapping`
on an annotation. It is confusing that such keys are exposed in content
assistance as using them will have no effect.

This commit removes the annotation processor from the build so that the
`@ConfigurationProperties` beans aren't processed anymore. Instead, manual
metadata is written for the two only keys that are effectively used in
regular configuration.

As a result, the `additional-spring-configuration-metadata` file has been
renamed to `spring-configuration-metadata` since nothing is processing it
anymore.

Closes gh-7887
2017-01-06 10:12:57 +01:00
Phillip Webb e015e13b4d Include `ErrorAttributes` in @WebMvcTest
Import the additional auto-configuration classes required for
`ErrorAttributes` and change the filter so that it's no longer
hidden.

Fixes gh-7867
2017-01-04 15:25:33 -08:00
Johnny Lim f915ae197a Polish 2017-01-04 09:53:45 +01:00
Phillip Webb 54aeff47a2 Add exclude support to @ImportAutoConfiguration
Update `@ImportAutoConfiguration` with support for an exclude attribute
that works in a similar way to `@EnableAutoConfiguration`.

Also update existing `@Test...` annotation with exclude attribute
aliases.

Fixes gh-6809
2016-12-30 00:31:30 -08:00
Phillip Webb 8b69856fc9 Polish 2016-12-28 15:23:26 -08:00
Spring Buildmaster 9057f9ae1f Next development version 2016-12-23 00:15:23 +00:00
Phillip Webb 6121208cbb Polish formatting 2016-12-19 12:47:03 -08:00
Phillip Webb 4b9cba351b Merge branch '1.4.x' into 1.5.x 2016-12-19 12:36:57 -08:00
Phillip Webb bd74c3d327 Polish formatting 2016-12-19 12:25:09 -08:00
Stephane Nicoll 21b815aabd Polish contribution
Closes gh-7560
2016-12-16 10:52:43 +01:00
Eddú Meléndez 5a7624df7c Add support for property spring.test.database.replace
Closes gh-7229
2016-12-16 09:40:55 +01:00
Stephane Nicoll d8d5950e99 Enable validation in `AutoConfigureWebMvc`
Closes gh-7582
2016-12-15 16:55:34 +01:00
Stephane Nicoll ee72e788ed Rename `spring-boot-junit-runners` to `spring-boot-test-support`
Closes gh-7421
2016-12-01 16:25:47 +01:00
Johnny Lim 423f8037ce Polish
Closes gh-7530
2016-11-30 08:31:13 +01:00
Stephane Nicoll 80da80f930 Make sure that test data sources are unique 2016-11-29 18:07:36 +01:00
Stephane Nicoll ba61faee5e Remove trailing char 2016-11-29 15:37:05 +01:00
Stephane Nicoll b618c70e52 Add test slice for pure jdbc tests
This commit adds `@JdbcTest`, a new test slice for pure jdbc tests. It
provides the same basic features than `@DataJpaTest`.

Closes gh-6563
2016-11-29 14:54:15 +01:00
Phillip Webb 5ed00b3501 Merge branch '1.4.x' into 1.5.x 2016-11-28 15:27:07 -08:00
Phillip Webb 357d072a60 Polish 2016-11-28 15:14:46 -08:00
Stephane Nicoll ca788a90e6 Merge branch '1.4.x' into 1.5.x 2016-11-24 15:31:40 +01:00
Stephane Nicoll 4bf645c615 `AutoconfigureTestDatabase` replace with a fresh database
Previously, two or more `@DataJpaTest` tests in the same test suite were
sharing the same in-memory database instance. This commit makes sure
that `TestDatabaseAutoConfiguration` creates a unique embedded database
for each test it operates on.

Closes gh-7473
2016-11-24 15:31:27 +01:00
Phillip Webb dc237043b8 Merge branch '1.4.x' into 1.5.x 2016-11-22 15:48:52 -08:00
Phillip Webb 74670cb20f Allow WebDriver beans to define their own scope
Update `WebDriverScope` so that only `WebDriver` beans with no explicit
scope are moved.

Fixes gh-7454
2016-11-22 15:48:28 -08:00
Andy Wilkinson b2a8be8bbe Merge branch '1.4.x' into 1.5.x 2016-11-21 13:40:11 +00:00
Andy Wilkinson 3423ca87b4 Ensure that RestClientTest can be used without Jackson on the class path
Closes gh-7431
2016-11-21 13:36:05 +00:00
Phillip Webb 764f13453a Merge branch '1.4.x' into 1.5.x 2016-11-15 13:58:54 -08:00
Phillip Webb bacf0878af Polish 2016-11-15 10:40:21 -08:00
Spring Buildmaster e712a9ba8c Next Development Version 2016-11-08 16:55:37 +00:00
Stephane Nicoll 5878e5eec5 Merge branch '1.4.x' into 1.5.x 2016-11-08 10:57:58 +01:00
Stephane Nicoll 318701daa7 Apply DispatcherServlet customizations to MockMvc
This commits makes sure that customizations on `DispatcherServlet` are
also applied to the `TestDispatcherServlet` that `MockMvc` is using
internally.

Closes gh-5891
2016-11-08 10:56:54 +01:00
Stephane Nicoll 3018e95261 Merge branch '1.4.x' into 1.5.x 2016-11-06 11:44:12 +01:00
Stephane Nicoll ebfd86ea26 Polish contribution
Closes gh-7326
2016-11-06 11:42:45 +01:00
sebastiankirsch e8b0a64872 Add @Inherited to all AutoConfigure* classes
See gh-7326
2016-11-06 11:39:12 +01:00
Phillip Webb 5b66ffbb4b Merge branch '1.4.x' into 1.5.x 2016-10-31 23:09:36 -07:00
Greg Potter 39d5881bf2 Respect 'primary' flag when replacing databases
Update TestDatabaseAutoConfiguration to ensure that the the `primary`
flag of the `BeanDefinition` is copied.

Closes gh-7217
2016-10-31 16:26:41 -07:00
Stephane Nicoll 4855bfb152 Merge branch '1.4.x' into 1.5.x 2016-10-24 11:11:56 +02:00
Stephane Nicoll a03ce0a9d1 Polish contribution
Add missing test

Closes gh-7193
2016-10-24 11:11:15 +02:00
Johnny Lim 0b5fbbedf4 Add a missing return
This commit adds a missing`return` in `getDataSourceBeanDefinition()`.

See gh-7193
2016-10-24 10:41:20 +02:00
Stephane Nicoll 6bd670edbc Initiate 1.4.x branch 2016-09-21 11:11:24 +02:00
Spring Buildmaster 7e9ed5e1a7 Next Development Version 2016-09-21 07:58:07 +00:00
Johnny Lim a994b11a73 Polish 2016-09-18 23:38:21 -07:00
Phillip Webb e239e64cb1 Only print MVC interactions when tests fail
Update `@AutoConfigureMockMvc` with a `printOnlyOnFailure` option which
allows errors to be printed only when tests fail. Defaults to `true`
meaning the logs are no longer cluttered with MVC results for passing
tests.

Fixes gh-6653
2016-09-18 23:37:46 -07:00
Andy Wilkinson 0a9bcd9893 Polish 2016-09-18 10:29:14 +01:00
Phillip Webb ac2609b585 Fix WebDriver lifecycle issues
Update WebDriver support to ensure that the `.quit()` method is called
after each test method runs and that a new WebDriver instance is
injected each time.

Support is provided by introducing a new `Scope` which is applied by
a ContextCustomizerFactory and reset by a TestExecutionListener.

Fixes gh-6641
2016-09-18 00:18:29 -07:00
Phillip Webb 0ef845b96e Polish 2016-09-17 20:05:21 -07:00
Phillip Webb 82ae6e4049 Improve @AutoConfigureTestDatabase failure message
Fixes gh-6916
2016-09-17 19:56:25 -07:00
Phillip Webb 2c621f4094 Fix @AutoConfigureTestDatabase imports
Update `@AutoConfigureTestDatabase` so that it always imports
`DataSourceAutoConfiguration`. Prior to this commit the annotation
could only be applied if something else also imported DataSource
auto-configuration.

Fixes gh-6897
2016-09-16 16:49:36 -07:00
Phillip Webb 3e19f8aa8d Relax TestEntityManager @ID restriction
Change TestEntityManager so that entities with an ID can be persisted.

Fixes gh-6546
2016-09-15 17:22:52 -07:00
Phillip Webb 25c4e261e9 Fix failing tests
See gh-6897
2016-09-15 17:16:26 -07:00
Phillip Webb 46815fc483 Fix potential @AutoConfigureTestDatabase NPE
Protect against the situation where no DataSource beans can be found
at all.

Fixes gh-6897
2016-09-15 16:06:56 -07:00
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
2016-09-15 10:14:21 -07:00
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
2016-09-14 22:03:07 -07:00
Phillip Webb 41a36c4d40 Prevent CastCastException when stripping root URI
Update RootUriRequestExpectationManager to only wrap requests when
they cannot be cast to MockClientHttpRequest. This prevents later
ClassCastExceptions from being thrown with @RestClientTests that
define expected body content.

Fixes gh-6845
2016-09-12 12:44:31 -07:00
Phillip Webb 41dc53f5dd Polish 2016-09-07 08:34:45 -07:00
Stephane Nicoll 52d7282f5e Auto-configure JdbcTemplate with DataJpaTest
This commit adds `JdbcTemplateAutoConfiguration` to the list of auto-
configurations that are applied with `DataJpaTest`. This effectively
allows to inject a `JdbcTemplate` in any `@DataJpaTest` test.

Closes gh-6802
2016-09-02 09:38:07 +02:00
Stephane Nicoll 2c61064d93 Fix property prefix
This commit fixes the prefix for the WebClient and WebDriver auto-config
so that it complies with the prefix set on `AutoconfigureWebMvc`

Closes gh-6727
2016-08-23 17:11:14 +02:00
Johnny Lim 524edaea51 Polish
Closes gh-6728
2016-08-23 15:13:33 +02:00
Andy Wilkinson 5f7e966955 Enable MessageSourceAutoConfiguration when using @WebMvcTest
Closes gh-6608
2016-08-16 14:35:06 +01:00
Phillip Webb f38bd7af37 Extract GSON/Jackson config to inner classes
Update JsonTestersAutoConfiguration so that GSON and Jackson specific
configuration are inner classes. This should prevent ClassNotFound
exception when the libraries are not on the classpath.

Fixes gh-6502
2016-08-02 15:14:30 -07:00
Brian Clozel d62827373d Fix Bean Condition on GsonTester FactoryBean
This commit fixes the `@ConditionalOnClass` typo on the GsonTester
FactoryBean, which was testing for `ObjectMapper` instead of `Gson`.

This means that the next condition `@ConditionalOnBean(Gson.class)`
throws a `ClassNotFoundException: com.google.gson.Gson` since it's
trying to load that class to check for an existing Bean of that type.

Fixes gh-6502
2016-07-29 10:24:29 +02:00
Spring Buildmaster 334baaeffd Next development version 2016-07-28 19:54:01 +00:00
Phillip Webb 5d9836b3b1 Refine unmapped property support
Replace `@UnmappedPropertyValue` with a `skip` attribute on
`@PropertyMapping` so that any default attribute value can be skipped.

Closes gh-6455
2016-07-27 16:27:24 -07:00
Phillip Webb 162b9e84a3 Polish 2016-07-26 22:47:51 -07:00
Phillip Webb 296dc7132b Allow JSON Testers to be `@Autowired`
Switch `@AutoConfigureJsonTesters` to use regular `@Autowired` injection
for JSON testers. Prior to this commit JSON Tester fields were
initialized directly which caused IDE issues and was also a little
confusing.

Fixes gh-6451
2016-07-26 21:41:37 -07:00
Phillip Webb 4a1e0d4544 Extend @AutoConfigureMockMvc print support
Update @AutoConfigureMockMvc to support extended print options including
`System.err` and `log.debug`. In addition the "default" print option
can now be overridden by adding `spring.test.mockmvc.print=...` to
`src/test/resources/application.properties`.

Fixes gh-6455
2016-07-25 13:17:26 -07:00
Phillip Webb 8355d8516b Add @UnmappedPropertyValue support
Update @PropertyMapping support to allow single enum values to be marked
as an @UnmappedPropertyValue. This change is primarily so that users can
replace "default" values globally for across all tests.

See gh-6455
2016-07-25 13:13:16 -07:00
Phillip Webb c265de2535 Use @AliasFor in @AutoConfigureRestDocs
Replace custom alias logic in @AutoConfigureRestDocs with @AliasFor.

Closes gh-6403
2016-07-15 16:24:58 -07:00
Andy Wilkinson 3286760073 Make it easier to add auto-configuration to a test slice
Previously, an entry had to be added to spring.factories using the
name of one of the @AutoConfigure… meta-annotations on the @…Test
annotation as the key. This indirection was unnecessarily complicated.

This commit simplifies things by allowing the name of the @…Test
annotation itself to be used as the key.

Closes gh-6335
2016-07-06 16:44:26 +01:00
Andy Wilkinson 52e8ad4b6b Drop back to Hibernate 5.0.9.Final
The upgrade to Hibernate 5.2.0.Final has provide to be too
problematic to live with. It requires Java 8, is incompatible with
a number of other projects in the Hibernate ecosystem, and it's
unclear for how long it will be maintained. We'd previously used
Hibernate 5.1.0.Final but its maintenance is also unclear with
Hibernate 5.1.1.Final being more than 3 months overdue.

This commit drops back to Hibernate 5.0.9.Final. This has a few
advantages:

- It's Java 7 compatible
- It's had some time to mature and should be reasonably free of
  regressions for those moving from 4.3.x
- It's used in both Wildfly and JBoss EAP so there's a fair chance
  that it will continue to be maintained.

Closes gh-6198
2016-06-21 20:09:21 +01:00
Stephane Nicoll 2ff9e3cfdc Upgrade to Hibernate 5.2
See gh-6111
2016-06-17 11:14:35 +02:00
Johnny Lim a70a8635f9 Polish
Closes gh-6155
2016-06-14 08:35:22 +02:00
Andy Wilkinson 50ca35bdae Remove use of deprecated API in REST Docs auto-config test
Closes gh-6128
2016-06-13 11:14:12 +01:00
Phillip Webb d87287fe72 Polish 2016-06-08 09:54:36 -07:00
Phillip Webb 5ab072be9c Polish 2016-06-08 09:27:40 -07:00
Johnny Lim 5de9516255 Fix typos
Closes gh-6114
2016-06-03 07:20:39 -04:00
Phillip Webb e1d74627f5 Make test auto-configuration classes public
Make test auto-configuration classes public so that they can be used
by others with @AutoConfigureBefore/@AutoConfigureAfter.

Fixes gh-6073
2016-05-31 13:30:18 -07:00
Phillip Webb 2eafb3d887 Add @RestClientTest support
Add @RestClientTest annotation that can be used when testing REST
clients. Provides auto-configuration for a MockRestServiceServer which
can be used when the bean under test builds a single RestTemplate
via the auto-configured RestTemplateBuilder.

Closes gh-6030
2016-05-31 10:18:07 -07:00
Andy Wilkinson 4a73eb6045 Fix capitalization of TestDatabaseAutoConfiguration in spring.factories
The joys of OS X's case-insensitive, case-preserving file system

See gh-6001
2016-05-27 17:59:30 +01:00
Andy Wilkinson 73b01cff4f Use spring.factories to declare each test slice's auto-config imports
Closes gh-6001
2016-05-27 17:04:48 +01:00
Andy Wilkinson 280ac90cef Polishing 349ec76: remove use of the diamond operator 2016-05-26 11:36:21 +01:00
Andy Wilkinson 349ec76e62 Update @WebMvcTest to auto-configure Spring HATEOAS
Closes gh-6043
2016-05-26 11:09:43 +01:00
Andy Wilkinson e9a226c8f8 Fix handling of annotations on super classes in AnnotationsPropertySource
Closes gh-6006
2016-05-23 12:36:17 +01:00
Johnny Lim 189f96687d Rename AutoConfigurationJson to AutoConfigureJson
Closes gh-6007
2016-05-21 09:44:04 +02:00
Phillip Webb cd365bcae1 Improve @PropertyMapping error message
Improve the message thrown when a @PropertyMapping is used in
combination with a @Component to include the actual annotations that
are causing the problem.

Fixes gh-5897
2016-05-13 20:09:03 -07:00
Johnny Lim 7c34dd87c1 Polish
Closes gh-5925
2016-05-12 07:55:19 +02:00
Andy Wilkinson de0bcaa50e Update WebMvcTest to auto-configure supported template engines
Closes gh-5801
2016-05-10 10:41:38 +01:00
Andy Wilkinson c1a2a77cbe Auto-configure Flyway and Liquibase when using DataJpaTest
Closes gh-5716
2016-05-10 10:13:17 +01:00
Andy Wilkinson 0a765e36f1 Protect against stack overflow when searching meta annotations
It is legal for an annotation to be annotated with itself. Previously,
when searching for meta annotations this could lead to a stack overflow.
This was likely to occur when using Kotlin as, like Java, its Target
annotation is annotated with itself. A stack overflow doesn’t occur
with Java’s Target annotation due to some short-circuiting logic for
annotations in java.lang.

This commit updates the logic for finding meta-annotations to
short-circuit when an annotation that has already been seen is
encountered.

Closes gh-5902
2016-05-10 09:39:55 +01:00
Andy Wilkinson 79b81a95c8 Use SpringBootContextLoader for tests annotated with @WebMvcTest
Previously, tests annotated with @WebMvcTest would use Spring
Framework’s WebDelegatingSmartContextLoader. This meant that
SpringApplication was not used to create the application context. One
effect of this was that Spring Boot’s logging system was not initialized
and large quantities of debug log output was produced due to Logback’s
default behaviour.

This commit updates WebMvcTestContextBootstrapper so that it uses
SpringBootContextLoader. This aligns the behaviour of @WebMvcTest
with the behaviour of @SpringBootTest and @DataJpaTest.

Closes gh-5847
2016-05-04 17:15:16 +01:00
Johnny Lim 7763c2ae4c Polish
Closes gh-5843
2016-05-03 09:33:32 +02:00
Johnny Lim 06143195d0 Make json-path and selenium-api optional
Make json-path and selenium-api optional in spring-boot-test and
spring-boot-test-autoconfigure.

Fixes gh-5828
2016-05-02 17:17:29 -07:00
Phillip Webb 02bd3dc62d Add @AutoConfigureCache annotation
Add @AutoConfigureCache annotation to configure the specific cache
manager to use with a test. By default the NoOpCacheManager is used.

The @JsonTest, @DataJpaTest and @WebMvcTests have also been updated to
use the annotation.

Fixes gh-5765
2016-05-02 17:02:18 -07:00
Phillip Webb 609cb52cd4 Move to relocated web classes
Refactor code to move from recently deprecated classes.

Closes gh-5822
2016-04-28 12:45:15 -07:00
Phillip Webb aea18671c1 Restructure web related classes
Reorganize web related classes for better separation of concerns.
Mainly this involves moving classes from `o.s.b.context.embedded`
that aren't directly tied to embedded servlet containers to
`o.s.b.web` and relocating everything from `o.s.b.context.web`.

See gh-5822
2016-04-28 12:45:15 -07:00