Author: davsclaus
Date: Sun Apr 29 14:05:50 2012
New Revision: 1331914

URL: http://svn.apache.org/viewvc?rev=1331914&view=rev
Log:
CAMEL-4513: Added unit test.

Added:
    
camel/trunk/camel-core/src/test/java/org/apache/camel/issues/RetryWhilePredicateExpressionIssueTest.java
    
camel/trunk/camel-core/src/test/java/org/apache/camel/issues/RetryWhileSimpleExpressionIssueTest.java

Added: 
camel/trunk/camel-core/src/test/java/org/apache/camel/issues/RetryWhilePredicateExpressionIssueTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/RetryWhilePredicateExpressionIssueTest.java?rev=1331914&view=auto
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/issues/RetryWhilePredicateExpressionIssueTest.java
 (added)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/issues/RetryWhilePredicateExpressionIssueTest.java
 Sun Apr 29 14:05:50 2012
@@ -0,0 +1,77 @@
+/**
+ * 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.issues;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Predicate;
+import org.apache.camel.builder.RouteBuilder;
+
+import static org.apache.camel.builder.PredicateBuilder.and;
+import static org.apache.camel.builder.PredicateBuilder.isNotNull;
+
+/**
+ *
+ */
+public class RetryWhilePredicateExpressionIssueTest extends ContextTestSupport 
{
+
+    public void testRetryWhilePredicate() throws Exception {
+        MyCoolDude dude = new MyCoolDude();
+        template.sendBodyAndHeader("direct:start", dude, "foo", 123);
+
+        assertEquals(3 + 1, dude.getCounter());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                onException(IllegalArgumentException.class)
+                    .handled(true)
+                    .retryWhile(new Predicate() {
+                        @Override
+                        public boolean matches(Exchange exchange) {
+                            Predicate predicate = 
and(simple("${body.areWeCool} == 'no'"), isNotNull(header("foo")));
+                            boolean answer = predicate.matches(exchange);
+                            return answer;
+                        }
+                    });
+
+                from("direct:start")
+                    .throwException(new IllegalArgumentException("Forced"));
+            }
+        };
+    }
+
+    public static class MyCoolDude {
+
+        private int counter;
+
+        public String areWeCool() {
+            if (counter++ < 3) {
+                return "no";
+            } else {
+                return "yes";
+            }
+        }
+
+        public int getCounter() {
+            return counter;
+        }
+    }
+}

Added: 
camel/trunk/camel-core/src/test/java/org/apache/camel/issues/RetryWhileSimpleExpressionIssueTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/RetryWhileSimpleExpressionIssueTest.java?rev=1331914&view=auto
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/issues/RetryWhileSimpleExpressionIssueTest.java
 (added)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/issues/RetryWhileSimpleExpressionIssueTest.java
 Sun Apr 29 14:05:50 2012
@@ -0,0 +1,71 @@
+/**
+ * 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.issues;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ *
+ */
+public class RetryWhileSimpleExpressionIssueTest extends ContextTestSupport {
+
+    public void testRetryWhileSimple() throws Exception {
+        getMockEndpoint("mock:error").expectedMessageCount(1);
+        
getMockEndpoint("mock:error").message(0).body().isInstanceOf(MyCoolDude.class);
+
+        MyCoolDude dude = new MyCoolDude();
+        template.sendBody("direct:start", dude);
+
+        assertMockEndpointsSatisfied();
+
+        assertEquals(3 + 1, dude.getCounter());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                onException(IllegalArgumentException.class)
+                    .retryWhile(simple("${body.areWeCool} == 'no'"))
+                    .handled(true)
+                    .to("mock:error");
+
+                from("direct:start")
+                    .throwException(new IllegalArgumentException("Forced"));
+            }
+        };
+    }
+
+    public static class MyCoolDude {
+
+        private int counter;
+
+        public String areWeCool() {
+            if (counter++ < 3) {
+                return "no";
+            } else {
+                return "yes";
+            }
+        }
+
+        public int getCounter() {
+            return counter;
+        }
+    }
+}


Reply via email to