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

jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit 897b8e997da680895f2c8f62c25e52dfee858ecd
Author: James Netherton <jamesnether...@gmail.com>
AuthorDate: Thu Oct 17 07:48:11 2024 +0100

    Add tests for JQ built in functions
    
    Fixes #6651
---
 .../component/jq/deployment/JqProcessor.java       | 17 ----------
 .../quarkus/component/jq/CamelJqRecorder.java      | 35 --------------------
 .../apache/camel/quarkus/component/jq/it/Book.java | 14 ++++++--
 .../camel/quarkus/component/jq/it/JqResource.java  | 37 ++++++++++++++++++++++
 .../camel/quarkus/component/jq/it/JqRoutes.java    |  8 +++++
 .../camel/quarkus/component/jq/it/JqTest.java      | 16 ++++++++++
 6 files changed, 73 insertions(+), 54 deletions(-)

diff --git 
a/extensions/jq/deployment/src/main/java/org/apache/camel/quarkus/component/jq/deployment/JqProcessor.java
 
b/extensions/jq/deployment/src/main/java/org/apache/camel/quarkus/component/jq/deployment/JqProcessor.java
index 7da36e17f0..9364f3c808 100644
--- 
a/extensions/jq/deployment/src/main/java/org/apache/camel/quarkus/component/jq/deployment/JqProcessor.java
+++ 
b/extensions/jq/deployment/src/main/java/org/apache/camel/quarkus/component/jq/deployment/JqProcessor.java
@@ -16,14 +16,8 @@
  */
 package org.apache.camel.quarkus.component.jq.deployment;
 
-import io.quarkus.arc.deployment.BeanContainerBuildItem;
-import io.quarkus.arc.deployment.UnremovableBeanBuildItem;
 import io.quarkus.deployment.annotations.BuildStep;
-import io.quarkus.deployment.annotations.ExecutionTime;
-import io.quarkus.deployment.annotations.Record;
 import io.quarkus.deployment.builditem.FeatureBuildItem;
-import net.thisptr.jackson.jq.Scope;
-import org.apache.camel.quarkus.component.jq.CamelJqRecorder;
 
 class JqProcessor {
 
@@ -33,15 +27,4 @@ class JqProcessor {
     FeatureBuildItem feature() {
         return new FeatureBuildItem(FEATURE);
     }
-
-    @BuildStep
-    UnremovableBeanBuildItem unremovableBeans() {
-        return UnremovableBeanBuildItem.beanTypes(Scope.class);
-    }
-
-    @Record(ExecutionTime.STATIC_INIT)
-    @BuildStep
-    void addCamelFunctionsToScope(BeanContainerBuildItem beanContainer, 
CamelJqRecorder recorder) {
-        recorder.addCamelFunctionsToScope(beanContainer.getValue());
-    }
 }
diff --git 
a/extensions/jq/runtime/src/main/java/org/apache/camel/quarkus/component/jq/CamelJqRecorder.java
 
b/extensions/jq/runtime/src/main/java/org/apache/camel/quarkus/component/jq/CamelJqRecorder.java
deleted file mode 100644
index 97292a27f7..0000000000
--- 
a/extensions/jq/runtime/src/main/java/org/apache/camel/quarkus/component/jq/CamelJqRecorder.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.quarkus.component.jq;
-
-import io.quarkus.arc.runtime.BeanContainer;
-import io.quarkus.runtime.annotations.Recorder;
-import net.thisptr.jackson.jq.Scope;
-import org.apache.camel.language.jq.JqFunctions;
-
-@Recorder
-public class CamelJqRecorder {
-
-    public void addCamelFunctionsToScope(BeanContainer beanContainer) {
-        Scope scope = beanContainer.beanInstance(Scope.class);
-        if (scope != null) {
-            JqFunctions.loadLocal(scope);
-        } else {
-            throw new IllegalStateException("Scope bean could not be resolved. 
Unable to load Camel JQ functions.");
-        }
-    }
-}
diff --git 
a/integration-tests/jq/src/main/java/org/apache/camel/quarkus/component/jq/it/Book.java
 
b/integration-tests/jq/src/main/java/org/apache/camel/quarkus/component/jq/it/Book.java
index 2400faea27..53b1906cf4 100644
--- 
a/integration-tests/jq/src/main/java/org/apache/camel/quarkus/component/jq/it/Book.java
+++ 
b/integration-tests/jq/src/main/java/org/apache/camel/quarkus/component/jq/it/Book.java
@@ -24,6 +24,7 @@ import io.quarkus.runtime.annotations.RegisterForReflection;
 public class Book {
     private String author;
     private String title;
+    private Integer price;
 
     public Book() {
     }
@@ -49,6 +50,14 @@ public class Book {
         this.title = title;
     }
 
+    public Integer getPrice() {
+        return price;
+    }
+
+    public void setPrice(Integer price) {
+        this.price = price;
+    }
+
     @Override
     public boolean equals(Object o) {
         if (this == o) {
@@ -58,11 +67,12 @@ public class Book {
             return false;
         }
         Book book = (Book) o;
-        return Objects.equals(getAuthor(), book.getAuthor()) && 
Objects.equals(getTitle(), book.getTitle());
+        return Objects.equals(getAuthor(), book.getAuthor()) && 
Objects.equals(getTitle(), book.getTitle())
+                && Objects.equals(getPrice(), book.getPrice());
     }
 
     @Override
     public int hashCode() {
-        return Objects.hash(getAuthor(), getTitle());
+        return Objects.hash(getAuthor(), getTitle(), getPrice());
     }
 }
diff --git 
a/integration-tests/jq/src/main/java/org/apache/camel/quarkus/component/jq/it/JqResource.java
 
b/integration-tests/jq/src/main/java/org/apache/camel/quarkus/component/jq/it/JqResource.java
index e7a539cd45..00a64923f4 100644
--- 
a/integration-tests/jq/src/main/java/org/apache/camel/quarkus/component/jq/it/JqResource.java
+++ 
b/integration-tests/jq/src/main/java/org/apache/camel/quarkus/component/jq/it/JqResource.java
@@ -16,7 +16,9 @@
  */
 package org.apache.camel.quarkus.component.jq.it;
 
+import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.fasterxml.jackson.databind.node.TextNode;
 import jakarta.enterprise.context.ApplicationScoped;
@@ -154,4 +156,39 @@ public class JqResource {
 
         endpoint.assertIsSatisfied(5000);
     }
+
+    @Path("/filter/length")
+    @GET
+    public void filterLength() throws Exception {
+        MockEndpoint endpoint = context.getEndpoint("mock:filterLength", 
MockEndpoint.class);
+        ObjectNode expected = mapper.createObjectNode().put("value", "123456");
+        endpoint.expectedBodiesReceived(expected);
+
+        producerTemplate.sendBody("direct:filterLength", 
mapper.createObjectNode().put("value", "12345"));
+        producerTemplate.sendBody("direct:filterLength", 
mapper.createObjectNode().put("value", "123456"));
+
+        endpoint.assertIsSatisfied(5000);
+    }
+
+    @Path("/select")
+    @GET
+    public void select() throws Exception {
+        MockEndpoint endpoint = context.getEndpoint("mock:select", 
MockEndpoint.class);
+        endpoint.expectedBodiesReceived("[\"Title 2\",\"Title 3\"]");
+
+        ArrayNode arrayNode = mapper.createArrayNode();
+        for (int i = 1; i <= 3; i++) {
+            ObjectNode node = mapper.createObjectNode();
+            node.withObject("")
+                    .put("author", "Author " + i)
+                    .put("title", "Title " + i)
+                    .put("price", +i * 10);
+            arrayNode.add(node);
+        }
+
+        JsonNode books = 
mapper.createObjectNode().withObject("/books").set("books", arrayNode);
+        producerTemplate.sendBody("direct:select", books);
+
+        endpoint.assertIsSatisfied(5000);
+    }
 }
diff --git 
a/integration-tests/jq/src/main/java/org/apache/camel/quarkus/component/jq/it/JqRoutes.java
 
b/integration-tests/jq/src/main/java/org/apache/camel/quarkus/component/jq/it/JqRoutes.java
index 7552f64f3f..5b3b1172d5 100644
--- 
a/integration-tests/jq/src/main/java/org/apache/camel/quarkus/component/jq/it/JqRoutes.java
+++ 
b/integration-tests/jq/src/main/java/org/apache/camel/quarkus/component/jq/it/JqRoutes.java
@@ -56,5 +56,13 @@ public class JqRoutes extends RouteBuilder {
                 .filter().jq(".value == \"valid\"")
                 .to("mock:filter");
 
+        from("direct:filterLength")
+                .filter().jq(".value | length > 5")
+                .to("mock:filterLength");
+
+        from("direct:select")
+                .transform().jq(".books[] | select(.price > 10) | .title")
+                .convertBodyTo(String.class)
+                .to("mock:select");
     }
 }
diff --git 
a/integration-tests/jq/src/test/java/org/apache/camel/quarkus/component/jq/it/JqTest.java
 
b/integration-tests/jq/src/test/java/org/apache/camel/quarkus/component/jq/it/JqTest.java
index 68c3cecd0c..159bfa4d75 100644
--- 
a/integration-tests/jq/src/test/java/org/apache/camel/quarkus/component/jq/it/JqTest.java
+++ 
b/integration-tests/jq/src/test/java/org/apache/camel/quarkus/component/jq/it/JqTest.java
@@ -31,6 +31,22 @@ class JqTest {
                 .statusCode(204);
     }
 
+    @Test
+    public void filterLength() {
+        RestAssured.given()
+                .get("/jq/filter/length")
+                .then()
+                .statusCode(204);
+    }
+
+    @Test
+    public void select() {
+        RestAssured.given()
+                .get("/jq/select")
+                .then()
+                .statusCode(204);
+    }
+
     @Test
     public void expression() {
         RestAssured.given()

Reply via email to