You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2011/09/10 07:43:16 UTC

svn commit: r1167462 [3/3] - in /camel/trunk/camel-core/src: main/java/org/apache/camel/builder/ main/java/org/apache/camel/language/simple/ main/java/org/apache/camel/language/simple/ast/ test/java/org/apache/camel/component/bean/ test/java/org/apache...

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleBackwardsCompatibleTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleBackwardsCompatibleTest.java?rev=1167462&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleBackwardsCompatibleTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleBackwardsCompatibleTest.java Sat Sep 10 05:43:14 2011
@@ -0,0 +1,75 @@
+/**
+ * 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.language.simple;
+
+import org.apache.camel.LanguageTestSupport;
+import org.apache.camel.Predicate;
+
+/**
+ *
+ */
+public class SimpleBackwardsCompatibleTest extends LanguageTestSupport {
+
+    @Override
+    protected String getLanguageName() {
+        return "simple";
+    }
+
+    public void testSimpleBody() throws Exception {
+        assertExpression(exchange, "${body}", "<hello id='m123'>world!</hello>");
+        assertExpression(exchange, "$simple{body}", "<hello id='m123'>world!</hello>");
+        assertExpression(exchange, "body", "<hello id='m123'>world!</hello>");
+
+        assertPredicate("${body}", true);
+        assertPredicate("body", true);
+    }
+
+    public void testSimpleHeader() throws Exception {
+        exchange.getIn().setHeader("foo", 123);
+        assertExpression(exchange, "${header.foo}", 123);
+        assertExpression(exchange, "header.foo", 123);
+
+        assertPredicate("${header.foo}", true);
+        assertPredicate("header.foo", true);
+
+        assertPredicate("${header.unknown}", false);
+        assertPredicate("header.unknown", false);
+    }
+
+    public void testSimpleLogicalAnd() throws Exception {
+        exchange.getIn().setBody("Hello");
+        exchange.getIn().setHeader("high", true);
+        exchange.getIn().setHeader("foo", 123);
+
+        SimplePredicateParser parser = new SimplePredicateParser("${header.high} == true and ${header.foo} == 123");
+        Predicate pre = parser.parsePredicate();
+
+        assertTrue("Should match", pre.matches(exchange));
+    }
+
+    public void testSimpleLogicalOr() throws Exception {
+        exchange.getIn().setBody("Hello");
+        exchange.getIn().setHeader("high", true);
+        exchange.getIn().setHeader("foo", 123);
+
+        SimplePredicateParser parser = new SimplePredicateParser("${header.high} == false or ${header.foo} == 123");
+        Predicate pre = parser.parsePredicate();
+
+        assertTrue("Should match", pre.matches(exchange));
+    }
+
+}

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleChangeFunctionTokensTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleChangeFunctionTokensTest.java?rev=1167462&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleChangeFunctionTokensTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleChangeFunctionTokensTest.java Sat Sep 10 05:43:14 2011
@@ -0,0 +1,78 @@
+/**
+ * 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.language.simple;
+
+import org.apache.camel.LanguageTestSupport;
+
+/**
+ *
+ */
+public class SimpleChangeFunctionTokensTest extends LanguageTestSupport {
+
+    @Override
+    protected String getLanguageName() {
+        return "simple";
+    }
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+
+        SimpleLanguage.changeFunctionStartToken("[[");
+        SimpleLanguage.changeFunctionEndToken("]]");
+    }
+
+    @Override
+    public void tearDown() throws Exception {
+        super.tearDown();
+
+        // replace old tokens
+        SimpleLanguage.changeFunctionStartToken("${", "$simple{");
+        SimpleLanguage.changeFunctionEndToken("}");
+    }
+
+    public void testSimpleBody() throws Exception {
+        assertExpression(exchange, "[[body]]", "<hello id='m123'>world!</hello>");
+
+        // old tokens do no longer work
+        assertExpression(exchange, "${body}", "${body}");
+    }
+
+    public void testSimpleConstantAndBody() throws Exception {
+        exchange.getIn().setBody("Camel");
+        assertExpression(exchange, "Hi [[body]] how are you", "Hi Camel how are you");
+        assertExpression(exchange, "'Hi '[[body]]' how are you'", "'Hi 'Camel' how are you'");
+
+        // old tokens do no longer work
+        assertExpression(exchange, "Hi ${body} how are you", "Hi ${body} how are you");
+    }
+
+    public void testSimpleConstantAndBodyAndHeader() throws Exception {
+        exchange.getIn().setBody("Camel");
+        exchange.getIn().setHeader("foo", "Tiger");
+        assertExpression(exchange, "Hi [[body]] how are [[header.foo]]", "Hi Camel how are Tiger");
+    }
+
+    public void testSimpleEqOperator() throws Exception {
+        exchange.getIn().setBody("Camel");
+        assertPredicate(exchange, "[[body]] == 'Tiger'", false);
+        assertPredicate(exchange, "[[body]] == 'Camel'", true);
+        assertPredicate(exchange, "[[body]] == \"Tiger\"", false);
+        assertPredicate(exchange, "[[body]] == \"Camel\"", true);
+    }
+
+}

Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java (from r1167201, camel/trunk/camel-core/src/test/java/org/apache/camel/language/SimpleOperatorTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/language/SimpleOperatorTest.java&r1=1167201&r2=1167462&rev=1167462&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/language/SimpleOperatorTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java Sat Sep 10 05:43:14 2011
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.language;
+package org.apache.camel.language.simple;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.LanguageTestSupport;
@@ -48,95 +48,81 @@ public class SimpleOperatorTest extends 
     }
 
     public void testAnd() throws Exception {
-        assertPredicate("${in.header.foo} == abc and ${in.header.bar} == 123", true);
-        assertPredicate("${in.header.foo} == abc and ${in.header.bar} == 444", false);
-        assertPredicate("${in.header.foo} == def and ${in.header.bar} == 123", false);
-        assertPredicate("${in.header.foo} == def and ${in.header.bar} == 444", false);
+        assertPredicate("${in.header.foo} == 'abc' && ${in.header.bar} == 123", true);
+        assertPredicate("${in.header.foo} == 'abc' && ${in.header.bar} == 444", false);
+        assertPredicate("${in.header.foo} == 'def' && ${in.header.bar} == 123", false);
+        assertPredicate("${in.header.foo} == 'def' && ${in.header.bar} == 444", false);
 
-        assertPredicate("${in.header.foo} == abc and ${in.header.bar} > 100", true);
-        assertPredicate("${in.header.foo} == abc and ${in.header.bar} < 200", true);
+        assertPredicate("${in.header.foo} == 'abc' && ${in.header.bar} > 100", true);
+        assertPredicate("${in.header.foo} == 'abc' && ${in.header.bar} < 200", true);
     }
 
     public void testTwoAnd() throws Exception {
         exchange.getIn().setBody("Hello World");
-        assertPredicate("${in.header.foo} == abc and ${in.header.bar} == 123 and ${body} == 'Hello World'", true);
-        assertPredicate("${in.header.foo} == 'abc' and ${in.header.bar} == 123 and ${body} == 'Hello World'", true);
-        assertPredicate("${in.header.foo} == abc and ${in.header.bar} == 123 and ${body} == 'Bye World'", false);
-        assertPredicate("${in.header.foo} == 'abc' and ${in.header.bar} == 123 and ${body} == 'Bye World'", false);
+        assertPredicate("${in.header.foo} == 'abc' && ${in.header.bar} == 123 && ${body} == 'Hello World'", true);
+        assertPredicate("${in.header.foo} == 'abc' && ${in.header.bar} == 123 && ${body} == 'Bye World'", false);
     }
 
     public void testThreeAnd() throws Exception {
         exchange.getIn().setBody("Hello World");
-        assertPredicate("${in.header.foo} == abc and ${in.header.bar} == 123 and ${body} == 'Hello World' and ${in.header.xx}} == null", true);
-        assertPredicate("${in.header.foo} == 'abc' and ${in.header.bar} == 123 and ${body} == 'Hello World' and ${in.header.xx}} == null", true);
+        assertPredicate("${in.header.foo} == 'abc' && ${in.header.bar} == 123 && ${body} == 'Hello World' && ${in.header.xx} == null", true);
     }
 
     public void testTwoOr() throws Exception {
         exchange.getIn().setBody("Hello World");
-        assertPredicate("${in.header.foo} == abc or ${in.header.bar} == 44 or ${body} == 'Bye World'", true);
-        assertPredicate("${in.header.foo} == 'abc' or ${in.header.bar} == 44 or ${body} == 'Bye World'", true);
-        assertPredicate("${in.header.foo} == xxx or ${in.header.bar} == 44 or ${body} == 'Bye World'", false);
-        assertPredicate("${in.header.foo} == 'xxx' or ${in.header.bar} == 44 or ${body} == 'Bye World'", false);
-        assertPredicate("${in.header.foo} == xxx or ${in.header.bar} == 44 or ${body} == 'Hello World'", true);
-        assertPredicate("${in.header.foo} == 'xxx' or ${in.header.bar} == 44 or ${body} == 'Hello World'", true);
-        assertPredicate("${in.header.foo} == xxx or ${in.header.bar} == 123 or ${body} == 'Bye World'", true);
-        assertPredicate("${in.header.foo} == 'xxx' or ${in.header.bar} == 123 or ${body} == 'Bye World'", true);
+        assertPredicate("${in.header.foo} == 'abc' || ${in.header.bar} == 44 || ${body} == 'Bye World'", true);
+        assertPredicate("${in.header.foo} == 'xxx' || ${in.header.bar} == 44 || ${body} == 'Bye World'", false);
+        assertPredicate("${in.header.foo} == 'xxx' || ${in.header.bar} == 44 || ${body} == 'Hello World'", true);
+        assertPredicate("${in.header.foo} == 'xxx' || ${in.header.bar} == 123 || ${body} == 'Bye World'", true);
     }
 
     public void testThreeOr() throws Exception {
         exchange.getIn().setBody("Hello World");
-        assertPredicate("${in.header.foo} == xxx or ${in.header.bar} == 44 or ${body} == 'Bye Moon' or ${body} contains 'World'", true);
-        assertPredicate("${in.header.foo} == 'xxx' or ${in.header.bar} == 44 or ${body} == 'Bye Moon' or ${body} contains 'World'", true);
-        assertPredicate("${in.header.foo} == xxx or ${in.header.bar} == 44 or ${body} == 'Bye Moon' or ${body} contains 'Moon'", false);
-        assertPredicate("${in.header.foo} == 'xxx' or ${in.header.bar} == 44 or ${body} == 'Bye Moon' or ${body} contains 'Moon'", false);
-        assertPredicate("${in.header.foo} == abc or ${in.header.bar} == 44 or ${body} == 'Bye Moon' or ${body} contains 'Moon'", true);
-        assertPredicate("${in.header.foo} == 'abc' or ${in.header.bar} == 44 or ${body} == 'Bye Moon' or ${body} contains 'Moon'", true);
-        assertPredicate("${in.header.foo} == xxx or ${in.header.bar} == 123 or ${body} == 'Bye Moon' or ${body} contains 'Moon'", true);
-        assertPredicate("${in.header.foo} == 'xxx' or ${in.header.bar} == 123 or ${body} == 'Bye Moon' or ${body} contains 'Moon'", true);
-        assertPredicate("${in.header.foo} == xxx or ${in.header.bar} == 44 or ${body} == 'Hello World' or ${body} contains 'Moon'", true);
-        assertPredicate("${in.header.foo} == 'xxx' or ${in.header.bar} == 44 or ${body} == 'Hello World' or ${body} contains 'Moon'", true);
+        assertPredicate("${in.header.foo} == 'xxx' || ${in.header.bar} == 44 || ${body} == 'Bye Moon' || ${body} contains 'World'", true);
+        assertPredicate("${in.header.foo} == 'xxx' || ${in.header.bar} == 44 || ${body} == 'Bye Moon' || ${body} contains 'Moon'", false);
+        assertPredicate("${in.header.foo} == 'abc' || ${in.header.bar} == 44 || ${body} == 'Bye Moon' || ${body} contains 'Moon'", true);
+        assertPredicate("${in.header.foo} == 'xxx' || ${in.header.bar} == 123 || ${body} == 'Bye Moon' || ${body} contains 'Moon'", true);
+        assertPredicate("${in.header.foo} == 'xxx' || ${in.header.bar} == 44 || ${body} == 'Hello World' || ${body} contains 'Moon'", true);
     }
 
     public void testAndWithQuotation() throws Exception {
-        assertPredicate("${in.header.foo} == 'abc' and ${in.header.bar} == '123'", true);
-        assertPredicate("${in.header.foo} == 'abc' and ${in.header.bar} == '444'", false);
-        assertPredicate("${in.header.foo} == 'def' and ${in.header.bar} == '123'", false);
-        assertPredicate("${in.header.foo} == 'def' and ${in.header.bar} == '444'", false);
+        assertPredicate("${in.header.foo} == 'abc' && ${in.header.bar} == '123'", true);
+        assertPredicate("${in.header.foo} == 'abc' && ${in.header.bar} == '444'", false);
+        assertPredicate("${in.header.foo} == 'def' && ${in.header.bar} == '123'", false);
+        assertPredicate("${in.header.foo} == 'def' && ${in.header.bar} == '444'", false);
 
-        assertPredicate("${in.header.foo} == 'abc' and ${in.header.bar} > '100'", true);
-        assertPredicate("${in.header.foo} == 'abc' and ${in.header.bar} < '200'", true);
+        assertPredicate("${in.header.foo} == 'abc' && ${in.header.bar} > '100'", true);
+        assertPredicate("${in.header.foo} == 'abc' && ${in.header.bar} < '200'", true);
     }
 
     public void testOr() throws Exception {
-        assertPredicate("${in.header.foo} == abc or ${in.header.bar} == 123", true);
-        assertPredicate("${in.header.foo} == abc or ${in.header.bar} == 444", true);
-        assertPredicate("${in.header.foo} == def or ${in.header.bar} == 123", true);
-        assertPredicate("${in.header.foo} == def or ${in.header.bar} == 444", false);
-
-        assertPredicate("${in.header.foo} == abc or ${in.header.bar} < 100", true);
-        assertPredicate("${in.header.foo} == abc or ${in.header.bar} < 200", true);
-        assertPredicate("${in.header.foo} == def or ${in.header.bar} < 200", true);
-        assertPredicate("${in.header.foo} == def or ${in.header.bar} < 100", false);
+        assertPredicate("${in.header.foo} == 'abc' || ${in.header.bar} == 123", true);
+        assertPredicate("${in.header.foo} == 'abc' || ${in.header.bar} == 444", true);
+        assertPredicate("${in.header.foo} == 'def' || ${in.header.bar} == 123", true);
+        assertPredicate("${in.header.foo} == 'def' || ${in.header.bar} == 444", false);
+
+        assertPredicate("${in.header.foo} == 'abc' || ${in.header.bar} < 100", true);
+        assertPredicate("${in.header.foo} == 'abc' || ${in.header.bar} < 200", true);
+        assertPredicate("${in.header.foo} == 'def' || ${in.header.bar} < 200", true);
+        assertPredicate("${in.header.foo} == 'def' || ${in.header.bar} < 100", false);
     }
 
     public void testOrWithQuotation() throws Exception {
-        assertPredicate("${in.header.foo} == 'abc' or ${in.header.bar} == '123'", true);
-        assertPredicate("${in.header.foo} == 'abc' or ${in.header.bar} == '444'", true);
-        assertPredicate("${in.header.foo} == 'def' or ${in.header.bar} == '123'", true);
-        assertPredicate("${in.header.foo} == 'def' or ${in.header.bar} == '444'", false);
-
-        assertPredicate("${in.header.foo} == 'abc' or ${in.header.bar} < '100'", true);
-        assertPredicate("${in.header.foo} == 'abc' or ${in.header.bar} < '200'", true);
-        assertPredicate("${in.header.foo} == 'def' or ${in.header.bar} < '200'", true);
-        assertPredicate("${in.header.foo} == 'def' or ${in.header.bar} < '100'", false);
+        assertPredicate("${in.header.foo} == 'abc' || ${in.header.bar} == '123'", true);
+        assertPredicate("${in.header.foo} == 'abc' || ${in.header.bar} == '444'", true);
+        assertPredicate("${in.header.foo} == 'def' || ${in.header.bar} == '123'", true);
+        assertPredicate("${in.header.foo} == 'def' || ${in.header.bar} == '444'", false);
+
+        assertPredicate("${in.header.foo} == 'abc' || ${in.header.bar} < '100'", true);
+        assertPredicate("${in.header.foo} == 'abc' || ${in.header.bar} < '200'", true);
+        assertPredicate("${in.header.foo} == 'def' || ${in.header.bar} < '200'", true);
+        assertPredicate("${in.header.foo} == 'def' || ${in.header.bar} < '100'", false);
     }
 
     public void testEqualOperator() throws Exception {
         // string to string comparison
         assertPredicate("${in.header.foo} == 'abc'", true);
-        assertPredicate("${in.header.foo} == abc", true);
         assertPredicate("${in.header.foo} == 'def'", false);
-        assertPredicate("${in.header.foo} == def", false);
         assertPredicate("${in.header.foo} == '1'", false);
 
         // integer to string comparison
@@ -150,9 +136,7 @@ public class SimpleOperatorTest extends 
     public void testNotEqualOperator() throws Exception {
         // string to string comparison
         assertPredicate("${in.header.foo} != 'abc'", false);
-        assertPredicate("${in.header.foo} != abc", false);
         assertPredicate("${in.header.foo} != 'def'", true);
-        assertPredicate("${in.header.foo} != def", true);
         assertPredicate("${in.header.foo} != '1'", true);
 
         // integer to string comparison
@@ -166,9 +150,7 @@ public class SimpleOperatorTest extends 
     public void testGreaterThanOperator() throws Exception {
         // string to string comparison
         assertPredicate("${in.header.foo} > 'aaa'", true);
-        assertPredicate("${in.header.foo} > aaa", true);
         assertPredicate("${in.header.foo} > 'def'", false);
-        assertPredicate("${in.header.foo} > def", false);
 
         // integer to string comparison
         assertPredicate("${in.header.bar} > '100'", true);
@@ -217,9 +199,7 @@ public class SimpleOperatorTest extends 
     public void testGreaterThanOrEqualOperator() throws Exception {
         // string to string comparison
         assertPredicate("${in.header.foo} >= 'aaa'", true);
-        assertPredicate("${in.header.foo} >= aaa", true);
         assertPredicate("${in.header.foo} >= 'abc'", true);
-        assertPredicate("${in.header.foo} >= abc", true);
         assertPredicate("${in.header.foo} >= 'def'", false);
 
         // integer to string comparison
@@ -233,9 +213,7 @@ public class SimpleOperatorTest extends 
     public void testLessThanOperator() throws Exception {
         // string to string comparison
         assertPredicate("${in.header.foo} < 'aaa'", false);
-        assertPredicate("${in.header.foo} < aaa", false);
         assertPredicate("${in.header.foo} < 'def'", true);
-        assertPredicate("${in.header.foo} < def", true);
 
         // integer to string comparison
         assertPredicate("${in.header.bar} < '100'", false);
@@ -248,9 +226,7 @@ public class SimpleOperatorTest extends 
     public void testLessThanOrEqualOperator() throws Exception {
         // string to string comparison
         assertPredicate("${in.header.foo} <= 'aaa'", false);
-        assertPredicate("${in.header.foo} <= aaa", false);
         assertPredicate("${in.header.foo} <= 'abc'", true);
-        assertPredicate("${in.header.foo} <= abc", true);
         assertPredicate("${in.header.foo} <= 'def'", true);
 
         // integer to string comparison
@@ -264,26 +240,20 @@ public class SimpleOperatorTest extends 
     public void testIsNull() throws Exception {
         assertPredicate("${in.header.foo} == null", false);
         assertPredicate("${in.header.none} == null", true);
-
-        assertPredicate("${in.header.foo} == 'null'", false);
-        assertPredicate("${in.header.none} == 'null'", true);
     }
 
     public void testIsNotNull() throws Exception {
         assertPredicate("${in.header.foo} != null", true);
         assertPredicate("${in.header.none} != null", false);
-
-        assertPredicate("${in.header.foo} != 'null'", true);
-        assertPredicate("${in.header.none} != 'null'", false);
     }
 
-    public void testRightOperatorIsSimpleLanauge() throws Exception {
+    public void testRightOperatorIsSimpleLanguage() throws Exception {
         // operator on right side is also using ${ } placeholders
         assertPredicate("${in.header.foo} == ${in.header.foo}", true);
         assertPredicate("${in.header.foo} == ${in.header.bar}", false);
     }
 
-    public void testRightOperatorIsBeanLanauge() throws Exception {
+    public void testRightOperatorIsBeanLanguage() throws Exception {
         // operator on right side is also using ${ } placeholders
         assertPredicate("${in.header.foo} == ${bean:generator.generateFilename}", true);
 
@@ -291,58 +261,49 @@ public class SimpleOperatorTest extends 
         assertPredicate("${in.header.bar} >= ${bean:generator.generateId}", true);
     }
 
-    public void testConstains() throws Exception {
+    public void testContains() throws Exception {
         assertPredicate("${in.header.foo} contains 'a'", true);
-        assertPredicate("${in.header.foo} contains a", true);
         assertPredicate("${in.header.foo} contains 'ab'", true);
         assertPredicate("${in.header.foo} contains 'abc'", true);
         assertPredicate("${in.header.foo} contains 'def'", false);
-        assertPredicate("${in.header.foo} contains def", false);
     }
 
-    public void testNotConstains() throws Exception {
+    public void testNotContains() throws Exception {
         assertPredicate("${in.header.foo} not contains 'a'", false);
-        assertPredicate("${in.header.foo} not contains a", false);
         assertPredicate("${in.header.foo} not contains 'ab'", false);
         assertPredicate("${in.header.foo} not contains 'abc'", false);
         assertPredicate("${in.header.foo} not contains 'def'", true);
-        assertPredicate("${in.header.foo} not contains def", true);
     }
 
     public void testRegex() throws Exception {
         assertPredicate("${in.header.foo} regex '^a..$'", true);
         assertPredicate("${in.header.foo} regex '^ab.$'", true);
-        assertPredicate("${in.header.foo} regex ^ab.$", true);
-        assertPredicate("${in.header.foo} regex ^d.*$", false);
+        assertPredicate("${in.header.foo} regex '^ab.$'", true);
+        assertPredicate("${in.header.foo} regex '^d.*$'", false);
 
         assertPredicate("${in.header.bar} regex '^\\d{3}'", true);
         assertPredicate("${in.header.bar} regex '^\\d{2}'", false);
-        assertPredicate("${in.header.bar} regex ^\\d{3}", true);
-        assertPredicate("${in.header.bar} regex ^\\d{2}", false);
     }
 
     public void testNotRegex() throws Exception {
         assertPredicate("${in.header.foo} not regex '^a..$'", false);
         assertPredicate("${in.header.foo} not regex '^ab.$'", false);
-        assertPredicate("${in.header.foo} not regex ^ab.$", false);
-        assertPredicate("${in.header.foo} not regex ^d.*$", true);
+        assertPredicate("${in.header.foo} not regex '^ab.$'", false);
+        assertPredicate("${in.header.foo} not regex '^d.*$'", true);
 
         assertPredicate("${in.header.bar} not regex '^\\d{3}'", false);
         assertPredicate("${in.header.bar} not regex '^\\d{2}'", true);
-        assertPredicate("${in.header.bar} not regex ^\\d{3}", false);
-        assertPredicate("${in.header.bar} not regex ^\\d{2}", true);
     }
 
     public void testIn() throws Exception {
         // string to string
         assertPredicate("${in.header.foo} in 'foo,abc,def'", true);
         assertPredicate("${in.header.foo} in ${bean:generator.generateFilename}", true);
-        assertPredicate("${in.header.foo} in foo,abc,def", true);
+        assertPredicate("${in.header.foo} in 'foo,abc,def'", true);
         assertPredicate("${in.header.foo} in 'foo,def'", false);
 
         // integer to string
         assertPredicate("${in.header.bar} in '100,123,200'", true);
-        assertPredicate("${in.header.bar} in 100,123,200", true);
         assertPredicate("${in.header.bar} in ${bean:generator.generateId}", true);
         assertPredicate("${in.header.bar} in '100,200'", false);
     }
@@ -351,12 +312,11 @@ public class SimpleOperatorTest extends 
         // string to string
         assertPredicate("${in.header.foo} not in 'foo,abc,def'", false);
         assertPredicate("${in.header.foo} not in ${bean:generator.generateFilename}", false);
-        assertPredicate("${in.header.foo} not in foo,abc,def", false);
+        assertPredicate("${in.header.foo} not in 'foo,abc,def'", false);
         assertPredicate("${in.header.foo} not in 'foo,def'", true);
 
         // integer to string
         assertPredicate("${in.header.bar} not in '100,123,200'", false);
-        assertPredicate("${in.header.bar} not in 100,123,200", false);
         assertPredicate("${in.header.bar} not in ${bean:generator.generateId}", false);
         assertPredicate("${in.header.bar} not in '100,200'", true);
     }
@@ -368,14 +328,11 @@ public class SimpleOperatorTest extends 
         assertPredicate("${in.header.foo} is 'String'", true);
         assertPredicate("${in.header.foo} is 'Integer'", false);
 
-        assertPredicate("${in.header.foo} is String", true);
-        assertPredicate("${in.header.foo} is Integer", false);
-
         try {
             assertPredicate("${in.header.foo} is com.mycompany.DoesNotExist", false);
             fail("Should have thrown an exception");
-        } catch (IllegalArgumentException e) {
-            assertTrue(e.getMessage().startsWith("Syntax error"));
+        } catch (SimpleIllegalSyntaxException e) {
+            assertEquals(20, e.getIndex());
         }
     }
 
@@ -386,83 +343,80 @@ public class SimpleOperatorTest extends 
         assertPredicate("${in.header.foo} not is 'String'", false);
         assertPredicate("${in.header.foo} not is 'Integer'", true);
 
-        assertPredicate("${in.header.foo} not is String", false);
-        assertPredicate("${in.header.foo} not is Integer", true);
-
         try {
             assertPredicate("${in.header.foo} not is com.mycompany.DoesNotExist", false);
             fail("Should have thrown an exception");
-        } catch (IllegalArgumentException e) {
-            assertTrue(e.getMessage().startsWith("Syntax error"));
+        } catch (SimpleIllegalSyntaxException e) {
+            assertEquals(24, e.getIndex());
         }
     }
 
     public void testRange() throws Exception {
-        assertPredicate("${in.header.bar} range 100..200", true);
-        assertPredicate("${in.header.bar} range 200..300", false);
+        assertPredicate("${in.header.bar} range '100..200'", true);
+        assertPredicate("${in.header.bar} range '200..300'", false);
 
-        assertPredicate("${in.header.foo} range 200..300", false);
-        assertPredicate("${bean:generator.generateId} range 123..130", true);
-        assertPredicate("${bean:generator.generateId} range 120..123", true);
-        assertPredicate("${bean:generator.generateId} range 120..122", false);
-        assertPredicate("${bean:generator.generateId} range 124..130", false);
+        assertPredicate("${in.header.foo} range '200..300'", false);
+        assertPredicate("${bean:generator.generateId} range '123..130'", true);
+        assertPredicate("${bean:generator.generateId} range '120..123'", true);
+        assertPredicate("${bean:generator.generateId} range '120..122'", false);
+        assertPredicate("${bean:generator.generateId} range '124..130'", false);
 
         try {
             assertPredicate("${in.header.foo} range abc..200", false);
             fail("Should have thrown an exception");
-        } catch (IllegalArgumentException e) {
-            assertTrue(e.getMessage().startsWith("Syntax error"));
+        } catch (SimpleIllegalSyntaxException e) {
+            assertEquals(23, e.getIndex());
         }
 
         try {
             assertPredicate("${in.header.foo} range abc..", false);
             fail("Should have thrown an exception");
-        } catch (IllegalArgumentException e) {
-            assertTrue(e.getMessage().startsWith("Syntax error"));
+        } catch (SimpleIllegalSyntaxException e) {
+            assertEquals(23, e.getIndex());
         }
 
         try {
             assertPredicate("${in.header.foo} range 100.200", false);
             fail("Should have thrown an exception");
-        } catch (IllegalArgumentException e) {
-            assertTrue(e.getMessage().startsWith("Syntax error"));
+        } catch (SimpleIllegalSyntaxException e) {
+            assertEquals(26, e.getIndex());
         }
 
-        assertPredicate("${in.header.bar} range 100..200 and ${in.header.foo} == abc" , true);
-        assertPredicate("${in.header.bar} range 200..300 and ${in.header.foo} == abc" , false);
-        assertPredicate("${in.header.bar} range 200..300 or ${in.header.foo} == abc" , true);
-        assertPredicate("${in.header.bar} range 200..300 or ${in.header.foo} == def" , false);
+        assertPredicate("${in.header.bar} range '100..200' && ${in.header.foo} == 'abc'" , true);
+        assertPredicate("${in.header.bar} range '200..300' && ${in.header.foo} == 'abc'" , false);
+        assertPredicate("${in.header.bar} range '200..300' || ${in.header.foo} == 'abc'" , true);
+        assertPredicate("${in.header.bar} range '200..300' || ${in.header.foo} == 'def'" , false);
     }
 
     public void testNotRange() throws Exception {
-        assertPredicate("${in.header.bar} not range 100..200", false);
-        assertPredicate("${in.header.bar} not range 200..300", true);
+        assertPredicate("${in.header.bar} not range '100..200'", false);
+        assertPredicate("${in.header.bar} not range '200..300'", true);
 
-        assertPredicate("${in.header.foo} not range 200..300", true);
-        assertPredicate("${bean:generator.generateId} not range 123..130", false);
-        assertPredicate("${bean:generator.generateId} not range 120..123", false);
-        assertPredicate("${bean:generator.generateId} not range 120..122", true);
-        assertPredicate("${bean:generator.generateId} not range 124..130", true);
+        assertPredicate("${in.header.foo} not range '200..300'", true);
+        assertPredicate("${bean:generator.generateId} not range '123..130'", false);
+        assertPredicate("${bean:generator.generateId} not range '120..123'", false);
+        assertPredicate("${bean:generator.generateId} not range '120..122'", true);
+        assertPredicate("${bean:generator.generateId} not range '124..130'", true);
 
         try {
             assertPredicate("${in.header.foo} not range abc..200", false);
             fail("Should have thrown an exception");
-        } catch (IllegalArgumentException e) {
-            assertTrue(e.getMessage().startsWith("Syntax error"));
+        } catch (SimpleIllegalSyntaxException e) {
+            assertEquals(27, e.getIndex());
         }
 
         try {
             assertPredicate("${in.header.foo} not range abc..", false);
             fail("Should have thrown an exception");
-        } catch (IllegalArgumentException e) {
-            assertTrue(e.getMessage().startsWith("Syntax error"));
+        } catch (SimpleIllegalSyntaxException e) {
+            assertEquals(27, e.getIndex());
         }
 
         try {
             assertPredicate("${in.header.foo} not range 100.200", false);
             fail("Should have thrown an exception");
-        } catch (IllegalArgumentException e) {
-            assertTrue(e.getMessage().startsWith("Syntax error"));
+        } catch (SimpleIllegalSyntaxException e) {
+            assertEquals(30, e.getIndex());
         }
     }
 

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleOperatorTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserExpressionInvalidTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserExpressionInvalidTest.java?rev=1167462&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserExpressionInvalidTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserExpressionInvalidTest.java Sat Sep 10 05:43:14 2011
@@ -0,0 +1,56 @@
+/**
+ * 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.language.simple;
+
+import org.apache.camel.ExchangeTestSupport;
+
+/**
+ *
+ */
+public class SimpleParserExpressionInvalidTest extends ExchangeTestSupport {
+
+    public void testSimpleFunctionInvalid() throws Exception {
+        SimpleExpressionParser parser = new SimpleExpressionParser("${body${foo}}");
+        try {
+            parser.parseExpression();
+            fail("Should thrown exception");
+        } catch (SimpleIllegalSyntaxException e) {
+            assertEquals(6, e.getIndex());
+        }
+    }
+
+    public void testSimpleUnbalanceFunction() throws Exception {
+        SimpleExpressionParser parser = new SimpleExpressionParser("${body is a nice day");
+        try {
+            parser.parseExpression();
+            fail("Should thrown exception");
+        } catch (SimpleIllegalSyntaxException e) {
+            assertEquals(19, e.getIndex());
+        }
+    }
+
+    public void testSimpleUnknownFunction() throws Exception {
+        SimpleExpressionParser parser = new SimpleExpressionParser("Hello ${foo} how are you?");
+        try {
+            parser.parseExpression();
+            fail("Should thrown exception");
+        } catch (SimpleIllegalSyntaxException e) {
+            assertEquals(6, e.getIndex());
+        }
+    }
+
+}

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserExpressionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserExpressionTest.java?rev=1167462&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserExpressionTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserExpressionTest.java Sat Sep 10 05:43:14 2011
@@ -0,0 +1,111 @@
+/**
+ * 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.language.simple;
+
+import org.apache.camel.ExchangeTestSupport;
+import org.apache.camel.Expression;
+
+/**
+ *
+ */
+public class SimpleParserExpressionTest extends ExchangeTestSupport {
+
+    public void testSimpleParserEol() throws Exception {
+        SimpleExpressionParser parser = new SimpleExpressionParser("Hello");
+        Expression exp = parser.parseExpression();
+
+        assertEquals("Hello", exp.evaluate(exchange, String.class));
+    }
+
+    public void testSimpleSingleQuote() throws Exception {
+        SimpleExpressionParser parser = new SimpleExpressionParser("'Hello'");
+        Expression exp = parser.parseExpression();
+
+        assertEquals("'Hello'", exp.evaluate(exchange, String.class));
+    }
+
+    public void testSimpleSingleQuoteWithFunction() throws Exception {
+        exchange.getIn().setBody("World");
+        SimpleExpressionParser parser = new SimpleExpressionParser("'Hello ${body} how are you?'");
+        Expression exp = parser.parseExpression();
+
+        assertEquals("'Hello World how are you?'", exp.evaluate(exchange, String.class));
+    }
+
+    public void testSimpleSingleQuoteWithFunctionBodyAs() throws Exception {
+        exchange.getIn().setBody("World");
+        SimpleExpressionParser parser = new SimpleExpressionParser("'Hello ${bodyAs(String)} how are you?'");
+        Expression exp = parser.parseExpression();
+
+        assertEquals("'Hello World how are you?'", exp.evaluate(exchange, String.class));
+    }
+
+    public void testSimpleSingleQuoteEol() throws Exception {
+        SimpleExpressionParser parser = new SimpleExpressionParser("'Hello' World");
+        Expression exp = parser.parseExpression();
+
+        assertEquals("'Hello' World", exp.evaluate(exchange, String.class));
+    }
+
+    public void testSimpleFunction() throws Exception {
+        exchange.getIn().setBody("World");
+        SimpleExpressionParser parser = new SimpleExpressionParser("${body}");
+        Expression exp = parser.parseExpression();
+
+        assertEquals("World", exp.evaluate(exchange, String.class));
+    }
+
+    public void testSimpleSingleQuoteWithEscape() throws Exception {
+        SimpleExpressionParser parser = new SimpleExpressionParser("Pay 200\\$ today");
+        Expression exp = parser.parseExpression();
+
+        assertEquals("Pay 200$ today", exp.evaluate(exchange, String.class));
+    }
+
+    public void testSimpleSingleQuoteWithEscapeEnd() throws Exception {
+        SimpleExpressionParser parser = new SimpleExpressionParser("Pay 200\\$");
+        Expression exp = parser.parseExpression();
+
+        assertEquals("Pay 200$", exp.evaluate(exchange, String.class));
+    }
+
+    public void testSimpleUnaryInc() throws Exception {
+        exchange.getIn().setBody("122");
+        SimpleExpressionParser parser = new SimpleExpressionParser("${body}++");
+        Expression exp = parser.parseExpression();
+
+        assertEquals("123", exp.evaluate(exchange, String.class));
+    }
+
+    public void testSimpleUnaryDec() throws Exception {
+        exchange.getIn().setBody("122");
+        SimpleExpressionParser parser = new SimpleExpressionParser("${body}--");
+        Expression exp = parser.parseExpression();
+
+        assertEquals("121", exp.evaluate(exchange, String.class));
+    }
+
+    public void testSimpleEscape() throws Exception {
+        exchange.getIn().setBody("World");
+        // we escape the $ which mean it will not be a function
+        SimpleExpressionParser parser = new SimpleExpressionParser("Hello \\${body\\} how are you?");
+        Expression exp = parser.parseExpression();
+
+        assertEquals("Hello ${body} how are you?", exp.evaluate(exchange, String.class));
+    }
+
+}

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserPredicateInvalidTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserPredicateInvalidTest.java?rev=1167462&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserPredicateInvalidTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserPredicateInvalidTest.java Sat Sep 10 05:43:14 2011
@@ -0,0 +1,112 @@
+/**
+ * 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.language.simple;
+
+import org.apache.camel.ExchangeTestSupport;
+
+/**
+ *
+ */
+public class SimpleParserPredicateInvalidTest extends ExchangeTestSupport {
+
+    public void testSimpleEqFunctionInvalid() throws Exception {
+        exchange.getIn().setBody("Hello");
+        exchange.getIn().setHeader("high", true);
+
+        SimplePredicateParser parser = new SimplePredicateParser("${header.high} == abc");
+        try {
+            parser.parsePredicate();
+            fail("Should thrown exception");
+        } catch (SimpleIllegalSyntaxException e) {
+            assertEquals(18, e.getIndex());
+        }
+    }
+
+    public void testSimpleInvalidSymbol() throws Exception {
+        exchange.getIn().setBody("Hello");
+        exchange.getIn().setHeader("high", true);
+
+        SimplePredicateParser parser = new SimplePredicateParser("${header.high} = true");
+        try {
+            parser.parsePredicate();
+            fail("Should thrown exception");
+        } catch (SimpleIllegalSyntaxException e) {
+            assertEquals(15, e.getIndex());
+        }
+    }
+
+    public void testSimpleUnevenSingleQuote() throws Exception {
+        exchange.getIn().setBody("foo");
+
+        SimplePredicateParser parser = new SimplePredicateParser("${body} == 'foo");
+        try {
+            parser.parsePredicate();
+            fail("Should thrown exception");
+        } catch (SimpleIllegalSyntaxException e) {
+            assertEquals(14, e.getIndex());
+        }
+    }
+
+    public void testSimpleUnevenDoubleQuote() throws Exception {
+        exchange.getIn().setBody("foo");
+
+        SimplePredicateParser parser = new SimplePredicateParser("${body} == \"foo");
+        try {
+            parser.parsePredicate();
+            fail("Should thrown exception");
+        } catch (SimpleIllegalSyntaxException e) {
+            assertEquals(14, e.getIndex());
+        }
+    }
+
+    public void testSimpleTwoAnd() throws Exception {
+        exchange.getIn().setBody("foo");
+
+        SimplePredicateParser parser = new SimplePredicateParser("${body} == 'foo' && && ${header} == 123");
+        try {
+            parser.parsePredicate();
+            fail("Should thrown exception");
+        } catch (SimpleIllegalSyntaxException e) {
+            assertEquals(20, e.getIndex());
+        }
+    }
+
+    public void testSimpleTwoOr() throws Exception {
+        exchange.getIn().setBody("foo");
+
+        SimplePredicateParser parser = new SimplePredicateParser("${body} == 'foo' || || ${header} == 123");
+        try {
+            parser.parsePredicate();
+            fail("Should thrown exception");
+        } catch (SimpleIllegalSyntaxException e) {
+            assertEquals(20, e.getIndex());
+        }
+    }
+
+    public void testSimpleTwoEq() throws Exception {
+        exchange.getIn().setBody("foo");
+
+        SimplePredicateParser parser = new SimplePredicateParser("${body} == == 'foo'");
+        try {
+            parser.parsePredicate();
+            fail("Should thrown exception");
+        } catch (SimpleIllegalSyntaxException e) {
+            assertEquals(11, e.getIndex());
+        }
+    }
+
+}

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserPredicateTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserPredicateTest.java?rev=1167462&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserPredicateTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserPredicateTest.java Sat Sep 10 05:43:14 2011
@@ -0,0 +1,181 @@
+/**
+ * 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.language.simple;
+
+import org.apache.camel.ExchangeTestSupport;
+import org.apache.camel.Predicate;
+
+/**
+ *
+ */
+public class SimpleParserPredicateTest extends ExchangeTestSupport {
+
+    public void testSimpleEq() throws Exception {
+        exchange.getIn().setBody("foo");
+
+        SimplePredicateParser parser = new SimplePredicateParser("${body} == 'foo'");
+        Predicate pre = parser.parsePredicate();
+
+        assertTrue(pre.matches(exchange));
+    }
+
+    public void testSimpleEqNumeric() throws Exception {
+        exchange.getIn().setBody(123);
+
+        SimplePredicateParser parser = new SimplePredicateParser("${body} == 123");
+        Predicate pre = parser.parsePredicate();
+
+        assertTrue("Should match", pre.matches(exchange));
+    }
+
+    public void testSimpleEqFunctionFunction() throws Exception {
+        exchange.getIn().setBody(122);
+        exchange.getIn().setHeader("val", 122);
+
+        SimplePredicateParser parser = new SimplePredicateParser("${body} == ${header.val}");
+        Predicate pre = parser.parsePredicate();
+
+        assertTrue("Should match", pre.matches(exchange));
+    }
+
+    public void testSimpleEqFunctionNumeric() throws Exception {
+        exchange.getIn().setBody(122);
+
+        SimplePredicateParser parser = new SimplePredicateParser("${body} == 122");
+        Predicate pre = parser.parsePredicate();
+
+        assertTrue("Should match", pre.matches(exchange));
+    }
+
+    public void testSimpleGtFunctionNumeric() throws Exception {
+        exchange.getIn().setBody(122);
+
+        SimplePredicateParser parser = new SimplePredicateParser("${body} > 120");
+        Predicate pre = parser.parsePredicate();
+
+        assertTrue("Should match", pre.matches(exchange));
+    }
+
+    public void testSimpleUnaryInc() throws Exception {
+        exchange.getIn().setBody(122);
+
+        SimplePredicateParser parser = new SimplePredicateParser("${body}++ == 123");
+        Predicate pre = parser.parsePredicate();
+
+        assertTrue("Should match", pre.matches(exchange));
+    }
+
+    public void testSimpleUnaryDec() throws Exception {
+        exchange.getIn().setBody(122);
+
+        SimplePredicateParser parser = new SimplePredicateParser("${body}-- == 121");
+        Predicate pre = parser.parsePredicate();
+
+        assertTrue("Should match", pre.matches(exchange));
+    }
+
+    public void testSimpleEqFunctionBoolean() throws Exception {
+        exchange.getIn().setBody("Hello");
+        exchange.getIn().setHeader("high", true);
+
+        SimplePredicateParser parser = new SimplePredicateParser("${header.high} == true");
+        Predicate pre = parser.parsePredicate();
+
+        assertTrue("Should match", pre.matches(exchange));
+    }
+
+    public void testSimpleEqFunctionBooleanSpaces() throws Exception {
+        exchange.getIn().setBody("Hello");
+        exchange.getIn().setHeader("high", true);
+
+        SimplePredicateParser parser = new SimplePredicateParser("${header.high}   ==     true");
+        Predicate pre = parser.parsePredicate();
+
+        assertTrue("Should match", pre.matches(exchange));
+    }
+
+    public void testSimpleLogicalAnd() throws Exception {
+        exchange.getIn().setBody("Hello");
+        exchange.getIn().setHeader("high", true);
+        exchange.getIn().setHeader("foo", 123);
+
+        SimplePredicateParser parser = new SimplePredicateParser("${header.high} == true && ${header.foo} == 123");
+        Predicate pre = parser.parsePredicate();
+
+        assertTrue("Should match", pre.matches(exchange));
+    }
+
+    public void testSimpleLogicalOr() throws Exception {
+        exchange.getIn().setBody("Hello");
+        exchange.getIn().setHeader("high", true);
+        exchange.getIn().setHeader("foo", 123);
+
+        SimplePredicateParser parser = new SimplePredicateParser("${header.high} == false || ${header.foo} == 123");
+        Predicate pre = parser.parsePredicate();
+
+        assertTrue("Should match", pre.matches(exchange));
+    }
+
+    public void testSimpleLogicalAndAnd() throws Exception {
+        exchange.getIn().setBody("Hello");
+        exchange.getIn().setHeader("high", true);
+        exchange.getIn().setHeader("foo", 123);
+        exchange.getIn().setHeader("bar", "beer");
+
+        SimplePredicateParser parser = new SimplePredicateParser("${header.high} == true && ${header.foo} == 123 && ${header.bar} == 'beer'");
+        Predicate pre = parser.parsePredicate();
+
+        assertTrue("Should match", pre.matches(exchange));
+    }
+
+    public void testSimpleManyAndLogical() throws Exception {
+        exchange.getIn().setBody("Hello");
+
+        StringBuilder sb = new StringBuilder();
+        for (int i = 0; i < 10; i++) {
+            exchange.getIn().setHeader("foo" + i, i);
+            sb.append("${header.foo").append(i).append("} == ").append(i);
+            if (i < 9) {
+                sb.append(" && ");
+            }
+        }
+
+        SimplePredicateParser parser = new SimplePredicateParser(sb.toString());
+        Predicate pre = parser.parsePredicate();
+
+        assertTrue("Should match", pre.matches(exchange));
+    }
+
+    public void testSimpleManyOrLogical() throws Exception {
+        exchange.getIn().setBody("Hello");
+
+        StringBuilder sb = new StringBuilder();
+        for (int i = 0; i < 10; i++) {
+            sb.append("${header.foo").append(i).append("} == ").append(i);
+            if (i < 9) {
+                sb.append(" || ");
+            }
+        }
+        sb.append(" || ${body} == 'Hello'");
+
+        SimplePredicateParser parser = new SimplePredicateParser(sb.toString());
+        Predicate pre = parser.parsePredicate();
+
+        assertTrue("Should match", pre.matches(exchange));
+    }
+
+}

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserRegexpPredicateTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserRegexpPredicateTest.java?rev=1167462&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserRegexpPredicateTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserRegexpPredicateTest.java Sat Sep 10 05:43:14 2011
@@ -0,0 +1,37 @@
+/**
+ * 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.language.simple;
+
+import org.apache.camel.ExchangeTestSupport;
+import org.apache.camel.Predicate;
+
+/**
+ * Unit test regexp function as the reg exp value should be template text only
+ * and not any embedded functions etc.
+ */
+public class SimpleParserRegexpPredicateTest extends ExchangeTestSupport {
+
+    public void testSimpleRegexp() throws Exception {
+        exchange.getIn().setBody("12.34.5678");
+
+        SimplePredicateParser parser = new SimplePredicateParser("${body} regex '^\\d{2}\\.\\d{2}\\.\\d{4}$'");
+        Predicate pre = parser.parsePredicate();
+
+        assertTrue(pre.matches(exchange));
+    }
+
+}

Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java (from r1167201, camel/trunk/camel-core/src/test/java/org/apache/camel/language/SimpleTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/language/SimpleTest.java&r1=1167201&r2=1167462&rev=1167462&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/language/SimpleTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java Sat Sep 10 05:43:14 2011
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.language;
+package org.apache.camel.language.simple;
 
 import java.util.ArrayList;
 import java.util.Calendar;
@@ -34,7 +34,6 @@ import org.apache.camel.LanguageTestSupp
 import org.apache.camel.component.bean.MethodNotFoundException;
 import org.apache.camel.impl.JndiRegistry;
 import org.apache.camel.language.bean.RuntimeBeanExpressionException;
-import org.apache.camel.language.simple.SimpleLanguage;
 import org.apache.camel.spi.Language;
 
 /**
@@ -246,7 +245,7 @@ public class SimpleTest extends Language
             assertExpression("${property.foobar[bar}", null);
             fail("Should have thrown an exception");
         } catch (ExpressionIllegalSyntaxException e) {
-            assertEquals("Illegal syntax: Valid syntax: ${property.OGNL} was: property.foobar[bar", e.getMessage());
+            assertTrue(e.getMessage().startsWith("Valid syntax: ${property.OGNL} was: property.foobar[bar at location 0"));
         }
     }
 
@@ -260,8 +259,8 @@ public class SimpleTest extends Language
         try {
             assertExpression("date:yyyyMMdd", "19740420");
             fail("Should thrown an exception");
-        } catch (ExpressionIllegalSyntaxException e) {
-            // expected
+        } catch (SimpleParserException e) {
+            assertEquals("Valid syntax: ${date:command:pattern} was: date:yyyyMMdd", e.getMessage());
         }
     }
 
@@ -306,8 +305,8 @@ public class SimpleTest extends Language
         try {
             assertExpression("hey ${foo", "bad expression!");
             fail("Should have thrown an exception!");
-        } catch (IllegalArgumentException e) {
-            log.debug("Caught expected exception: " + e, e);
+        } catch (SimpleIllegalSyntaxException e) {
+            assertEquals(8, e.getIndex());
         }
     }
 
@@ -404,10 +403,10 @@ public class SimpleTest extends Language
         exchange.getIn().setBody(null);
 
         try {
-            assertExpression("${body} is null", false);
+            assertPredicate("${body} is null", false);
             fail("Should have thrown an exception");
-        } catch (IllegalArgumentException e) {
-            assertEquals("Syntax error in is operator: ${body} is null cannot be null. It must be a class type.", e.getMessage());
+        } catch (SimpleIllegalSyntaxException e) {
+            assertEquals(11, e.getIndex());
         }
     }
 
@@ -438,7 +437,7 @@ public class SimpleTest extends Language
             assertExpression("${headerAs(unknown String)}", null);
             fail("Should have thrown an exception");
         } catch (ExpressionIllegalSyntaxException e) {
-            assertEquals("Illegal syntax: Valid syntax: ${headerAs(key, type)} was: headerAs(unknown String)", e.getMessage());
+            assertTrue(e.getMessage().startsWith("Valid syntax: ${headerAs(key, type)} was: headerAs(unknown String)"));
         }
 
         try {
@@ -454,21 +453,21 @@ public class SimpleTest extends Language
             assertExpression("hey ${xxx} how are you?", "");
             fail("Should have thrown an exception");
         } catch (ExpressionIllegalSyntaxException e) {
-            assertEquals("Illegal syntax: xxx", e.getMessage());
+            assertTrue(e.getMessage().startsWith("Unknown function: xxx at location 4"));
         }
 
         try {
             assertExpression("${xxx}", "");
             fail("Should have thrown an exception");
         } catch (ExpressionIllegalSyntaxException e) {
-            assertEquals("Illegal syntax: xxx", e.getMessage());
+            assertTrue(e.getMessage().startsWith("Unknown function: xxx at location 0"));
         }
 
         try {
             assertExpression("${bodyAs(xxx}", "");
             fail("Should have thrown an exception");
         } catch (ExpressionIllegalSyntaxException e) {
-            assertEquals("Illegal syntax: Valid syntax: ${bodyAs(type)} was: bodyAs(xxx", e.getMessage());
+            assertTrue(e.getMessage().startsWith("Valid syntax: ${bodyAs(type)} was: bodyAs(xxx"));
         }
     }
 
@@ -547,7 +546,7 @@ public class SimpleTest extends Language
             assertExpression("${header.foo[bar}", null);
             fail("Should have thrown an exception");
         } catch (ExpressionIllegalSyntaxException e) {
-            assertEquals("Illegal syntax: Valid syntax: ${header.name[key]} was: header.foo[bar", e.getMessage());
+            assertTrue(e.getMessage().startsWith("Valid syntax: ${header.name[key]} was: header.foo[bar"));
         }
     }
 
@@ -609,15 +608,15 @@ public class SimpleTest extends Language
 
         exchange.getIn().setBody(camel);
 
-        assertExpression("${in.body.getName} contains 'Camel'", true);
-        assertExpression("${in.body.getName} contains 'Tiger'", false);
-        assertExpression("${in.body.getAge} < 10", true);
-        assertExpression("${in.body.getAge} > 10", false);
-        assertExpression("${in.body.getAge} <= '6'", true);
-        assertExpression("${in.body.getAge} > '6'", false);
+        assertPredicate("${in.body.getName} contains 'Camel'", true);
+        assertPredicate("${in.body.getName} contains 'Tiger'", false);
+        assertPredicate("${in.body.getAge} < 10", true);
+        assertPredicate("${in.body.getAge} > 10", false);
+        assertPredicate("${in.body.getAge} <= '6'", true);
+        assertPredicate("${in.body.getAge} > '6'", false);
 
-        assertExpression("${in.body.getAge} < ${body.getFriend.getAge}'", true);
-        assertExpression("${in.body.getFriend.isDangerous} == true", true);
+        assertPredicate("${in.body.getAge} < ${body.getFriend.getAge}", true);
+        assertPredicate("${in.body.getFriend.isDangerous} == true", true);
     }
 
     public void testBodyOGNLSimpleOperatorShorthand() throws Exception {
@@ -627,15 +626,15 @@ public class SimpleTest extends Language
 
         exchange.getIn().setBody(camel);
 
-        assertExpression("${in.body.name} contains 'Camel'", true);
-        assertExpression("${in.body.name} contains 'Tiger'", false);
-        assertExpression("${in.body.age} < 10", true);
-        assertExpression("${in.body.age} > 10", false);
-        assertExpression("${in.body.age} <= '6'", true);
-        assertExpression("${in.body.age} > '6'", false);
+        assertPredicate("${in.body.name} contains 'Camel'", true);
+        assertPredicate("${in.body.name} contains 'Tiger'", false);
+        assertPredicate("${in.body.age} < 10", true);
+        assertPredicate("${in.body.age} > 10", false);
+        assertPredicate("${in.body.age} <= '6'", true);
+        assertPredicate("${in.body.age} > '6'", false);
 
-        assertExpression("${in.body.age} < ${body.friend.age}'", true);
-        assertExpression("${in.body.friend.dangerous} == true", true);
+        assertPredicate("${in.body.age} < ${body.friend.age}", true);
+        assertPredicate("${in.body.friend.dangerous} == true", true);
     }
 
     public void testBodyOGNLNested() throws Exception {

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date