Merge pull request #1209 from garyrussell/gh-1206

* gh-1206:
  Restore AMQP vHost leading `/` support
pull/1230/head
Phillip Webb 11 years ago
commit 8265cf06b7

@ -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