You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/07/10 09:19:45 UTC
git commit: CAMEL-7582 Support to look up the multiple statments
script result
Repository: camel
Updated Branches:
refs/heads/master 6b0623ebd -> 3fd9fbedd
CAMEL-7582 Support to look up the multiple statments script result
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3fd9fbed
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3fd9fbed
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3fd9fbed
Branch: refs/heads/master
Commit: 3fd9fbedd4fb4d665f75e27f6bd7f8ff3573cb10
Parents: 6b0623e
Author: Willem Jiang <wi...@gmail.com>
Authored: Thu Jul 10 15:13:24 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Thu Jul 10 15:13:24 2014 +0800
----------------------------------------------------------------------
.../camel/builder/script/ScriptBuilder.java | 4 ++
.../script/LanguagePythonStatementsTest.java | 46 ++++++++++++++++++++
.../camel-script/src/test/resources/mypython.py | 3 ++
3 files changed, 53 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/3fd9fbed/components/camel-script/src/main/java/org/apache/camel/builder/script/ScriptBuilder.java
----------------------------------------------------------------------
diff --git a/components/camel-script/src/main/java/org/apache/camel/builder/script/ScriptBuilder.java b/components/camel-script/src/main/java/org/apache/camel/builder/script/ScriptBuilder.java
index 5301ea4..eda38b0 100644
--- a/components/camel-script/src/main/java/org/apache/camel/builder/script/ScriptBuilder.java
+++ b/components/camel-script/src/main/java/org/apache/camel/builder/script/ScriptBuilder.java
@@ -413,6 +413,10 @@ public class ScriptBuilder implements Expression, Predicate, Processor {
}
}
}
+ // As the script could have multiple statement, we need to look up the result from the engine value set
+ if (result == null) {
+ result = engine.get("result");
+ }
return result;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/3fd9fbed/components/camel-script/src/test/java/org/apache/camel/builder/script/LanguagePythonStatementsTest.java
----------------------------------------------------------------------
diff --git a/components/camel-script/src/test/java/org/apache/camel/builder/script/LanguagePythonStatementsTest.java b/components/camel-script/src/test/java/org/apache/camel/builder/script/LanguagePythonStatementsTest.java
new file mode 100644
index 0000000..0ba25f2
--- /dev/null
+++ b/components/camel-script/src/test/java/org/apache/camel/builder/script/LanguagePythonStatementsTest.java
@@ -0,0 +1,46 @@
+/**
+ * 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.builder.script;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class LanguagePythonStatementsTest extends CamelTestSupport {
+
+ @Test
+ public void testSendMatchingMessage() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceived(7, 9);
+
+ sendBody("direct:start", 3);
+ sendBody("direct:start", 4);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() throws Exception {
+ from("direct:start")
+ .to("language:python:classpath:mypython.py")
+ .to("mock:result");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/3fd9fbed/components/camel-script/src/test/resources/mypython.py
----------------------------------------------------------------------
diff --git a/components/camel-script/src/test/resources/mypython.py b/components/camel-script/src/test/resources/mypython.py
new file mode 100644
index 0000000..e50a7f3
--- /dev/null
+++ b/components/camel-script/src/test/resources/mypython.py
@@ -0,0 +1,3 @@
+bar = "baz";
+
+result = body * 2 + 1
\ No newline at end of file