camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hadr...@apache.org
Subject svn commit: r672004 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/model/ test/java/org/apache/camel/processor/
Date Thu, 26 Jun 2008 19:32:21 GMT
Author: hadrian
Date: Thu Jun 26 12:32:21 2008
New Revision: 672004

URL: http://svn.apache.org/viewvc?rev=672004&view=rev
Log:
fix CAMEL-481

Added:
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptRouteTestSupport.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithPredicateAndStopRouteTest.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithStopRouteTest.java
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptType.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptRouteTest.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithPredicateAndProceedRouteTest.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithPredicateRouteTest.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithoutProceedRouteTest.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptType.java?rev=672004&r1=672003&r2=672004&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptType.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptType.java
Thu Jun 26 12:32:21 2008
@@ -43,6 +43,10 @@
 
     @XmlTransient
     private ProceedType proceed = new ProceedType();
+    @XmlTransient
+    private Boolean stop = Boolean.FALSE;
+    @XmlTransient
+    private Boolean usePredicate = Boolean.FALSE;
 
     @Override
     public String toString() {
@@ -69,6 +73,7 @@
      * Applies this interceptor only if the given predicate is true
      */
     public ChoiceType when(Predicate predicate) {
+    	usePredicate = Boolean.TRUE;
         ChoiceType choice = choice().when(PredicateBuilder.not(predicate));
         choice.addOutput(proceed);
         return choice.otherwise();
@@ -78,6 +83,10 @@
         return proceed;
     }
 
+    public void stopIntercept() {
+    	stop = Boolean.TRUE;
+    }
+
     public InterceptType createProxy() {
         InterceptType answer = new InterceptType();
         answer.getOutputs().addAll(this.getOutputs());
@@ -86,31 +95,42 @@
         // a bit ugly, operating based on the assumption that the proceed is
         // in its outputs (if proceed() was called) and/or in the
         // outputs of the otherwise or last when clause for the predicated version.
-        proxifyProceed(this.getProceed(), answer.getProceed(), answer);
-
         if (answer.getOutputs().size() > 0) {
-            // this is for the predicate version
-            ProcessorType processor = answer;
-            processor = (ProcessorType) answer.getOutputs().get(0);
-            if (processor instanceof ChoiceType) {
-                ChoiceType choice = (ChoiceType) processor;
-                proxifyProceed(this.getProceed(), answer.getProceed(),
-                        choice.getWhenClauses().get(choice.getWhenClauses().size() - 1));
-                proxifyProceed(this.getProceed(), answer.getProceed(), choice.getOtherwise());
+            // this is for the predicate version or if a choice() is present
+        	ChoiceType choice = null;
+            for (ProcessorType processor : answer.getOutputs()) {
+	            if (processor instanceof ChoiceType) {
+                    choice = (ChoiceType) processor;
+                    
+                    // for the predicated version we add the proceed() to otherwise()
+                    // before knowing if stop() will follow, so let's make a small adjustment
+                    if (usePredicate.booleanValue() && stop.booleanValue()) {
+                    	WhenType when = choice.getWhenClauses().get(0);
+                    	when.getOutputs().remove(this.getProceed());
+                    }
+                    addProceedProxy(this.getProceed(), answer.getProceed(),
+                        choice.getWhenClauses().get(choice.getWhenClauses().size() - 1),
usePredicate.booleanValue() && !stop.booleanValue());
+                    addProceedProxy(this.getProceed(), answer.getProceed(), choice.getOtherwise(),
false);
+                    break;
+                }
             }
-        }
+            if (choice == null) {
+                addProceedProxy(this.getProceed(), answer.getProceed(), answer, !stop.booleanValue());
+            }
+        }        
         return answer;
     }
 
-    private void proxifyProceed(ProceedType orig, ProceedType proxy, ProcessorType<?>
processor) {
+    private void addProceedProxy(ProceedType orig, ProceedType proxy, ProcessorType<?>
processor, boolean force) {
         int index = processor.getOutputs().indexOf(orig);
         if (index >= 0) {
-            // replace original proceed with proxy
             processor.addOutput(proxy);
-
+            // replace original proceed with proxy
             List<ProcessorType<?>> outs = processor.getOutputs();
             outs.remove(proxy);
             outs.set(index, proxy);
+        } else if (force) {
+            processor.addOutput(proxy);
         }
     }
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java?rev=672004&r1=672003&r2=672004&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorType.java
Thu Jun 26 12:32:21 2008
@@ -903,10 +903,10 @@
 
     public Type proceed() {
         ProceedType proceed = null;
-        ProcessorType currentProcessor = this;
 
-        if (currentProcessor instanceof InterceptType) {
-            proceed = ((InterceptType) currentProcessor).getProceed();
+        if (this instanceof InterceptType) {
+            proceed = ((InterceptType) this).getProceed();
+            LOG.info("proceed() is the implied and hence not needed for an intercept()");
         }
         if (proceed == null) {
             for (ProcessorType node = parent; node != null; node = node.getParent()) {
@@ -927,6 +927,25 @@
         return (Type) this;
     }
 
+    public Type stop() {
+        if (this instanceof InterceptType) {
+            ((InterceptType) this).stopIntercept();
+        } else {
+        	ProcessorType<?> node;
+            for (node = parent; node != null; node = node.getParent()) {
+                if (node instanceof InterceptType) {
+                    ((InterceptType) node).stopIntercept();
+                    break;
+                }
+            }
+            if (node == null) {
+                throw new IllegalArgumentException("Cannot use stop() without being within
an intercept() block");
+            }
+        }
+
+        return (Type) this;
+    }
+    
     public ExceptionType exception(Class exceptionType) {
         ExceptionType answer = new ExceptionType(exceptionType);
         addOutput(answer);

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptRouteTest.java?rev=672004&r1=672003&r2=672004&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptRouteTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptRouteTest.java
Thu Jun 26 12:32:21 2008
@@ -16,42 +16,13 @@
  */
 package org.apache.camel.processor;
 
-import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
 
 /**
  * @version $Revision$
  */
-public class InterceptRouteTest extends ContextTestSupport {
-    private MockEndpoint a;
-    private MockEndpoint b;
-
-    public void testSendMatchingMessage() throws Exception {
-        b.expectedMessageCount(1);
-        a.expectedMessageCount(0);
-
-        template.sendBodyAndHeader("direct:start", "<matched/>", "foo", "bar");
-
-        assertMockEndpointsSatisifed();
-    }
-
-    public void testSendNotMatchingMessage() throws Exception {
-        a.expectedMessageCount(1);
-        b.expectedMessageCount(0);
-
-        template.sendBodyAndHeader("direct:start", "<notMatched/>", "foo", "notMatchedHeaderValue");
-
-        assertMockEndpointsSatisifed();
-    }
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        a = getMockEndpoint("mock:a");
-        b = getMockEndpoint("mock:b");
-    }
-
+public class InterceptRouteTest extends InterceptRouteTestSupport {
+	@Override
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
@@ -63,4 +34,16 @@
             }
         };
     }
+
+	@Override
+	protected void prepareMatchingTest() {
+        a.expectedMessageCount(0);
+        b.expectedMessageCount(1);
+    }
+
+	@Override
+	protected void prepareNonMatchingTest() {
+        a.expectedMessageCount(1);
+        b.expectedMessageCount(0);
+	}
 }
\ No newline at end of file

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptRouteTestSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptRouteTestSupport.java?rev=672004&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptRouteTestSupport.java
(added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptRouteTestSupport.java
Thu Jun 26 12:32:21 2008
@@ -0,0 +1,51 @@
+/**
+ * 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.processor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version $Revision: 647400 $
+ */
+public abstract class InterceptRouteTestSupport extends ContextTestSupport {
+    protected MockEndpoint a;
+    protected MockEndpoint b;
+
+    public void testSendMatchingMessage() throws Exception {
+    	prepareMatchingTest();
+        template.sendBodyAndHeader("direct:start", "<matched/>", "foo", "bar");
+        assertMockEndpointsSatisifed();
+    }
+
+    public void testSendNonMatchingMessage() throws Exception {
+    	prepareNonMatchingTest();
+        template.sendBodyAndHeader("direct:start", "<notMatched/>", "foo", "notMatchedHeaderValue");
+        assertMockEndpointsSatisifed();
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        a = getMockEndpoint("mock:a");
+        b = getMockEndpoint("mock:b");
+    }
+
+    protected abstract void prepareMatchingTest();
+
+    protected abstract void prepareNonMatchingTest();
+}

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithPredicateAndProceedRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithPredicateAndProceedRouteTest.java?rev=672004&r1=672003&r2=672004&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithPredicateAndProceedRouteTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithPredicateAndProceedRouteTest.java
Thu Jun 26 12:32:21 2008
@@ -16,42 +16,13 @@
  */
 package org.apache.camel.processor;
 
-import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
 
 /**
  * @version $Revision$
  */
-public class InterceptWithPredicateAndProceedRouteTest extends ContextTestSupport {
-    private MockEndpoint a;
-    private MockEndpoint b;
-
-    public void testSendMatchingMessage() throws Exception {
-        a.expectedMessageCount(1);
-        b.expectedMessageCount(1);
-
-        template.sendBodyAndHeader("direct:start", "<matched/>", "foo", "bar");
-
-        assertMockEndpointsSatisifed();
-    }
-
-    public void testSendNotMatchingMessage() throws Exception {
-        a.expectedMessageCount(1);
-        b.expectedMessageCount(0);
-
-        template.sendBodyAndHeader("direct:start", "<notMatched/>", "foo", "notMatchedHeaderValue");
-
-        assertMockEndpointsSatisifed();
-    }
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        a = getMockEndpoint("mock:a");
-        b = getMockEndpoint("mock:b");
-    }
-
+public class InterceptWithPredicateAndProceedRouteTest extends InterceptRouteTestSupport
{
+	@Override
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
@@ -61,4 +32,16 @@
             }
         };
     }
+
+	@Override
+	protected void prepareMatchingTest() {
+        a.expectedMessageCount(1);
+        b.expectedMessageCount(1);
+	}
+
+	@Override
+	protected void prepareNonMatchingTest() {
+        a.expectedMessageCount(1);
+        b.expectedMessageCount(0);
+	}
 }
\ No newline at end of file

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithPredicateAndStopRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithPredicateAndStopRouteTest.java?rev=672004&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithPredicateAndStopRouteTest.java
(added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithPredicateAndStopRouteTest.java
Thu Jun 26 12:32:21 2008
@@ -0,0 +1,49 @@
+/**
+ * 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.processor;
+
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision:  $
+ */
+public class InterceptWithPredicateAndStopRouteTest extends
+		InterceptRouteTestSupport {
+
+	@Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                intercept(header("foo").isEqualTo("bar")).to("mock:b").stop();
+
+                from("direct:start").to("mock:a");
+            }
+        };
+    }
+
+	@Override
+	protected void prepareMatchingTest() {
+        a.expectedMessageCount(0);
+        b.expectedMessageCount(1);
+	}
+
+	@Override
+	protected void prepareNonMatchingTest() {
+        a.expectedMessageCount(0);
+        b.expectedMessageCount(0);
+	}
+}

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithPredicateRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithPredicateRouteTest.java?rev=672004&r1=672003&r2=672004&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithPredicateRouteTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithPredicateRouteTest.java
Thu Jun 26 12:32:21 2008
@@ -16,41 +16,13 @@
  */
 package org.apache.camel.processor;
 
-import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
 
 /**
  * @version $Revision$
  */
-public class InterceptWithPredicateRouteTest extends ContextTestSupport {
-    private MockEndpoint a;
-    private MockEndpoint b;
-
-    public void testSendMatchingMessage() throws Exception {
-        b.expectedMessageCount(1);
-
-        template.sendBodyAndHeader("direct:start", "<matched/>", "foo", "bar");
-
-        assertMockEndpointsSatisifed();
-    }
-
-    public void testSendNotMatchingMessage() throws Exception {
-        a.expectedMessageCount(1);
-        b.expectedMessageCount(0);
-
-        template.sendBodyAndHeader("direct:start", "<notMatched/>", "foo", "notMatchedHeaderValue");
-
-        assertMockEndpointsSatisifed();
-    }
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        a = getMockEndpoint("mock:a");
-        b = getMockEndpoint("mock:b");
-    }
-
+public class InterceptWithPredicateRouteTest extends InterceptRouteTestSupport {
+	@Override
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
@@ -60,4 +32,16 @@
             }
         };
     }
+
+	@Override
+	protected void prepareMatchingTest() {
+        a.expectedMessageCount(0);
+        b.expectedMessageCount(1);
+	}
+
+	@Override
+	protected void prepareNonMatchingTest() {
+        a.expectedMessageCount(1);
+        b.expectedMessageCount(0);
+	}
 }
\ No newline at end of file

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithStopRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithStopRouteTest.java?rev=672004&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithStopRouteTest.java
(added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithStopRouteTest.java
Thu Jun 26 12:32:21 2008
@@ -0,0 +1,48 @@
+/**
+ * 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.processor;
+
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision:  $
+ */
+public class InterceptWithStopRouteTest extends InterceptRouteTestSupport {
+
+	@Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                intercept().filter(header("foo").isEqualTo("bar")).to("mock:b").stop();
+
+                from("direct:start").to("mock:a");
+            }
+        };
+    }
+
+	@Override
+	protected void prepareMatchingTest() {
+        a.expectedMessageCount(0);
+        b.expectedMessageCount(1);
+	}
+
+	@Override
+	protected void prepareNonMatchingTest() {
+        a.expectedMessageCount(0);
+        b.expectedMessageCount(0);
+	}
+}

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithoutProceedRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithoutProceedRouteTest.java?rev=672004&r1=672003&r2=672004&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithoutProceedRouteTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithoutProceedRouteTest.java
Thu Jun 26 12:32:21 2008
@@ -16,50 +16,32 @@
  */
 package org.apache.camel.processor;
 
-import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
 
 /**
  * @version $Revision$
  */
-public class InterceptWithoutProceedRouteTest extends ContextTestSupport {
-    private MockEndpoint a;
-    private MockEndpoint b;
-
-    public void testSendMatchingMessage() throws Exception {
-        b.expectedMessageCount(1);
-        a.expectedMessageCount(0);
-
-        template.sendBodyAndHeader("direct:start", "<matched/>", "foo", "bar");
-
-        assertMockEndpointsSatisifed();
-    }
-
-    public void testSendNotMatchingMessage() throws Exception {
-        b.expectedMessageCount(0);
-        a.expectedMessageCount(0);
-
-        template.sendBodyAndHeader("direct:start", "<notMatched/>", "foo", "notMatchedHeaderValue");
-
-        assertMockEndpointsSatisifed();
-    }
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        a = getMockEndpoint("mock:a");
-        b = getMockEndpoint("mock:b");
-    }
-
+public class InterceptWithoutProceedRouteTest extends InterceptRouteTestSupport {
+	@Override
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
-                // we will disable the output to 'mock:a' since we never proceed()
                 intercept().filter(header("foo").isEqualTo("bar")).to("mock:b");
 
                 from("direct:start").to("mock:a");
             }
         };
     }
+
+	@Override
+	protected void prepareMatchingTest() {
+        a.expectedMessageCount(1);
+        b.expectedMessageCount(1);
+	}
+
+	@Override
+	protected void prepareNonMatchingTest() {
+        a.expectedMessageCount(1);
+        b.expectedMessageCount(0);
+	}
 }
\ No newline at end of file



Mime
View raw message