Commit fd2e3b35 authored by Phillip Webb's avatar Phillip Webb

Merge branch '1.5.x'

parents 6ef4ea9a 931ce15d
......@@ -93,7 +93,8 @@ public class EnvironmentMvcEndpoint extends EndpointMvcAdapter
@Override
protected Object getOptionalValue(Environment source, String name) {
Object result = ((EnvironmentEndpoint) getDelegate()).getResolver().getProperty(name, Object.class);
Object result = ((EnvironmentEndpoint) getDelegate()).getResolver()
.getProperty(name, Object.class);
if (result != null) {
result = ((EnvironmentEndpoint) getDelegate()).sanitize(name, result);
}
......
......@@ -112,8 +112,9 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
assertThat(systemProperties.get("my.services.cleardb-free.credentials"))
.isEqualTo("******");
assertThat(systemProperties.get("foo.mycredentials.uri")).isEqualTo("******");
clearSystemProperties("my.services.amqp-free.credentials.uri", "credentials.http_api_uri",
"my.services.cleardb-free.credentials", "foo.mycredentials.uri");
clearSystemProperties("my.services.amqp-free.credentials.uri",
"credentials.http_api_uri", "my.services.cleardb-free.credentials",
"foo.mycredentials.uri");
}
@SuppressWarnings("unchecked")
......@@ -208,14 +209,13 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
@Test
public void propertyWithPlaceholderResolved() throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"my.foo: ${bar.blah}", "bar.blah: hello");
EnvironmentTestUtils.addEnvironment(this.context, "my.foo: ${bar.blah}",
"bar.blah: hello");
this.context.register(Config.class);
this.context.refresh();
EnvironmentEndpoint report = getEndpointBean();
Map<String, Object> env = report.invoke();
Map<String, Object> testProperties = (Map<String, Object>) env
.get("test");
Map<String, Object> testProperties = (Map<String, Object>) env.get("test");
assertThat(testProperties.get("my.foo")).isEqualTo("hello");
}
......@@ -223,14 +223,12 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
@Test
public void propertyWithPlaceholderNotResolved() throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"my.foo: ${bar.blah}");
EnvironmentTestUtils.addEnvironment(this.context, "my.foo: ${bar.blah}");
this.context.register(Config.class);
this.context.refresh();
EnvironmentEndpoint report = getEndpointBean();
Map<String, Object> env = report.invoke();
Map<String, Object> testProperties = (Map<String, Object>) env
.get("test");
Map<String, Object> testProperties = (Map<String, Object>) env.get("test");
assertThat(testProperties.get("my.foo")).isEqualTo("${bar.blah}");
}
......@@ -244,8 +242,7 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
this.context.refresh();
EnvironmentEndpoint report = getEndpointBean();
Map<String, Object> env = report.invoke();
Map<String, Object> testProperties = (Map<String, Object>) env
.get("test");
Map<String, Object> testProperties = (Map<String, Object>) env.get("test");
assertThat(testProperties.get("my.foo")).isEqualTo("http://******://hello");
}
......@@ -259,16 +256,17 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
this.context.refresh();
EnvironmentEndpoint report = getEndpointBean();
Map<String, Object> env = report.invoke();
Map<String, Object> testProperties = (Map<String, Object>) env
.get("test");
assertThat(testProperties.get("my.foo")).isEqualTo("http://${bar.password}://hello");
Map<String, Object> testProperties = (Map<String, Object>) env.get("test");
assertThat(testProperties.get("my.foo"))
.isEqualTo("http://${bar.password}://hello");
}
@SuppressWarnings("unchecked")
@Test
@SuppressWarnings("unchecked")
public void propertyWithTypeOtherThanStringShouldNotFail() throws Exception {
this.context = new AnnotationConfigApplicationContext();
MutablePropertySources propertySources = this.context.getEnvironment().getPropertySources();
MutablePropertySources propertySources = this.context.getEnvironment()
.getPropertySources();
Map<String, Object> source = new HashMap<String, Object>();
source.put("foo", Collections.singletonMap("bar", "baz"));
propertySources.addFirst(new MapPropertySource("test", source));
......@@ -276,8 +274,7 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
this.context.refresh();
EnvironmentEndpoint report = getEndpointBean();
Map<String, Object> env = report.invoke();
Map<String, Object> testProperties = (Map<String, Object>) env
.get("test");
Map<String, Object> testProperties = (Map<String, Object>) env.get("test");
Map<String, String> foo = (Map<String, String>) testProperties.get("foo");
assertThat(foo.get("bar")).isEqualTo("baz");
}
......
......@@ -161,11 +161,10 @@ public class EnvironmentMvcEndpointTests {
.andExpect(content().string(containsString("\"my.foo\":\"******\"")));
}
@SuppressWarnings("unchecked")
@Test
public void propertyWithTypeOtherThanStringShouldNotFail() throws Exception {
ConfigurableEnvironment environment = (ConfigurableEnvironment) this.context.getEnvironment();
MutablePropertySources propertySources = environment.getPropertySources();
MutablePropertySources propertySources = ((ConfigurableEnvironment) this.context
.getEnvironment()).getPropertySources();
Map<String, Object> source = new HashMap<String, Object>();
source.put("foo", Collections.singletonMap("bar", "baz"));
propertySources.addFirst(new MapPropertySource("test", source));
......
......@@ -296,7 +296,7 @@ public class RabbitAutoConfigurationTests {
@Test
public void testSimpleRabbitListenerContainerFactoryWithCustomSettings() {
load(new Class<?>[] { MessageConvertersConfiguration.class,
MessageRecoverersConfiguration.class },
MessageRecoverersConfiguration.class },
"spring.rabbitmq.listener.simple.retry.enabled:true",
"spring.rabbitmq.listener.simple.retry.maxAttempts:4",
"spring.rabbitmq.listener.simple.retry.initialInterval:2000",
......@@ -346,29 +346,31 @@ public class RabbitAutoConfigurationTests {
@Test
public void testRabbitListenerContainerFactoryConfigurersAreAvailable() {
load(TestConfiguration.class,
"spring.rabbitmq.listener.simple.concurrency:5",
load(TestConfiguration.class, "spring.rabbitmq.listener.simple.concurrency:5",
"spring.rabbitmq.listener.simple.maxConcurrency:10",
"spring.rabbitmq.listener.simple.prefetch:40",
"spring.rabbitmq.listener.direct.consumers-per-queue:5",
"spring.rabbitmq.listener.direct.prefetch:40");
assertThat(this.context.getBeansOfType(
SimpleRabbitListenerContainerFactoryConfigurer.class)).hasSize(1);
assertThat(this.context.getBeansOfType(
DirectRabbitListenerContainerFactoryConfigurer.class)).hasSize(1);
assertThat(this.context
.getBeansOfType(SimpleRabbitListenerContainerFactoryConfigurer.class))
.hasSize(1);
assertThat(this.context
.getBeansOfType(DirectRabbitListenerContainerFactoryConfigurer.class))
.hasSize(1);
}
@Test
public void testSimpleRabbitListenerContainerFactoryConfigurerUsesConfig() {
load(TestConfiguration.class,
"spring.rabbitmq.listener.type:direct", // listener type is irrelevant
load(TestConfiguration.class, "spring.rabbitmq.listener.type:direct", // listener
// type is
// irrelevant
"spring.rabbitmq.listener.simple.concurrency:5",
"spring.rabbitmq.listener.simple.maxConcurrency:10",
"spring.rabbitmq.listener.simple.prefetch:40");
SimpleRabbitListenerContainerFactoryConfigurer configurer = this.context
.getBean(SimpleRabbitListenerContainerFactoryConfigurer.class);
SimpleRabbitListenerContainerFactory factory =
mock(SimpleRabbitListenerContainerFactory.class);
SimpleRabbitListenerContainerFactory factory = mock(
SimpleRabbitListenerContainerFactory.class);
configurer.configure(factory, mock(ConnectionFactory.class));
verify(factory).setConcurrentConsumers(5);
verify(factory).setMaxConcurrentConsumers(10);
......@@ -377,14 +379,15 @@ public class RabbitAutoConfigurationTests {
@Test
public void testDirectRabbitListenerContainerFactoryConfigurerUsesConfig() {
load(TestConfiguration.class,
"spring.rabbitmq.listener.type:simple", // listener type is irrelevant
load(TestConfiguration.class, "spring.rabbitmq.listener.type:simple", // listener
// type is
// irrelevant
"spring.rabbitmq.listener.direct.consumers-per-queue:5",
"spring.rabbitmq.listener.direct.prefetch:40");
DirectRabbitListenerContainerFactoryConfigurer configurer = this.context
.getBean(DirectRabbitListenerContainerFactoryConfigurer.class);
DirectRabbitListenerContainerFactory factory =
mock(DirectRabbitListenerContainerFactory.class);
DirectRabbitListenerContainerFactory factory = mock(
DirectRabbitListenerContainerFactory.class);
configurer.configure(factory, mock(ConnectionFactory.class));
verify(factory).setConsumersPerQueue(5);
verify(factory).setPrefetchCount(40);
......
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