[camel-k] branch master updated: runtime(groovy) : improve registry dsl

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[camel-k] branch master updated: runtime(groovy) : improve registry dsl

lburgazzoli-2
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.git


The following commit(s) were added to refs/heads/master by this push:
     new 35aa1b3  runtime(groovy) : improve registry dsl
35aa1b3 is described below

commit 35aa1b3d39508ea901be7a7a1c5f4d256ce0eabb
Author: lburgazzoli <[hidden email]>
AuthorDate: Tue Oct 9 21:49:18 2018 +0200

    runtime(groovy) : improve registry dsl
---
 runtime/examples/camel-caffeine.groovy                            | 8 +++-----
 runtime/examples/routes.groovy                                    | 2 +-
 .../org/apache/camel/k/groovy/dsl/RegistryConfiguration.groovy    | 4 ++++
 .../groovy/org/apache/camel/k/groovy/dsl/IntegrationTest.groovy   | 2 ++
 runtime/groovy/src/test/resources/routes-with-bindings.groovy     | 8 +++++---
 5 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/runtime/examples/camel-caffeine.groovy b/runtime/examples/camel-caffeine.groovy
index 84da8fc..1a70c25 100644
--- a/runtime/examples/camel-caffeine.groovy
+++ b/runtime/examples/camel-caffeine.groovy
@@ -1,16 +1,14 @@
 //
 // To run this integrations use:
 //
-//     kamel run -d camel:groovy runtime/examples/camel-caffeine.groovy
+//     kamel run --runtime groovy runtime/examples/camel-caffeine.groovy
 //
-import com.github.benmanes.caffeine.cache.Cache;
-import com.github.benmanes.caffeine.cache.Caffeine;
 
-Cache cache = Caffeine.newBuilder().recordStats().build();
+import com.github.benmanes.caffeine.cache.Caffeine
 
 context {
     registry {
-        bind 'caffeineCache', cache
+        caffeineCache = Caffeine.newBuilder().recordStats().build()
     }
 }
 
diff --git a/runtime/examples/routes.groovy b/runtime/examples/routes.groovy
index 091713f..aef7ad3 100644
--- a/runtime/examples/routes.groovy
+++ b/runtime/examples/routes.groovy
@@ -27,7 +27,7 @@ context {
     // configure registry
     //
     registry {
-        bind 'myProcessor', processor {
+        myProcessor = processor {
             it.in.headers['RandomValue'] = ThreadLocalRandom.current().nextInt()
         }
     }
diff --git a/runtime/groovy/src/main/groovy/org/apache/camel/k/groovy/dsl/RegistryConfiguration.groovy b/runtime/groovy/src/main/groovy/org/apache/camel/k/groovy/dsl/RegistryConfiguration.groovy
index 340c56b..0b7b23d 100644
--- a/runtime/groovy/src/main/groovy/org/apache/camel/k/groovy/dsl/RegistryConfiguration.groovy
+++ b/runtime/groovy/src/main/groovy/org/apache/camel/k/groovy/dsl/RegistryConfiguration.groovy
@@ -28,4 +28,8 @@ class RegistryConfiguration {
     def bind(String name, value) {
         registry.bind(name, value)
     }
+
+    def propertyMissing(String name, value) {
+        registry.bind(name, value)
+    }
 }
diff --git a/runtime/groovy/src/test/groovy/org/apache/camel/k/groovy/dsl/IntegrationTest.groovy b/runtime/groovy/src/test/groovy/org/apache/camel/k/groovy/dsl/IntegrationTest.groovy
index 785b2e4..1b6a1e6 100644
--- a/runtime/groovy/src/test/groovy/org/apache/camel/k/groovy/dsl/IntegrationTest.groovy
+++ b/runtime/groovy/src/test/groovy/org/apache/camel/k/groovy/dsl/IntegrationTest.groovy
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.k.groovy.dsl
 
+import org.apache.camel.Processor
 import org.apache.camel.component.log.LogComponent
 import org.apache.camel.component.seda.SedaComponent
 import org.apache.camel.k.jvm.Runtime
@@ -67,6 +68,7 @@ class IntegrationTest extends Specification {
         then:
         runtime.camelContext.registry.lookup('myEntry1') == 'myRegistryEntry1'
         runtime.camelContext.registry.lookup('myEntry2') == 'myRegistryEntry2'
+        runtime.camelContext.registry.lookup('myEntry3') instanceof Processor
     }
 
     def "load integration with component configuration"()  {
diff --git a/runtime/groovy/src/test/resources/routes-with-bindings.groovy b/runtime/groovy/src/test/resources/routes-with-bindings.groovy
index cf589e1..6595b23 100644
--- a/runtime/groovy/src/test/resources/routes-with-bindings.groovy
+++ b/runtime/groovy/src/test/resources/routes-with-bindings.groovy
@@ -1,8 +1,10 @@
-
 context {
     registry {
-        bind 'myEntry1', 'myRegistryEntry1'
-        bind 'myEntry2', 'myRegistryEntry2'
+        myEntry1 = 'myRegistryEntry1'
+        myEntry2 = 'myRegistryEntry2'
+        myEntry3 = processor {
+            it.in.headers['test'] = 'value'
+        }
     }
 }