You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/09/25 08:18:51 UTC

[camel-k-runtime] 03/05: Added test case of wrong component property and method setting

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

lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git

commit d7a758bee4bb9e5def658f815b5a2e74de5d0847
Author: Willem Jiang <wi...@gmail.com>
AuthorDate: Sun Sep 15 19:57:29 2019 +0800

    Added test case of wrong component property and method setting
---
 .../loader/groovy/dsl/ComponentsConfiguration.groovy |  6 ++++--
 .../camel/k/loader/groovy/dsl/IntegrationTest.groovy | 20 ++++++++++++++++++++
 ...-with-component-wrong-method-configuration.groovy | 13 +++++++++++++
 ...ith-component-wrong-property-configuration.groovy | 13 +++++++++++++
 4 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/camel-k-loader-groovy/src/main/groovy/org/apache/camel/k/loader/groovy/dsl/ComponentsConfiguration.groovy b/camel-k-loader-groovy/src/main/groovy/org/apache/camel/k/loader/groovy/dsl/ComponentsConfiguration.groovy
index 65698ea..a5f67d7 100644
--- a/camel-k-loader-groovy/src/main/groovy/org/apache/camel/k/loader/groovy/dsl/ComponentsConfiguration.groovy
+++ b/camel-k-loader-groovy/src/main/groovy/org/apache/camel/k/loader/groovy/dsl/ComponentsConfiguration.groovy
@@ -18,6 +18,7 @@ package org.apache.camel.k.loader.groovy.dsl
 
 import org.apache.camel.CamelContext
 import org.apache.camel.Component
+import org.apache.camel.support.PropertyBindingSupport
 
 class ComponentsConfiguration {
     private final CamelContext context
@@ -48,10 +49,10 @@ class ComponentsConfiguration {
         }
 
         if (type.isAssignableFrom(component.class)) {
-            callable.resolveStrategy = Closure.DELEGATE_FIRST
+            // Just make sure the closure context is belong to component
+            callable.resolveStrategy = Closure.DELEGATE_ONLY
             callable.delegate = new ComponentConfiguration(component)
             callable.call()
-
             return
         }
 
@@ -81,4 +82,5 @@ class ComponentsConfiguration {
 
         throw new MissingMethodException(name, this, args)
     }
+
 }
diff --git a/camel-k-loader-groovy/src/test/groovy/org/apache/camel/k/loader/groovy/dsl/IntegrationTest.groovy b/camel-k-loader-groovy/src/test/groovy/org/apache/camel/k/loader/groovy/dsl/IntegrationTest.groovy
index a6f5e55..d95745b 100644
--- a/camel-k-loader-groovy/src/test/groovy/org/apache/camel/k/loader/groovy/dsl/IntegrationTest.groovy
+++ b/camel-k-loader-groovy/src/test/groovy/org/apache/camel/k/loader/groovy/dsl/IntegrationTest.groovy
@@ -22,6 +22,7 @@ import org.apache.camel.component.log.LogComponent
 import org.apache.camel.component.seda.SedaComponent
 import org.apache.camel.impl.DefaultCamelContext
 import org.apache.camel.k.Runtime
+import org.apache.camel.k.listener.RoutesConfigurer
 import org.apache.camel.model.ModelCamelContext
 import org.apache.camel.processor.FatalFallbackErrorHandler
 import org.apache.camel.processor.SendProcessor
@@ -31,6 +32,7 @@ import org.apache.camel.support.DefaultHeaderFilterStrategy
 import spock.lang.Specification
 
 import javax.sql.DataSource
+import java.util.concurrent.atomic.AtomicBoolean
 
 import static org.apache.camel.k.listener.RoutesConfigurer.forRoutes
 
@@ -106,6 +108,24 @@ class IntegrationTest extends Specification {
             }
     }
 
+    def "load integration with component error property configuration"()  {
+        when:
+            forRoutes('classpath:routes-with-component-wrong-property-configuration.groovy').accept(Runtime.Phase.ConfigureRoutes, runtime)
+        then:
+            def e =  thrown org.apache.camel.RuntimeCamelException
+            assert e.message.contains("No such property: queueNumber for class: org.apache.camel.component.seda.SedaComponent")
+
+    }
+
+    def "load integration with component error method configuration"()  {
+        when:
+        forRoutes('classpath:routes-with-component-wrong-method-configuration.groovy').accept(Runtime.Phase.ConfigureRoutes, runtime)
+        then:
+        def e =  thrown org.apache.camel.RuntimeCamelException
+        assert e.message.contains("No signature of method: org.apache.camel.component.seda.SedaComponent.queueNumber()")
+
+    }
+
     def "load integration with error handler"()  {
         when:
             forRoutes('classpath:routes-with-error-handler.groovy').accept(Runtime.Phase.ConfigureRoutes, runtime)
diff --git a/camel-k-loader-groovy/src/test/resources/routes-with-component-wrong-method-configuration.groovy b/camel-k-loader-groovy/src/test/resources/routes-with-component-wrong-method-configuration.groovy
new file mode 100644
index 0000000..3242370
--- /dev/null
+++ b/camel-k-loader-groovy/src/test/resources/routes-with-component-wrong-method-configuration.groovy
@@ -0,0 +1,13 @@
+import org.apache.camel.component.seda.SedaComponent
+
+context {
+    components {
+        mySeda(SedaComponent) {
+            // a wrong method name
+            queueNumber 33
+        }
+    }
+}
+
+from('timer:tick')
+        .to('log:info')
diff --git a/camel-k-loader-groovy/src/test/resources/routes-with-component-wrong-property-configuration.groovy b/camel-k-loader-groovy/src/test/resources/routes-with-component-wrong-property-configuration.groovy
new file mode 100644
index 0000000..0efb194
--- /dev/null
+++ b/camel-k-loader-groovy/src/test/resources/routes-with-component-wrong-property-configuration.groovy
@@ -0,0 +1,13 @@
+import org.apache.camel.component.seda.SedaComponent
+
+context {
+    components {
+        mySeda(SedaComponent) {
+            // a wrong property name
+            queueNumber = 33
+        }
+    }
+}
+
+from('timer:tick')
+        .to('log:info')