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 c50b70a8d782db1cab3c0bf3989d091d42e1f88c
Author: lburgazzoli <lburgazz...@gmail.com>
AuthorDate: Tue Sep 3 14:07:38 2019 +0200

    chore(test): remove dependencies on runtime from camel-k-loader-groovy
---
 camel-k-loader-groovy/pom.xml                      |   5 -
 .../k/loader/groovy/dsl/IntegrationTest.groovy     | 136 +++++++++------------
 .../groovy/dsl/extension/LogExtensionTest.groovy   |  18 +--
 3 files changed, 66 insertions(+), 93 deletions(-)

diff --git a/camel-k-loader-groovy/pom.xml b/camel-k-loader-groovy/pom.xml
index 0589a7b..4ff0534 100644
--- a/camel-k-loader-groovy/pom.xml
+++ b/camel-k-loader-groovy/pom.xml
@@ -70,11 +70,6 @@
         <!-- ******************************* -->
 
         <dependency>
-            <groupId>org.apache.camel.k</groupId>
-            <artifactId>camel-k-runtime-main</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
             <groupId>org.apache.camel</groupId>
             <artifactId>camel-main</artifactId>
             <scope>test</scope>
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 695c952..a6f5e55 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
@@ -20,9 +20,9 @@ import org.apache.camel.Predicate
 import org.apache.camel.Processor
 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.k.main.ApplicationRuntime
+import org.apache.camel.model.ModelCamelContext
 import org.apache.camel.processor.FatalFallbackErrorHandler
 import org.apache.camel.processor.SendProcessor
 import org.apache.camel.processor.channel.DefaultChannel
@@ -31,114 +31,92 @@ import org.apache.camel.support.DefaultHeaderFilterStrategy
 import spock.lang.Specification
 
 import javax.sql.DataSource
-import java.util.concurrent.atomic.AtomicInteger
-import java.util.concurrent.atomic.AtomicReference
+
+import static org.apache.camel.k.listener.RoutesConfigurer.forRoutes
 
 class IntegrationTest extends Specification {
+
+    private ModelCamelContext context
+    private Runtime runtime
+
+    def setup() {
+        this.context = new DefaultCamelContext()
+        this.runtime = Runtime.of(context)
+    }
+
+
+    def cleanup() {
+        if (this.context != null) {
+            this.context.stop()
+        }
+    }
+
     def "load integration with rest"()  {
         when:
-            def runtime = new ApplicationRuntime()
-            
runtime.addListener(RoutesConfigurer.forRoutes('classpath:routes-with-rest.groovy'))
-            runtime.addListener(Runtime.Phase.Started, { runtime.stop() })
-            runtime.run()
+            
forRoutes('classpath:routes-with-rest.groovy').accept(Runtime.Phase.ConfigureRoutes,
 runtime)
 
         then:
-            runtime.camelContext.restConfiguration.host == 'my-host'
-            runtime.camelContext.restConfiguration.port == 9192
-            runtime.camelContext.getRestConfiguration('undertow', false).host 
== 'my-undertow-host'
-            runtime.camelContext.getRestConfiguration('undertow', false).port 
== 9193
-            runtime.camelContext.restDefinitions.size() == 1
-            runtime.camelContext.restDefinitions[0].path == '/my/path'
+            context.restConfiguration.host == 'my-host'
+            context.restConfiguration.port == 9192
+            context.getRestConfiguration('undertow', false).host == 
'my-undertow-host'
+            context.getRestConfiguration('undertow', false).port == 9193
+            context.restDefinitions.size() == 1
+            context.restDefinitions[0].path == '/my/path'
     }
 
     def "load integration with beans"()  {
         when:
-            def runtime = new ApplicationRuntime()
-            
runtime.addListener(RoutesConfigurer.forRoutes('classpath:routes-with-beans.groovy'))
-            runtime.addListener(Runtime.Phase.Started, { runtime.stop() })
-            runtime.run()
+            
forRoutes('classpath:routes-with-beans.groovy').accept(Runtime.Phase.ConfigureRoutes,
 runtime)
 
         then:
-            runtime.camelContext.registry.findByType(DataSource).size() == 1
-            runtime.camelContext.registry.lookupByName('dataSource') 
instanceof DataSource
-            
runtime.camelContext.registry.findByType(HeaderFilterStrategy).size() == 1
-            runtime.camelContext.registry.lookupByName('filterStrategy') 
instanceof DefaultHeaderFilterStrategy
+            context.registry.findByType(DataSource).size() == 1
+            context.registry.lookupByName('dataSource') instanceof DataSource
+            context.registry.findByType(HeaderFilterStrategy).size() == 1
+            context.registry.lookupByName('filterStrategy') instanceof 
DefaultHeaderFilterStrategy
 
-            runtime.camelContext.registry.lookupByName('myProcessor') 
instanceof Processor
-            runtime.camelContext.registry.lookupByName('myPredicate') 
instanceof Predicate
+            context.registry.lookupByName('myProcessor') instanceof Processor
+            context.registry.lookupByName('myPredicate') instanceof Predicate
     }
 
     def "load integration with bindings"()  {
         when:
-            def runtime = new ApplicationRuntime()
-            
runtime.addListener(RoutesConfigurer.forRoutes('classpath:routes-with-bindings.groovy'))
-            runtime.addListener(Runtime.Phase.Started, { runtime.stop() })
-            runtime.run()
+            
forRoutes('classpath:routes-with-bindings.groovy').accept(Runtime.Phase.ConfigureRoutes,
 runtime)
 
         then:
-            runtime.camelContext.registry.lookupByName('myEntry1') == 
'myRegistryEntry1'
-            runtime.camelContext.registry.lookupByName('myEntry2') == 
'myRegistryEntry2'
-            runtime.camelContext.registry.lookupByName('myEntry3') instanceof 
Processor
+            context.registry.lookupByName('myEntry1') == 'myRegistryEntry1'
+            context.registry.lookupByName('myEntry2') == 'myRegistryEntry2'
+            context.registry.lookupByName('myEntry3') instanceof Processor
     }
 
     def "load integration with component configuration"()  {
-        given:
-            def sedaSize = new AtomicInteger()
-            def sedaConsumers = new AtomicInteger()
-            def mySedaSize = new AtomicInteger()
-            def mySedaConsumers = new AtomicInteger()
-            def format = new AtomicReference()
-
         when:
-            def runtime = new ApplicationRuntime()
-            
runtime.addListener(RoutesConfigurer.forRoutes('classpath:routes-with-component-configuration.groovy'))
-            runtime.addListener(Runtime.Phase.Started, {
-                def seda = it.camelContext.getComponent('seda', SedaComponent)
-                def mySeda = it.camelContext.getComponent('mySeda', 
SedaComponent)
-                def log = it.camelContext.getComponent('log', LogComponent)
-
-                assert seda != null
-                assert mySeda != null
-                assert log != null
-
-                sedaSize = seda.queueSize
-                sedaConsumers = seda.concurrentConsumers
-                mySedaSize = mySeda.queueSize
-                mySedaConsumers = mySeda.concurrentConsumers
-                format = log.exchangeFormatter
-
-                runtime.stop()
-            })
-
-            runtime.run()
+            
forRoutes('classpath:routes-with-component-configuration.groovy').accept(Runtime.Phase.ConfigureRoutes,
 runtime)
+
         then:
-            sedaSize == 1234
-            sedaConsumers == 12
-            mySedaSize == 4321
-            mySedaConsumers == 21
-            format != null
+            with(context.getComponent('seda', SedaComponent)) {
+                queueSize == 1234
+                concurrentConsumers == 12
+            }
+            with(context.getComponent('mySeda', SedaComponent)) {
+                queueSize == 4321
+                concurrentConsumers == 21
+            }
+            with(context.getComponent('log', LogComponent)) {
+                exchangeFormatter != 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')
+            
forRoutes('classpath:routes-with-error-handler.groovy').accept(Runtime.Phase.ConfigureRoutes,
 runtime)
 
-                runtime.stop()
-            })
-            runtime.run()
+            context.start()
         then:
-            onExceptions.size() == 1
-            onExceptions[0] instanceof FatalFallbackErrorHandler
+            context.routes?.size() == 1
+            context.routes[0].routeContext.getOnException('my-on-exception') 
!= null
+            context.routes[0].routeContext.getOnException('my-on-exception') 
instanceof FatalFallbackErrorHandler
 
-            def eh = onExceptions[0] as FatalFallbackErrorHandler
+            def eh = 
context.routes[0].routeContext.getOnException('my-on-exception')  as 
FatalFallbackErrorHandler
             def ch = eh.processor as DefaultChannel
 
             ch.output instanceof SendProcessor
diff --git 
a/camel-k-loader-groovy/src/test/groovy/org/apache/camel/k/loader/groovy/dsl/extension/LogExtensionTest.groovy
 
b/camel-k-loader-groovy/src/test/groovy/org/apache/camel/k/loader/groovy/dsl/extension/LogExtensionTest.groovy
index be463a0..a5a4b5e 100644
--- 
a/camel-k-loader-groovy/src/test/groovy/org/apache/camel/k/loader/groovy/dsl/extension/LogExtensionTest.groovy
+++ 
b/camel-k-loader-groovy/src/test/groovy/org/apache/camel/k/loader/groovy/dsl/extension/LogExtensionTest.groovy
@@ -25,19 +25,19 @@ class LogExtensionTest extends Specification {
 
     def "invoke extension method - formatter"()  {
         given:
-        def ctx = new DefaultCamelContext()
+            def ctx = new DefaultCamelContext()
 
         when:
-        def log = new LogComponent()
-        log.formatter {
-            "body: $it.in.body"
-        }
+            def log = new LogComponent()
+            log.formatter {
+                "body: $it.in.body"
+            }
 
-        def ex = new DefaultExchange(ctx)
-        ex.in.body = 'hello'
-        def result = log.exchangeFormatter.format(ex)
+            def ex = new DefaultExchange(ctx)
+            ex.in.body = 'hello'
+            def result = log.exchangeFormatter.format(ex)
 
         then:
-        result == 'body: hello'
+            result == 'body: hello'
     }
 }

Reply via email to