pull/9965/head
Andy Wilkinson 7 years ago
parent e9aeb9ad63
commit abf39915e8

@ -417,12 +417,10 @@ public class HealthIndicatorAutoConfigurationTests {
private ContextConsumer<AssertableApplicationContext> hasSingleHealthIndicator( private ContextConsumer<AssertableApplicationContext> hasSingleHealthIndicator(
Class<? extends HealthIndicator> type) { Class<? extends HealthIndicator> type) {
return (context) -> { return (context) -> assertThat(context).getBeans(HealthIndicator.class).hasSize(1)
assertThat(context).getBeans(HealthIndicator.class).hasSize(1) .hasValueSatisfying(
.hasValueSatisfying(new Condition<>( new Condition<>((indicator) -> indicator.getClass().equals(type),
(indicator) -> indicator.getClass().equals(type),
"Wrong indicator type")); "Wrong indicator type"));
};
} }
@Configuration @Configuration

@ -40,10 +40,10 @@ public class WebClientCodecCustomizer implements WebClientCustomizer {
@Override @Override
public void customize(WebClient.Builder webClientBuilder) { public void customize(WebClient.Builder webClientBuilder) {
webClientBuilder webClientBuilder
.exchangeStrategies(ExchangeStrategies.builder().codecs((codecs) -> { .exchangeStrategies(ExchangeStrategies.builder()
this.codecCustomizers .codecs((codecs) -> this.codecCustomizers
.forEach((customizer) -> customizer.customize(codecs)); .forEach((customizer) -> customizer.customize(codecs)))
}).build()); .build());
} }
} }

@ -105,38 +105,33 @@ public class CacheAutoConfigurationTests {
@Test @Test
public void noEnableCaching() { public void noEnableCaching() {
this.contextRunner.withUserConfiguration(EmptyConfiguration.class) this.contextRunner.withUserConfiguration(EmptyConfiguration.class).run(
.run((context) -> { (context) -> assertThat(context).doesNotHaveBean(CacheManager.class));
assertThat(context).doesNotHaveBean(CacheManager.class);
});
} }
@Test @Test
public void cacheManagerBackOff() { public void cacheManagerBackOff() {
this.contextRunner.withUserConfiguration(CustomCacheManagerConfiguration.class) this.contextRunner.withUserConfiguration(CustomCacheManagerConfiguration.class)
.run((context) -> { .run((context) -> assertThat(
assertThat(getCacheManager(context, ConcurrentMapCacheManager.class) getCacheManager(context, ConcurrentMapCacheManager.class)
.getCacheNames()).containsOnly("custom1"); .getCacheNames()).containsOnly("custom1"));
});
} }
@Test @Test
public void cacheManagerFromSupportBackOff() { public void cacheManagerFromSupportBackOff() {
this.contextRunner this.contextRunner
.withUserConfiguration(CustomCacheManagerFromSupportConfiguration.class) .withUserConfiguration(CustomCacheManagerFromSupportConfiguration.class)
.run((context) -> { .run((context) -> assertThat(
assertThat(getCacheManager(context, ConcurrentMapCacheManager.class) getCacheManager(context, ConcurrentMapCacheManager.class)
.getCacheNames()).containsOnly("custom1"); .getCacheNames()).containsOnly("custom1"));
});
} }
@Test @Test
public void cacheResolverFromSupportBackOff() throws Exception { public void cacheResolverFromSupportBackOff() throws Exception {
this.contextRunner this.contextRunner
.withUserConfiguration(CustomCacheResolverFromSupportConfiguration.class) .withUserConfiguration(CustomCacheResolverFromSupportConfiguration.class)
.run((context) -> { .run((context) -> assertThat(context)
assertThat(context).doesNotHaveBean(CacheManager.class); .doesNotHaveBean(CacheManager.class));
});
} }
@Test @Test
@ -151,21 +146,19 @@ public class CacheAutoConfigurationTests {
@Test @Test
public void notSupportedCachingMode() { public void notSupportedCachingMode() {
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class) this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
.withPropertyValues("spring.cache.type=foobar").run((context) -> { .withPropertyValues("spring.cache.type=foobar")
assertThat(context).getFailure() .run((context) -> assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class) .isInstanceOf(BeanCreationException.class).hasMessageContaining(
.hasMessageContaining( "Failed to bind properties under 'spring.cache.type'"));
"Failed to bind properties under 'spring.cache.type'");
});
} }
@Test @Test
public void simpleCacheExplicit() { public void simpleCacheExplicit() {
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class) this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
.withPropertyValues("spring.cache.type=simple").run((context) -> { .withPropertyValues("spring.cache.type=simple")
assertThat(getCacheManager(context, ConcurrentMapCacheManager.class) .run((context) -> assertThat(
.getCacheNames()).isEmpty(); getCacheManager(context, ConcurrentMapCacheManager.class)
}); .getCacheNames()).isEmpty());
} }
@Test @Test
@ -206,13 +199,11 @@ public class CacheAutoConfigurationTests {
@Test @Test
public void genericCacheExplicit() { public void genericCacheExplicit() {
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class) this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
.withPropertyValues("spring.cache.type=generic").run((context) -> { .withPropertyValues("spring.cache.type=generic")
assertThat(context).getFailure() .run((context) -> assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class) .isInstanceOf(BeanCreationException.class)
.hasMessageContaining( .hasMessageContaining("No cache manager could be auto-configured")
"No cache manager could be auto-configured") .hasMessageContaining("GENERIC"));
.hasMessageContaining("GENERIC");
});
} }
@Test @Test
@ -339,13 +330,11 @@ public class CacheAutoConfigurationTests {
@Test @Test
public void jCacheCacheNoProviderExplicit() { public void jCacheCacheNoProviderExplicit() {
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class) this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
.withPropertyValues("spring.cache.type=jcache").run((context) -> { .withPropertyValues("spring.cache.type=jcache")
assertThat(context).getFailure() .run((context) -> assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class) .isInstanceOf(BeanCreationException.class)
.hasMessageContaining( .hasMessageContaining("No cache manager could be auto-configured")
"No cache manager could be auto-configured") .hasMessageContaining("JCACHE"));
.hasMessageContaining("JCACHE");
});
} }
@Test @Test
@ -416,11 +405,9 @@ public class CacheAutoConfigurationTests {
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class) this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
.withPropertyValues("spring.cache.type=jcache", .withPropertyValues("spring.cache.type=jcache",
"spring.cache.jcache.provider=" + wrongCachingProviderClassName) "spring.cache.jcache.provider=" + wrongCachingProviderClassName)
.run((context) -> { .run((context) -> assertThat(context).getFailure()
assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class) .isInstanceOf(BeanCreationException.class)
.hasMessageContaining(wrongCachingProviderClassName); .hasMessageContaining(wrongCachingProviderClassName));
});
} }
@Test @Test
@ -448,12 +435,10 @@ public class CacheAutoConfigurationTests {
.withPropertyValues("spring.cache.type=jcache", .withPropertyValues("spring.cache.type=jcache",
"spring.cache.jcache.provider=" + cachingProviderFqn, "spring.cache.jcache.provider=" + cachingProviderFqn,
"spring.cache.jcache.config=" + configLocation) "spring.cache.jcache.config=" + configLocation)
.run((context) -> { .run((context) -> assertThat(context).getFailure()
assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class) .isInstanceOf(BeanCreationException.class)
.hasMessageContaining("does not exist") .hasMessageContaining("does not exist")
.hasMessageContaining(configLocation); .hasMessageContaining(configLocation));
});
} }
@Test @Test
@ -692,10 +677,9 @@ public class CacheAutoConfigurationTests {
.withPropertyValues("spring.cache.type=infinispan", .withPropertyValues("spring.cache.type=infinispan",
"spring.cache.cacheNames[0]=foo", "spring.cache.cacheNames[0]=foo",
"spring.cache.cacheNames[1]=bar") "spring.cache.cacheNames[1]=bar")
.run((context) -> { .run((context) -> assertThat(
assertThat(getCacheManager(context, SpringEmbeddedCacheManager.class) getCacheManager(context, SpringEmbeddedCacheManager.class)
.getCacheNames()).containsOnly("foo", "bar"); .getCacheNames()).containsOnly("foo", "bar"));
});
} }
@Test @Test
@ -719,10 +703,9 @@ public class CacheAutoConfigurationTests {
"spring.cache.jcache.provider=" + cachingProviderClassName, "spring.cache.jcache.provider=" + cachingProviderClassName,
"spring.cache.cacheNames[0]=foo", "spring.cache.cacheNames[0]=foo",
"spring.cache.cacheNames[1]=bar") "spring.cache.cacheNames[1]=bar")
.run((context) -> { .run((context) -> assertThat(
assertThat(getCacheManager(context, JCacheCacheManager.class) getCacheManager(context, JCacheCacheManager.class)
.getCacheNames()).containsOnly("foo", "bar"); .getCacheNames()).containsOnly("foo", "bar"));
});
} }
@Test @Test
@ -751,11 +734,10 @@ public class CacheAutoConfigurationTests {
"spring.cache.jcache.provider=" + cachingProviderClassName, "spring.cache.jcache.provider=" + cachingProviderClassName,
"spring.cache.cacheNames[0]=foo", "spring.cache.cacheNames[0]=foo",
"spring.cache.cacheNames[1]=bar") "spring.cache.cacheNames[1]=bar")
.run((context) -> { .run((context) ->
// see customizer // see customizer
assertThat(getCacheManager(context, JCacheCacheManager.class) assertThat(getCacheManager(context, JCacheCacheManager.class)
.getCacheNames()).containsOnly("foo", "custom1"); .getCacheNames()).containsOnly("foo", "custom1"));
});
} }
finally { finally {
Caching.getCachingProvider(cachingProviderClassName).close(); Caching.getCachingProvider(cachingProviderClassName).close();

@ -70,11 +70,9 @@ public class HazelcastAutoConfigurationClientTests {
.withSystemProperties(HazelcastClientConfiguration.CONFIG_SYSTEM_PROPERTY .withSystemProperties(HazelcastClientConfiguration.CONFIG_SYSTEM_PROPERTY
+ "=classpath:org/springframework/boot/autoconfigure/hazelcast/" + "=classpath:org/springframework/boot/autoconfigure/hazelcast/"
+ "hazelcast-client-specific.xml") + "hazelcast-client-specific.xml")
.run((context) -> { .run((context) -> assertThat(context).getBean(HazelcastInstance.class)
assertThat(context).getBean(HazelcastInstance.class)
.isInstanceOf(HazelcastInstance.class) .isInstanceOf(HazelcastInstance.class)
.has(nameStartingWith("hz.client_")); .has(nameStartingWith("hz.client_")));
});
} }
@Test @Test
@ -83,11 +81,9 @@ public class HazelcastAutoConfigurationClientTests {
.withPropertyValues( .withPropertyValues(
"spring.hazelcast.config=org/springframework/boot/autoconfigure/" "spring.hazelcast.config=org/springframework/boot/autoconfigure/"
+ "hazelcast/hazelcast-client-specific.xml") + "hazelcast/hazelcast-client-specific.xml")
.run((context) -> { .run((context) -> assertThat(context).getBean(HazelcastInstance.class)
assertThat(context).getBean(HazelcastInstance.class)
.isInstanceOf(HazelcastClientProxy.class) .isInstanceOf(HazelcastClientProxy.class)
.has(nameStartingWith("hz.client_")); .has(nameStartingWith("hz.client_")));
});
} }
@Test @Test
@ -95,32 +91,26 @@ public class HazelcastAutoConfigurationClientTests {
this.contextRunner this.contextRunner
.withPropertyValues( .withPropertyValues(
"spring.hazelcast.config=hazelcast-client-default.xml") "spring.hazelcast.config=hazelcast-client-default.xml")
.run((context) -> { .run((context) -> assertThat(context).getBean(HazelcastInstance.class)
assertThat(context).getBean(HazelcastInstance.class)
.isInstanceOf(HazelcastClientProxy.class) .isInstanceOf(HazelcastClientProxy.class)
.has(nameStartingWith("hz.client_")); .has(nameStartingWith("hz.client_")));
});
} }
@Test @Test
public void unknownConfigFile() { public void unknownConfigFile() {
this.contextRunner this.contextRunner
.withPropertyValues("spring.hazelcast.config=foo/bar/unknown.xml") .withPropertyValues("spring.hazelcast.config=foo/bar/unknown.xml")
.run((context) -> { .run((context) -> assertThat(context).getFailure()
assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class) .isInstanceOf(BeanCreationException.class)
.hasMessageContaining("foo/bar/unknown.xml"); .hasMessageContaining("foo/bar/unknown.xml"));
});
} }
@Test @Test
public void clientConfigTakesPrecedence() { public void clientConfigTakesPrecedence() {
this.contextRunner.withUserConfiguration(HazelcastServerAndClientConfig.class) this.contextRunner.withUserConfiguration(HazelcastServerAndClientConfig.class)
.withPropertyValues("spring.hazelcast.config=this-is-ignored.xml") .withPropertyValues("spring.hazelcast.config=this-is-ignored.xml")
.run((context) -> { .run((context) -> assertThat(context).getBean(HazelcastInstance.class)
assertThat(context).getBean(HazelcastInstance.class) .isInstanceOf(HazelcastClientProxy.class));
.isInstanceOf(HazelcastClientProxy.class);
});
} }
private Condition<HazelcastInstance> nameStartingWith(String prefix) { private Condition<HazelcastInstance> nameStartingWith(String prefix) {

@ -99,11 +99,9 @@ public class HazelcastAutoConfigurationServerTests {
public void unknownConfigFile() { public void unknownConfigFile() {
this.contextRunner this.contextRunner
.withPropertyValues("spring.hazelcast.config=foo/bar/unknown.xml") .withPropertyValues("spring.hazelcast.config=foo/bar/unknown.xml")
.run((context) -> { .run((context) -> assertThat(context).getFailure()
assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class) .isInstanceOf(BeanCreationException.class)
.hasMessageContaining("foo/bar/unknown.xml"); .hasMessageContaining("foo/bar/unknown.xml"));
});
} }
@Test @Test

@ -85,10 +85,8 @@ public class DataSourceAutoConfigurationTests {
EmbeddedDatabaseConnection.override = EmbeddedDatabaseConnection.NONE; EmbeddedDatabaseConnection.override = EmbeddedDatabaseConnection.NONE;
this.contextRunner this.contextRunner
.withPropertyValues("spring.datasource.url:jdbc:not-going-to-work") .withPropertyValues("spring.datasource.url:jdbc:not-going-to-work")
.run((context) -> { .run((context) -> assertThat(context).getFailure()
assertThat(context).getFailure() .isInstanceOf(BeanCreationException.class));
.isInstanceOf(BeanCreationException.class);
});
} }
finally { finally {
EmbeddedDatabaseConnection.override = null; EmbeddedDatabaseConnection.override = null;
@ -100,11 +98,9 @@ public class DataSourceAutoConfigurationTests {
this.contextRunner this.contextRunner
.withPropertyValues( .withPropertyValues(
"spring.datasource.driverClassName:org.none.jdbcDriver") "spring.datasource.driverClassName:org.none.jdbcDriver")
.run((context) -> { .run((context) -> assertThat(context).getFailure()
assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class) .isInstanceOf(BeanCreationException.class)
.hasMessageContaining("org.none.jdbcDriver"); .hasMessageContaining("org.none.jdbcDriver"));
});
} }
@Test @Test
@ -217,10 +213,8 @@ public class DataSourceAutoConfigurationTests {
@Test @Test
public void testDefaultDataSourceCanBeOverridden() throws Exception { public void testDefaultDataSourceCanBeOverridden() throws Exception {
this.contextRunner.withUserConfiguration(TestDataSourceConfiguration.class) this.contextRunner.withUserConfiguration(TestDataSourceConfiguration.class)
.run((context) -> { .run((context) -> assertThat(context).getBean(DataSource.class)
assertThat(context).getBean(DataSource.class) .isInstanceOf(BasicDataSource.class));
.isInstanceOf(BasicDataSource.class);
});
} }
@Test @Test

@ -414,13 +414,11 @@ public class JmsAutoConfigurationTests {
@Test @Test
public void enableJmsAutomatically() throws Exception { public void enableJmsAutomatically() throws Exception {
this.contextRunner.withUserConfiguration(NoEnableJmsConfiguration.class) this.contextRunner.withUserConfiguration(NoEnableJmsConfiguration.class)
.run((context) -> { .run((context) -> assertThat(context)
assertThat(context)
.hasBean( .hasBean(
JmsListenerConfigUtils.JMS_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME) JmsListenerConfigUtils.JMS_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME)
.hasBean( .hasBean(
JmsListenerConfigUtils.JMS_LISTENER_ENDPOINT_REGISTRY_BEAN_NAME); JmsListenerConfigUtils.JMS_LISTENER_ENDPOINT_REGISTRY_BEAN_NAME));
});
} }
@Configuration @Configuration

@ -56,9 +56,7 @@ public class HttpHandlerAutoConfigurationTests {
public void shouldConfigureHttpHandlerAnnotation() { public void shouldConfigureHttpHandlerAnnotation() {
this.contextRunner this.contextRunner
.withConfiguration(AutoConfigurations.of(WebFluxAutoConfiguration.class)) .withConfiguration(AutoConfigurations.of(WebFluxAutoConfiguration.class))
.run((context) -> { .run((context) -> assertThat(context).hasSingleBean(HttpHandler.class));
assertThat(context).hasSingleBean(HttpHandler.class);
});
} }
@Configuration @Configuration

@ -55,12 +55,9 @@ public class WebServicesAutoConfigurationTests {
@Test @Test
public void customPathMustBeginWithASlash() { public void customPathMustBeginWithASlash() {
this.contextRunner.withPropertyValues("spring.webservices.path=invalid") this.contextRunner.withPropertyValues("spring.webservices.path=invalid")
.run((context) -> { .run((context) -> assertThat(context).getFailure()
assertThat(context).getFailure() .isInstanceOf(BeanCreationException.class).hasMessageContaining(
.isInstanceOf(BeanCreationException.class) "Failed to bind properties under 'spring.webservices'"));
.hasMessageContaining(
"Failed to bind properties under 'spring.webservices'");
});
} }
@Test @Test

@ -446,10 +446,9 @@ public class SysVinitLaunchScriptIT {
extends DockerCmdExecFactoryImpl { extends DockerCmdExecFactoryImpl {
private SpringBootDockerCmdExecFactory() { private SpringBootDockerCmdExecFactory() {
withClientRequestFilters((requestContext) -> { withClientRequestFilters((requestContext) ->
// Workaround for https://go-review.googlesource.com/#/c/3821/ // Workaround for https://go-review.googlesource.com/#/c/3821/
requestContext.getHeaders().add("Connection", "close"); requestContext.getHeaders().add("Connection", "close"));
});
} }
private CopyToContainerCmdExec createCopyToContainerCmdExec() { private CopyToContainerCmdExec createCopyToContainerCmdExec() {

@ -138,11 +138,10 @@ class WebTestClientContextCustomizer implements ContextCustomizer {
Collection<CodecCustomizer> codecCustomizers = context Collection<CodecCustomizer> codecCustomizers = context
.getBeansOfType(CodecCustomizer.class).values(); .getBeansOfType(CodecCustomizer.class).values();
if (!CollectionUtils.isEmpty(codecCustomizers)) { if (!CollectionUtils.isEmpty(codecCustomizers)) {
clientBuilder.exchangeStrategies( clientBuilder.exchangeStrategies(ExchangeStrategies.builder()
ExchangeStrategies.builder().codecs((codecs) -> { .codecs((codecs) -> codecCustomizers.forEach(
codecCustomizers.forEach((codecCustomizer) -> codecCustomizer (codecCustomizer) -> codecCustomizer.customize(codecs)))
.customize(codecs)); .build());
}).build());
} }
} }

@ -54,9 +54,9 @@ public abstract class AbstractApplicationContextRunnerTests<T extends AbstractAp
public void runWithSystemPropertiesShouldSetAndRemoveProperties() { public void runWithSystemPropertiesShouldSetAndRemoveProperties() {
String key = "test." + UUID.randomUUID().toString(); String key = "test." + UUID.randomUUID().toString();
assertThat(System.getProperties().containsKey(key)).isFalse(); assertThat(System.getProperties().containsKey(key)).isFalse();
get().withSystemProperties(key + "=value").run((context) -> { get().withSystemProperties(key + "=value")
assertThat(System.getProperties()).containsEntry(key, "value"); .run((context) -> assertThat(System.getProperties()).containsEntry(key,
}); "value"));
assertThat(System.getProperties().containsKey(key)).isFalse(); assertThat(System.getProperties().containsKey(key)).isFalse();
} }
@ -66,9 +66,8 @@ public abstract class AbstractApplicationContextRunnerTests<T extends AbstractAp
String key = "test." + UUID.randomUUID().toString(); String key = "test." + UUID.randomUUID().toString();
assertThat(System.getProperties().containsKey(key)).isFalse(); assertThat(System.getProperties().containsKey(key)).isFalse();
get().withSystemProperties(key + "=value") get().withSystemProperties(key + "=value")
.withUserConfiguration(FailingConfig.class).run((context) -> { .withUserConfiguration(FailingConfig.class)
assertThat(context).hasFailed(); .run((context) -> assertThat(context).hasFailed());
});
assertThat(System.getProperties().containsKey(key)).isFalse(); assertThat(System.getProperties().containsKey(key)).isFalse();
} }
@ -79,9 +78,9 @@ public abstract class AbstractApplicationContextRunnerTests<T extends AbstractAp
System.setProperty(key, "value"); System.setProperty(key, "value");
try { try {
assertThat(System.getProperties().getProperty(key)).isEqualTo("value"); assertThat(System.getProperties().getProperty(key)).isEqualTo("value");
get().withSystemProperties(key + "=newValue").run((context) -> { get().withSystemProperties(key + "=newValue")
assertThat(System.getProperties()).containsEntry(key, "newValue"); .run((context) -> assertThat(System.getProperties())
}); .containsEntry(key, "newValue"));
assertThat(System.getProperties().getProperty(key)).isEqualTo("value"); assertThat(System.getProperties().getProperty(key)).isEqualTo("value");
} }
finally { finally {
@ -96,9 +95,9 @@ public abstract class AbstractApplicationContextRunnerTests<T extends AbstractAp
System.setProperty(key, "value"); System.setProperty(key, "value");
try { try {
assertThat(System.getProperties().getProperty(key)).isEqualTo("value"); assertThat(System.getProperties().getProperty(key)).isEqualTo("value");
get().withSystemProperties(key + "=").run((context) -> { get().withSystemProperties(key + "=")
assertThat(System.getProperties()).doesNotContainKey(key); .run((context) -> assertThat(System.getProperties())
}); .doesNotContainKey(key));
assertThat(System.getProperties().getProperty(key)).isEqualTo("value"); assertThat(System.getProperties().getProperty(key)).isEqualTo("value");
} }
finally { finally {

Loading…
Cancel
Save