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/10/18 15:33:57 UTC

[camel-k-runtime] 02/02: kotlin: improve dsl

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 b76954db68cb47eb8e3808e2d9c80589c2934efe
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Fri Oct 18 15:06:43 2019 +0200

    kotlin: improve dsl
---
 camel-k-loader-kotlin/pom.xml                      | 10 +++++
 ...ntextConfiguration.kt => CamelConfiguration.kt} | 20 +++++----
 .../k/loader/kotlin/dsl/ComponentsConfiguration.kt | 24 ++++++-----
 ...onfiguration.kt => DataFormatsConfiguration.kt} | 29 +++++++------
 .../loader/kotlin/dsl/IntegrationConfiguration.kt  |  4 +-
 ...tConfiguration.kt => LanguagesConfiguration.kt} | 29 +++++++------
 .../camel/k/loader/kotlin/dsl/IntegrationTest.kt   | 49 ++++++++++++++++------
 .../src/test/resources/routes-new.kts              | 17 +++++++-
 .../src/test/resources/routes-with-beans.kts       | 16 +++++++
 .../src/test/resources/routes-with-bindings.kts    | 16 -------
 .../routes-with-component-configuration.kts        | 28 -------------
 .../routes-with-components-configuration.kts}      | 39 +++++++++--------
 .../routes-with-dataformats-configuration.kts}     | 30 ++++++-------
 .../test/resources/routes-with-error-handler.kts   | 17 +++++++-
 .../routes-with-languages-configuration.kts}       | 31 ++++++--------
 .../src/test/resources/routes-with-rest.kts        | 17 +++++++-
 .../src/test/resources/routes.kts                  | 17 +++++++-
 17 files changed, 232 insertions(+), 161 deletions(-)

diff --git a/camel-k-loader-kotlin/pom.xml b/camel-k-loader-kotlin/pom.xml
index bc74dc6..b5ce015 100644
--- a/camel-k-loader-kotlin/pom.xml
+++ b/camel-k-loader-kotlin/pom.xml
@@ -107,6 +107,16 @@
             <artifactId>camel-main</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-bean</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-jackson</artifactId>
+            <scope>test</scope>
+        </dependency>
 
         <!-- ******************************* -->
         <!-- test deps :: misc               -->
diff --git a/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/ContextConfiguration.kt b/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/CamelConfiguration.kt
similarity index 73%
copy from camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/ContextConfiguration.kt
copy to camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/CamelConfiguration.kt
index 847c945..cd42b97 100644
--- a/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/ContextConfiguration.kt
+++ b/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/CamelConfiguration.kt
@@ -17,20 +17,24 @@
 package org.apache.camel.k.loader.kotlin.dsl
 
 import org.apache.camel.CamelContext
-import org.apache.camel.spi.Registry
 
-class ContextConfiguration (
-        private val context: CamelContext,
-        private val registry: Registry) {
+class CamelConfiguration (
+        private val context: CamelContext) {
 
-    fun registry(block: RegistryConfiguration.() -> Unit): RegistryConfiguration {
-        val delegate = RegistryConfiguration(registry)
+    fun components(block: ComponentsConfiguration.() -> Unit): ComponentsConfiguration {
+        val delegate = ComponentsConfiguration(context)
         delegate.block()
         return delegate
     }
 
-    fun components(block: ComponentsConfiguration.() -> Unit): ComponentsConfiguration {
-        val delegate = ComponentsConfiguration(context)
+    fun languages(block: LanguagesConfiguration.() -> Unit): LanguagesConfiguration {
+        val delegate = LanguagesConfiguration(context)
+        delegate.block()
+        return delegate
+    }
+
+    fun dataFormats(block: DataFormatsConfiguration.() -> Unit): DataFormatsConfiguration {
+        val delegate = DataFormatsConfiguration(context)
         delegate.block()
         return delegate
     }
diff --git a/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/ComponentsConfiguration.kt b/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/ComponentsConfiguration.kt
index ea00781..2820839 100644
--- a/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/ComponentsConfiguration.kt
+++ b/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/ComponentsConfiguration.kt
@@ -21,23 +21,27 @@ import org.apache.camel.Component
 
 class ComponentsConfiguration(val context: CamelContext) {
     inline fun <reified T : Component> component(name: String, block: T.() -> Unit) : T {
-        var component = context.getComponent(name, true, false)
+        var target = context.getComponent(name, true, false)
+        var bind = false
+
+        if (target != null && target !is T) {
+            throw IllegalArgumentException("Type mismatch, expected: " + T::class.java + ", got: " + target.javaClass)
+        }
 
         // if the component is not found, let's create a new one. This is
         // equivalent to create a new named component, useful to create
         // multiple instances of the same component but with different setup
-        if (component == null) {
-            component = T::class.java.newInstance()
-
-            // let's the camel context be aware of the new component
-            context.addComponent(name, component)
+        if (target == null) {
+            target = context.injector.newInstance(T::class.java)
+            bind = true
         }
 
-        if (component is T) {
-            component.block()
-            return component
+        block.invoke(target as T)
+
+        if (bind) {
+            context.registry.bind(name, T::class.java, target)
         }
 
-        throw IllegalArgumentException("Type mismatch, expected: " + T::class.java + ", got: " + component.javaClass)
+        return target
     }
 }
\ No newline at end of file
diff --git a/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/ContextConfiguration.kt b/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/DataFormatsConfiguration.kt
similarity index 61%
copy from camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/ContextConfiguration.kt
copy to camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/DataFormatsConfiguration.kt
index 847c945..c0fd4df 100644
--- a/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/ContextConfiguration.kt
+++ b/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/DataFormatsConfiguration.kt
@@ -17,21 +17,24 @@
 package org.apache.camel.k.loader.kotlin.dsl
 
 import org.apache.camel.CamelContext
-import org.apache.camel.spi.Registry
+import org.apache.camel.spi.DataFormat
 
-class ContextConfiguration (
-        private val context: CamelContext,
-        private val registry: Registry) {
+class DataFormatsConfiguration(val context: CamelContext) {
+    inline fun <reified T : DataFormat> dataFormat(name: String, block: T.() -> Unit) : T {
+        var target = context.registry.lookupByNameAndType(name, T::class.java)
+        var bind = false
 
-    fun registry(block: RegistryConfiguration.() -> Unit): RegistryConfiguration {
-        val delegate = RegistryConfiguration(registry)
-        delegate.block()
-        return delegate
-    }
+        if (target == null) {
+            target = context.injector.newInstance(T::class.java)
+            bind = true
+        }
+
+        block.invoke(target)
+
+        if (bind) {
+            context.registry.bind(name, T::class.java, target)
+        }
 
-    fun components(block: ComponentsConfiguration.() -> Unit): ComponentsConfiguration {
-        val delegate = ComponentsConfiguration(context)
-        delegate.block()
-        return delegate
+        return target
     }
 }
\ No newline at end of file
diff --git a/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/IntegrationConfiguration.kt b/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/IntegrationConfiguration.kt
index da2f45c..a02c394 100644
--- a/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/IntegrationConfiguration.kt
+++ b/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/IntegrationConfiguration.kt
@@ -43,8 +43,8 @@ abstract class IntegrationConfiguration(
         BeansConfiguration(context).block()
     }
 
-    fun context(block: ContextConfiguration.() -> Unit) {
-        ContextConfiguration(context, registry).block()
+    fun camel(block: CamelConfiguration.() -> Unit) {
+        CamelConfiguration(context).block()
     }
 
     fun from(uri: String): RouteDefinition {
diff --git a/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/ContextConfiguration.kt b/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/LanguagesConfiguration.kt
similarity index 61%
copy from camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/ContextConfiguration.kt
copy to camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/LanguagesConfiguration.kt
index 847c945..2afc1f9 100644
--- a/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/ContextConfiguration.kt
+++ b/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/LanguagesConfiguration.kt
@@ -17,21 +17,24 @@
 package org.apache.camel.k.loader.kotlin.dsl
 
 import org.apache.camel.CamelContext
-import org.apache.camel.spi.Registry
+import org.apache.camel.spi.Language
 
-class ContextConfiguration (
-        private val context: CamelContext,
-        private val registry: Registry) {
+class LanguagesConfiguration(val context: CamelContext) {
+    inline fun <reified T : Language> language(name: String, block: T.() -> Unit) : T {
+        var target = context.registry.lookupByNameAndType(name, T::class.java)
+        var bind = false
 
-    fun registry(block: RegistryConfiguration.() -> Unit): RegistryConfiguration {
-        val delegate = RegistryConfiguration(registry)
-        delegate.block()
-        return delegate
-    }
+        if (target == null) {
+            target = context.injector.newInstance(T::class.java)
+            bind = true
+        }
+
+        block.invoke(target)
+
+        if (bind) {
+            context.registry.bind(name, T::class.java, target)
+        }
 
-    fun components(block: ComponentsConfiguration.() -> Unit): ComponentsConfiguration {
-        val delegate = ComponentsConfiguration(context)
-        delegate.block()
-        return delegate
+        return target
     }
 }
\ No newline at end of file
diff --git a/camel-k-loader-kotlin/src/test/kotlin/org/apache/camel/k/loader/kotlin/dsl/IntegrationTest.kt b/camel-k-loader-kotlin/src/test/kotlin/org/apache/camel/k/loader/kotlin/dsl/IntegrationTest.kt
index 9f14169..66702db 100644
--- a/camel-k-loader-kotlin/src/test/kotlin/org/apache/camel/k/loader/kotlin/dsl/IntegrationTest.kt
+++ b/camel-k-loader-kotlin/src/test/kotlin/org/apache/camel/k/loader/kotlin/dsl/IntegrationTest.kt
@@ -18,11 +18,13 @@ package org.apache.camel.k.loader.kotlin.dsl
 
 import org.apache.camel.Predicate
 import org.apache.camel.Processor
+import org.apache.camel.component.jackson.JacksonDataFormat
 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.forRoutes
+import org.apache.camel.language.bean.BeanLanguage
 import org.apache.camel.model.ModelCamelContext
 import org.apache.camel.model.rest.GetVerbDefinition
 import org.apache.camel.model.rest.PostVerbDefinition
@@ -85,22 +87,11 @@ class IntegrationTest {
     }
 
     @Test
-    fun `load integration with binding`() {
+    fun `load integration with components configuration`() {
         val context = DefaultCamelContext()
         val runtime = Runtime.of(context)
 
-        forRoutes("classpath:routes-with-bindings.kts").accept(Runtime.Phase.ConfigureRoutes, runtime)
-
-        assertThat(context.registry.lookupByName("my-entry")).isEqualTo("myRegistryEntry1")
-        assertThat(context.registry.lookupByName("my-proc")).isInstanceOf(Processor::class.java)
-    }
-
-    @Test
-    fun `load integration with component configuration`() {
-        val context = DefaultCamelContext()
-        val runtime = Runtime.of(context)
-
-        forRoutes("classpath:routes-with-component-configuration.kts").accept(Runtime.Phase.ConfigureRoutes, runtime)
+        forRoutes("classpath:routes-with-components-configuration.kts").accept(Runtime.Phase.ConfigureRoutes, runtime)
 
         val seda = context.getComponent("seda", SedaComponent::class.java)
         val mySeda = context.getComponent("mySeda", SedaComponent::class.java)
@@ -114,6 +105,38 @@ class IntegrationTest {
     }
 
     @Test
+    fun `load integration with languages configuration`() {
+        val context = DefaultCamelContext()
+        val runtime = Runtime.of(context)
+
+        forRoutes("classpath:routes-with-languages-configuration.kts").accept(Runtime.Phase.ConfigureRoutes, runtime)
+
+        val bean = context.resolveLanguage("bean") as BeanLanguage
+        assertThat(bean.beanType).isEqualTo(String::class.java)
+        assertThat(bean.method).isEqualTo("toUpperCase")
+
+        val mybean = context.resolveLanguage("my-bean") as BeanLanguage
+        assertThat(mybean.beanType).isEqualTo(String::class.java)
+        assertThat(mybean.method).isEqualTo("toLowerCase")
+    }
+
+    @Test
+    fun `load integration with dataformats configuration`() {
+        val context = DefaultCamelContext()
+        val runtime = Runtime.of(context)
+
+        forRoutes("classpath:routes-with-dataformats-configuration.kts").accept(Runtime.Phase.ConfigureRoutes, runtime)
+
+        val jackson = context.resolveDataFormat("json-jackson") as JacksonDataFormat
+        assertThat(jackson.unmarshalType).isEqualTo(Map::class.java)
+        assertThat(jackson.isPrettyPrint).isTrue()
+
+        val myjackson = context.resolveDataFormat("my-jackson") as JacksonDataFormat
+        assertThat(myjackson.unmarshalType).isEqualTo(String::class.java)
+        assertThat(myjackson.isPrettyPrint).isFalse()
+    }
+
+    @Test
     fun `load integration with error handler`() {
         val context = DefaultCamelContext()
         val runtime = Runtime.of(context)
diff --git a/camel-k-loader-kotlin/src/test/resources/routes-new.kts b/camel-k-loader-kotlin/src/test/resources/routes-new.kts
index af6ac29..7f8b923 100644
--- a/camel-k-loader-kotlin/src/test/resources/routes-new.kts
+++ b/camel-k-loader-kotlin/src/test/resources/routes-new.kts
@@ -1,2 +1,17 @@
-
+/*
+ * 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.
+ */
 println("test")
\ No newline at end of file
diff --git a/camel-k-loader-kotlin/src/test/resources/routes-with-beans.kts b/camel-k-loader-kotlin/src/test/resources/routes-with-beans.kts
index 2356dc9..52f596f 100644
--- a/camel-k-loader-kotlin/src/test/resources/routes-with-beans.kts
+++ b/camel-k-loader-kotlin/src/test/resources/routes-with-beans.kts
@@ -1,3 +1,19 @@
+/*
+ * 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.
+ */
 beans {
     bean<org.apache.commons.dbcp2.BasicDataSource>("dataSource") {
         driverClassName = "org.h2.Driver"
diff --git a/camel-k-loader-kotlin/src/test/resources/routes-with-bindings.kts b/camel-k-loader-kotlin/src/test/resources/routes-with-bindings.kts
deleted file mode 100644
index b4feaeb..0000000
--- a/camel-k-loader-kotlin/src/test/resources/routes-with-bindings.kts
+++ /dev/null
@@ -1,16 +0,0 @@
-
-context {
-    registry {
-        bind("my-entry", "myRegistryEntry1")
-        bind("my-proc", processor {
-            e -> e.getIn().body = "Hello"
-        })
-    }
-}
-
-
-from("timer:tick")
-    .process().message {
-        m -> m.headers["MyHeader"] = "MyHeaderValue"
-    }
-    .to("log:info")
\ No newline at end of file
diff --git a/camel-k-loader-kotlin/src/test/resources/routes-with-component-configuration.kts b/camel-k-loader-kotlin/src/test/resources/routes-with-component-configuration.kts
deleted file mode 100644
index a93be0c..0000000
--- a/camel-k-loader-kotlin/src/test/resources/routes-with-component-configuration.kts
+++ /dev/null
@@ -1,28 +0,0 @@
-import org.apache.camel.Exchange
-import org.apache.camel.component.log.LogComponent
-import org.apache.camel.component.seda.SedaComponent
-
-context {
-
-    components {
-
-        component<LogComponent>("log") {
-            setExchangeFormatter {
-                e: Exchange -> "" + e.getIn().body
-            }
-        }
-
-        component<SedaComponent>("seda") {
-            queueSize = 1234
-            concurrentConsumers = 12
-        }
-
-        component<SedaComponent>("mySeda") {
-            queueSize = 4321
-            concurrentConsumers = 21
-        }
-    }
-}
-
-from("timer:tick")
-    .to("log:info")
\ No newline at end of file
diff --git a/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/ContextConfiguration.kt b/camel-k-loader-kotlin/src/test/resources/routes-with-components-configuration.kts
similarity index 56%
copy from camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/ContextConfiguration.kt
copy to camel-k-loader-kotlin/src/test/resources/routes-with-components-configuration.kts
index 847c945..3fdf39c 100644
--- a/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/ContextConfiguration.kt
+++ b/camel-k-loader-kotlin/src/test/resources/routes-with-components-configuration.kts
@@ -1,4 +1,4 @@
-/**
+/*
  * 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.
@@ -14,24 +14,29 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.k.loader.kotlin.dsl
+import org.apache.camel.Exchange
+import org.apache.camel.component.log.LogComponent
+import org.apache.camel.component.seda.SedaComponent
 
-import org.apache.camel.CamelContext
-import org.apache.camel.spi.Registry
+camel {
+    components {
+        component<LogComponent>("log") {
+            setExchangeFormatter {
+                e: Exchange -> "" + e.getIn().body
+            }
+        }
 
-class ContextConfiguration (
-        private val context: CamelContext,
-        private val registry: Registry) {
+        component<SedaComponent>("seda") {
+            queueSize = 1234
+            concurrentConsumers = 12
+        }
 
-    fun registry(block: RegistryConfiguration.() -> Unit): RegistryConfiguration {
-        val delegate = RegistryConfiguration(registry)
-        delegate.block()
-        return delegate
+        component<SedaComponent>("mySeda") {
+            queueSize = 4321
+            concurrentConsumers = 21
+        }
     }
+}
 
-    fun components(block: ComponentsConfiguration.() -> Unit): ComponentsConfiguration {
-        val delegate = ComponentsConfiguration(context)
-        delegate.block()
-        return delegate
-    }
-}
\ No newline at end of file
+from("timer:tick")
+    .to("log:info")
\ No newline at end of file
diff --git a/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/ContextConfiguration.kt b/camel-k-loader-kotlin/src/test/resources/routes-with-dataformats-configuration.kts
similarity index 56%
copy from camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/ContextConfiguration.kt
copy to camel-k-loader-kotlin/src/test/resources/routes-with-dataformats-configuration.kts
index 847c945..b5cc267 100644
--- a/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/ContextConfiguration.kt
+++ b/camel-k-loader-kotlin/src/test/resources/routes-with-dataformats-configuration.kts
@@ -1,4 +1,4 @@
-/**
+/*
  * 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.
@@ -14,24 +14,18 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.k.loader.kotlin.dsl
+import org.apache.camel.component.jackson.JacksonDataFormat
 
-import org.apache.camel.CamelContext
-import org.apache.camel.spi.Registry
+camel {
+    dataFormats {
+        dataFormat<JacksonDataFormat>("json-jackson") {
+            unmarshalType = Map::class.java
+            isPrettyPrint = true
+        }
 
-class ContextConfiguration (
-        private val context: CamelContext,
-        private val registry: Registry) {
-
-    fun registry(block: RegistryConfiguration.() -> Unit): RegistryConfiguration {
-        val delegate = RegistryConfiguration(registry)
-        delegate.block()
-        return delegate
-    }
-
-    fun components(block: ComponentsConfiguration.() -> Unit): ComponentsConfiguration {
-        val delegate = ComponentsConfiguration(context)
-        delegate.block()
-        return delegate
+        dataFormat<JacksonDataFormat>("my-jackson") {
+            unmarshalType = String::class.java
+            isPrettyPrint = false
+        }
     }
 }
\ No newline at end of file
diff --git a/camel-k-loader-kotlin/src/test/resources/routes-with-error-handler.kts b/camel-k-loader-kotlin/src/test/resources/routes-with-error-handler.kts
index 6bc6678..ed55f49 100644
--- a/camel-k-loader-kotlin/src/test/resources/routes-with-error-handler.kts
+++ b/camel-k-loader-kotlin/src/test/resources/routes-with-error-handler.kts
@@ -1,4 +1,19 @@
-
+/*
+ * 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.java)
     .id("my-on-exception")
     .to("log:exception")
diff --git a/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/ContextConfiguration.kt b/camel-k-loader-kotlin/src/test/resources/routes-with-languages-configuration.kts
similarity index 56%
rename from camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/ContextConfiguration.kt
rename to camel-k-loader-kotlin/src/test/resources/routes-with-languages-configuration.kts
index 847c945..065497a 100644
--- a/camel-k-loader-kotlin/src/main/kotlin/org/apache/camel/k/loader/kotlin/dsl/ContextConfiguration.kt
+++ b/camel-k-loader-kotlin/src/test/resources/routes-with-languages-configuration.kts
@@ -1,4 +1,4 @@
-/**
+/*
  * 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.
@@ -14,24 +14,17 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.k.loader.kotlin.dsl
+import org.apache.camel.language.bean.BeanLanguage
 
-import org.apache.camel.CamelContext
-import org.apache.camel.spi.Registry
-
-class ContextConfiguration (
-        private val context: CamelContext,
-        private val registry: Registry) {
-
-    fun registry(block: RegistryConfiguration.() -> Unit): RegistryConfiguration {
-        val delegate = RegistryConfiguration(registry)
-        delegate.block()
-        return delegate
-    }
-
-    fun components(block: ComponentsConfiguration.() -> Unit): ComponentsConfiguration {
-        val delegate = ComponentsConfiguration(context)
-        delegate.block()
-        return delegate
+camel {
+    languages {
+        language<BeanLanguage>("bean") {
+            beanType = String::class.java
+            method = "toUpperCase"
+        }
+        language<BeanLanguage>("my-bean") {
+            beanType = String::class.java
+            method = "toLowerCase"
+        }
     }
 }
\ No newline at end of file
diff --git a/camel-k-loader-kotlin/src/test/resources/routes-with-rest.kts b/camel-k-loader-kotlin/src/test/resources/routes-with-rest.kts
index 8d4d82e..37f2828 100644
--- a/camel-k-loader-kotlin/src/test/resources/routes-with-rest.kts
+++ b/camel-k-loader-kotlin/src/test/resources/routes-with-rest.kts
@@ -1,4 +1,19 @@
-
+/*
+ * 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.
+ */
 rest {
     configuration {
         host = "my-host"
diff --git a/camel-k-loader-kotlin/src/test/resources/routes.kts b/camel-k-loader-kotlin/src/test/resources/routes.kts
index 5bf9c94..7d28bb5 100644
--- a/camel-k-loader-kotlin/src/test/resources/routes.kts
+++ b/camel-k-loader-kotlin/src/test/resources/routes.kts
@@ -1,4 +1,19 @@
-
+/*
+ * 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.
+ */
 from("timer:tick")
     .process().message {
         m -> m.headers["MyHeader"] = "MyHeaderValue"