Author: ningjiang
Date: Mon Dec 26 03:49:42 2011
New Revision: 1224673

URL: http://svn.apache.org/viewvc?rev=1224673&view=rev
Log:
Added unit tests based on the mailing list question

Added:
    
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/language/SpringSimpleRegexTest.java
   (with props)
    
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/language/springSimpleRegexContext.xml
   (with props)
Modified:
    
camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserPredicateTest.java
    
camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserRegexpPredicateTest.java

Modified: 
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=1224673&r1=1224672&r2=1224673&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserPredicateTest.java
 (original)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserPredicateTest.java
 Mon Dec 26 03:49:42 2011
@@ -177,5 +177,13 @@ public class SimpleParserPredicateTest e
 
         assertTrue("Should match", pre.matches(exchange));
     }
+    
+    public void testSimpleExpressionPredicate() throws Exception {
+        exchange.getIn().setBody("Hello");
+        exchange.getIn().setHeader("number", "1234");
+        SimplePredicateParser parser = new 
SimplePredicateParser("${in.header.number} regex '\\d{4}'");
+        Predicate pre = parser.parsePredicate();
+        assertTrue("Should match", pre.matches(exchange));
+    }
 
 }

Modified: 
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=1224673&r1=1224672&r2=1224673&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserRegexpPredicateTest.java
 (original)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/language/simple/SimpleParserRegexpPredicateTest.java
 Mon Dec 26 03:49:42 2011
@@ -32,6 +32,9 @@ public class SimpleParserRegexpPredicate
         Predicate pre = parser.parsePredicate();
 
         assertTrue(pre.matches(exchange));
+        
+        exchange.getIn().setBody("12.2a.22ab");
+        assertFalse(pre.matches(exchange));
     }
 
 }

Added: 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/language/SpringSimpleRegexTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/language/SpringSimpleRegexTest.java?rev=1224673&view=auto
==============================================================================
--- 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/language/SpringSimpleRegexTest.java
 (added)
+++ 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/language/SpringSimpleRegexTest.java
 Mon Dec 26 03:49:42 2011
@@ -0,0 +1,39 @@
+/**
+ * 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;
+
+import org.apache.camel.spring.SpringTestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class SpringSimpleRegexTest extends SpringTestSupport {
+
+    @Override
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new 
ClassPathXmlApplicationContext("org/apache/camel/language/springSimpleRegexContext.xml");
+    }
+    
+    public void testSimpleRegex() {
+        String result = template.requestBody("direct:start", "Something is 
wrong", String.class);
+        System.out.println("result : " + result);
+        
+        result = template.requestBody("direct:start", "12.34.5678", 
String.class);
+        System.out.println("result : " + result);
+    }
+    
+
+}

Propchange: 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/language/SpringSimpleRegexTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/language/SpringSimpleRegexTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/language/springSimpleRegexContext.xml
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/language/springSimpleRegexContext.xml?rev=1224673&view=auto
==============================================================================
--- 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/language/springSimpleRegexContext.xml
 (added)
+++ 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/language/springSimpleRegexContext.xml
 Mon Dec 26 03:49:42 2011
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+
+  <camelContext xmlns="http://camel.apache.org/schema/spring";>
+      <route>
+             <from uri="direct:start" />
+             <choice>
+                 <when>
+                     <simple>${body} regex '^\d{2}\.\d{2}\.\d{4}$'</simple>
+                         <setBody>
+                             <constant>Found the result.</constant>
+                         </setBody>
+                  </when>
+                  <otherwise>
+                     <setBody>
+                         <constant>Let's keep looking.</constant>
+                     </setBody>
+                  </otherwise>
+             </choice>
+      </route>
+  </camelContext>
+
+</beans>

Propchange: 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/language/springSimpleRegexContext.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/language/springSimpleRegexContext.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/language/springSimpleRegexContext.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml


Reply via email to