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 2022/10/24 10:47:18 UTC

[camel] branch main updated: CAMEL-18641: Add python language to java-dsl

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


The following commit(s) were added to refs/heads/main by this push:
     new 4a73f6669f9 CAMEL-18641: Add python language to java-dsl
4a73f6669f9 is described below

commit 4a73f6669f9df24c16d0ea91b114b6725bc819c4
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Oct 24 12:47:00 2022 +0200

    CAMEL-18641: Add python language to java-dsl
---
 .../camel/language/python/PythonChoiceTest.java    | 54 ++++++++++++++++++++++
 .../org/apache/camel/builder/ExpressionClause.java | 10 ++++
 2 files changed, 64 insertions(+)

diff --git a/components/camel-python/src/test/java/org/apache/camel/language/python/PythonChoiceTest.java b/components/camel-python/src/test/java/org/apache/camel/language/python/PythonChoiceTest.java
new file mode 100644
index 00000000000..7bf7acbf0a8
--- /dev/null
+++ b/components/camel-python/src/test/java/org/apache/camel/language/python/PythonChoiceTest.java
@@ -0,0 +1,54 @@
+/*
+ * 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.language.python;
+
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+public class PythonChoiceTest extends CamelTestSupport {
+
+    @Test
+    public void testPythonChoice() throws Exception {
+        getMockEndpoint("mock:foo").expectedBodiesReceived("Hello");
+        getMockEndpoint("mock:bar").expectedBodiesReceived("Bye");
+        getMockEndpoint("mock:other").expectedBodiesReceived("Hi World");
+
+        template.sendBody("direct:start", "Bye");
+        template.sendBody("direct:start", "Hi World");
+        template.sendBody("direct:start", "Hello");
+
+        MockEndpoint.assertIsSatisfied(context);
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                        .choice()
+                        .when().python("body == 'Hello'").to("mock:foo")
+                        .when().python("body == 'Bye'").to("mock:bar")
+                        .otherwise().to("mock:other");
+
+            }
+        };
+    }
+}
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/builder/ExpressionClause.java b/core/camel-core-model/src/main/java/org/apache/camel/builder/ExpressionClause.java
index 5cab2fd8bea..a4a530e2d07 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/builder/ExpressionClause.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/builder/ExpressionClause.java
@@ -592,6 +592,16 @@ public class ExpressionClause<T> implements Expression, Predicate {
         return delegate.ognl(text);
     }
 
+    /**
+     * Evaluates a Python expression.
+     *
+     * @param  text the expression to be evaluated
+     * @return      the builder to continue processing the DSL
+     */
+    public T python(String text) {
+        return delegate.python(text);
+    }
+
     /**
      * Evaluates a <a href="http://camel.apache.org/mvel.html">MVEL expression</a>
      *