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 2023/08/04 15:26:38 UTC

[camel] 01/01: CAMEL-19714: camel-jsonpath - Need to have json-smart as dependency for predicates to work.

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch jsonsmart
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 71b46b098a5998dc8a225d4575a2f48f3d116fd3
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Aug 4 17:26:24 2023 +0200

    CAMEL-19714: camel-jsonpath - Need to have json-smart as dependency for predicates to work.
---
 components/camel-jsonpath/pom.xml                  | 11 +++--
 .../jsonpath/JsonPathPredicateJsonSmartTest.java   | 48 ++++++++++++++++++++++
 .../src/test/resources/messages.json               | 17 ++++++++
 parent/pom.xml                                     |  1 +
 4 files changed, 71 insertions(+), 6 deletions(-)

diff --git a/components/camel-jsonpath/pom.xml b/components/camel-jsonpath/pom.xml
index 63bb954c481..fec0baf83e5 100644
--- a/components/camel-jsonpath/pom.xml
+++ b/components/camel-jsonpath/pom.xml
@@ -46,16 +46,15 @@
             <artifactId>camel-file</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>net.minidev</groupId>
+            <artifactId>json-smart</artifactId>
+            <version>${json-smart-version}</version>
+        </dependency>
         <dependency>
             <groupId>com.jayway.jsonpath</groupId>
             <artifactId>json-path</artifactId>
             <version>${json-path-version}</version>
-            <exclusions>
-                <exclusion>
-                    <groupId>net.minidev</groupId>
-                    <artifactId>json-smart</artifactId>
-                </exclusion>
-            </exclusions>
         </dependency>
         <dependency>
             <groupId>com.fasterxml.jackson.core</groupId>
diff --git a/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathPredicateJsonSmartTest.java b/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathPredicateJsonSmartTest.java
new file mode 100644
index 00000000000..8690f49f0bb
--- /dev/null
+++ b/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathPredicateJsonSmartTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.jsonpath;
+
+import java.io.File;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Predicate;
+import org.apache.camel.spi.Language;
+import org.apache.camel.support.DefaultExchange;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class JsonPathPredicateJsonSmartTest extends CamelTestSupport {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    @Test
+    public void testPredicate() {
+        Exchange exchange = new DefaultExchange(context);
+        exchange.getIn().setBody(new File("src/test/resources/messages.json"));
+
+        Language lan = context.resolveLanguage("jsonpath");
+        Predicate pre = lan.createPredicate("$.messages[?(!@.bot_id)]");
+        boolean bot = pre.matches(exchange);
+        assertTrue(bot, "Should have message from bot");
+    }
+
+}
diff --git a/components/camel-jsonpath/src/test/resources/messages.json b/components/camel-jsonpath/src/test/resources/messages.json
new file mode 100644
index 00000000000..1b099d19b4d
--- /dev/null
+++ b/components/camel-jsonpath/src/test/resources/messages.json
@@ -0,0 +1,17 @@
+{
+  "messages": [
+    {
+      "id": 1,
+      "text": "Hello, this is a message from a user."
+    },
+    {
+      "id": 2,
+      "text": "This is another message from a user."
+    },
+    {
+      "id": 3,
+      "text": "This message is from a bot.",
+      "bot_id": "123"
+    }
+  ]
+}
\ No newline at end of file
diff --git a/parent/pom.xml b/parent/pom.xml
index 6762952f9f5..e311c13ff99 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -283,6 +283,7 @@
         <jsonassert-version>1.5.1</jsonassert-version>
         <json-path-version>2.8.0</json-path-version>
         <json-patch-version>1.13</json-patch-version>
+        <json-smart-version>2.5.0</json-smart-version>
         <jsonata4java-version>2.4.3</jsonata4java-version>
         <json-schema-validator-version>2.2.14</json-schema-validator-version>
         <json-unit-version>3.0.0</json-unit-version>