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


The following commit(s) were added to refs/heads/main by this push:
     new 828dca6ed6a Make SimpleFunction beans unremovable and test Simple 
custom functions
828dca6ed6a is described below

commit 828dca6ed6ac6b23495d1e9182d64a11a0fb6575
Author: James Netherton <[email protected]>
AuthorDate: Sat Nov 28 07:42:34 2026 +0000

    Make SimpleFunction beans unremovable and test Simple custom functions
    
    SimpleFunction beans are looked up from the Camel registry by type when a
    Simple expression references them, so ArC removed them as unused and route
    creation failed with "No custom simple function with name".
    
    Add test coverage for custom functions provided as CDI beans and registered
    programmatically via SimpleFunctionRegistry.
    
    Co-authored-by: Claude Opus 5.5 <[email protected]>
---
 .../core/deployment/CamelBeansProcessor.java       |  5 +-
 .../languages/it/ReverseTextSimpleFunction.java    | 36 ++++++++++++
 .../languages/it/SimpleCustomFunctionRoutes.java   | 66 ++++++++++++++++++++++
 .../core/languages/it/SimpleCustomFunctionIT.java  | 24 ++++++++
 .../languages/it/SimpleCustomFunctionTest.java     | 62 ++++++++++++++++++++
 5 files changed, 192 insertions(+), 1 deletion(-)

diff --git 
a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelBeansProcessor.java
 
b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelBeansProcessor.java
index 85ff7e04552..18ca65a8b18 100644
--- 
a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelBeansProcessor.java
+++ 
b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelBeansProcessor.java
@@ -70,6 +70,8 @@ class CamelBeansProcessor {
             "org.apache.camel.Producer");
     private static final DotName PREDICATE_TYPE = DotName.createSimple(
             "org.apache.camel.Predicate");
+    private static final DotName SIMPLE_FUNCTION_TYPE = DotName.createSimple(
+            "org.apache.camel.spi.SimpleFunction");
 
     private static final Set<DotName> UNREMOVABLE_BEANS_TYPES = 
CamelSupport.setOf(
             ROUTES_BUILDER_TYPE,
@@ -79,7 +81,8 @@ class CamelBeansProcessor {
             LANGUAGE_TYPE,
             COMPONENT_TYPE,
             PRODUCER_TYPE,
-            PREDICATE_TYPE);
+            PREDICATE_TYPE,
+            SIMPLE_FUNCTION_TYPE);
 
     private static final DotName[] CATALOG_SCHEMA_TYPES = {
             DotName.createSimple(Component.class.getName()),
diff --git 
a/integration-test-groups/foundation/core-languages/src/main/java/org/apache/camel/quarkus/core/languages/it/ReverseTextSimpleFunction.java
 
b/integration-test-groups/foundation/core-languages/src/main/java/org/apache/camel/quarkus/core/languages/it/ReverseTextSimpleFunction.java
new file mode 100644
index 00000000000..3203c71798b
--- /dev/null
+++ 
b/integration-test-groups/foundation/core-languages/src/main/java/org/apache/camel/quarkus/core/languages/it/ReverseTextSimpleFunction.java
@@ -0,0 +1,36 @@
+/*
+ * 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.core.languages.it;
+
+import jakarta.enterprise.context.ApplicationScoped;
+import org.apache.camel.Exchange;
+import org.apache.camel.spi.SimpleFunction;
+
+@ApplicationScoped
+public class ReverseTextSimpleFunction implements SimpleFunction {
+
+    @Override
+    public String getName() {
+        return "reverseText";
+    }
+
+    @Override
+    public Object apply(Exchange exchange, Object input) {
+        return new 
StringBuilder(exchange.getContext().getTypeConverter().convertTo(String.class, 
input)).reverse()
+                .toString();
+    }
+}
diff --git 
a/integration-test-groups/foundation/core-languages/src/main/java/org/apache/camel/quarkus/core/languages/it/SimpleCustomFunctionRoutes.java
 
b/integration-test-groups/foundation/core-languages/src/main/java/org/apache/camel/quarkus/core/languages/it/SimpleCustomFunctionRoutes.java
new file mode 100644
index 00000000000..75b155fa00d
--- /dev/null
+++ 
b/integration-test-groups/foundation/core-languages/src/main/java/org/apache/camel/quarkus/core/languages/it/SimpleCustomFunctionRoutes.java
@@ -0,0 +1,66 @@
+/*
+ * 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.core.languages.it;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spi.SimpleFunction;
+import org.apache.camel.spi.SimpleFunctionRegistry;
+import org.apache.camel.support.ExpressionAdapter;
+import org.apache.camel.support.PluginHelper;
+
+public class SimpleCustomFunctionRoutes extends RouteBuilder {
+
+    @Override
+    public void configure() {
+        SimpleFunctionRegistry registry = 
PluginHelper.getSimpleFunctionRegistry(getContext());
+
+        registry.addFunction(new SimpleFunction() {
+            @Override
+            public String getName() {
+                return "greet";
+            }
+
+            @Override
+            public Object apply(Exchange exchange, Object input) {
+                return "Hello " + input;
+            }
+        });
+
+        registry.addFunction("shout", new ExpressionAdapter() {
+            @Override
+            public Object evaluate(Exchange exchange) {
+                return 
exchange.getMessage().getBody(String.class).toUpperCase() + "!";
+            }
+        });
+
+        from("direct:simpleCustomFunctionBean")
+                .transform().simple("${function(reverseText)}");
+
+        from("direct:simpleCustomFunctionBeanShorthand")
+                .transform().simple("${reverseText(${header.text})}");
+
+        from("direct:simpleCustomFunction")
+                .transform().simple("${function(greet)}");
+
+        from("direct:simpleCustomFunctionWithParameter")
+                .transform().simple("${function(greet,${header.name})}");
+
+        from("direct:simpleCustomFunctionExpression")
+                .transform().simple("${shout()}");
+    }
+}
diff --git 
a/integration-test-groups/foundation/core-languages/src/test/java/org/apache/camel/quarkus/core/languages/it/SimpleCustomFunctionIT.java
 
b/integration-test-groups/foundation/core-languages/src/test/java/org/apache/camel/quarkus/core/languages/it/SimpleCustomFunctionIT.java
new file mode 100644
index 00000000000..f8838d76842
--- /dev/null
+++ 
b/integration-test-groups/foundation/core-languages/src/test/java/org/apache/camel/quarkus/core/languages/it/SimpleCustomFunctionIT.java
@@ -0,0 +1,24 @@
+/*
+ * 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.core.languages.it;
+
+import io.quarkus.test.junit.QuarkusIntegrationTest;
+
+@QuarkusIntegrationTest
+class SimpleCustomFunctionIT extends SimpleCustomFunctionTest {
+
+}
diff --git 
a/integration-test-groups/foundation/core-languages/src/test/java/org/apache/camel/quarkus/core/languages/it/SimpleCustomFunctionTest.java
 
b/integration-test-groups/foundation/core-languages/src/test/java/org/apache/camel/quarkus/core/languages/it/SimpleCustomFunctionTest.java
new file mode 100644
index 00000000000..ce7cabe7119
--- /dev/null
+++ 
b/integration-test-groups/foundation/core-languages/src/test/java/org/apache/camel/quarkus/core/languages/it/SimpleCustomFunctionTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.core.languages.it;
+
+import io.quarkus.test.junit.QuarkusTest;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.CoreMatchers.is;
+
+@QuarkusTest
+class SimpleCustomFunctionTest {
+
+    @Test
+    void customFunctionFromRegistryBean() {
+        
given().body("Camel").when().post("/core-languages/route/simpleCustomFunctionBean/String").then()
+                .statusCode(200)
+                .body(is("lemaC"));
+    }
+
+    @Test
+    void customFunctionFromRegistryBeanShorthand() {
+        
given().body("ignored").when().post("/core-languages/header/simpleCustomFunctionBeanShorthand/text/Quarkus").then()
+                .statusCode(200)
+                .body(is("sukrauQ"));
+    }
+
+    @Test
+    void customFunctionAddedToFunctionRegistry() {
+        
given().body("Camel").when().post("/core-languages/route/simpleCustomFunction/String").then()
+                .statusCode(200)
+                .body(is("Hello Camel"));
+    }
+
+    @Test
+    void customFunctionWithParameter() {
+        
given().body("ignored").when().post("/core-languages/header/simpleCustomFunctionWithParameter/name/Quarkus").then()
+                .statusCode(200)
+                .body(is("Hello Quarkus"));
+    }
+
+    @Test
+    void customFunctionExpressionAddedToFunctionRegistry() {
+        
given().body("camel").when().post("/core-languages/route/simpleCustomFunctionExpression/String").then()
+                .statusCode(200)
+                .body(is("CAMEL!"));
+    }
+}

Reply via email to