CAMEL-8270 exchangeName in the URI is optional

CAMEL-8270 Added an unit test for it


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/329666bd
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/329666bd
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/329666bd

Branch: refs/heads/camel-2.14.x
Commit: 329666bd1cb440acf1e94997ad96cafaf8d66c2e
Parents: 2f175cb
Author: Willem Jiang <[email protected]>
Authored: Thu Apr 30 14:40:00 2015 +0800
Committer: Willem Jiang <[email protected]>
Committed: Thu Apr 30 15:02:55 2015 +0800

----------------------------------------------------------------------
 .../camel/component/rabbitmq/RabbitMQComponent.java     |  6 +++---
 .../camel/component/rabbitmq/RabbitMQEndpointTest.java  | 12 ++++++++++++
 2 files changed, 15 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/329666bd/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQComponent.java
----------------------------------------------------------------------
diff --git 
a/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQComponent.java
 
b/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQComponent.java
index 7c76d6d..f24ff24 100644
--- 
a/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQComponent.java
+++ 
b/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQComponent.java
@@ -46,10 +46,10 @@ public class RabbitMQComponent extends DefaultComponent {
         URI host = new URI("http://"; + remaining);
         String hostname = host.getHost();
         int portNumber = host.getPort();
-        if (host.getPath().trim().length() <= 1) {
-            throw new IllegalArgumentException("No URI path as the 
exchangeName for the RabbitMQEndpoint, the URI is " + uri);
+        String exchangeName = ""; // We need to support the exchange to be "" 
the path is empty
+        if (host.getPath().trim().length() > 1) {
+            exchangeName = host.getPath().substring(1);
         }
-        String exchangeName = host.getPath().substring(1);
 
         // ConnectionFactory reference
         ConnectionFactory connectionFactory = 
resolveAndRemoveReferenceParameter(params, "connectionFactory", 
ConnectionFactory.class);

http://git-wip-us.apache.org/repos/asf/camel/blob/329666bd/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQEndpointTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQEndpointTest.java
 
b/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQEndpointTest.java
index afae40d..5aa95d4 100644
--- 
a/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQEndpointTest.java
+++ 
b/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQEndpointTest.java
@@ -61,6 +61,18 @@ public class RabbitMQEndpointTest extends CamelTestSupport {
         assertEquals(tag, 
exchange.getIn().getHeader(RabbitMQConstants.DELIVERY_TAG));
         assertEquals(body, exchange.getIn().getBody());
     }
+    
+    @Test
+    public void testExchangeNameIsOptional() throws Exception {
+        RabbitMQEndpoint endpoint1 = 
context.getEndpoint("rabbitmq:localhost/", RabbitMQEndpoint.class);
+        assertEquals("Get a wrong exchange name", "", 
endpoint1.getExchangeName());
+
+        RabbitMQEndpoint endpoint2 = 
context.getEndpoint("rabbitmq:localhost?autoAck=false", RabbitMQEndpoint.class);
+        assertEquals("Get a wrong exchange name", "", 
endpoint2.getExchangeName());
+        
+        RabbitMQEndpoint endpoint3 = 
context.getEndpoint("rabbitmq:localhost/exchange", RabbitMQEndpoint.class);
+        assertEquals("Get a wrong exchange name", "exchange", 
endpoint3.getExchangeName());
+    }
 
     @Test
     public void testCreatingRabbitExchangeSetsCustomHeaders() throws Exception 
{

Reply via email to