Commit c201c1da authored by Phillip Webb's avatar Phillip Webb

Polish

parent 9384e5c3
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
......
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
......@@ -48,10 +48,8 @@ public class H2ConsoleProperties {
public void setPath(String path) {
Assert.notNull(path, "Path must not be null");
Assert.isTrue(path.length() > 1,
"Path must have length greater than 1");
Assert.isTrue(path.startsWith("/"),
"Path must start with '/'");
Assert.isTrue(path.length() > 1, "Path must have length greater than 1");
Assert.isTrue(path.startsWith("/"), "Path must start with '/'");
this.path = path;
}
......
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
......@@ -45,10 +45,8 @@ public class WebServicesProperties {
public void setPath(String path) {
Assert.notNull(path, "Path must not be null");
Assert.isTrue(path.length() > 1,
"Path must have length greater than 1");
Assert.isTrue(path.startsWith("/"),
"Path must start with '/'");
Assert.isTrue(path.length() > 1, "Path must have length greater than 1");
Assert.isTrue(path.startsWith("/"), "Path must start with '/'");
this.path = path;
}
......
......@@ -41,33 +41,31 @@ import static org.mockito.Mockito.mock;
public class CouchbaseAutoConfigurationIntegrationTests {
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
CouchbaseAutoConfiguration.class));
.withConfiguration(
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
CouchbaseAutoConfiguration.class));
@Rule
public final CouchbaseTestServer couchbase = new CouchbaseTestServer();
@Test
public void defaultConfiguration() {
this.contextRunner
.withPropertyValues("spring.couchbase.bootstrapHosts=localhost")
.run((context) -> {
assertThat(context).hasSingleBean(Cluster.class)
.hasSingleBean(ClusterInfo.class)
.hasSingleBean(CouchbaseEnvironment.class)
.hasSingleBean(Bucket.class);
});
this.contextRunner.withPropertyValues("spring.couchbase.bootstrapHosts=localhost")
.run((context) -> assertThat(context).hasSingleBean(Cluster.class)
.hasSingleBean(ClusterInfo.class)
.hasSingleBean(CouchbaseEnvironment.class)
.hasSingleBean(Bucket.class));
}
@Test
public void customConfiguration() {
this.contextRunner
.withUserConfiguration(CustomConfiguration.class)
this.contextRunner.withUserConfiguration(CustomConfiguration.class)
.withPropertyValues("spring.couchbase.bootstrapHosts=localhost")
.run((context) -> {
assertThat(context.getBeansOfType(Cluster.class)).hasSize(2);
assertThat(context.getBeansOfType(ClusterInfo.class)).hasSize(1);
assertThat(context.getBeansOfType(CouchbaseEnvironment.class)).hasSize(1);
assertThat(context.getBeansOfType(CouchbaseEnvironment.class))
.hasSize(1);
assertThat(context.getBeansOfType(Bucket.class)).hasSize(2);
});
}
......
......@@ -47,14 +47,13 @@ import static org.mockito.Mockito.mock;
public class CouchbaseAutoConfigurationTests {
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
CouchbaseAutoConfiguration.class));
.withConfiguration(
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
CouchbaseAutoConfiguration.class));
@Test
public void bootstrapHostsIsRequired() {
this.contextRunner.run((context) -> {
assertNoCouchbaseBeans(context);
});
this.contextRunner.run((context) -> assertNoCouchbaseBeans(context));
}
@Test
......@@ -80,19 +79,17 @@ public class CouchbaseAutoConfigurationTests {
private void assertNoCouchbaseBeans(AssertableApplicationContext context) {
// No beans are going to be created
assertThat(context).doesNotHaveBean(CouchbaseEnvironment.class)
.doesNotHaveBean(ClusterInfo.class)
.doesNotHaveBean(Cluster.class)
.doesNotHaveBean(ClusterInfo.class).doesNotHaveBean(Cluster.class)
.doesNotHaveBean(Bucket.class);
}
@Test
public void customizeEnvEndpoints() {
testCouchbaseEnv(env -> {
assertThat(env.kvEndpoints()).isEqualTo(4);
assertThat(env.queryEndpoints()).isEqualTo(5);
assertThat(env.viewEndpoints()).isEqualTo(6);
},
"spring.couchbase.env.endpoints.keyValue=4",
assertThat(env.kvEndpoints()).isEqualTo(4);
assertThat(env.queryEndpoints()).isEqualTo(5);
assertThat(env.viewEndpoints()).isEqualTo(6);
}, "spring.couchbase.env.endpoints.keyValue=4",
"spring.couchbase.env.endpoints.query=5",
"spring.couchbase.env.endpoints.view=6");
}
......@@ -100,13 +97,12 @@ public class CouchbaseAutoConfigurationTests {
@Test
public void customizeEnvTimeouts() {
testCouchbaseEnv(env -> {
assertThat(env.connectTimeout()).isEqualTo(100);
assertThat(env.kvTimeout()).isEqualTo(200);
assertThat(env.queryTimeout()).isEqualTo(300);
assertThat(env.socketConnectTimeout()).isEqualTo(400);
assertThat(env.viewTimeout()).isEqualTo(500);
},
"spring.couchbase.env.timeouts.connect=100",
assertThat(env.connectTimeout()).isEqualTo(100);
assertThat(env.kvTimeout()).isEqualTo(200);
assertThat(env.queryTimeout()).isEqualTo(300);
assertThat(env.socketConnectTimeout()).isEqualTo(400);
assertThat(env.viewTimeout()).isEqualTo(500);
}, "spring.couchbase.env.timeouts.connect=100",
"spring.couchbase.env.timeouts.keyValue=200",
"spring.couchbase.env.timeouts.query=300",
"spring.couchbase.env.timeouts.socket-connect=400",
......@@ -116,34 +112,33 @@ public class CouchbaseAutoConfigurationTests {
@Test
public void enableSslNoEnabledFlag() {
testCouchbaseEnv(env -> {
assertThat(env.sslEnabled()).isTrue();
assertThat(env.sslKeystoreFile()).isEqualTo("foo");
assertThat(env.sslKeystorePassword()).isEqualTo("secret");
},
"spring.couchbase.env.ssl.keyStore=foo",
assertThat(env.sslEnabled()).isTrue();
assertThat(env.sslKeystoreFile()).isEqualTo("foo");
assertThat(env.sslKeystorePassword()).isEqualTo("secret");
}, "spring.couchbase.env.ssl.keyStore=foo",
"spring.couchbase.env.ssl.keyStorePassword=secret");
}
@Test
public void disableSslEvenWithKeyStore() {
testCouchbaseEnv(env -> {
assertThat(env.sslEnabled()).isFalse();
assertThat(env.sslKeystoreFile()).isNull();
assertThat(env.sslKeystorePassword()).isNull();
},
"spring.couchbase.env.ssl.enabled=false",
assertThat(env.sslEnabled()).isFalse();
assertThat(env.sslKeystoreFile()).isNull();
assertThat(env.sslKeystorePassword()).isNull();
}, "spring.couchbase.env.ssl.enabled=false",
"spring.couchbase.env.ssl.keyStore=foo",
"spring.couchbase.env.ssl.keyStorePassword=secret");
}
private void testCouchbaseEnv(Consumer<DefaultCouchbaseEnvironment> environmentConsumer,
private void testCouchbaseEnv(
Consumer<DefaultCouchbaseEnvironment> environmentConsumer,
String... environment) {
this.contextRunner.withUserConfiguration(CouchbaseTestConfigurer.class)
.withPropertyValues(environment)
.run((context) -> {
CouchbaseProperties properties = context.getBean(CouchbaseProperties.class);
DefaultCouchbaseEnvironment env = new CouchbaseConfiguration(properties)
.couchbaseEnvironment();
.withPropertyValues(environment).run((context) -> {
CouchbaseProperties properties = context
.getBean(CouchbaseProperties.class);
DefaultCouchbaseEnvironment env = new CouchbaseConfiguration(
properties).couchbaseEnvironment();
environmentConsumer.accept(env);
});
}
......@@ -151,12 +146,12 @@ public class CouchbaseAutoConfigurationTests {
@Test
public void customizeEnvWithCustomCouchbaseConfiguration() {
this.contextRunner.withUserConfiguration(CustomCouchbaseConfiguration.class)
.withPropertyValues(
"spring.couchbase.bootstrap-hosts=localhost",
.withPropertyValues("spring.couchbase.bootstrap-hosts=localhost",
"spring.couchbase.env.timeouts.connect=100")
.run((context) -> {
assertThat(context).hasSingleBean(CouchbaseConfiguration.class);
DefaultCouchbaseEnvironment env = context.getBean(DefaultCouchbaseEnvironment.class);
DefaultCouchbaseEnvironment env = context
.getBean(DefaultCouchbaseEnvironment.class);
assertThat(env.socketConnectTimeout()).isEqualTo(5000);
assertThat(env.connectTimeout()).isEqualTo(2000);
});
......
......@@ -53,12 +53,11 @@ public class WebClientAutoConfigurationTests {
@Test
public void shouldCreateBuilder() {
this.contextRunner
.run((context) -> {
WebClient.Builder builder = context.getBean(WebClient.Builder.class);
WebClient webClient = builder.build();
assertThat(webClient).isNotNull();
});
this.contextRunner.run((context) -> {
WebClient.Builder builder = context.getBean(WebClient.Builder.class);
WebClient webClient = builder.build();
assertThat(webClient).isNotNull();
});
}
......@@ -67,7 +66,8 @@ public class WebClientAutoConfigurationTests {
this.contextRunner.withUserConfiguration(CodecConfiguration.class)
.run((context) -> {
WebClient.Builder builder = context.getBean(WebClient.Builder.class);
CodecCustomizer codecCustomizer = context.getBean(CodecCustomizer.class);
CodecCustomizer codecCustomizer = context
.getBean(CodecCustomizer.class);
WebClientCodecCustomizer clientCustomizer = context
.getBean(WebClientCodecCustomizer.class);
builder.build();
......@@ -81,7 +81,8 @@ public class WebClientAutoConfigurationTests {
this.contextRunner.withUserConfiguration(WebClientCustomizerConfig.class)
.run((context) -> {
WebClient.Builder builder = context.getBean(WebClient.Builder.class);
WebClientCustomizer customizer = context.getBean(WebClientCustomizer.class);
WebClientCustomizer customizer = context
.getBean(WebClientCustomizer.class);
builder.build();
verify(customizer).customize(any(WebClient.Builder.class));
});
......@@ -95,12 +96,15 @@ public class WebClientAutoConfigurationTests {
ClientHttpConnector firstConnector = mock(ClientHttpConnector.class);
given(firstConnector.connect(any(), any(), any()))
.willReturn(Mono.just(response));
WebClient.Builder firstBuilder = context.getBean(WebClient.Builder.class);
firstBuilder.clientConnector(firstConnector).baseUrl("http://first.example.org");
WebClient.Builder firstBuilder = context
.getBean(WebClient.Builder.class);
firstBuilder.clientConnector(firstConnector)
.baseUrl("http://first.example.org");
ClientHttpConnector secondConnector = mock(ClientHttpConnector.class);
given(secondConnector.connect(any(), any(), any()))
.willReturn(Mono.just(response));
WebClient.Builder secondBuilder = context.getBean(WebClient.Builder.class);
WebClient.Builder secondBuilder = context
.getBean(WebClient.Builder.class);
secondBuilder.clientConnector(secondConnector)
.baseUrl("http://second.example.org");
assertThat(firstBuilder).isNotEqualTo(secondBuilder);
......@@ -110,7 +114,8 @@ public class WebClientAutoConfigurationTests {
eq(URI.create("http://first.example.org/foo")), any());
verify(secondConnector).connect(eq(HttpMethod.GET),
eq(URI.create("http://second.example.org/foo")), any());
WebClientCustomizer customizer = context.getBean(WebClientCustomizer.class);
WebClientCustomizer customizer = context
.getBean(WebClientCustomizer.class);
verify(customizer, times(1)).customize(any(WebClient.Builder.class));
});
}
......@@ -118,8 +123,7 @@ public class WebClientAutoConfigurationTests {
@Test
public void shouldNotCreateClientBuilderIfAlreadyPresent() {
this.contextRunner.withUserConfiguration(WebClientCustomizerConfig.class,
CustomWebClientBuilderConfig.class)
.run((context) -> {
CustomWebClientBuilderConfig.class).run((context) -> {
WebClient.Builder builder = context.getBean(WebClient.Builder.class);
assertThat(builder).isInstanceOf(MyWebClientBuilder.class);
});
......
......@@ -25,7 +25,6 @@ import java.util.Set;
import java.util.stream.Collectors;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.boot.context.properties.bind.BinderTests.JavaBean;
......@@ -306,7 +305,6 @@ public class CollectionBinderTests {
}
@Test
@Ignore
public void bindToCollectionWithNoDefaultConstructor() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.items", "a,b,c,c");
......@@ -389,8 +387,7 @@ public class CollectionBinderTests {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.bar[0]", "hello");
this.sources.add(source);
Bindable<ClonedArrayBean> target = Bindable
.of(ClonedArrayBean.class);
Bindable<ClonedArrayBean> target = Bindable.of(ClonedArrayBean.class);
ClonedArrayBean bean = this.binder.bind("foo", target).get();
assertThat(bean.getBar()).contains("hello");
}
......@@ -468,7 +465,6 @@ public class CollectionBinderTests {
}
}
public static class ClonedArrayBean {
private String[] bar;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment