You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2010/07/01 06:26:35 UTC

svn commit: r959498 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/component/direct/DirectConsumer.java test/java/org/apache/camel/component/direct/DirectEndpointRouteInlinedTest.java

Author: davsclaus
Date: Thu Jul  1 04:26:35 2010
New Revision: 959498

URL: http://svn.apache.org/viewvc?rev=959498&view=rev
Log:
Fixed tests with direct endpoint detecting its the same consumer being started.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/DirectEndpointRouteInlinedTest.java   (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectConsumer.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectConsumer.java?rev=959498&r1=959497&r2=959498&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectConsumer.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectConsumer.java Thu Jul  1 04:26:35 2010
@@ -38,10 +38,13 @@ public class DirectConsumer extends Defa
 
     public void start() throws Exception {
         // add consumer to endpoint
-        if (endpoint.hasConsumer(this)) {
+        boolean existing = this == endpoint.getConsumer(); 
+        if (!existing && endpoint.hasConsumer(this)) {
             throw new IllegalArgumentException("Cannot add a 2nd consumer to the same endpoint. Endpoint " + endpoint + " only allows one consumer.");
         }
-        endpoint.addConsumer(this);
+        if (!existing) {
+            endpoint.addConsumer(this);
+        }
         super.start();
     }
 

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/DirectEndpointRouteInlinedTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/DirectEndpointRouteInlinedTest.java?rev=959498&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/DirectEndpointRouteInlinedTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/DirectEndpointRouteInlinedTest.java Thu Jul  1 04:26:35 2010
@@ -0,0 +1,59 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.direct;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class DirectEndpointRouteInlinedTest extends ContextTestSupport {
+
+    public void testDirect() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").to("mock:result");
+            }
+        });
+        context.start();
+
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testDirectExistingExists() throws Exception {
+        try {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    from("direct:start").to("mock:result");
+
+                    from("direct:start").to("mock:bar");
+                }
+            });
+            fail("Should have thrown exception");
+        } catch (IllegalArgumentException e) {
+            assertEquals("Cannot add a 2nd consumer to the same endpoint. Endpoint Endpoint[direct://start] only allows one consumer.", e.getMessage());
+        }
+    }
+
+}

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/DirectEndpointRouteInlinedTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/DirectEndpointRouteInlinedTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date