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 2020/02/24 12:58:31 UTC

[camel] branch master updated: CAMEL-14597: Added unit test

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 219c93e  CAMEL-14597: Added unit test
219c93e is described below

commit 219c93e5d11361ef8a982966dbf5b442f2050a0e
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Feb 24 13:58:03 2020 +0100

    CAMEL-14597: Added unit test
---
 .../camel/test/blueprint/BeanStaticMethodTest.java | 39 ++++++++++++++++++++++
 .../test/blueprint/BlueprintStaticMethodRoute.java | 31 +++++++++++++++++
 .../camel/test/blueprint/beanStaticMethodRoute.xml | 34 +++++++++++++++++++
 core/camel-base/src/main/docs/simple-language.adoc |  2 +-
 .../BeanSimpleLanguageStaticMethodIssueTest.java   | 32 ++++++++++++++++++
 .../modules/ROOT/pages/simple-language.adoc        |  2 +-
 .../modules/ROOT/pages/simple-language.adoc        |  2 +-
 7 files changed, 139 insertions(+), 3 deletions(-)

diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/BeanStaticMethodTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/BeanStaticMethodTest.java
new file mode 100644
index 0000000..7196a0c
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/BeanStaticMethodTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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.test.blueprint;
+
+import org.junit.Test;
+
+public class BeanStaticMethodTest extends CamelBlueprintTestSupport {
+
+    @Override
+    protected String getBlueprintDescriptor() {
+        return "org/apache/camel/test/blueprint/beanStaticMethodRoute.xml";
+    }
+
+    @Test
+    public void testStaticMethod() throws Exception {
+        getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:result").message(0).exchangeProperty("foo").isNotNull();
+        getMockEndpoint("mock:result").message(0).exchangeProperty("bar").isNotNull();
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+}
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/BlueprintStaticMethodRoute.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/BlueprintStaticMethodRoute.java
new file mode 100644
index 0000000..0106ab8
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/BlueprintStaticMethodRoute.java
@@ -0,0 +1,31 @@
+/*
+ * 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.test.blueprint;
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class BlueprintStaticMethodRoute extends RouteBuilder {
+
+    @Override
+    public void configure() throws Exception {
+        from("direct:start")
+                .setProperty("foo").method(System.class, "currentTimeMillis")
+                .setProperty("bar").simple("${bean:type:java.lang.System?method=currentTimeMillis}")
+                .to("mock:result");
+    }
+
+}
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/beanStaticMethodRoute.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/beanStaticMethodRoute.xml
new file mode 100644
index 0000000..0872297
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/beanStaticMethodRoute.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+           xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
+           xsi:schemaLocation="
+             http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.0.0.xsd
+             http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
+
+  
+  <bean id="myRoute" class="org.apache.camel.test.blueprint.BlueprintStaticMethodRoute" />
+
+  <camelContext xmlns="http://camel.apache.org/schema/blueprint">
+    <routeBuilder ref="myRoute"/>
+  </camelContext>
+
+</blueprint>
diff --git a/core/camel-base/src/main/docs/simple-language.adoc b/core/camel-base/src/main/docs/simple-language.adoc
index 83a598d..c5acb3e 100644
--- a/core/camel-base/src/main/docs/simple-language.adoc
+++ b/core/camel-base/src/main/docs/simple-language.adoc
@@ -182,7 +182,7 @@ Command accepts offsets such as: *now-24h* or *in.header.xxx+1h* or even *now+1h
 Specifying a method name you must use dot as separator. We also support
 the ?method=methodname syntax that is used by the xref:components::bean-component.adoc[Bean]
 component. Camel will by default lookup a bean by the given name. However if you need to refer
-to a bean class then you can prefix with type, such as `bean:type:fqnClassName`.
+to a bean class (such as calling a static method) then you can prefix with type, such as `bean:type:fqnClassName`.
 
 |`properties:key:default` |String |Lookup a property with the given key. If the key does
 not exists or has no value, then an optional default value can be
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/bean/BeanSimpleLanguageStaticMethodIssueTest.java b/core/camel-core/src/test/java/org/apache/camel/component/bean/BeanSimpleLanguageStaticMethodIssueTest.java
new file mode 100644
index 0000000..6567dcf
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/component/bean/BeanSimpleLanguageStaticMethodIssueTest.java
@@ -0,0 +1,32 @@
+package org.apache.camel.component.bean;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class BeanSimpleLanguageStaticMethodIssueTest extends ContextTestSupport {
+
+    @Test
+    public void testStaticMethod() throws Exception {
+        getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:result").message(0).exchangeProperty("foo").isNotNull();
+        getMockEndpoint("mock:result").message(0).exchangeProperty("bar").isNotNull();
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .setProperty("foo").method(System.class, "currentTimeMillis")
+                    .setProperty("bar").simple("${bean:type:java.lang.System?method=currentTimeMillis}")
+                    .to("mock:result");
+            }
+        };
+    }
+}
diff --git a/docs/components/modules/ROOT/pages/simple-language.adoc b/docs/components/modules/ROOT/pages/simple-language.adoc
index e640eef..ac942b1 100644
--- a/docs/components/modules/ROOT/pages/simple-language.adoc
+++ b/docs/components/modules/ROOT/pages/simple-language.adoc
@@ -183,7 +183,7 @@ Command accepts offsets such as: *now-24h* or *in.header.xxx+1h* or even *now+1h
 Specifying a method name you must use dot as separator. We also support
 the ?method=methodname syntax that is used by the xref:components::bean-component.adoc[Bean]
 component. Camel will by default lookup a bean by the given name. However if you need to refer
-to a bean class then you can prefix with type, such as `bean:type:fqnClassName`.
+to a bean class (such as calling a static method) then you can prefix with type, such as `bean:type:fqnClassName`.
 
 |`properties:key:default` |String |Lookup a property with the given key. If the key does
 not exists or has no value, then an optional default value can be
diff --git a/docs/user-manual/modules/ROOT/pages/simple-language.adoc b/docs/user-manual/modules/ROOT/pages/simple-language.adoc
index e640eef..ac942b1 100644
--- a/docs/user-manual/modules/ROOT/pages/simple-language.adoc
+++ b/docs/user-manual/modules/ROOT/pages/simple-language.adoc
@@ -183,7 +183,7 @@ Command accepts offsets such as: *now-24h* or *in.header.xxx+1h* or even *now+1h
 Specifying a method name you must use dot as separator. We also support
 the ?method=methodname syntax that is used by the xref:components::bean-component.adoc[Bean]
 component. Camel will by default lookup a bean by the given name. However if you need to refer
-to a bean class then you can prefix with type, such as `bean:type:fqnClassName`.
+to a bean class (such as calling a static method) then you can prefix with type, such as `bean:type:fqnClassName`.
 
 |`properties:key:default` |String |Lookup a property with the given key. If the key does
 not exists or has no value, then an optional default value can be