This commit is contained in:
Phillip Webb
2015-09-05 10:38:30 -07:00
parent 67402405db
commit 6e29ee4557
125 changed files with 638 additions and 506 deletions

View File

@@ -41,9 +41,6 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.util.ConcurrentReferenceHashMap;
import org.springframework.util.StringUtils;
import static org.springframework.util.StringUtils.commaDelimitedListToStringArray;
import static org.springframework.util.StringUtils.trimAllWhitespace;
/**
* {@link EnableAutoConfiguration Auto-configuration} for {@link MessageSource}.
*
@@ -90,8 +87,9 @@ public class MessageSourceAutoConfiguration {
public MessageSource messageSource() {
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
if (StringUtils.hasText(this.basename)) {
messageSource
.setBasenames(commaDelimitedListToStringArray(trimAllWhitespace(this.basename)));
messageSource.setBasenames(StringUtils
.commaDelimitedListToStringArray(StringUtils
.trimAllWhitespace(this.basename)));
}
if (this.encoding != null) {
messageSource.setDefaultEncoding(this.encoding.name());
@@ -152,7 +150,8 @@ public class MessageSourceAutoConfiguration {
private ConditionOutcome getMatchOutcomeForBasename(ConditionContext context,
String basename) {
for (String name : commaDelimitedListToStringArray(trimAllWhitespace(basename))) {
for (String name : StringUtils.commaDelimitedListToStringArray(StringUtils
.trimAllWhitespace(basename))) {
for (Resource resource : getResources(context.getClassLoader(), name)) {
if (resource.exists()) {
return ConditionOutcome.match("Bundle found for "
@@ -193,6 +192,7 @@ public class MessageSourceAutoConfiguration {
}
}
catch (Throwable ex) {
// Ignore
}
ROOT_CLASSLOADER = classLoader;
}

View File

@@ -27,7 +27,10 @@ import org.springframework.util.Assert;
*
* @author Phillip Webb
*/
class CacheConfigurations {
final class CacheConfigurations {
private CacheConfigurations() {
}
private static final Map<CacheType, Class<?>> MAPPINGS;
static {

View File

@@ -45,7 +45,7 @@ import org.springframework.util.ObjectUtils;
* @author Phillip Webb
* @author Andy Wilkinson
*/
public class ConditionEvaluationReport {
public final class ConditionEvaluationReport {
private static final String BEAN_NAME = "autoConfigurationReport";

View File

@@ -103,10 +103,11 @@ public class GroovyTemplateAutoConfiguration {
&& codeSource.getLocation().toString().contains("-all")) {
return true;
}
return false;
}
catch (Exception ex) {
return false;
}
return false;
}
@Bean

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2012-2014 the original author or authors.
* Copyright 2012-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.groovy.template;
import java.io.IOException;

View File

@@ -43,6 +43,12 @@ import org.springframework.integration.monitor.IntegrationMBeanExporter;
@AutoConfigureAfter(JmxAutoConfiguration.class)
public class IntegrationAutoConfiguration {
@Bean
@ConditionalOnMissingBean(MBeanServer.class)
public MBeanServer mbeanServer() {
return new JmxAutoConfiguration().mbeanServer();
}
@Configuration
@EnableIntegration
protected static class IntegrationConfiguration {
@@ -56,10 +62,4 @@ public class IntegrationAutoConfiguration {
protected static class IntegrationJmxConfiguration {
}
@Bean
@ConditionalOnMissingBean(MBeanServer.class)
public MBeanServer mbeanServer() {
return new JmxAutoConfiguration().mbeanServer();
}
}

View File

@@ -39,6 +39,13 @@ import org.springframework.context.annotation.Configuration;
@ConditionalOnMissingBean(ConnectionFactory.class)
class ActiveMQConnectionFactoryConfiguration {
@Bean
@ConditionalOnProperty(prefix = "spring.activemq", name = "pooled", havingValue = "false", matchIfMissing = true)
public ActiveMQConnectionFactory jmsConnectionFactory(ActiveMQProperties properties) {
return new ActiveMQConnectionFactoryFactory(properties)
.createConnectionFactory(ActiveMQConnectionFactory.class);
}
@ConditionalOnClass(PooledConnectionFactory.class)
static class PooledConnectionFactoryConfiguration {
@@ -55,11 +62,4 @@ class ActiveMQConnectionFactoryConfiguration {
}
}
@Bean
@ConditionalOnProperty(prefix = "spring.activemq", name = "pooled", havingValue = "false", matchIfMissing = true)
public ActiveMQConnectionFactory jmsConnectionFactory(ActiveMQProperties properties) {
return new ActiveMQConnectionFactoryFactory(properties)
.createConnectionFactory(ActiveMQConnectionFactory.class);
}
}

View File

@@ -20,3 +20,4 @@
* @author Eddú Meléndez
*/
package org.springframework.boot.autoconfigure.jms.artemis;

View File

@@ -67,7 +67,7 @@ public class DeviceDelegatingViewResolverProperties {
}
public boolean isEnableFallback() {
return enableFallback;
return this.enableFallback;
}
public String getNormalPrefix() {

View File

@@ -60,8 +60,7 @@ import de.flapdoodle.embed.process.config.io.ProcessOutput;
import de.flapdoodle.embed.process.io.Processors;
import de.flapdoodle.embed.process.io.Slf4jLevel;
import de.flapdoodle.embed.process.io.progress.Slf4jProgressListener;
import static de.flapdoodle.embed.process.runtime.Network.localhostIsIPv6;
import de.flapdoodle.embed.process.runtime.Network;
/**
* {@link EnableAutoConfiguration Auto-configuration} for Embedded Mongo.
@@ -139,7 +138,7 @@ public class EmbeddedMongoAutoConfiguration {
MongodConfigBuilder builder = new MongodConfigBuilder()
.version(featureAwareVersion);
if (getPort() > 0) {
builder.net(new Net(getPort(), localhostIsIPv6()));
builder.net(new Net(getPort(), Network.localhostIsIPv6()));
}
return builder.build();
}
@@ -196,7 +195,7 @@ public class EmbeddedMongoAutoConfiguration {
* A workaround for the lack of a {@code toString} implementation on
* {@code GenericFeatureAwareVersion}.
*/
private static class ToStringFriendlyFeatureAwareVersion implements
private final static class ToStringFriendlyFeatureAwareVersion implements
IFeatureAwareVersion {
private final String version;

View File

@@ -80,7 +80,7 @@ public class EntityManagerFactoryBuilder {
/**
* A fluent builder for a LocalContainerEntityManagerFactoryBean.
*/
public class Builder {
public final class Builder {
private DataSource dataSource;

View File

@@ -75,6 +75,35 @@ public class OAuth2AuthorizationServerConfiguration extends
@Autowired(required = false)
private TokenStore tokenStore;
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
ClientDetailsServiceBuilder<InMemoryClientDetailsServiceBuilder>.ClientBuilder builder = clients
.inMemory().withClient(this.details.getClientId());
builder.secret(this.details.getClientSecret())
.resourceIds(this.details.getResourceIds().toArray(new String[0]))
.authorizedGrantTypes(
this.details.getAuthorizedGrantTypes().toArray(new String[0]))
.authorities(
AuthorityUtils.authorityListToSet(this.details.getAuthorities())
.toArray(new String[0]))
.scopes(this.details.getScope().toArray(new String[0]));
if (this.details.getRegisteredRedirectUri() != null) {
builder.redirectUris(this.details.getRegisteredRedirectUri().toArray(
new String[0]));
}
}
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints)
throws Exception {
if (this.tokenStore != null) {
endpoints.tokenStore(this.tokenStore);
}
if (this.details.getAuthorizedGrantTypes().contains("password")) {
endpoints.authenticationManager(this.authenticationManager);
}
}
@Configuration
protected static class ClientDetailsLogger {
@@ -119,33 +148,4 @@ public class OAuth2AuthorizationServerConfiguration extends
}
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
ClientDetailsServiceBuilder<InMemoryClientDetailsServiceBuilder>.ClientBuilder builder = clients
.inMemory().withClient(this.details.getClientId());
builder.secret(this.details.getClientSecret())
.resourceIds(this.details.getResourceIds().toArray(new String[0]))
.authorizedGrantTypes(
this.details.getAuthorizedGrantTypes().toArray(new String[0]))
.authorities(
AuthorityUtils.authorityListToSet(this.details.getAuthorities())
.toArray(new String[0]))
.scopes(this.details.getScope().toArray(new String[0]));
if (this.details.getRegisteredRedirectUri() != null) {
builder.redirectUris(this.details.getRegisteredRedirectUri().toArray(
new String[0]));
}
}
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints)
throws Exception {
if (this.tokenStore != null) {
endpoints.tokenStore(this.tokenStore);
}
if (this.details.getAuthorizedGrantTypes().contains("password")) {
endpoints.authenticationManager(this.authenticationManager);
}
}
}

View File

@@ -50,13 +50,11 @@ public class TemplateLocation {
return true;
}
try {
if (anyExists(resolver)) {
return true;
}
return anyExists(resolver);
}
catch (IOException ex) {
return false;
}
return false;
}
private boolean anyExists(ResourcePatternResolver resolver) throws IOException {

View File

@@ -96,14 +96,15 @@ public class BasicErrorController implements ErrorController {
protected HttpStatus getStatus(HttpServletRequest request) {
Integer statusCode = (Integer) request
.getAttribute("javax.servlet.error.status_code");
if (statusCode != null) {
try {
return HttpStatus.valueOf(statusCode);
}
catch (Exception ex) {
}
if (statusCode == null) {
return HttpStatus.INTERNAL_SERVER_ERROR;
}
try {
return HttpStatus.valueOf(statusCode);
}
catch (Exception ex) {
return HttpStatus.INTERNAL_SERVER_ERROR;
}
return HttpStatus.INTERNAL_SERVER_ERROR;
}
}

View File

@@ -122,65 +122,59 @@ public class DispatcherServletAutoConfiguration {
return checkServletRegistrations(beanFactory);
}
}
private static ConditionOutcome checkServlets(
ConfigurableListableBeanFactory beanFactory) {
List<String> servlets = Arrays.asList(beanFactory.getBeanNamesForType(
DispatcherServlet.class, false, false));
boolean containsDispatcherBean = beanFactory
.containsBean(DEFAULT_DISPATCHER_SERVLET_BEAN_NAME);
if (servlets.isEmpty()) {
if (containsDispatcherBean) {
return ConditionOutcome.noMatch("found no DispatcherServlet "
+ "but a non-DispatcherServlet named "
private ConditionOutcome checkServlets(ConfigurableListableBeanFactory beanFactory) {
List<String> servlets = Arrays.asList(beanFactory.getBeanNamesForType(
DispatcherServlet.class, false, false));
boolean containsDispatcherBean = beanFactory
.containsBean(DEFAULT_DISPATCHER_SERVLET_BEAN_NAME);
if (servlets.isEmpty()) {
if (containsDispatcherBean) {
return ConditionOutcome.noMatch("found no DispatcherServlet "
+ "but a non-DispatcherServlet named "
+ DEFAULT_DISPATCHER_SERVLET_BEAN_NAME);
}
return ConditionOutcome.match("no DispatcherServlet found");
}
if (servlets.contains(DEFAULT_DISPATCHER_SERVLET_BEAN_NAME)) {
return ConditionOutcome.noMatch("found DispatcherServlet named "
+ DEFAULT_DISPATCHER_SERVLET_BEAN_NAME);
}
return ConditionOutcome.match("no DispatcherServlet found");
}
if (servlets.contains(DEFAULT_DISPATCHER_SERVLET_BEAN_NAME)) {
return ConditionOutcome.noMatch("found DispatcherServlet named "
+ DEFAULT_DISPATCHER_SERVLET_BEAN_NAME);
}
if (containsDispatcherBean) {
return ConditionOutcome.noMatch("found non-DispatcherServlet named "
+ DEFAULT_DISPATCHER_SERVLET_BEAN_NAME);
if (containsDispatcherBean) {
return ConditionOutcome.noMatch("found non-DispatcherServlet named "
+ DEFAULT_DISPATCHER_SERVLET_BEAN_NAME);
}
return ConditionOutcome.match("one or more DispatcherServlets "
+ "found and none is named " + DEFAULT_DISPATCHER_SERVLET_BEAN_NAME);
}
return ConditionOutcome.match("one or more DispatcherServlets "
+ "found and none is named " + DEFAULT_DISPATCHER_SERVLET_BEAN_NAME);
}
private static ConditionOutcome checkServletRegistrations(
ConfigurableListableBeanFactory beanFactory) {
List<String> registrations = Arrays.asList(beanFactory.getBeanNamesForType(
ServletRegistrationBean.class, false, false));
boolean containsDispatcherRegistrationBean = beanFactory
.containsBean(DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME);
if (registrations.isEmpty()) {
if (containsDispatcherRegistrationBean) {
return ConditionOutcome.noMatch("found no ServletRegistrationBean "
+ "but a non-ServletRegistrationBean named "
private ConditionOutcome checkServletRegistrations(
ConfigurableListableBeanFactory beanFactory) {
List<String> registrations = Arrays.asList(beanFactory.getBeanNamesForType(
ServletRegistrationBean.class, false, false));
boolean containsDispatcherRegistrationBean = beanFactory
.containsBean(DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME);
if (registrations.isEmpty()) {
if (containsDispatcherRegistrationBean) {
return ConditionOutcome.noMatch("found no ServletRegistrationBean "
+ "but a non-ServletRegistrationBean named "
+ DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME);
}
return ConditionOutcome.match("no ServletRegistrationBean found");
}
if (registrations.contains(DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME)) {
return ConditionOutcome.noMatch("found ServletRegistrationBean named "
+ DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME);
}
return ConditionOutcome.match("no ServletRegistrationBean found");
}
if (containsDispatcherRegistrationBean) {
return ConditionOutcome
.noMatch("found non-ServletRegistrationBean named "
+ DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME);
}
return ConditionOutcome
.match("one or more ServletRegistrationBeans is found and none is named "
+ DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME);
if (registrations.contains(DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME)) {
return ConditionOutcome.noMatch("found ServletRegistrationBean named "
+ DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME);
}
if (containsDispatcherRegistrationBean) {
return ConditionOutcome.noMatch("found non-ServletRegistrationBean named "
+ DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME);
}
return ConditionOutcome
.match("one or more ServletRegistrationBeans is found and none is named "
+ DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME);
}
}

View File

@@ -75,13 +75,12 @@ import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/**
* Tests for {@link CacheAutoConfiguration}.
@@ -145,7 +144,7 @@ public class CacheAutoConfigurationTests {
public void simpleCacheExplicit() {
load(DefaultCacheConfiguration.class, "spring.cache.type=simple");
ConcurrentMapCacheManager cacheManager = validateCacheManager(ConcurrentMapCacheManager.class);
assertThat(cacheManager.getCacheNames(), is(empty()));
assertThat(cacheManager.getCacheNames(), empty());
}
@Test
@@ -191,7 +190,7 @@ public class CacheAutoConfigurationTests {
public void redisCacheExplicit() {
load(RedisCacheConfiguration.class, "spring.cache.type=redis");
RedisCacheManager cacheManager = validateCacheManager(RedisCacheManager.class);
assertThat(cacheManager.getCacheNames(), is(empty()));
assertThat(cacheManager.getCacheNames(), empty());
}
@Test
@@ -207,7 +206,7 @@ public class CacheAutoConfigurationTests {
public void noOpCacheExplicit() {
load(DefaultCacheConfiguration.class, "spring.cache.type=none");
NoOpCacheManager cacheManager = validateCacheManager(NoOpCacheManager.class);
assertThat(cacheManager.getCacheNames(), is(empty()));
assertThat(cacheManager.getCacheNames(), empty());
}
@Test
@@ -224,9 +223,9 @@ public class CacheAutoConfigurationTests {
load(DefaultCacheConfiguration.class, "spring.cache.type=jcache",
"spring.cache.jcache.provider=" + cachingProviderFqn);
JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class);
assertThat(cacheManager.getCacheNames(), is(empty()));
assertThat(cacheManager.getCacheNames(), empty());
assertThat(this.context.getBean(javax.cache.CacheManager.class),
is(cacheManager.getCacheManager()));
equalTo(cacheManager.getCacheManager()));
}
@Test
@@ -263,7 +262,7 @@ public class CacheAutoConfigurationTests {
load(JCacheCustomCacheManager.class, "spring.cache.type=jcache");
JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class);
assertThat(cacheManager.getCacheManager(),
is(this.context.getBean("customJCacheCacheManager")));
equalTo(this.context.getBean("customJCacheCacheManager")));
}
@Test
@@ -284,7 +283,8 @@ public class CacheAutoConfigurationTests {
"spring.cache.jcache.config=" + configLocation);
JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class);
Resource configResource = new ClassPathResource(configLocation);
assertThat(cacheManager.getCacheManager().getURI(), is(configResource.getURI()));
assertThat(cacheManager.getCacheManager().getURI(),
equalTo(configResource.getURI()));
}
@Test
@@ -307,7 +307,7 @@ public class CacheAutoConfigurationTests {
containsInAnyOrder("cacheTest1", "cacheTest2"));
assertThat(cacheManager.getCacheNames(), hasSize(2));
assertThat(this.context.getBean(net.sf.ehcache.CacheManager.class),
is(cacheManager.getCacheManager()));
equalTo(cacheManager.getCacheManager()));
}
@Test
@@ -325,7 +325,7 @@ public class CacheAutoConfigurationTests {
load(EhCacheCustomCacheManager.class, "spring.cache.type=ehcache");
EhCacheCacheManager cacheManager = validateCacheManager(EhCacheCacheManager.class);
assertThat(cacheManager.getCacheManager(),
is(this.context.getBean("customEhCacheCacheManager")));
equalTo(this.context.getBean("customEhCacheCacheManager")));
}
@Test
@@ -337,7 +337,7 @@ public class CacheAutoConfigurationTests {
assertThat(cacheManager.getCacheNames(), containsInAnyOrder("defaultCache"));
assertThat(cacheManager.getCacheNames(), hasSize(1));
assertThat(this.context.getBean(HazelcastInstance.class),
is(new DirectFieldAccessor(cacheManager)
equalTo(new DirectFieldAccessor(cacheManager)
.getPropertyValue("hazelcastInstance")));
}
@@ -367,7 +367,7 @@ public class CacheAutoConfigurationTests {
assertThat(
new DirectFieldAccessor(cacheManager)
.getPropertyValue("hazelcastInstance"),
is(this.context.getBean("customHazelcastInstance")));
equalTo(this.context.getBean("customHazelcastInstance")));
}
@Test
@@ -384,9 +384,9 @@ public class CacheAutoConfigurationTests {
assertThat(
new DirectFieldAccessor(cacheManager)
.getPropertyValue("hazelcastInstance"),
is((Object) hazelcastInstance));
equalTo((Object) hazelcastInstance));
assertThat(hazelcastInstance.getConfig().getConfigurationFile(),
is(new ClassPathResource(mainConfig).getFile()));
equalTo(new ClassPathResource(mainConfig).getFile()));
}
@Test
@@ -404,11 +404,11 @@ public class CacheAutoConfigurationTests {
HazelcastCacheManager cacheManager = validateCacheManager(HazelcastCacheManager.class);
HazelcastInstance cacheHazelcastInstance = (HazelcastInstance) new DirectFieldAccessor(
cacheManager).getPropertyValue("hazelcastInstance");
assertThat(cacheHazelcastInstance, is(not(hazelcastInstance))); // Our custom
assertThat(cacheHazelcastInstance, not(hazelcastInstance)); // Our custom
assertThat(hazelcastInstance.getConfig().getConfigurationFile(),
is(new ClassPathResource(mainConfig).getFile()));
equalTo(new ClassPathResource(mainConfig).getFile()));
assertThat(cacheHazelcastInstance.getConfig().getConfigurationFile(),
is(new ClassPathResource(cacheConfig).getFile()));
equalTo(new ClassPathResource(cacheConfig).getFile()));
}
@Test
@@ -432,7 +432,8 @@ public class CacheAutoConfigurationTests {
JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class);
Resource configResource = new ClassPathResource(configLocation);
assertThat(cacheManager.getCacheManager().getURI(), is(configResource.getURI()));
assertThat(cacheManager.getCacheManager().getURI(),
equalTo(configResource.getURI()));
}
@Test
@@ -486,7 +487,8 @@ public class CacheAutoConfigurationTests {
JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class);
Resource configResource = new ClassPathResource(configLocation);
assertThat(cacheManager.getCacheManager().getURI(), is(configResource.getURI()));
assertThat(cacheManager.getCacheManager().getURI(),
equalTo(configResource.getURI()));
}
@Test
@@ -538,7 +540,7 @@ public class CacheAutoConfigurationTests {
private <T extends CacheManager> T validateCacheManager(Class<T> type) {
CacheManager cacheManager = this.context.getBean(CacheManager.class);
assertThat("Wrong cache manager type", cacheManager, is(instanceOf(type)));
assertThat("Wrong cache manager type", cacheManager, instanceOf(type));
return type.cast(cacheManager);
}
@@ -615,8 +617,8 @@ public class CacheAutoConfigurationTests {
@Bean
public javax.cache.CacheManager customJCacheCacheManager() {
javax.cache.CacheManager cacheManager = mock(javax.cache.CacheManager.class);
when(cacheManager.getCacheNames())
.thenReturn(Collections.<String>emptyList());
given(cacheManager.getCacheNames()).willReturn(
Collections.<String>emptyList());
return cacheManager;
}
@@ -650,8 +652,8 @@ public class CacheAutoConfigurationTests {
@Bean
public net.sf.ehcache.CacheManager customEhCacheCacheManager() {
net.sf.ehcache.CacheManager cacheManager = mock(net.sf.ehcache.CacheManager.class);
when(cacheManager.getStatus()).thenReturn(Status.STATUS_ALIVE);
when(cacheManager.getCacheNames()).thenReturn(new String[0]);
given(cacheManager.getStatus()).willReturn(Status.STATUS_ALIVE);
given(cacheManager.getCacheNames()).willReturn(new String[0]);
return cacheManager;
}
@@ -675,7 +677,7 @@ public class CacheAutoConfigurationTests {
@Bean
public ConfigurationBuilder configurationBuilder() {
ConfigurationBuilder builder = mock(ConfigurationBuilder.class);
when(builder.build()).thenReturn(new ConfigurationBuilder().build());
given(builder.build()).willReturn(new ConfigurationBuilder().build());
return builder;
}

View File

@@ -108,7 +108,7 @@ public class ConditionalOnSingleCandidateTests {
}
@Configuration
@ConditionalOnSingleCandidate(value = String.class)
@ConditionalOnSingleCandidate(String.class)
protected static class OnBeanSingleCandidateConfiguration {
@Bean

View File

@@ -25,7 +25,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
/**
@@ -47,13 +47,13 @@ public class ConfigurationPropertiesAutoConfigurationTests {
@Test
public void processAnnotatedBean() {
load(new Class[] { AutoConfig.class, SampleBean.class }, "foo.name:test");
assertThat(this.context.getBean(SampleBean.class).getName(), is("test"));
assertThat(this.context.getBean(SampleBean.class).getName(), equalTo("test"));
}
@Test
public void processAnnotatedBeanNoAutoConfig() {
load(new Class[] { SampleBean.class }, "foo.name:test");
assertThat(this.context.getBean(SampleBean.class).getName(), is("default"));
assertThat(this.context.getBean(SampleBean.class).getName(), equalTo("default"));
}
private void load(Class<?>[] configs, String... environment) {

View File

@@ -32,8 +32,8 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.Configuration;
import org.springframework.data.solr.repository.config.EnableSolrRepositories;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;
/**

View File

@@ -52,7 +52,7 @@ public class FlywayAutoConfigurationTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();;
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
@Before
public void init() {

View File

@@ -35,9 +35,9 @@ import com.hazelcast.config.QueueConfig;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.hamcrest.collection.IsMapContaining.hasKey;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertThat;
/**
@@ -65,7 +65,7 @@ public class HazelcastAutoConfigurationTests {
HazelcastInstance hazelcastInstance = this.context
.getBean(HazelcastInstance.class);
assertThat(hazelcastInstance.getConfig().getConfigurationUrl(),
is(new ClassPathResource("hazelcast.xml").getURL()));
equalTo(new ClassPathResource("hazelcast.xml").getURL()));
}
@Test
@@ -93,7 +93,7 @@ public class HazelcastAutoConfigurationTests {
HazelcastInstance hazelcastInstance = this.context
.getBean(HazelcastInstance.class);
assertThat(hazelcastInstance.getConfig().getConfigurationFile(),
is(new ClassPathResource(
equalTo(new ClassPathResource(
"org/springframework/boot/autoconfigure/hazelcast"
+ "/hazelcast-specific.xml").getFile()));
}
@@ -104,7 +104,7 @@ public class HazelcastAutoConfigurationTests {
HazelcastInstance hazelcastInstance = this.context
.getBean(HazelcastInstance.class);
assertThat(hazelcastInstance.getConfig().getConfigurationUrl(),
is(new ClassPathResource("hazelcast-default.xml").getURL()));
equalTo(new ClassPathResource("hazelcast-default.xml").getURL()));
}
@Test
@@ -125,9 +125,9 @@ public class HazelcastAutoConfigurationTests {
HazelcastInstance hazelcastInstance = this.context
.getBean(HazelcastInstance.class);
assertThat(hazelcastInstance.getConfig().getInstanceName(),
is("my-test-instance"));
equalTo("my-test-instance"));
// Should reuse any existing instance by default.
assertThat(hazelcastInstance, is(existingHazelcastInstance));
assertThat(hazelcastInstance, equalTo(existingHazelcastInstance));
}
finally {
existingHazelcastInstance.shutdown();

View File

@@ -160,13 +160,6 @@ public class JacksonAutoConfigurationTests {
assertThat(mapper.getDateFormat(), is(instanceOf(MyDateFormat.class)));
}
public static class MyDateFormat extends SimpleDateFormat {
public MyDateFormat() {
super("yyyy-MM-dd HH:mm:ss");
}
}
@Test
public void noCustomPropertyNamingStrategy() throws Exception {
this.context.register(JacksonAutoConfiguration.class);
@@ -419,6 +412,13 @@ public class JacksonAutoConfigurationTests {
objectMapper.writeValueAsString(dateTime));
}
public static class MyDateFormat extends SimpleDateFormat {
public MyDateFormat() {
super("yyyy-MM-dd HH:mm:ss");
}
}
@Configuration
protected static class MockObjectMapperConfig {
@@ -469,7 +469,7 @@ public class JacksonAutoConfigurationTests {
}
protected static class Foo {
protected static final class Foo {
private String name;

View File

@@ -309,7 +309,7 @@ public class ArtemisAutoConfigurationTests {
return applicationContext;
}
private static class DestinationChecker {
private final static class DestinationChecker {
private final JmsTemplate jmsTemplate;

View File

@@ -323,7 +323,7 @@ public class HornetQAutoConfigurationTests {
return applicationContext;
}
private static class DestinationChecker {
private final static class DestinationChecker {
private final JmsTemplate jmsTemplate;

View File

@@ -64,7 +64,7 @@ public class TestableInitialContextFactory implements InitialContextFactory {
return context;
}
private static class TestableContext extends InitialContext {
private final static class TestableContext extends InitialContext {
private final Map<String, Object> bindings = new HashMap<String, Object>();

View File

@@ -110,6 +110,7 @@ public class JooqAutoConfigurationTests {
fail("An DataIntegrityViolationException should have been thrown.");
}
catch (DataIntegrityViolationException ex) {
// Ignore
}
dsl.transaction(new AssertFetch(dsl, "select count(*) as total from jooqtest;",
equalTo("2")));
@@ -137,6 +138,7 @@ public class JooqAutoConfigurationTests {
fail("A DataIntegrityViolationException should have been thrown.");
}
catch (DataIntegrityViolationException ex) {
// Ignore
}
dsl.transaction(new AssertFetch(dsl,
"select count(*) as total from jooqtest_tx;", equalTo("1")));

View File

@@ -24,10 +24,12 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoDataAutoConfiguration;
import org.springframework.boot.test.EnvironmentTestUtils;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.util.SocketUtils;
import com.mongodb.CommandResult;
import com.mongodb.MongoClient;
@@ -36,10 +38,7 @@ import de.flapdoodle.embed.mongo.distribution.Feature;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.springframework.boot.test.EnvironmentTestUtils.addEnvironment;
import static org.springframework.util.SocketUtils.findAvailableTcpPort;
/**
* Tests for {@link EmbeddedMongoAutoConfiguration}.
@@ -71,9 +70,9 @@ public class EmbeddedMongoAutoConfigurationTests {
@Test
public void customFeatures() {
this.context = new AnnotationConfigApplicationContext();
int mongoPort = findAvailableTcpPort();
addEnvironment(this.context, "spring.data.mongodb.port=" + mongoPort,
"spring.mongodb.embedded.features=TEXT_SEARCH, SYNC_DELAY");
int mongoPort = SocketUtils.findAvailableTcpPort();
EnvironmentTestUtils.addEnvironment(this.context, "spring.data.mongodb.port="
+ mongoPort, "spring.mongodb.embedded.features=TEXT_SEARCH, SYNC_DELAY");
this.context.register(EmbeddedMongoAutoConfiguration.class);
this.context.refresh();
assertThat(this.context.getBean(EmbeddedMongoProperties.class).getFeatures(),
@@ -83,25 +82,26 @@ public class EmbeddedMongoAutoConfigurationTests {
@Test
public void randomlyAllocatedPortIsAvailableWhenCreatingMongoClient() {
this.context = new AnnotationConfigApplicationContext();
addEnvironment(this.context, "spring.data.mongodb.port=0");
EnvironmentTestUtils.addEnvironment(this.context, "spring.data.mongodb.port=0");
this.context.register(EmbeddedMongoAutoConfiguration.class,
MongoClientConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
assertThat(
this.context.getBean(MongoClient.class).getAddress().getPort(),
is(equalTo(Integer.valueOf(this.context.getEnvironment().getProperty(
"local.mongo.port")))));
equalTo(Integer.valueOf(this.context.getEnvironment().getProperty(
"local.mongo.port"))));
}
private void assertVersionConfiguration(String configuredVersion,
String expectedVersion) {
this.context = new AnnotationConfigApplicationContext();
int mongoPort = findAvailableTcpPort();
addEnvironment(this.context, "spring.data.mongodb.port=" + mongoPort);
int mongoPort = SocketUtils.findAvailableTcpPort();
EnvironmentTestUtils.addEnvironment(this.context, "spring.data.mongodb.port="
+ mongoPort);
if (configuredVersion != null) {
addEnvironment(this.context, "spring.mongodb.embedded.version="
+ configuredVersion);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.mongodb.embedded.version=" + configuredVersion);
}
this.context.register(MongoAutoConfiguration.class,
MongoDataAutoConfiguration.class, EmbeddedMongoAutoConfiguration.class);

View File

@@ -345,6 +345,7 @@ public class SecurityAutoConfigurationTests {
fail("Expected Exception");
}
catch (AuthenticationException success) {
// Expected
}
token = new UsernamePasswordAuthenticationToken("foo", "bar");

View File

@@ -92,7 +92,7 @@ import org.springframework.web.client.RestTemplate;
import com.fasterxml.jackson.databind.JsonNode;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertThat;
/**
* Verify Spring Security OAuth2 auto-configuration secures end points properly, accepts

View File

@@ -109,7 +109,7 @@ public class CustomOAuth2SsoConfigurationTests {
@RestController
public static class TestController {
@RequestMapping(value = "/ui/test")
@RequestMapping("/ui/test")
public String test() {
return "test";
}

View File

@@ -67,6 +67,7 @@ public class AbstractSocialAutoConfigurationTests {
fail("Unexpected bean in context of type " + beanClass.getName());
}
catch (NoSuchBeanDefinitionException ex) {
// Expected
}
}

View File

@@ -21,8 +21,8 @@ import java.nio.charset.Charset;
import org.junit.Test;
import org.springframework.util.MimeTypeUtils;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasToString;
import static org.junit.Assert.assertThat;
/**
* Tests for {@link AbstractViewResolverProperties}.

View File

@@ -64,8 +64,8 @@ import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* Tests for {@link JtaAutoConfiguration}.
@@ -276,10 +276,10 @@ public class JtaAutoConfigurationTests {
XASession session = mock(XASession.class);
TemporaryQueue queue = mock(TemporaryQueue.class);
XAResource resource = mock(XAResource.class);
when(connectionFactory.createXAConnection()).thenReturn(connection);
when(connection.createXASession()).thenReturn(session);
when(session.createTemporaryQueue()).thenReturn(queue);
when(session.getXAResource()).thenReturn(resource);
given(connectionFactory.createXAConnection()).willReturn(connection);
given(connection.createXASession()).willReturn(session);
given(session.createTemporaryQueue()).willReturn(queue);
given(session.getXAResource()).willReturn(resource);
return wrapper.wrapConnectionFactory(connectionFactory);
}

View File

@@ -101,7 +101,7 @@ public class BasicErrorControllerDirectMockMvcTests {
WebMvcIncludedConfiguration.class).run("--server.port=0",
"--error.whitelabel.enabled=false"));
thrown.expect(ServletException.class);
this.thrown.expect(ServletException.class);
this.mockMvc.perform(get("/error").accept(MediaType.TEXT_HTML));
}

View File

@@ -174,7 +174,7 @@ public class BasicErrorControllerIntegrationTests {
}
@ResponseStatus(value = HttpStatus.NOT_ACCEPTABLE)
@ResponseStatus(HttpStatus.NOT_ACCEPTABLE)
@SuppressWarnings("serial")
private static class NoReasonExpectedException extends RuntimeException {

View File

@@ -186,7 +186,7 @@ public class BasicErrorControllerMockMvcTests {
}
@ResponseStatus(value = HttpStatus.NOT_FOUND)
@ResponseStatus(HttpStatus.NOT_FOUND)
private static class NotFoundException extends RuntimeException {
public NotFoundException(String string) {

View File

@@ -95,10 +95,6 @@ public class MultipartAutoConfigurationTests {
equalTo(1));
}
@Configuration
public static class ContainerWithNothing {
}
@Test
public void containerWithNoMultipartJettyConfiguration() {
this.context = new AnnotationConfigEmbeddedWebApplicationContext(
@@ -112,19 +108,6 @@ public class MultipartAutoConfigurationTests {
verifyServletWorks();
}
@Configuration
public static class ContainerWithNoMultipartJetty {
@Bean
JettyEmbeddedServletContainerFactory containerFactory() {
return new JettyEmbeddedServletContainerFactory();
}
@Bean
WebController controller() {
return new WebController();
}
}
@Test
public void containerWithNoMultipartUndertowConfiguration() {
this.context = new AnnotationConfigEmbeddedWebApplicationContext(
@@ -138,19 +121,6 @@ public class MultipartAutoConfigurationTests {
equalTo(1));
}
@Configuration
public static class ContainerWithNoMultipartUndertow {
@Bean
UndertowEmbeddedServletContainerFactory containerFactory() {
return new UndertowEmbeddedServletContainerFactory();
}
@Bean
WebController controller() {
return new WebController();
}
}
@Test
public void containerWithNoMultipartTomcatConfiguration() {
this.context = new AnnotationConfigEmbeddedWebApplicationContext(
@@ -249,6 +219,36 @@ public class MultipartAutoConfigurationTests {
String.class));
}
@Configuration
public static class ContainerWithNothing {
}
@Configuration
public static class ContainerWithNoMultipartJetty {
@Bean
JettyEmbeddedServletContainerFactory containerFactory() {
return new JettyEmbeddedServletContainerFactory();
}
@Bean
WebController controller() {
return new WebController();
}
}
@Configuration
public static class ContainerWithNoMultipartUndertow {
@Bean
UndertowEmbeddedServletContainerFactory containerFactory() {
return new UndertowEmbeddedServletContainerFactory();
}
@Bean
WebController controller() {
return new WebController();
}
}
@Configuration
@Import({ EmbeddedServletContainerAutoConfiguration.class,
DispatcherServletAutoConfiguration.class, MultipartAutoConfiguration.class,

View File

@@ -42,7 +42,7 @@ import org.springframework.boot.context.embedded.ServletContextInitializer;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;