This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 4ea31f9 CAMEL-15704: camel-csimple - Compiled simple language.
4ea31f9 is described below
commit 4ea31f95dd48f2932b65b63ac357bccb3086dbc2
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Dec 8 14:23:14 2020 +0100
CAMEL-15704: camel-csimple - Compiled simple language.
---
.../csimple/joor/CSimpleDecHeaderTest.java | 48 ++++++++++++++++++++++
.../csimple/joor/CSimpleIncHeaderTest.java | 48 ++++++++++++++++++++++
.../camel/language/csimple/CSimpleHelper.java | 16 ++++++--
3 files changed, 108 insertions(+), 4 deletions(-)
diff --git
a/components/camel-csimple-joor/src/test/java/org/apache/camel/language/csimple/joor/CSimpleDecHeaderTest.java
b/components/camel-csimple-joor/src/test/java/org/apache/camel/language/csimple/joor/CSimpleDecHeaderTest.java
new file mode 100644
index 0000000..ce48977
--- /dev/null
+++
b/components/camel-csimple-joor/src/test/java/org/apache/camel/language/csimple/joor/CSimpleDecHeaderTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.csimple.joor;
+
+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 CSimpleDecHeaderTest extends CamelTestSupport {
+
+ @Test
+ public void testDecHeader() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(1);
+ mock.message(0).header("myCounter").isEqualTo(122);
+ mock.message(0).header("myCounter").isInstanceOf(Integer.class);
+
+ template.sendBodyAndHeader("direct:start", "Hello World", "myCounter",
123);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").setHeader("myCounter",
csimple("${header.myCounter}--")).to("mock:result");
+ }
+ };
+ }
+
+}
diff --git
a/components/camel-csimple-joor/src/test/java/org/apache/camel/language/csimple/joor/CSimpleIncHeaderTest.java
b/components/camel-csimple-joor/src/test/java/org/apache/camel/language/csimple/joor/CSimpleIncHeaderTest.java
new file mode 100644
index 0000000..6e90421
--- /dev/null
+++
b/components/camel-csimple-joor/src/test/java/org/apache/camel/language/csimple/joor/CSimpleIncHeaderTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.csimple.joor;
+
+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 CSimpleIncHeaderTest extends CamelTestSupport {
+
+ @Test
+ public void testIncHeader() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(1);
+ mock.message(0).header("myCounter").isEqualTo(124);
+ mock.message(0).header("myCounter").isInstanceOf(Integer.class);
+
+ template.sendBodyAndHeader("direct:start", "Hello World", "myCounter",
123);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").setHeader("myCounter",
csimple("${header.myCounter}++")).to("mock:result");
+ }
+ };
+ }
+
+}
diff --git
a/core/camel-core-languages/src/main/java/org/apache/camel/language/csimple/CSimpleHelper.java
b/core/camel-core-languages/src/main/java/org/apache/camel/language/csimple/CSimpleHelper.java
index 7f78093..502ea04 100644
---
a/core/camel-core-languages/src/main/java/org/apache/camel/language/csimple/CSimpleHelper.java
+++
b/core/camel-core-languages/src/main/java/org/apache/camel/language/csimple/CSimpleHelper.java
@@ -437,9 +437,13 @@ public final class CSimpleHelper {
return beanLanguage;
}
- public static long increment(Exchange exchange, Object number) {
+ public static Object increment(Exchange exchange, Object number) {
Number num =
exchange.getContext().getTypeConverter().tryConvertTo(Number.class, exchange,
number);
- if (num != null) {
+ if (num instanceof Integer) {
+ int val = num.intValue();
+ val++;
+ return val;
+ } else if (num instanceof Long) {
long val = num.longValue();
val++;
return val;
@@ -450,9 +454,13 @@ public final class CSimpleHelper {
}
}
- public static long decrement(Exchange exchange, Object number) {
+ public static Object decrement(Exchange exchange, Object number) {
Number num =
exchange.getContext().getTypeConverter().tryConvertTo(Number.class, exchange,
number);
- if (num != null) {
+ if (num instanceof Integer) {
+ int val = num.intValue();
+ val--;
+ return val;
+ } else if (num instanceof Long) {
long val = num.longValue();
val--;
return val;