Commit Graph

207 Commits (1.5.x)

Author SHA1 Message Date
Johnny Lim 423f8037ce Polish
Closes gh-7530
8 years ago
Stephane Nicoll 80da80f930 Make sure that test data sources are unique 8 years ago
Stephane Nicoll ba61faee5e Remove trailing char 8 years ago
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
8 years ago
Phillip Webb 5ed00b3501 Merge branch '1.4.x' into 1.5.x 8 years ago
Phillip Webb 357d072a60 Polish 8 years ago
Stephane Nicoll ca788a90e6 Merge branch '1.4.x' into 1.5.x 8 years ago
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
8 years ago
Phillip Webb dc237043b8 Merge branch '1.4.x' into 1.5.x 8 years ago
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
8 years ago
Andy Wilkinson b2a8be8bbe Merge branch '1.4.x' into 1.5.x 8 years ago
Andy Wilkinson 3423ca87b4 Ensure that RestClientTest can be used without Jackson on the class path
Closes gh-7431
8 years ago
Phillip Webb 764f13453a Merge branch '1.4.x' into 1.5.x 8 years ago
Phillip Webb bacf0878af Polish 8 years ago
Spring Buildmaster e712a9ba8c Next Development Version 8 years ago
Stephane Nicoll 5878e5eec5 Merge branch '1.4.x' into 1.5.x 8 years ago
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
8 years ago
Stephane Nicoll 3018e95261 Merge branch '1.4.x' into 1.5.x 8 years ago
Stephane Nicoll ebfd86ea26 Polish contribution
Closes gh-7326
8 years ago
sebastiankirsch e8b0a64872 Add @Inherited to all AutoConfigure* classes
See gh-7326
8 years ago
Phillip Webb 5b66ffbb4b Merge branch '1.4.x' into 1.5.x 8 years ago
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
8 years ago
Stephane Nicoll 4855bfb152 Merge branch '1.4.x' into 1.5.x 8 years ago
Stephane Nicoll a03ce0a9d1 Polish contribution
Add missing test

Closes gh-7193
8 years ago
Johnny Lim 0b5fbbedf4 Add a missing return
This commit adds a missing`return` in `getDataSourceBeanDefinition()`.

See gh-7193
8 years ago
Stephane Nicoll 6bd670edbc Initiate 1.4.x branch 8 years ago
Spring Buildmaster 7e9ed5e1a7 Next Development Version 8 years ago
Johnny Lim a994b11a73 Polish 8 years ago
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
8 years ago
Andy Wilkinson 0a9bcd9893 Polish 8 years ago
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
8 years ago
Phillip Webb 0ef845b96e Polish 8 years ago
Phillip Webb 82ae6e4049 Improve @AutoConfigureTestDatabase failure message
Fixes gh-6916
8 years ago
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
8 years ago
Phillip Webb 3e19f8aa8d Relax TestEntityManager @ID restriction
Change TestEntityManager so that entities with an ID can be persisted.

Fixes gh-6546
8 years ago
Phillip Webb 25c4e261e9 Fix failing tests
See gh-6897
8 years ago
Phillip Webb 46815fc483 Fix potential @AutoConfigureTestDatabase NPE
Protect against the situation where no DataSource beans can be found
at all.

Fixes gh-6897
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
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
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
8 years ago
Phillip Webb 41dc53f5dd Polish 8 years ago
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
8 years ago
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
8 years ago
Johnny Lim 524edaea51 Polish
Closes gh-6728
8 years ago
Andy Wilkinson 5f7e966955 Enable MessageSourceAutoConfiguration when using @WebMvcTest
Closes gh-6608
8 years ago
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
8 years ago
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
8 years ago
Spring Buildmaster 334baaeffd Next development version 8 years ago
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
8 years ago
Phillip Webb 162b9e84a3 Polish 8 years ago
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
8 years ago
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
8 years ago
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
8 years ago
Phillip Webb c265de2535 Use @AliasFor in @AutoConfigureRestDocs
Replace custom alias logic in @AutoConfigureRestDocs with @AliasFor.

Closes gh-6403
8 years ago
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
8 years ago
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
9 years ago
Stephane Nicoll 2ff9e3cfdc Upgrade to Hibernate 5.2
See gh-6111
9 years ago
Johnny Lim a70a8635f9 Polish
Closes gh-6155
9 years ago
Andy Wilkinson 50ca35bdae Remove use of deprecated API in REST Docs auto-config test
Closes gh-6128
9 years ago
Phillip Webb d87287fe72 Polish 9 years ago
Phillip Webb 5ab072be9c Polish 9 years ago
Johnny Lim 5de9516255 Fix typos
Closes gh-6114
9 years ago
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
9 years ago
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
9 years ago
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
9 years ago
Andy Wilkinson 73b01cff4f Use spring.factories to declare each test slice's auto-config imports
Closes gh-6001
9 years ago
Andy Wilkinson 280ac90cef Polishing 349ec76: remove use of the diamond operator 9 years ago
Andy Wilkinson 349ec76e62 Update @WebMvcTest to auto-configure Spring HATEOAS
Closes gh-6043
9 years ago
Andy Wilkinson e9a226c8f8 Fix handling of annotations on super classes in AnnotationsPropertySource
Closes gh-6006
9 years ago
Johnny Lim 189f96687d Rename AutoConfigurationJson to AutoConfigureJson
Closes gh-6007
9 years ago
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
9 years ago
Johnny Lim 7c34dd87c1 Polish
Closes gh-5925
9 years ago
Andy Wilkinson de0bcaa50e Update WebMvcTest to auto-configure supported template engines
Closes gh-5801
9 years ago
Andy Wilkinson c1a2a77cbe Auto-configure Flyway and Liquibase when using DataJpaTest
Closes gh-5716
9 years ago
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
9 years ago
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
9 years ago
Johnny Lim 7763c2ae4c Polish
Closes gh-5843
9 years ago
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
9 years ago
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
9 years ago
Phillip Webb 609cb52cd4 Move to relocated web classes
Refactor code to move from recently deprecated classes.

Closes gh-5822
9 years ago
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
9 years ago
Andy Wilkinson 9153ca9526 Auto-configure MockMvc with Spring Security
When Spring Security and its spring-security-test module are on the
classpath, `@WebMvcTest` will now auto-configure Spring Security and
configure its MockMvc-based test support. This behaviour can be
disabled using the new secure attribute on `@WebMvcTest` and
`@AutoConfigureMockMvc`.

Closes gh-5476
9 years ago
Andy Wilkinson 41ddda4a15 Support the use of @AliasFor with @PropertyMapping
Previously, when @AliasFor was used, the value of the mapped property
would be incorrect as the value of the canonical attribute would be
used, rather than the value of the alias.

This commit updates AnnotationsPropertySource to use a merged annotation
as the source of attribute values, thereby ensuring that any aliased
attributes are configured correctly.

Closes gh-5821
9 years ago
Andy Wilkinson 34b6915607 Consider meta-annotations when creating an AnnotationsPropertySource
Previously, meta-annotations were not considered when looking for
annotations that may have property mappings but were considered when
looking for a `@PropertyMapping` annotation. This led to three
problems:

1. Properties that should have been included in the property source
   were not included
2. Properties that were included may have had the wrong name
3. Properties were included when they should not have been

`@DataJpaTests` provided a concrete example of all three problems:

1. The `replace` and `connection` attributes from
   `@AutoConfigureTestDatabase` were not included in the property
   source
2. The `showSql` attribute from `@DataJpaTest` was mapped as
   `spring.test.database.spring.jpa.show-sql`
3. The `useDefaultFilters` attribute from `@DataJpaTest` was included
   in the property source.

This commit updates AnnotationsPropertySource to consider
meta-annotations when looking for attributes that should be mapped.
This addresses the first problem. Furthermore,
AnnotationsPropertySource has been updated to no longer consider
meta-annotations when looking for a type-level property mapping.
This addresses the second and third problems.

Closes gh-5794
9 years ago
Phillip Webb 93382648ab Formatting 9 years ago
Johnny Lim 6d48ee9593 Polish
Closes gh-5714
9 years ago
Andy Wilkinson 35270e939f Update dependency management for Selenium and its HTMLUnit Driver
Closes gh-5705
9 years ago
Johnny Lim c154990024 Polish
Closes gh-5691
9 years ago
Phillip Webb 21bc166c95 Rename Import*AutoConfiguration classes
Rename Import*AutoConfiguration classes to AutoConfigure*.

Fixes gh-5692
9 years ago
Johnny Lim 90d897eb9d Polish
Closes gh-5685
9 years ago
Phillip Webb dbd577545d Remove trailing whitespace 9 years ago
Johnny Lim 10a73381e6 Remove a test doing nothing
Closes gh-5673
9 years ago
Phillip Webb b398b3319c Rename @SpringApplicationTest -> @SpringBootTest
Rename @SpringApplicationTest to SpringBootTest and
@SpringApplicationContextLoader to @SpringBootContextLoader.

Fixes gh-5562
9 years ago
Andy Wilkinson e41ccfae3c Correct javadoc tag 9 years ago
Andy Wilkinson eb3180d581 Provide test auto-configuration for Spring REST Docs
This commit introduces a new annotation, @AutoConfigureRestDocs,
which can be used to enable auto-configuration of Spring REST Docs.
The auto-configuration removes the need to use Spring REST Docs' JUnit
rule and will automatically configure MockMvc. Combined with the new
auto-configuration for MockMvc it allows a test class to be free of
boilerplate configuration:

@RunWith(SpringRunner.class)
@WebMvcTest
@AutoConfigureRestDocs(outputDir = "target/generated-snippets",
        uriScheme = "https", uriHost = "api.example.com",
        uriPort = 443)
public class ExampleDocumentationTests {

    @Autowired
    private MockMvc mvc;

    @Test
    public void documentIndex() {
        // …
    }

}

For more advanced customization a RestDocsMockMvcConfigurationCustomizer
bean can be used.

If a RestDocumentationResultHandler is found in the context, it will
be passed to the ConfigurableMockMvcBuilder's alwaysDo method as part
of its customization.

Closes gh-5563
9 years ago
Andy Wilkinson f99bfccd51 Polishing 9 years ago
Andy Wilkinson b630b080ce Make it easier to customize the auto-configured MockMvcBuilder
Closes gh-5556
9 years ago
Phillip Webb 893a6c32f3 Upgrade to checkstyle 6.17
Fixes gh-5547
9 years ago
Johnny Lim a28dd9d9e6 Polish
Closes gh-5532
9 years ago
Stephane Nicoll 6be92675c2 Remove dependency version from child pom 9 years ago
Phillip Webb 81d5635571 Add @DataJpaTest annotation
Add @DataJpaTest and @AutoConfigureTestDatabase annotations to allow
testing of an application "slice" that only deals JPA.

See gh-4901
9 years ago
Phillip Webb bbc91cc03f Add @WebMvcTest annotation
Add @WebMvcTest and @AutoConfigureMockMvc annotations to allow testing
of an application "slice" that only deals with Spring MVC.

See gh-4901
9 years ago
Phillip Webb 0bd89017b6 Add @JsonTest annotation
Add @JsonTest and @AutoConfigureJsonTesters annotations to allow testing
of an application "slice" that only deals with JSON marshalling.

See gh-4901
9 years ago
Phillip Webb 56fd4e1f76 Add TypeExcludeFilters support
Provide a way for auto-configuration tests to easily filter scanned
components.

See gh-4901
9 years ago
Phillip Webb 46099c753b Add @PropertyMapping support
Add @PropertyMapping annotation which can be used to mark annotation
attributes that should contribute Environment properties.

Provides a quick way for tests to change auto-configuration behavior in
a structured way.

Fixes gh-4901
9 years ago
Phillip Webb e5f224118b Print AutoConfigureReport on test failures
Add a TestExecutionListener to print the auto-configuration report
when a test cannot load.

See gh-4901
9 years ago
Phillip Webb 6d934bb270 Add spring-boot-test-autoconfigure module
Add a new test module to deal with auto-configuration in tests.

See gh-4901
9 years ago