camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r790462 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/builder/ main/java/org/apache/camel/processor/ main/java/org/apache/camel/spi/ test/java/org/apache/camel/builder/ test/java/org/apache/camel/issues/ test/java/org/apache/...
Date Thu, 02 Jul 2009 05:19:37 GMT
Author: davsclaus
Date: Thu Jul  2 05:19:36 2009
New Revision: 790462

URL: http://svn.apache.org/viewvc?rev=790462&view=rev
Log:
Added predicates for startsWith endsWith. Fixed some TODO that was already done or not needed.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/issues/RegExPredicateIssueTest.java
  (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/PredicateBuilder.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/spi/EndpointStrategy.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/builder/PredicateBuilderTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRetryRouteTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/PredicateBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/PredicateBuilder.java?rev=790462&r1=790461&r2=790462&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/PredicateBuilder.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/PredicateBuilder.java Thu
Jul  2 05:19:36 2009
@@ -338,6 +338,58 @@
         };
     }
 
+    public static Predicate startsWith(final Expression left, final Expression right) {
+        return new BinaryPredicateSupport(left, right) {
+
+            protected boolean matches(Exchange exchange, Object leftValue, Object rightValue)
{
+                if (leftValue == null && rightValue == null) {
+                    // they are equal
+                    return true;
+                } else if (leftValue == null || rightValue == null) {
+                    // only one of them is null so they are not equal
+                    return false;
+                }
+                String leftStr = exchange.getContext().getTypeConverter().convertTo(String.class,
leftValue);
+                String rightStr = exchange.getContext().getTypeConverter().convertTo(String.class,
rightValue);
+                if (leftStr != null && rightStr != null) {
+                    return leftStr.startsWith(rightStr);
+                } else {
+                    return false;
+                }
+            }
+
+            protected String getOperationText() {
+                return "startsWith";
+            }
+        };
+    }
+
+    public static Predicate endsWith(final Expression left, final Expression right) {
+        return new BinaryPredicateSupport(left, right) {
+
+            protected boolean matches(Exchange exchange, Object leftValue, Object rightValue)
{
+                if (leftValue == null && rightValue == null) {
+                    // they are equal
+                    return true;
+                } else if (leftValue == null || rightValue == null) {
+                    // only one of them is null so they are not equal
+                    return false;
+                }
+                String leftStr = exchange.getContext().getTypeConverter().convertTo(String.class,
leftValue);
+                String rightStr = exchange.getContext().getTypeConverter().convertTo(String.class,
rightValue);
+                if (leftStr != null && rightStr != null) {
+                    return leftStr.endsWith(rightStr);
+                } else {
+                    return false;
+                }
+            }
+
+            protected String getOperationText() {
+                return "endsWith";
+            }
+        };
+    }
+
     /**
      * Returns a predicate which is true if the expression matches the given
      * regular expression

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java?rev=790462&r1=790461&r2=790462&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/ValueBuilder.java Thu Jul
 2 05:19:36 2009
@@ -113,6 +113,16 @@
         return onNewPredicate(PredicateBuilder.in(predicates));
     }
 
+    public Predicate startsWith(Object value) {
+        Expression right = asExpression(value);
+        return onNewPredicate(PredicateBuilder.startsWith(expression, right));
+    }
+
+    public Predicate endsWith(Object value) {
+        Expression right = asExpression(value);
+        return onNewPredicate(PredicateBuilder.endsWith(expression, right));
+    }
+
     /**
      * Create a predicate that the left hand expression contains the value of
      * the right hand expression

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java?rev=790462&r1=790461&r2=790462&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
Thu Jul  2 05:19:36 2009
@@ -39,9 +39,6 @@
  */
 public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport implements Processor
{
 
-    // TODO: support onException being able to use other onException to route they exceptions
-    // (hard one to get working, has not been supported before)
-
     protected final Processor deadLetter;
     protected final String deadLetterUri;
     protected final Processor output;

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/EndpointStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/EndpointStrategy.java?rev=790462&r1=790461&r2=790462&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/spi/EndpointStrategy.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/spi/EndpointStrategy.java Thu Jul
 2 05:19:36 2009
@@ -30,10 +30,6 @@
  */
 public interface EndpointStrategy {
 
-    // TODO: Add more strategy methods for other endpoint related methods, such as lookup,
remove etc.
-    // and add a base class EndpointStrategySupport that has noop impl of all methods so
you can extend it
-    // if you only want to do custom behavior in one of the methods
-
     /**
      * Register the endpoint.
      *

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/builder/PredicateBuilderTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/PredicateBuilderTest.java?rev=790462&r1=790461&r2=790462&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/builder/PredicateBuilderTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/builder/PredicateBuilderTest.java
Thu Jul  2 05:19:36 2009
@@ -82,6 +82,38 @@
         assertMatches(header("name").in("Hiram", "Jonathan", "James", "Claus"));
     }
 
+    public void testStartsWith() throws Exception {
+        assertMatches(header("name").startsWith("J"));
+        assertMatches(header("name").startsWith("James"));
+        assertDoesNotMatch(header("name").startsWith("C"));
+
+        assertMatches(header("size").startsWith("1"));
+        assertMatches(header("size").startsWith("10"));
+        assertDoesNotMatch(header("size").startsWith("99"));
+        assertDoesNotMatch(header("size").startsWith("9"));
+
+        assertMatches(header("size").startsWith(1));
+        assertMatches(header("size").startsWith(10));
+        assertDoesNotMatch(header("size").startsWith(99));
+        assertDoesNotMatch(header("size").startsWith(9));
+    }
+
+    public void testEndsWith() throws Exception {
+        assertMatches(header("name").endsWith("mes"));
+        assertMatches(header("name").endsWith("James"));
+        assertDoesNotMatch(header("name").endsWith("world"));
+
+        assertMatches(header("size").endsWith("0"));
+        assertMatches(header("size").endsWith("10"));
+        assertDoesNotMatch(header("size").endsWith("99"));
+        assertDoesNotMatch(header("size").endsWith("9"));
+
+        assertMatches(header("size").endsWith(0));
+        assertMatches(header("size").endsWith(10));
+        assertDoesNotMatch(header("size").endsWith(99));
+        assertDoesNotMatch(header("size").endsWith(9));
+    }
+
     @Override
     protected void setUp() throws Exception {
         super.setUp();

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/issues/RegExPredicateIssueTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/RegExPredicateIssueTest.java?rev=790462&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/issues/RegExPredicateIssueTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/issues/RegExPredicateIssueTest.java
Thu Jul  2 05:19:36 2009
@@ -0,0 +1,58 @@
+/**
+ * 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;
+
+/**
+ * @version $Revision$
+ */
+public class RegExPredicateIssueTest extends ContextTestSupport {
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:a")
+                    .choice()
+                        .when(body(String.class).regex("^0.*$")).to("mock:result")
+                        .otherwise().to("mock:other")
+                    .end();
+            }
+        };
+    }
+
+    public void testMatch() throws Exception {
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+        getMockEndpoint("mock:other").expectedMessageCount(0);
+
+        template.sendBody("direct:a", "000000000001111111");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testNotMatch() throws Exception {
+        getMockEndpoint("mock:result").expectedMessageCount(0);
+        getMockEndpoint("mock:other").expectedMessageCount(1);
+
+        template.sendBody("direct:a", "900000000001111111");
+
+        assertMockEndpointsSatisfied();
+    }
+}

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

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

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRetryRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRetryRouteTest.java?rev=790462&r1=790461&r2=790462&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRetryRouteTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRetryRouteTest.java
Thu Jul  2 05:19:36 2009
@@ -42,14 +42,13 @@
     };
 
     public void testSuccessfulRetry() throws Exception {
-        // TODO: See CAMEL-1551
-//        a.expectedBodiesReceived("in");
-//        b.expectedBodiesReceived("in");
-//        error.expectedMessageCount(0);
+        a.expectedBodiesReceived("in");
+        b.expectedBodiesReceived("in");
+        error.expectedMessageCount(0);
 
-//        template.sendBody("direct:start", "in");
+        template.sendBody("direct:start", "in");
 
-//        MockEndpoint.assertIsSatisfied(a, b, error);
+        MockEndpoint.assertIsSatisfied(a, b, error);
     }
 
     @Override



Mime
View raw message