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

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

commit 756de9ade271641ac81730ed74b0e15a4dffebe3
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Thu Oct 31 17:04:50 2024 +0100

    CAMEL-21412: camel-test - Make it easy to use expression outside route 
builder
---
 .../org/apache/camel/test/junit5/CamelTestSupport.java     | 14 ++++++++++++++
 .../org/apache/camel/test/junit5/CamelTestSupportTest.java | 10 ++++++++++
 2 files changed, 24 insertions(+)

diff --git 
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java
 
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java
index 79ac56eab57..88966d5d193 100644
--- 
a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java
+++ 
b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java
@@ -24,6 +24,7 @@ import org.apache.camel.Exchange;
 import org.apache.camel.NoSuchEndpointException;
 import org.apache.camel.Processor;
 import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.LanguageBuilderFactory;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.model.ProcessorDefinition;
@@ -313,6 +314,19 @@ public abstract class CamelTestSupport extends 
AbstractTestSupport
         // noop
     }
 
+    /**
+     * A utility method allowing to build any language using a fluent syntax 
as shown in the next example:
+     *
+     * <pre>
+     *  var exp = expression().tokenize().token("\n").end()
+     * </pre>
+     *
+     * @return an entry point to the builder of all supported languages.
+     */
+    protected LanguageBuilderFactory expression() {
+        return new LanguageBuilderFactory();
+    }
+
     /**
      * Override to use a custom {@link Registry}.
      * <p>
diff --git 
a/components/camel-test/camel-test-junit5/src/test/java/org/apache/camel/test/junit5/CamelTestSupportTest.java
 
b/components/camel-test/camel-test-junit5/src/test/java/org/apache/camel/test/junit5/CamelTestSupportTest.java
index d1e935306b8..34dd529ce42 100644
--- 
a/components/camel-test/camel-test-junit5/src/test/java/org/apache/camel/test/junit5/CamelTestSupportTest.java
+++ 
b/components/camel-test/camel-test-junit5/src/test/java/org/apache/camel/test/junit5/CamelTestSupportTest.java
@@ -56,6 +56,16 @@ public class CamelTestSupportTest extends CamelTestSupport {
         assertNotNull(mock);
     }
 
+    @Test
+    public void testExpression() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        
mock.message(0).body().matches(expression().simple().expression("${body} 
contains ' foo '").trim(false).end());
+
+        template.sendBody("direct:start", "    foo    ");
+
+        mock.assertIsSatisfied();
+    }
+
     @Override
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {

Reply via email to