Commit Graph

253 Commits

Author SHA1 Message Date
Johnny Lim
29898c73d3 Remove superflous if in MockitoPostProcessor
The `if` in registerSpies() is not required as it's covered by the
Assert check.

Closes gh-5889
2016-05-13 20:09:02 -07:00
Johnny Lim
7a62b7d066 Polish
Closes gh-5936
2016-05-13 08:55:28 +02:00
Phillip Webb
cdfbf28099 Allow @MockBean/@SpyBean on Spring AOP proxies
Update Mockito support so that AOP Proxies automatically get additional
`Advice` that allows them to work with Mockito. Prior to this commit a
call to `verify` would fail because exiting AOP advice would confuse
Mockito and an `UnfinishedVerificationException` would be thrown.

The `MockitoAopProxyTargetInterceptor` works by detecting calls to a
mock that have been proceeded by `verify()` and bypassing AOP to
directly call the mock.

The order that `@SpyBean` creation occurs has also been updated to
ensure that that the spy is created before AOP advice is applied.
Without this, the creation of a spy would fail because Mockito copies
'state' to the newly created spied instance. Unfortunately, in the case
of AOP proxies, 'state' includes cglib interceptor fields. This means
that Mockito's own interceptors are clobbered by Spring's AOP
interceptors.

Fixes gh-5837
2016-05-11 20:20:02 -07:00
Phillip Webb
cf6212b955 Polish 2016-05-10 10:22:37 -07:00
Johnny Lim
38dc9ec441 Polish 2016-05-10 14:48:42 +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
db21bcdff6 Make SpringApplicationConfiguration use SpringApplicationContextLoader
The intention in 1.4 is for the deprecated testing functionality to
behave exactly as it did in 1.3. To help with this, this commit
updates SpringApplicationConfiguration to use
SpringApplicationContextLoader as its loader, just as it did in 1.3.

Closes gh-5882
2016-05-09 12:27:44 +01:00
Dave Syer
bdc71f693c Fix checksyle 'violations' 2016-05-06 13:11:09 +01:00
Dave Syer
be398741e1 Fix binary incompatibility of old TestRestTemplate
The TestRestTemplate is deprecated (so people can still use it)
but unusable because it only has constructors which depend on the
new options enum.
2016-05-06 13:07:39 +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
Johnny Lim
e5715df7e3 Polish
Closes gh-5836
2016-05-02 17:08:34 -07:00
Johnny Lim
0efa0038c3 Polish
Closes gh-5815
2016-04-30 10:24:33 +02: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
a7cb689f95 Move @LocalServerPort annotation
Move the @LocalServerPort to org.springframework.boot.context.embedded
since it's only really useful when working with embedded servlet
containers.

See gh-5822
2016-04-28 12:45:15 -07:00
Phillip Webb
93382648ab Formatting 2016-04-24 22:54:27 -07:00
Andy Wilkinson
aa19c19753 Merge branch '1.3.x' 2016-04-20 10:58:50 +01:00
Andy Wilkinson
601791c664 Configure test property sources before ConfigFileApplicationListener runs
Previously, SpringBootContextLoader configured the environment with the
test property sources using an ApplicationContextInitializer. This was
because TestPropertySourceUtils did not provide a method to directly
configure the environment using properties files, it had to be done
via an application context. An unwanted side-effect of this was that
the test property sources were not being configured before
ConfigFileApplicationListener examined the environment to determine the
name and locations of the files that it should be loading.

This commit takes advantage of a new method that was added to
TestPropertySourceUtils which allows properties files to be added
directly to the environment without using an application context. This
means that the use of the ApplicationContextInitializer can be removed
and the test property sources can be applied to the environment before
the application context is created.

Closes gh-5728
2016-04-19 13:30:18 +01:00
Stephane Nicoll
786004e297 Fix build 2016-04-16 10:58:28 +02:00
Phillip Webb
cf41512e66 Don't throw checked exceptions from Assert classes
Fixes gh-5709
2016-04-15 22:46:12 -07:00
Andy Wilkinson
35270e939f Update dependency management for Selenium and its HTMLUnit Driver
Closes gh-5705
2016-04-15 17:08:04 +01:00
Johnny Lim
90d897eb9d Polish
Closes gh-5685
2016-04-14 08:03:52 +02:00
Andy Wilkinson
a37ae5d556 Polish test property source changes made in 69b08291
TestPropertySourcesInitializer needs to be ordered with a high
precedence, specifically higher than
ContextIdApplicationContextInitializer, to ensure that any properties
used in setting the context’s id are available in the environment.

Closes gh-4828
2016-04-07 11:34:36 +01:00
Andy Wilkinson
69b0829199 Align precedence of @SpringBootTest properties with @TestPropertySource
This commit updates the precedence of properties configured using
@SpringBootTest to align with @TestPropertySource. Properties configured
using properties on @SpringBootTest are now added to the same property
source as those configured using properties on @TestPropertySource so
the precedence described in the javadoc of @TestPropertySource now
applies in full. Additionally, if both @TestPropertySource properties
and @SpringBootTest properties configure the same property, the value
from @TestPropertySource will win.

Closes gh-4828
2016-04-07 10:41:07 +01:00
Phillip Webb
01c9d72644 Polish 2016-04-06 15:19:58 -07:00
Johnny Lim
a55315b5b5 Polish
Closes gh-5614
2016-04-06 10:25:45 +02:00
Johnny Lim
8864f85b82 Remove System.out.println() 2016-04-04 22:37:37 -07:00
Phillip Webb
b398b3319c Rename @SpringApplicationTest -> @SpringBootTest
Rename @SpringApplicationTest to SpringBootTest and
@SpringApplicationContextLoader to @SpringBootContextLoader.

Fixes gh-5562
2016-04-04 22:36:58 -07:00
Phillip Webb
b0b190b362 Delete @SpringApplicationConfiguration
Remove the @SpringApplicationConfiguration annotation since it offers
little value over @SpringApplicationTest.

See gh-5562
2016-04-04 22:36:58 -07:00
Stephane Nicoll
0a8975bc84 Polish 2016-04-02 08:05:02 +02:00
Phillip Webb
34070e5a8e Add Support for Mockito spies
Add a @SpyBean annotation that can be used to create spies.

Fixes gh-5538
2016-04-01 17:16:40 -07:00
Andy Wilkinson
33f0ea3480 Rework SpringApplicationTest to support web modes
Rework the new testing support so that @SpringApplicationTest can be
used for standard integration tests, web integration tests with a
mock Servlet environment and web integration tests with an embedded
servlet container. This means that it a replacement for 1.3's
@IntegrationTest and @WebIntegrationTest and allows all
SpringApplication testing to be configured using a common annotation.

The old @IntegrationTest and @WebIntegrationTest along with their
supporting classes have been reinstated to their previous form (while
remaining deprecated). This should ensure that they continue to work
in 1.4 exactly as they did in 1.3 giving users a smooth path to
@SpringApplicationTest.

See gh-5477
2016-03-31 21:35:10 -07:00
Phillip Webb
893a6c32f3 Upgrade to checkstyle 6.17
Fixes gh-5547
2016-03-31 13:14:53 -07:00
Johnny Lim
a28dd9d9e6 Polish
Closes gh-5532
2016-03-30 08:43:23 +02:00
Johnny Lim
51bbe5e37a Polish
Closes gh-5508
2016-03-28 11:47:02 +02:00
Johnny Lim
46517cddd8 Fix MockDefinition.toString()
Closes gh-5500
2016-03-27 17:52:03 +02:00
Phillip Webb
a3bfc29e6e Fix warnings 2016-03-25 12:46:53 -07:00
Phillip Webb
ae1d352d34 Allow @Import to be used directly on test classes
Remove the need for a nested @Configuration class when writing a test
that need to @Import configuration.

Primarily added to allow @ImportAutoConfiguration to be used directly
on test classes.

Fixes gh-5473
2016-03-23 22:20:17 -07:00
Phillip Webb
ab7b48de84 Provide TestRestTemplate for @WebIntegrationTests
Add a ContextCustomizerFactory to provide TestRestTemplate as a bean for
tests annotated with WebIntegrationTests. Additionally provide support
for automatically expanding URLs of the form `/example` to
`http://localhost:${local.server.port}/example`.

Fixes gh-5227
2016-03-23 22:20:11 -07:00
Phillip Webb
cbea16ec01 Support HtmlUnit and Selenium localhost resolution
Provide variants of `WebClient` and `WebConnectionHtmlUnitDriver` that
automatically resolve relative URLs to "localhost:${local.server.port}".

Fixes gh-5472
2016-03-23 22:20:02 -07:00
Phillip Webb
24ab2bd891 Add utilities to help with JSON testing
Add Jackson, Gson and Basic String helper classes that allow AssertJ
assertions to be used to test JSON.

Fixes gh-5471
2016-03-23 22:19:52 -07:00
Phillip Webb
45c4f5f3f1 Add @MockBean support
Add a `@MockBean` annotation which can be used to setup and inject mocks
into an application context. The annotation can be used on test classes,
test fields, configuration classes or configuration fields. When used on
a field the annotation also acts as an injection point.

Fixes gh-5042
2016-03-23 22:19:44 -07:00
Phillip Webb
0829a1bde8 Drop superfluous annotations
Update internal tests to drop annotations that can now
be inferred.

Fixes gh-5470
2016-03-23 22:19:36 -07:00
Phillip Webb
7dffb702b5 Unify use of @BootStrapWith
Update @IntegrationTest to use @BootstrapWith rather than an explicitly
defined set of test execution listeners.

Also introduce a new @SpringApplicationTest annotation that is similar
to  @SpringApplicationConfiguration but a bootstrapper.

Fixes gh-5230
2016-03-23 22:19:33 -07:00
Phillip Webb
90950cfb1c Automatically find test configurations
Allow detection of `@SpringBootConfiguration` classes for both standard
spring tests and bootstrap (@IntegrationTest @WebIntegrationTest) based
tests.

Closes gh-5295
2016-03-23 22:19:04 -07:00
Phillip Webb
600a06af83 Auto-exclude test components from scanning
Add TestTypeExcludeFilter which will automatically attempt to exclude
test only configurations. All `@Configuration` annotated inner-classes
of tests are automatically excluded. The `@TestConfiguration` annotation
can be used to explicitly if a configuration needs explicit exclusion.

See gh-5295
See gh-4901
2016-03-23 22:18:56 -07:00
Phillip Webb
40c2e24a58 Fix SpringApplicationContextLoader customizers
Update SpringApplicationContextLoader to call ContextCustomizers in the
same way as other classes in `spring-test`.

Fixes gh-5294
2016-03-23 22:18:22 -07:00
Phillip Webb
c28f552883 Migrate SpringJUnit4ClassRunner to SpringRunner
Replace all existing SpringJUnit4ClassRunner references with the new
SpringRunner alias.

Fixes gh-5292
2016-03-23 22:18:18 -07:00
Phillip Webb
aef7f4bcb1 Restructure spring-boot-test packages
Create a new package structure for `spring-boot-test` and deprecate
existing classes.

Fixes gh-5293
2016-03-23 22:17:27 -07:00
Stephane Nicoll
2526a54e31 Polish contribution
Closes gh-5337
2016-03-14 14:24:24 +01:00
Anand Shah
f6a32a1d5a Add @LocalServerPort
Closes gh-5262
2016-03-14 14:24:24 +01:00
Andy Wilkinson
44ddfcc7fa Upgrade copyright headers of all files changed in 2016 2016-02-25 12:09:42 +00:00
Phillip Webb
89b7704977 Extract spring-boot-test.jar
Relocate the `org.springframework.boot.test` package from the
`spring-boot.jar` to `spring-boot-test.jar`.

Fixes gh-5184
2016-02-19 19:28:37 -08:00