Restore AMQP vHost leading `/` support

Update RabbitProperties since vHosts have no restrictions requiring a
leading slash and can have any number of leading slashes.

Fixes gh-1206
pull/1230/head
Gary Russell 11 years ago committed by Phillip Webb
parent fd3e5eceeb
commit ce0cbe05bf

@ -143,11 +143,7 @@ public class RabbitProperties {
}
public void setVirtualHost(String virtualHost) {
while (virtualHost.startsWith("/") && virtualHost.length() > 0) {
virtualHost = virtualHost.substring(1);
}
this.virtualHost = ("".equals(virtualHost) ? "/" : virtualHost);
}
}

@ -38,7 +38,7 @@ import static org.junit.Assert.assertNotNull;
*
* @author Greg Turnquist
*/
public class RabbitAutoconfigurationTests {
public class RabbitAutoConfigurationTests {
private AnnotationConfigApplicationContext context;
@ -74,7 +74,7 @@ public class RabbitAutoconfigurationTests {
.getBean(CachingConnectionFactory.class);
assertEquals("remote-server", connectionFactory.getHost());
assertEquals(9000, connectionFactory.getPort());
assertEquals("vhost", connectionFactory.getVirtualHost());
assertEquals("/vhost", connectionFactory.getVirtualHost());
}
@Test
@ -89,6 +89,30 @@ public class RabbitAutoconfigurationTests {
assertEquals("/", connectionFactory.getVirtualHost());
}
@Test
public void testRabbitTemplateVirtualHostNoLeadingSlash() {
this.context = new AnnotationConfigApplicationContext();
this.context.register(TestConfiguration.class, RabbitAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.rabbitmq.virtual_host:foo");
this.context.refresh();
CachingConnectionFactory connectionFactory = this.context
.getBean(CachingConnectionFactory.class);
assertEquals("foo", connectionFactory.getVirtualHost());
}
@Test
public void testRabbitTemplateVirtualHostMultiLeadingSlashes() {
this.context = new AnnotationConfigApplicationContext();
this.context.register(TestConfiguration.class, RabbitAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.rabbitmq.virtual_host:///foo");
this.context.refresh();
CachingConnectionFactory connectionFactory = this.context
.getBean(CachingConnectionFactory.class);
assertEquals("///foo", connectionFactory.getVirtualHost());
}
@Test
public void testRabbitTemplateDefaultVirtualHost() {
this.context = new AnnotationConfigApplicationContext();

@ -99,7 +99,7 @@ public class RabbitPropertiesTests {
@Test
public void testCustomFalsyVirtualHost() {
this.properties.setVirtualHost("/myvHost");
assertEquals("myvHost", this.properties.getVirtualHost());
assertEquals("/myvHost", this.properties.getVirtualHost());
}
}

Loading…
Cancel
Save