This commit is contained in:
Andy Wilkinson 2017-09-18 19:23:26 +01:00
parent febf30ef0a
commit d1cf308bd2
4 changed files with 25 additions and 29 deletions

View File

@ -68,7 +68,7 @@ public class ConfigurationPropertiesReportEndpointAutoConfigurationTests {
private ContextConsumer<AssertableApplicationContext> validateTestProperties( private ContextConsumer<AssertableApplicationContext> validateTestProperties(
String dbPassword, String myTestProperty) { String dbPassword, String myTestProperty) {
return context -> { return (context) -> {
assertThat(context) assertThat(context)
.hasSingleBean(ConfigurationPropertiesReportEndpoint.class); .hasSingleBean(ConfigurationPropertiesReportEndpoint.class);
ConfigurationPropertiesReportEndpoint endpoint = context ConfigurationPropertiesReportEndpoint endpoint = context

View File

@ -65,7 +65,7 @@ public class EnvironmentEndpointAutoConfigurationTests {
private ContextConsumer<AssertableApplicationContext> validateSystemProperties( private ContextConsumer<AssertableApplicationContext> validateSystemProperties(
String dbPassword, String apiKey) { String dbPassword, String apiKey) {
return context -> { return (context) -> {
assertThat(context).hasSingleBean(EnvironmentEndpoint.class); assertThat(context).hasSingleBean(EnvironmentEndpoint.class);
EnvironmentEndpoint endpoint = context.getBean(EnvironmentEndpoint.class); EnvironmentEndpoint endpoint = context.getBean(EnvironmentEndpoint.class);
EnvironmentDescriptor env = endpoint.environment(null); EnvironmentDescriptor env = endpoint.environment(null);

View File

@ -543,77 +543,72 @@ public class RabbitAutoConfigurationTests {
@Test @Test
// Make sure that we at least attempt to load the store // Make sure that we at least attempt to load the store
public void enableSslWithNonExistingKeystoreShouldFail() { public void enableSslWithNonExistingKeystoreShouldFail() {
this.contextRunner this.contextRunner.withUserConfiguration(TestConfiguration.class)
.withUserConfiguration(TestConfiguration.class)
.withPropertyValues("spring.rabbitmq.ssl.enabled:true", .withPropertyValues("spring.rabbitmq.ssl.enabled:true",
"spring.rabbitmq.ssl.keyStore=foo", "spring.rabbitmq.ssl.keyStore=foo",
"spring.rabbitmq.ssl.keyStorePassword=secret") "spring.rabbitmq.ssl.keyStorePassword=secret")
.run(context -> { .run((context) -> {
assertThat(context).hasFailed(); assertThat(context).hasFailed();
assertThat(context).getFailure().hasMessageContaining("foo"); assertThat(context).getFailure().hasMessageContaining("foo");
assertThat(context).getFailure().hasMessageContaining("does not exist"); assertThat(context).getFailure()
.hasMessageContaining("does not exist");
}); });
} }
@Test @Test
// Make sure that we at least attempt to load the store // Make sure that we at least attempt to load the store
public void enableSslWithNonExistingTrustStoreShouldFail() { public void enableSslWithNonExistingTrustStoreShouldFail() {
this.contextRunner this.contextRunner.withUserConfiguration(TestConfiguration.class)
.withUserConfiguration(TestConfiguration.class) .withPropertyValues("spring.rabbitmq.ssl.enabled:true",
.withPropertyValues(
"spring.rabbitmq.ssl.enabled:true",
"spring.rabbitmq.ssl.trustStore=bar", "spring.rabbitmq.ssl.trustStore=bar",
"spring.rabbitmq.ssl.trustStorePassword=secret") "spring.rabbitmq.ssl.trustStorePassword=secret")
.run((context) -> { .run((context) -> {
assertThat(context).hasFailed(); assertThat(context).hasFailed();
assertThat(context).getFailure().hasMessageContaining("bar"); assertThat(context).getFailure().hasMessageContaining("bar");
assertThat(context).getFailure().hasMessageContaining("does not exist"); assertThat(context).getFailure()
.hasMessageContaining("does not exist");
}); });
} }
@Test @Test
public void enableSslWithInvalidKeystoreTypeShouldFail() throws Exception { public void enableSslWithInvalidKeystoreTypeShouldFail() throws Exception {
this.contextRunner this.contextRunner.withUserConfiguration(TestConfiguration.class)
.withUserConfiguration(TestConfiguration.class) .withPropertyValues("spring.rabbitmq.ssl.enabled:true",
.withPropertyValues(
"spring.rabbitmq.ssl.enabled:true",
"spring.rabbitmq.ssl.keyStore=foo", "spring.rabbitmq.ssl.keyStore=foo",
"spring.rabbitmq.ssl.keyStoreType=fooType") "spring.rabbitmq.ssl.keyStoreType=fooType")
.run(context -> { .run((context) -> {
assertThat(context).hasFailed(); assertThat(context).hasFailed();
assertThat(context).getFailure().hasMessageContaining("fooType"); assertThat(context).getFailure().hasMessageContaining("fooType");
assertThat(context).getFailure().hasRootCauseInstanceOf(NoSuchAlgorithmException.class); assertThat(context).getFailure()
.hasRootCauseInstanceOf(NoSuchAlgorithmException.class);
}); });
} }
@Test @Test
public void enableSslWithInvalidTrustStoreTypeShouldFail() throws Exception { public void enableSslWithInvalidTrustStoreTypeShouldFail() throws Exception {
this.contextRunner this.contextRunner.withUserConfiguration(TestConfiguration.class)
.withUserConfiguration(TestConfiguration.class) .withPropertyValues("spring.rabbitmq.ssl.enabled:true",
.withPropertyValues(
"spring.rabbitmq.ssl.enabled:true",
"spring.rabbitmq.ssl.trustStore=bar", "spring.rabbitmq.ssl.trustStore=bar",
"spring.rabbitmq.ssl.trustStoreType=barType") "spring.rabbitmq.ssl.trustStoreType=barType")
.run(context -> { .run((context) -> {
assertThat(context).hasFailed(); assertThat(context).hasFailed();
assertThat(context).getFailure().hasMessageContaining("barType"); assertThat(context).getFailure().hasMessageContaining("barType");
assertThat(context).getFailure().hasRootCauseInstanceOf(NoSuchAlgorithmException.class); assertThat(context).getFailure()
.hasRootCauseInstanceOf(NoSuchAlgorithmException.class);
}); });
} }
@Test @Test
public void enableSslWithKeystoreTypeAndTrustStoreTypeShouldWork() throws Exception { public void enableSslWithKeystoreTypeAndTrustStoreTypeShouldWork() throws Exception {
this.contextRunner this.contextRunner.withUserConfiguration(TestConfiguration.class)
.withUserConfiguration(TestConfiguration.class) .withPropertyValues("spring.rabbitmq.ssl.enabled:true",
.withPropertyValues(
"spring.rabbitmq.ssl.enabled:true",
"spring.rabbitmq.ssl.keyStore=/org/springframework/boot/autoconfigure/amqp/test.jks", "spring.rabbitmq.ssl.keyStore=/org/springframework/boot/autoconfigure/amqp/test.jks",
"spring.rabbitmq.ssl.keyStoreType=jks", "spring.rabbitmq.ssl.keyStoreType=jks",
"spring.rabbitmq.ssl.keyStorePassword=secret", "spring.rabbitmq.ssl.keyStorePassword=secret",
"spring.rabbitmq.ssl.trustStore=/org/springframework/boot/autoconfigure/amqp/test.jks", "spring.rabbitmq.ssl.trustStore=/org/springframework/boot/autoconfigure/amqp/test.jks",
"spring.rabbitmq.ssl.trustStoreType=jks", "spring.rabbitmq.ssl.trustStoreType=jks",
"spring.rabbitmq.ssl.trustStorePassword=secret") "spring.rabbitmq.ssl.trustStorePassword=secret")
.run(context -> assertThat(context).hasNotFailed()); .run((context) -> assertThat(context).hasNotFailed());
} }
private com.rabbitmq.client.ConnectionFactory getTargetConnectionFactory( private com.rabbitmq.client.ConnectionFactory getTargetConnectionFactory(

View File

@ -70,7 +70,8 @@ public class EndpointMappingTests {
@Test @Test
public void subPathWithoutALeadingSlashIsSeparatedFromBasePathBySingleSlash() { public void subPathWithoutALeadingSlashIsSeparatedFromBasePathBySingleSlash() {
assertThat(new EndpointMapping("/test").createSubPath("one")).isEqualTo("/test/one"); assertThat(new EndpointMapping("/test").createSubPath("one"))
.isEqualTo("/test/one");
} }
@Test @Test