camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1144796 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/builder/NotifyBuilder.java test/java/org/apache/camel/builder/NotifyBuilderWhenDoneByIndexTest.java
Date Sun, 10 Jul 2011 09:24:54 GMT
Author: davsclaus
Date: Sun Jul 10 09:24:54 2011
New Revision: 1144796

URL: http://svn.apache.org/viewvc?rev=1144796&view=rev
Log:
CAMEL-4205: Added whenDoneByIndex to NotifyBuilder.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderWhenDoneByIndexTest.java
  (contents, props changed)
      - copied, changed from r1144788, camel/trunk/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java?rev=1144796&r1=1144795&r2=1144796&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/NotifyBuilder.java Sun Jul
10 09:24:54 2011
@@ -316,6 +316,65 @@ public class NotifyBuilder {
     }
 
     /**
+     * Sets a condition when tne <tt>n'th</tt> (by index) {@link Exchange} is
done being processed.
+     * <p/>
+     * The difference between <i>done</i> and <i>completed</i> is
that done can also include failed
+     * messages, where as completed is only successful processed messages.
+     *
+     * @param index the message by index to be done
+     * @return the builder
+     */
+    public NotifyBuilder whenDoneByIndex(final int index) {
+        stack.add(new EventPredicateSupport() {
+            private int current;
+            private String id;
+            private boolean done;
+
+            @Override
+            public boolean onExchangeCreated(Exchange exchange) {
+                if (current == index) {
+                    id = exchange.getExchangeId();
+                }
+                current++;
+                return true;
+            }
+
+            @Override
+            public boolean onExchangeCompleted(Exchange exchange) {
+                if (exchange.getExchangeId().equals(id)) {
+                    done = true;
+                }
+                return true;
+            }
+
+            @Override
+            public boolean onExchangeFailed(Exchange exchange) {
+                if (exchange.getExchangeId().equals(id)) {
+                    done = true;
+                }
+                return true;
+            }
+
+            public boolean matches() {
+                return done;
+            }
+
+            @Override
+            public void reset() {
+                current = 0;
+                id = null;
+                done = false;
+            }
+
+            @Override
+            public String toString() {
+                return "whenDoneByIndex(" + index + ")";
+            }
+        });
+        return this;
+    }
+
+    /**
      * Sets a condition when <tt>number</tt> of {@link Exchange} has been completed.
      * <p/>
      * The number matching is <i>at least</i> based which means that if more
messages received

Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderWhenDoneByIndexTest.java
(from r1144788, camel/trunk/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderWhenDoneByIndexTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderWhenDoneByIndexTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderTest.java&r1=1144788&r2=1144796&rev=1144796&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderWhenDoneByIndexTest.java
Sun Jul 10 09:24:54 2011
@@ -16,848 +16,38 @@
  */
 package org.apache.camel.builder;
 
+import java.util.concurrent.atomic.AtomicInteger;
+
 import org.apache.camel.ContextTestSupport;
-import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
 
 /**
  * @version 
  */
-public class NotifyBuilderTest extends ContextTestSupport {
-
-    public void testMustBeCreated() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context).whenDone(1);
-
-        try {
-            notify.matches();
-            fail("Should have thrown an exception");
-        } catch (IllegalStateException e) {
-            assertEquals("NotifyBuilder has not been created. Invoke the create() method
before matching.", e.getMessage());
-        }
-    }
-
-    public void testDirectWhenExchangeDoneSimple() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .from("direct:foo").whenDone(1)
-                .create();
-
-        assertEquals("from(direct:foo).whenDone(1)", notify.toString());
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "A");
-
-        assertEquals(true, notify.matches());
-    }
-
-    public void testDirectBeerWhenExchangeDoneSimple() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .from("direct:beer").whenDone(1)
-                .create();
-
-        assertEquals("from(direct:beer).whenDone(1)", notify.toString());
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:beer", "A");
-
-        assertEquals(true, notify.matches());
-    }
-
-    public void testDirectFromRoute() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .fromRoute("foo").whenDone(1)
-                .create();
-
-        assertEquals("fromRoute(foo).whenDone(1)", notify.toString());
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:bar", "A");
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "B");
-        assertEquals(true, notify.matches());
-    }
-
-    public void testDirectFromRouteReceived() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .fromRoute("foo").whenReceived(1)
-                .create();
-
-        assertEquals("fromRoute(foo).whenReceived(1)", notify.toString());
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:bar", "A");
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "B");
-        assertEquals(true, notify.matches());
-    }
-
-    public void testWhenExchangeDone() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .from("direct:foo").whenDone(5)
-                .create();
-
-        assertEquals("from(direct:foo).whenDone(5)", notify.toString());
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "A");
-        template.sendBody("direct:foo", "B");
-        template.sendBody("direct:foo", "C");
-
-        template.sendBody("direct:bar", "D");
-        template.sendBody("direct:bar", "E");
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "F");
-        template.sendBody("direct:bar", "G");
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "H");
-        template.sendBody("direct:bar", "I");
-
-        assertEquals(true, notify.matches());
-    }
-
-    public void testWhenExchangeDoneAnd() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .from("direct:foo").whenDone(5)
-                .and().from("direct:bar").whenDone(7)
-                .create();
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "A");
-        template.sendBody("direct:foo", "B");
-        template.sendBody("direct:foo", "C");
-
-        template.sendBody("direct:bar", "D");
-        template.sendBody("direct:bar", "E");
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "F");
-        template.sendBody("direct:bar", "G");
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "H");
-        template.sendBody("direct:bar", "I");
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:bar", "J");
-        template.sendBody("direct:bar", "K");
-        template.sendBody("direct:bar", "L");
-
-        assertEquals(true, notify.matches());
-    }
-
-    public void testFromRouteWhenExchangeDoneAnd() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .fromRoute("foo").whenDone(5)
-                .and().fromRoute("bar").whenDone(7)
-                .create();
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "A");
-        template.sendBody("direct:foo", "B");
-        template.sendBody("direct:foo", "C");
-
-        template.sendBody("direct:bar", "D");
-        template.sendBody("direct:bar", "E");
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "F");
-        template.sendBody("direct:bar", "G");
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "H");
-        template.sendBody("direct:bar", "I");
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:bar", "J");
-        template.sendBody("direct:bar", "K");
-        template.sendBody("direct:bar", "L");
-
-        assertEquals(true, notify.matches());
-    }
-
-    public void testFromRouteAndNot() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .fromRoute("foo").whenDone(2)
-                .and().fromRoute("bar").whenReceived(1)
-                .not().fromRoute("cake").whenDone(1)
-                .create();
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "A");
-        template.sendBody("direct:foo", "B");
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:bar", "C");
-        assertEquals(true, notify.matches());
-
-        template.sendBody("direct:foo", "D");
-        template.sendBody("direct:bar", "E");
-        assertEquals(true, notify.matches());
-
-        // and now the cake to make it false
-        template.sendBody("direct:cake", "F");
-        assertEquals(false, notify.matches());
-    }
-
-    public void testWhenExchangeDoneOr() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .from("direct:foo").whenDone(5)
-                .or().from("direct:bar").whenDone(7)
-                .create();
-
-        assertEquals("from(direct:foo).whenDone(5).or().from(direct:bar).whenDone(7)", notify.toString());
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "A");
-        template.sendBody("direct:foo", "B");
-        template.sendBody("direct:foo", "C");
-
-        template.sendBody("direct:bar", "D");
-        template.sendBody("direct:bar", "E");
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:bar", "G");
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:bar", "I");
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:bar", "J");
-        template.sendBody("direct:bar", "K");
-        template.sendBody("direct:bar", "L");
-
-        assertEquals(true, notify.matches());
-    }
-
-    public void testWhenExchangeDoneNot() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .from("direct:foo").whenDone(5)
-                .not().from("direct:bar").whenDone(1)
-                .create();
-
-        assertEquals("from(direct:foo).whenDone(5).not().from(direct:bar).whenDone(1)", notify.toString());
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "A");
-        template.sendBody("direct:foo", "B");
-        template.sendBody("direct:foo", "C");
-        template.sendBody("direct:foo", "D");
-
-        assertEquals(false, notify.matches());
-        template.sendBody("direct:foo", "E");
-        assertEquals(true, notify.matches());
-
-        template.sendBody("direct:foo", "F");
-        assertEquals(true, notify.matches());
-
-        template.sendBody("direct:bar", "G");
-        assertEquals(false, notify.matches());
-    }
-
-    public void testWhenExchangeDoneOrFailure() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .whenDone(5)
-                .or().whenFailed(1)
-                .create();
-
-        assertEquals("whenDone(5).or().whenFailed(1)", notify.toString());
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "A");
-        template.sendBody("direct:foo", "B");
-        template.sendBody("direct:foo", "D");
-
-        assertEquals(false, notify.matches());
-
-        try {
-            template.sendBody("direct:fail", "E");
-        } catch (Exception e) {
-            // ignore
-        }
-
-        assertEquals(true, notify.matches());
-    }
-
-    public void testWhenExchangeDoneNotFailure() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .whenDone(5)
-                .not().whenFailed(1)
-                .create();
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "A");
-        template.sendBody("direct:foo", "B");
-        template.sendBody("direct:foo", "D");
-        template.sendBody("direct:bar", "E");
-        template.sendBody("direct:bar", "F");
-
-        assertEquals(true, notify.matches());
-
-        try {
-            template.sendBody("direct:fail", "G");
-        } catch (Exception e) {
-            // ignore
-        }
-
-        assertEquals(false, notify.matches());
-    }
-
-    public void testFilterWhenExchangeDone() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .filter(body().contains("World")).whenDone(3)
-                .create();
-
-        assertEquals("filter(body contains World).whenDone(3)", notify.toString());
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "Hello World");
-        template.sendBody("direct:foo", "Hi World");
-        template.sendBody("direct:foo", "A");
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:bar", "B");
-        template.sendBody("direct:bar", "C");
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:bar", "Bye World");
-
-        assertEquals(true, notify.matches());
-
-        template.sendBody("direct:foo", "D");
-        template.sendBody("direct:bar", "Hey World");
-
-        assertEquals(true, notify.matches());
-    }
-
-    public void testFromFilterWhenExchangeDone() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .from("direct:foo").filter(body().contains("World")).whenDone(3)
-                .create();
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "Hello World");
-        template.sendBody("direct:foo", "Hi World");
-        template.sendBody("direct:foo", "A");
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:bar", "B");
-        template.sendBody("direct:foo", "C");
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:bar", "Bye World");
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:bar", "D");
-        template.sendBody("direct:foo", "Hey World");
-
-        assertEquals(true, notify.matches());
-
-        template.sendBody("direct:bar", "E");
-        template.sendBody("direct:foo", "Hi Again World");
-
-        assertEquals(true, notify.matches());
-    }
-
-    public void testFromFilterBuilderWhenExchangeDone() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .filter().xpath("/person[@name='James']").whenDone(1)
-                .create();
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "<person name='Claus'/>");
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "<person name='Jonathan'/>");
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "<person name='James'/>");
-        assertEquals(true, notify.matches());
-
-        template.sendBody("direct:foo", "<person name='Hadrian'/>");
-        assertEquals(true, notify.matches());
-    }
-
-    public void testWhenExchangeCompleted() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .whenCompleted(5)
-                .create();
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "A");
-        template.sendBody("direct:foo", "B");
-        template.sendBody("direct:bar", "C");
-
-        try {
-            template.sendBody("direct:fail", "D");
-        } catch (Exception e) {
-            // ignore
-        }
-
-        try {
-            template.sendBody("direct:fail", "E");
-        } catch (Exception e) {
-            // ignore
-        }
-
-        // should NOT be completed as it only counts successful exchanges
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:bar", "F");
-        template.sendBody("direct:foo", "G");
-        template.sendBody("direct:bar", "H");
+public class NotifyBuilderWhenDoneByIndexTest extends ContextTestSupport {
 
-        // now it should match
-        assertEquals(true, notify.matches());
-    }
-
-    public void testWhenExchangeExactlyDone() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .whenExactlyDone(5)
-                .create();
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "A");
-        template.sendBody("direct:foo", "B");
-        template.sendBody("direct:foo", "C");
-
-        template.sendBody("direct:bar", "D");
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:bar", "E");
-        assertEquals(true, notify.matches());
-
-        template.sendBody("direct:foo", "F");
-        assertEquals(false, notify.matches());
-    }
-
-    public void testWhenExchangeExactlyComplete() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .whenExactlyCompleted(5)
-                .create();
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "A");
-        template.sendBody("direct:foo", "B");
-        template.sendBody("direct:foo", "C");
-
-        template.sendBody("direct:bar", "D");
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:bar", "E");
-        assertEquals(true, notify.matches());
-
-        template.sendBody("direct:foo", "F");
-        assertEquals(false, notify.matches());
-    }
-
-    public void testWhenExchangeExactlyFailed() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .whenExactlyFailed(2)
-                .create();
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "A");
-        template.sendBody("direct:foo", "B");
-        template.sendBody("direct:foo", "C");
-
-        try {
-            template.sendBody("direct:fail", "D");
-        } catch (Exception e) {
-            // ignore
-        }
-
-        template.sendBody("direct:bar", "E");
-        assertEquals(false, notify.matches());
-
-        try {
-            template.sendBody("direct:fail", "F");
-        } catch (Exception e) {
-            // ignore
-        }
-        assertEquals(true, notify.matches());
-
-        template.sendBody("direct:bar", "G");
-        assertEquals(true, notify.matches());
-
-        try {
-            template.sendBody("direct:fail", "H");
-        } catch (Exception e) {
-            // ignore
-        }
-        assertEquals(false, notify.matches());
-    }
-
-    public void testWhenAnyReceivedMatches() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .whenAnyReceivedMatches(body().contains("Camel"))
-                .create();
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "Hello World");
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "Bye World");
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:bar", "Hello Camel");
-        assertEquals(true, notify.matches());
-    }
-
-    public void testWhenAllReceivedMatches() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .whenAllReceivedMatches(body().contains("Camel"))
-                .create();
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "Hello Camel");
-        assertEquals(true, notify.matches());
-
-        template.sendBody("direct:foo", "Bye Camel");
-        assertEquals(true, notify.matches());
-
-        template.sendBody("direct:bar", "Hello World");
-        assertEquals(false, notify.matches());
-    }
-
-    public void testWhenAnyDoneMatches() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .whenAnyDoneMatches(body().contains("Bye"))
-                .create();
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "Hi World");
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:cake", "Camel");
-        assertEquals(true, notify.matches());
-
-        template.sendBody("direct:foo", "Damn World");
-        assertEquals(true, notify.matches());
-    }
-
-    public void testWhenAllDoneMatches() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .whenAllDoneMatches(body().contains("Bye"))
-                .create();
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:cake", "Camel");
-        assertEquals(true, notify.matches());
-
-        template.sendBody("direct:cake", "World");
-        assertEquals(true, notify.matches());
-
-        template.sendBody("direct:foo", "Hi World");
-        assertEquals(false, notify.matches());
-    }
-
-    public void testWhenBodiesReceived() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .whenBodiesReceived("Hi World", "Hello World")
-                .create();
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "Hi World");
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "Hello World");
-        assertEquals(true, notify.matches());
-
-        // should keep being true
-        template.sendBody("direct:foo", "Bye World");
-        assertEquals(true, notify.matches());
-
-        template.sendBody("direct:foo", "Damn World");
-        assertEquals(true, notify.matches());
-    }
-
-    public void testWhenBodiesDone() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .whenBodiesDone("Bye World", "Bye Camel")
-                .create();
-
-        assertEquals(false, notify.matches());
-
-        template.requestBody("direct:cake", "World");
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:cake", "Camel");
-        assertEquals(true, notify.matches());
-
-        // should keep being true
-        template.sendBody("direct:foo", "Damn World");
-        assertEquals(true, notify.matches());
-    }
-
-    public void testWhenExactBodiesReceived() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .whenExactBodiesReceived("Hi World", "Hello World")
-                .create();
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "Hi World");
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "Hello World");
-        assertEquals(true, notify.matches());
-
-        // should not keep being true
-        template.sendBody("direct:foo", "Bye World");
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "Damn World");
-        assertEquals(false, notify.matches());
-    }
-
-    public void testWhenExactBodiesDone() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .whenExactBodiesDone("Bye World", "Bye Camel")
-                .create();
-
-        assertEquals(false, notify.matches());
-
-        template.requestBody("direct:cake", "World");
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:cake", "Camel");
-        assertEquals(true, notify.matches());
-
-        // should NOT keep being true
-        template.sendBody("direct:foo", "Damn World");
-        assertEquals(false, notify.matches());
-    }
-
-    public void testWhenReceivedSatisfied() throws Exception {
-        // lets use a mock to set the expressions as it got many great assertions for that
-        // notice we use mock:assert which does NOT exist in the route, its just a pseudo
name
-        MockEndpoint mock = getMockEndpoint("mock:assert");
-        mock.expectedBodiesReceivedInAnyOrder("Hello World", "Bye World", "Hi World");
-
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .from("direct:foo").whenDoneSatisfied(mock)
-                .create();
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "Bye World");
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "Hello World");
-        assertEquals(false, notify.matches());
-
-        // the notify  is based on direct:foo so sending to bar should not trigger match
-        template.sendBody("direct:bar", "Hi World");
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "Hi World");
-        assertEquals(true, notify.matches());
-    }
-
-    public void testWhenReceivedNotSatisfied() throws Exception {
-        // lets use a mock to set the expressions as it got many great assertions for that
-        // notice we use mock:assert which does NOT exist in the route, its just a pseudo
name
-        MockEndpoint mock = getMockEndpoint("mock:assert");
-        mock.expectedMessageCount(2);
-        mock.message(1).body().contains("Camel");
-
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .from("direct:foo").whenReceivedNotSatisfied(mock)
-                .create();
-
-        // is always false to start with
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "Bye World");
-        assertEquals(true, notify.matches());
-
-        template.sendBody("direct:foo", "Hello Camel");
-        assertEquals(false, notify.matches());
-    }
-
-    public void testWhenNotSatisfiedUsingSatisfied() throws Exception {
-        // lets use a mock to set the expressions as it got many great assertions for that
-        // notice we use mock:assert which does NOT exist in the route, its just a pseudo
name
-        MockEndpoint mock = getMockEndpoint("mock:assert");
-        mock.expectedMessageCount(2);
-        mock.message(1).body().contains("Camel");
-
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .from("direct:foo").whenReceivedSatisfied(mock)
-                .create();
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "Bye World");
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "Hello Camel");
-        assertEquals(true, notify.matches());
-    }
-
-    public void testComplexOrCamel() throws Exception {
-        MockEndpoint mock = getMockEndpoint("mock:assert");
-        mock.expectedBodiesReceivedInAnyOrder("Hello World", "Bye World", "Hi World");
-
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .from("direct:foo").whenReceivedSatisfied(mock)
-                .and().from("direct:bar").whenExactlyDone(5).whenAnyReceivedMatches(body().contains("Camel"))
-                .create();
-
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "Bye World");
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "Hello World");
-        assertEquals(false, notify.matches());
-
-        // the notify  is based on direct:foo so sending to bar should not trigger match
-        template.sendBody("direct:bar", "Hi World");
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "Hi World");
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:bar", "Hi Camel");
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:bar", "A");
-        template.sendBody("direct:bar", "B");
-        template.sendBody("direct:bar", "C");
-        assertEquals(true, notify.matches());
-    }
-
-    public void testWhenDoneSatisfied() throws Exception {
-        // lets use a mock to set the expressions as it got many great assertions for that
-        // notice we use mock:assert which does NOT exist in the route, its just a pseudo
name
-        MockEndpoint mock = getMockEndpoint("mock:assert");
-        mock.expectedBodiesReceived("Bye World", "Bye Camel");
-
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .whenDoneSatisfied(mock)
-                .create();
-
-        // is always false to start with
-        assertEquals(false, notify.matches());
-
-        template.requestBody("direct:cake", "World");
-        assertEquals(false, notify.matches());
-
-        template.requestBody("direct:cake", "Camel");
-        assertEquals(true, notify.matches());
-
-        template.requestBody("direct:cake", "Damn");
-        // will still be true as the mock has been completed
-        assertEquals(true, notify.matches());
-    }
-
-    public void testWhenDoneNotSatisfied() throws Exception {
-        // lets use a mock to set the expressions as it got many great assertions for that
-        // notice we use mock:assert which does NOT exist in the route, its just a pseudo
name
-        MockEndpoint mock = getMockEndpoint("mock:assert");
-        mock.expectedBodiesReceived("Bye World", "Bye Camel");
-
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .whenDoneNotSatisfied(mock)
-                .create();
-
-        // is always false to start with
-        assertEquals(false, notify.matches());
-
-        template.requestBody("direct:cake", "World");
-        assertEquals(true, notify.matches());
-
-        template.requestBody("direct:cake", "Camel");
-        assertEquals(false, notify.matches());
-
-        template.requestBody("direct:cake", "Damn");
-        // will still be false as the mock has been completed
-        assertEquals(false, notify.matches());
-    }
+    public void testDoneByIndex() throws Exception {
+        final AtomicInteger counter = new AtomicInteger();
+        getMockEndpoint("mock:split").whenAnyExchangeReceived(new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                counter.incrementAndGet();
+            }
+        });
 
-    public void testReset() throws Exception {
+        // notify when the 1st exchange is done (by index)
         NotifyBuilder notify = new NotifyBuilder(context)
-                .whenExactlyDone(1)
+                .whenDoneByIndex(0)
                 .create();
 
-        template.sendBody("direct:foo", "Hello World");
-        assertEquals(true, notify.matches());
-
-        template.sendBody("direct:foo", "Bye World");
         assertEquals(false, notify.matches());
 
-        // reset
-        notify.reset();
-        assertEquals(false, notify.matches());
+        template.sendBody("seda:foo", "A,B,C");
 
-        template.sendBody("direct:foo", "Hello World");
-        assertEquals(true, notify.matches());
+        assertEquals(true, notify.matchesMockWaitTime());
 
-        template.sendBody("direct:foo", "Bye World");
-        assertEquals(false, notify.matches());
-    }
-
-    public void testResetBodiesReceived() throws Exception {
-        NotifyBuilder notify = new NotifyBuilder(context)
-                .whenBodiesReceived("Hello World", "Bye World")
-                .create();
-
-        template.sendBody("direct:foo", "Hello World");
-        template.sendBody("direct:foo", "Bye World");
-        assertEquals(true, notify.matches());
-
-        // reset
-        notify.reset();
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "Hello World");
-        assertEquals(false, notify.matches());
-
-        template.sendBody("direct:foo", "Bye World");
-        assertEquals(true, notify.matches());
+        assertEquals(3, counter.get());
     }
 
     @Override
@@ -865,15 +55,12 @@ public class NotifyBuilderTest extends C
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("direct:foo").routeId("foo").to("mock:foo");
-
-                from("direct:bar").routeId("bar").to("mock:bar");
-
-                from("direct:fail").routeId("fail").throwException(new IllegalArgumentException("Damn"));
-
-                from("direct:cake").routeId("cake").transform(body().prepend("Bye ")).to("log:cake");
-
-                from("direct:beer").routeId("beer").to("log:beer").to("mock:beer");
+                from("seda:foo").routeId("foo")
+                    .delay(500)
+                    .split(body().tokenize(","))
+                        .to("mock:split")
+                    .end()
+                    .to("mock:foo");
             }
         };
     }

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderWhenDoneByIndexTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/builder/NotifyBuilderWhenDoneByIndexTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message