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 0ea2447627fef8531ec94a7a6559260db81fdbb7
Author: lburgazzoli <lburgazz...@gmail.com>
AuthorDate: Mon Jul 8 15:40:30 2019 +0200

    groovy: add missing methods from route builder / builder support
---
 .../k/groovy/dsl/IntegrationConfiguration.groovy   | 41 +++++++++++++++++-----
 .../camel/k/groovy/dsl/IntegrationTest.groovy      | 39 ++++++++++++++++----
 .../resources/routes-with-error-handler.groovy     | 23 ++++++++++++
 3 files changed, 88 insertions(+), 15 deletions(-)

diff --git 
a/camel-k-runtime-groovy/src/main/groovy/org/apache/camel/k/groovy/dsl/IntegrationConfiguration.groovy
 
b/camel-k-runtime-groovy/src/main/groovy/org/apache/camel/k/groovy/dsl/IntegrationConfiguration.groovy
index b47f509..9544874 100644
--- 
a/camel-k-runtime-groovy/src/main/groovy/org/apache/camel/k/groovy/dsl/IntegrationConfiguration.groovy
+++ 
b/camel-k-runtime-groovy/src/main/groovy/org/apache/camel/k/groovy/dsl/IntegrationConfiguration.groovy
@@ -16,23 +16,22 @@
  */
 package org.apache.camel.k.groovy.dsl
 
-import org.apache.camel.CamelContext
 import org.apache.camel.Exchange
 import org.apache.camel.Predicate
 import org.apache.camel.Processor
 import org.apache.camel.builder.RouteBuilder
 import org.apache.camel.k.jvm.dsl.Components
-import org.apache.camel.model.ProcessorDefinition
+import org.apache.camel.model.*
 import org.apache.camel.spi.Registry
 
-class IntegrationConfiguration {
-    final CamelContext context
+class IntegrationConfiguration extends org.apache.camel.builder.BuilderSupport 
{
     final Registry registry
     final Components components
     final RouteBuilder builder
 
     IntegrationConfiguration(RouteBuilder builder) {
-        this.context = builder.getContext()
+        super(builder.context)
+
         this.registry = this.context.registry
         this.components = new Components(this.context)
         this.builder = builder
@@ -50,10 +49,6 @@ class IntegrationConfiguration {
         callable.call()
     }
 
-    ProcessorDefinition from(String endpoint) {
-        return builder.from(endpoint)
-    }
-
     def processor(@DelegatesTo(Exchange) Closure<?> callable) {
         return new Processor() {
             @Override
@@ -73,4 +68,32 @@ class IntegrationConfiguration {
             }
         }
     }
+
+    ProcessorDefinition from(String endpoint) {
+        return builder.from(endpoint)
+    }
+
+    OnExceptionDefinition onException(Class<? extends Throwable> exception) {
+        return builder.onException(exception)
+    }
+
+    OnCompletionDefinition onCompletion() {
+        return builder.onCompletion()
+    }
+
+    InterceptDefinition intercept() {
+        return builder.intercept()
+    }
+
+    InterceptFromDefinition interceptFrom() {
+        return builder.interceptFrom()
+    }
+
+    InterceptFromDefinition interceptFrom(String uri) {
+        return builder.interceptFrom(uri)
+    }
+
+    InterceptSendToEndpointDefinition interceptSendToEndpoint(String uri) {
+        return builder.interceptSendToEndpoint(uri)
+    }
 }
diff --git 
a/camel-k-runtime-groovy/src/test/groovy/org/apache/camel/k/groovy/dsl/IntegrationTest.groovy
 
b/camel-k-runtime-groovy/src/test/groovy/org/apache/camel/k/groovy/dsl/IntegrationTest.groovy
index d92ec11..e85a4ae 100644
--- 
a/camel-k-runtime-groovy/src/test/groovy/org/apache/camel/k/groovy/dsl/IntegrationTest.groovy
+++ 
b/camel-k-runtime-groovy/src/test/groovy/org/apache/camel/k/groovy/dsl/IntegrationTest.groovy
@@ -22,6 +22,9 @@ import org.apache.camel.component.seda.SedaComponent
 import org.apache.camel.k.Runtime
 import org.apache.camel.k.jvm.ApplicationRuntime
 import org.apache.camel.k.listener.RoutesConfigurer
+import org.apache.camel.processor.FatalFallbackErrorHandler
+import org.apache.camel.processor.SendProcessor
+import org.apache.camel.processor.channel.DefaultChannel
 import spock.lang.Specification
 
 import java.util.concurrent.atomic.AtomicInteger
@@ -86,13 +89,37 @@ class IntegrationTest extends Specification {
                 runtime.stop()
             })
 
-        runtime.run()
+            runtime.run()
+        then:
+            sedaSize == 1234
+            sedaConsumers == 12
+            mySedaSize == 4321
+            mySedaConsumers == 21
+            format != null
+    }
+
+    def "load integration with error handler"()  {
+        given:
+            def onExceptions = []
+        when:
+            def runtime = new ApplicationRuntime()
+            
runtime.addListener(RoutesConfigurer.forRoutes('classpath:routes-with-error-handler.groovy'))
+            runtime.addListener(Runtime.Phase.Started, {
+                it.camelContext.routes?.size() == 1
+                
it.camelContext.routes[0].routeContext.getOnException('my-on-exception') != null
+
+                onExceptions << 
it.camelContext.routes[0].routeContext.getOnException('my-on-exception')
 
+                runtime.stop()
+            })
+            runtime.run()
         then:
-        sedaSize == 1234
-        sedaConsumers == 12
-        mySedaSize == 4321
-        mySedaConsumers == 21
-        format != null
+            onExceptions.size() == 1
+            onExceptions[0] instanceof FatalFallbackErrorHandler
+
+            def eh = onExceptions[0] as FatalFallbackErrorHandler
+            def ch = eh.processor as DefaultChannel
+
+            ch.output instanceof SendProcessor
     }
 }
diff --git 
a/camel-k-runtime-groovy/src/test/resources/routes-with-error-handler.groovy 
b/camel-k-runtime-groovy/src/test/resources/routes-with-error-handler.groovy
new file mode 100644
index 0000000..fa36c49
--- /dev/null
+++ b/camel-k-runtime-groovy/src/test/resources/routes-with-error-handler.groovy
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+
+onException(IllegalArgumentException.class)
+    .id('my-on-exception')
+    .to('log:exception')
+
+from('timer:tick')
+    .to('log:info')
\ No newline at end of file

Reply via email to