svn commit: r674289 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/model/ test/java/org/apache/camel/issues/ test/java/org/apache/camel/processor/

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r674289 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/model/ test/java/org/apache/camel/issues/ test/java/org/apache/camel/processor/

davsclaus-2
Author: davsclaus
Date: Sun Jul  6 05:26:20 2008
New Revision: 674289

URL: http://svn.apache.org/viewvc?rev=674289&view=rev
Log:
CAMEL-676: intercept with predicate doesnt proceed if predicate test was false. Intercept with predicate doesn't proceed as default if proceed() was not given. And fixed special cases for the stop().

Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptType.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/InterceptorPredicateProceedAndStopTest.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/InterceptWithPredicateRouteTest.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptorSimpleRouteTest.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=674289&r1=674288&r2=674289&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 Sun Jul  6 05:26:20 2008
@@ -100,6 +100,7 @@
             ChoiceType choice = null;
             for (ProcessorType processor : answer.getOutputs()) {
                 if (processor instanceof ChoiceType) {
+                    // special cases for predicates (choices)
                     choice = (ChoiceType) processor;
 
                     // for the predicated version we add the proceed() to otherwise()
@@ -108,16 +109,31 @@
                         WhenType when = choice.getWhenClauses().get(0);
                         when.getOutputs().remove(this.getProceed());
                     }
+
+                    // add proceed to the when clause
                     addProceedProxy(this.getProceed(), answer.getProceed(),
                         choice.getWhenClauses().get(choice.getWhenClauses().size() - 1), usePredicate.booleanValue() && !stop.booleanValue());
-                    addProceedProxy(this.getProceed(), answer.getProceed(), choice.getOtherwise(), false);
+
+                    // force adding a proceed at the end (otherwise) if its not a stop type
+                    addProceedProxy(this.getProceed(), answer.getProceed(), choice.getOtherwise(), !stop.booleanValue());
+
+                    if (stop.booleanValue()) {
+                        // must add proceed to when clause if stop is explictiy declared, otherwise when the
+                        // predicate test fails then there is no proceed
+                        // See example: InterceptorSimpleRouteTest (City Paris is never proceeded)  
+                        addProceedProxy(this.getProceed(), answer.getProceed(),
+                            choice.getWhenClauses().get(choice.getWhenClauses().size() - 1), usePredicate.booleanValue());
+                    }
+
                     break;
                 }
             }
             if (choice == null) {
+                // force adding a proceed at the end if its not a stop type
                 addProceedProxy(this.getProceed(), answer.getProceed(), answer, !stop.booleanValue());
             }
         }
+
         return answer;
     }
 
@@ -133,4 +149,5 @@
             processor.addOutput(proxy);
         }
     }
+
 }

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/InterceptorPredicateProceedAndStopTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/InterceptorPredicateProceedAndStopTest.java?rev=674289&r1=674288&r2=674289&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/InterceptorPredicateProceedAndStopTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/InterceptorPredicateProceedAndStopTest.java Sun Jul  6 05:26:20 2008
@@ -102,8 +102,7 @@
         template.sendBodyAndHeader("seda:order", "Camel in Action", "user", "test");
 
         mockTest.assertIsSatisfied();
-        // TODO: Fix me in CAMEL-676 and the mockOk assertion should pass
-        //mockOk.assertIsSatisfied();
+        mockOk.assertIsSatisfied();
     }
 
     public void testInterceptorWithPredicateAndProceed() throws Exception {

Modified: 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=674289&r1=674288&r2=674289&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithPredicateAndStopRouteTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptWithPredicateAndStopRouteTest.java Sun Jul  6 05:26:20 2008
@@ -43,7 +43,7 @@
 
     @Override
     protected void prepareNonMatchingTest() {
-        a.expectedMessageCount(0);
+        a.expectedMessageCount(1);
         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=674289&r1=674288&r2=674289&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 Sun Jul  6 05:26:20 2008
@@ -26,6 +26,7 @@
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
+                // no stop so the message will proceed in its normal route also
                 intercept(header("foo").isEqualTo("bar")).to("mock:b");
 
                 from("direct:start").to("mock:a");
@@ -35,7 +36,7 @@
 
     @Override
     protected void prepareMatchingTest() {
-        a.expectedMessageCount(0);
+        a.expectedMessageCount(1);
         b.expectedMessageCount(1);
     }
 

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptorSimpleRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptorSimpleRouteTest.java?rev=674289&r1=674288&r2=674289&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptorSimpleRouteTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/InterceptorSimpleRouteTest.java Sun Jul  6 05:26:20 2008
@@ -42,7 +42,8 @@
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {
-                intercept(header("city").isEqualTo("London")).to("mock:intercepted");
+                // In Camel 1.4 proceed is default so we must use stop to not route it to the result mock
+                intercept(header("city").isEqualTo("London")).to("mock:intercepted").stop();
                 from("seda:a").to("mock:result");
             }
         };