163 Commits

Author SHA1 Message Date
Johnny Lim
30a677646f Polish
Closes gh-7030
2016-09-28 16:45:19 +02:00
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
2016-09-21 14:30:28 +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
Stephane Nicoll
111743275f Polish 2016-09-19 15:17:27 +02:00
Johnny Lim
a994b11a73 Polish 2016-09-18 23:38:21 -07:00
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
2016-09-17 19:33:06 -07:00
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
2016-09-17 18:43:43 -07:00
Phillip Webb
04448d6bd9 Polish 2016-09-17 18:43:43 -07:00
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
2016-09-16 11:17:23 +02:00
Phillip Webb
25c4e261e9 Fix failing tests
See gh-6897
2016-09-15 17:16:26 -07:00
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
2016-09-15 16:55:49 -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
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
2016-09-15 11:16:42 +01: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
Andy Wilkinson
21a25ce855 Revert "Fail fast if @WebAppConfiguration and @SpringBootTest are used together"
This reverts commit c54cdd6735d2aff65e441583197a1ffb325df9c6.
2016-09-14 15:04:34 +01:00
Andy Wilkinson
c54cdd6735 Fail fast if @WebAppConfiguration and @SpringBootTest are used together
Closes gh-6795
2016-09-14 14:59:32 +01:00
Johnny Lim
caa4c0800f Polish
Closes gh-6872
2016-09-13 09:25:06 +02:00
Phillip Webb
3684c2ec56 Ensure argument matchers work with AOP spies
Update MockitoAopProxyTargetInterceptor to deal with deal with any
existing argument matchers when working with the VerificationMode.

Prior to this commit `@SpyBean` when combined with AOP could not support
argument matchers.

Fixes gh-6871
2016-09-12 14:53: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
Johnny Lim
11aa4d0749 Fix ResetMocksTestExecutionListenerTests
Align test implementation with names.

Closes gh-6842
2016-09-08 16:13:59 -07:00
Phillip Webb
41dc53f5dd Polish 2016-09-07 08:34:45 -07:00
Johnny Lim
4b9f6869f0 Polish
Closes gh-6817
2016-09-05 09:08:08 +02:00
Andy Wilkinson
0e00a49dcc Prevent beans created with @MockBean from being post-processed
Post-processing of mocked beans causes a number of problems:

 - The mock may be proxied for asynchronous processing which can cause
   problems when configuring expectations on a mock (gh-6573)
 - The mock may be proxied so that its return values can be cached or
   so that its methods can be transactional. This causes problems with
   verification of the expected calls to a mock (gh-6573, gh-5837)
 - If the mock is created from a class that uses field injection, the
   container will attempt to inject values into its fields. This causes
   problems if the mock is being created to avoid the use of one of
   those dependencies (gh-6663)
 - Proxying a mocked bean can lead to a JDK proxy being created
   (if proxyTargetClass=false) as the mock implements a Mockito
   interface. This can then cause injection failures as the types don’t
   match (gh-6405, gh-6665)

All of these problems can be avoided if a mocked bean is not
post-processed. Avoiding post-processing prevents proxies from being
created and autowiring from being performed. This commit avoids
post-processing by registering mocked beans as singletons as well as
via a bean definition. The latter is still used by the context for type
matching purposes.

Closes gh-6573, gh-6663, gh-6664
2016-09-02 10:23:06 +02:00
Andy Wilkinson
3814e509a3 Polish @deprecated javadoc and link to replacements where available
Closes gh-6765
2016-08-31 14:34:49 +01:00
Phillip Webb
a985a5c861 Update @MockBean to support generics
Update @MockBean and @SpyBean to support field generics. Prior to this
commit the following fields would fail with a "Duplicate mock
definition" exception:

  @MockBean
  private IdentityProvider<PasswordIdentity> passwordIdentityProvider;

  @MockBean
  private IdentityProvider<Oauth2Identity> oauth2IdentityProvider;

Fixes gh-6602
2016-08-29 21:42:44 +01:00
Phillip Webb
565ad79856 Polish 2016-08-29 20:26:30 +01:00
Andy Wilkinson
3c5cf02882 Provide method to create TestRestTemplate with basic auth from existing
Closes gh-6732
2016-08-25 12:07:19 +01:00
Andy Wilkinson
2377d78a40 Update auto-configured TestRestTemplate to use SSL when it’s enabled
Closes gh-6731
2016-08-25 09:47:23 +01:00
Andy Wilkinson
5a1741e2e8 Improve documentation of when TestRestTemplate is auto-configured
Closes gh-6729
2016-08-23 15:48:40 +01:00
Andy Wilkinson
f117b93d49 Polish “Add constructor to TestRestTemplate that takes a RestTemplateBuilder”
Closes gh-6702
2016-08-22 20:51:54 +01:00
Maciej Walkowiak
53d7fd5aab Add constructor to TestRestTemplate that takes a RestTemplateBuilder
Closes gh-6706
See gh-6702
2016-08-22 20:51:54 +01:00
Andy Wilkinson
1752773815 Default JSON loading to UTF-8 and provide methods to configure charset
Closes gh-6597
2016-08-16 15:17:30 +01:00
Andy Wilkinson
f4985abf3c Use factoryBeanObjectType attribute to find factory bean to replace
Previously, MockitoPostProcessor would fail to replace a factory bean
with a mock if the factory bean didn't return a matching type from
getObjectType(). This prevented Spring Data respoitories from being
replaced with a mock as Spring Data's repository factory beans
generally do not know the specific repository type that they will
produce when MockPostProcesser (a bean factory post-processor) is
running.

Spring Data has been updated to add a factoryBeanObjectType attribute
to its factory bean definitions. MockitoPostProcessor has been updated
to look for FactoryBeans with this attribute and to use its value
to determine whether or not the factory bean produces a bean of the
required type and, therefore, should be replaced with a mock.

Closes gh-6541
2016-08-10 10:27:00 +01:00
Spring Buildmaster
334baaeffd Next development version 2016-07-28 19:54:01 +00:00
Johnny Lim
9627d0ed66 Polish
Closes gh-6487
2016-07-27 12:29:33 +01:00
Phillip Webb
753a7e1d33 Document how to to customize the TestRestTemplate
Update the reference documentation and add some additional Javadoc to
provide hints on how to customize the `TestRestTemplate`.

Fixes gh-6465
2016-07-26 22:08:53 -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
Andy Wilkinson
ec7a9a32b9 Upgrade to AssertJ 2.5.0
Closes gh-6473
2016-07-26 21:19:02 +01:00
Phillip Webb
05ff4ed4e0 Upgrade to Tomcat 8.5.4 & remove tomcat-juli
Upgrade the managed Tomcat dependency to 8.5.4 and remove `tomcat-juli`
since it's now included in `tomcat-embed-core`.

Fixes gh-6192
2016-07-18 17:52:35 -07:00
Johnny Lim
a9f6ae4422 Polish
Closes gh-6374
2016-07-12 08:46:58 +02:00
Phillip Webb
43afc149a1 Consider WebAppConfiguration in @SpringBootTest
Update SpringBootTestContextBootstrapper to consider the
`@WebAppConfiguration` annotation and use sensible resourceBasePath
defaults.

Fixes gh-6371
2016-07-11 16:38:10 -07:00
Marcin Zajaczkowski
ed829d7981 Fix compatibility with Mockito 2.0
Update MockDefinition to only call `Answers.get()` if a direct cast
isn't possible. This provides compatibility with Mockito 2.0 (currently
2.0.47-beta) without breaking support for Mockto 1.x.

Closes gh-6323
2016-07-06 14:28:36 -07:00
Andy Wilkinson
92bb24e365 Avoid synchronizing on this and use an internal monitor instead
Where possible, code that previously synchronized on this (or on the
class in the case of static methods) has been updated to use an
internal monitor object instead. This allows the locking model that's
employed to be an implementation detail rather than part of the
class's API.

Classes that override a synchronized method continue to declare
the overriding method as synchronized. This ensures that locking
is consistent across the superclass and its subclass.

Closes gh-6262
2016-07-01 10:44:23 +01:00
Phillip Webb
be884d4e33 Polish 2016-06-29 10:57:43 -07:00
Stephane Nicoll
669da59b4a Polish 2016-06-29 16:28:41 +02:00
Johnny Lim
5bc9d5b380 Polish
Closes gh-6244
2016-06-29 08:08:53 +02:00
Stephane Nicoll
f54bec835d Move BasicAuthorizationInterceptor
`BasicAuthorizationInterceptor` is now available in the core framework
and this commit uses that instead of the outdated copy in Boot.

Closes gh-6237
2016-06-29 08:07:30 +02:00
Andy Wilkinson
f28e3d54c5 Upgrade to Tomcat 8.5.3
This commit changes the default version of Tomcat to 8.5.3 while
also retaining support for Tomcat 8.0 and 7.0. The main difference
in 8.5 is that the ServerSocketFactory abstraction that allowed the
TrustStore and KeyStore to be configured programatically no longer
exists. This logic has been replaced with the use of a custom URL
protocol (springbootssl) that provides access to the key store and
trust store of an SslStoreProvider. In addition to working with 8.5,
this approach has the advantage of also working with 8.0 and 7.0.

Closes gh-6164
2016-06-20 13:27:47 +01:00
Johnny Lim
a70a8635f9 Polish
Closes gh-6155
2016-06-14 08:35:22 +02:00