camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject git commit: Added some tests for the predicate of jsonpath
Date Wed, 13 Aug 2014 01:53:55 GMT
Repository: camel
Updated Branches:
  refs/heads/master c46be6a3d -> ee5550732


Added some tests for the predicate of jsonpath


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ee555073
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ee555073
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ee555073

Branch: refs/heads/master
Commit: ee55507323daff1ba058c8535915b4b3cb931faf
Parents: c46be6a
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Wed Aug 13 09:52:12 2014 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Wed Aug 13 09:52:28 2014 +0800

----------------------------------------------------------------------
 .../apache/camel/jsonpath/JsonPathCBRTest.java  | 24 ++++++++++++++++++++
 .../camel/jsonpath/JsonPathLanguageTest.java    |  6 +++++
 2 files changed, 30 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/ee555073/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathCBRTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathCBRTest.java
b/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathCBRTest.java
index 358c173..8638133 100644
--- a/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathCBRTest.java
+++ b/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathCBRTest.java
@@ -37,9 +37,33 @@ public class JsonPathCBRTest extends CamelTestSupport {
                             .to("mock:average")
                         .otherwise()
                             .to("mock:expensive");
+                
+                from("direct:bicycle")
+                    .choice()
+                        .when().method(new BeanPredicate())
+                            .to("mock:cheap")
+                        .otherwise()
+                            .to("mock:expensive");
             }
         };
     }
+    
+    public static class BeanPredicate {
+        public boolean checkPrice(@JsonPath("$.store.bicycle.price") double price) {
+            return price < 20;
+        }
+    }
+    
+    @Test
+    public void testCheapBicycle() throws Exception {
+        getMockEndpoint("mock:cheap").expectedMessageCount(1);
+        getMockEndpoint("mock:average").expectedMessageCount(0);
+        getMockEndpoint("mock:expensive").expectedMessageCount(0);
+
+        template.sendBody("direct:bicycle", new File("src/test/resources/cheap.json"));
+
+        assertMockEndpointsSatisfied();
+    }
 
     @Test
     public void testCheap() throws Exception {

http://git-wip-us.apache.org/repos/asf/camel/blob/ee555073/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathLanguageTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathLanguageTest.java
b/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathLanguageTest.java
index 7f886ff..0773760 100644
--- a/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathLanguageTest.java
+++ b/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathLanguageTest.java
@@ -48,6 +48,12 @@ public class JsonPathLanguageTest extends CamelTestSupport {
         assertEquals(2, authors.size());
         assertEquals("Nigel Rees", authors.get(0));
         assertEquals("Evelyn Waugh", authors.get(1));
+        
+        exp = lan.createExpression("$.store.bicycle.price");
+        String price = exp.evaluate(exchange, String.class);
+        assertEquals("Got a wrong result", "19.95", price);
+        
+        
     }
 
     @Test


Mime
View raw message