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
The following commit(s) were added to refs/heads/master by this push:
new 3706645 kotlin: cleanup loader and tests
3706645 is described below
commit 37066451dfa2519aaa80d0a597c209161ccce9fd
Author: lburgazzoli <[email protected]>
AuthorDate: Wed Aug 19 16:38:56 2020 +0200
kotlin: cleanup loader and tests
---
...LoaderTest.java => KotlinSourceLoaderTest.java} | 2 +-
.../k/loader/kotlin/KotlinSourceLoaderTest.kt | 176 +++++++++++++++++++++
.../org/apache/camel/k/loader/kotlin/LoaderTest.kt | 97 ------------
.../camel/k/loader/kotlin/dsl/IntegrationTest.kt | 166 -------------------
.../camel/k/loader/kotlin/support/TestRuntime.kt | 73 +++++++++
5 files changed, 250 insertions(+), 264 deletions(-)
diff --git
a/camel-k-loader-kotlin/camel-k-loader-kotlin-itests/src/test/java/org/apache/camel/k/loader/kotlin/itests/LoaderTest.java
b/camel-k-loader-kotlin/camel-k-loader-kotlin-itests/src/test/java/org/apache/camel/k/loader/kotlin/itests/KotlinSourceLoaderTest.java
similarity index 97%
rename from
camel-k-loader-kotlin/camel-k-loader-kotlin-itests/src/test/java/org/apache/camel/k/loader/kotlin/itests/LoaderTest.java
rename to
camel-k-loader-kotlin/camel-k-loader-kotlin-itests/src/test/java/org/apache/camel/k/loader/kotlin/itests/KotlinSourceLoaderTest.java
index bc25de7..b0b5f0a 100644
---
a/camel-k-loader-kotlin/camel-k-loader-kotlin-itests/src/test/java/org/apache/camel/k/loader/kotlin/itests/LoaderTest.java
+++
b/camel-k-loader-kotlin/camel-k-loader-kotlin-itests/src/test/java/org/apache/camel/k/loader/kotlin/itests/KotlinSourceLoaderTest.java
@@ -26,7 +26,7 @@ import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
-public class LoaderTest {
+public class KotlinSourceLoaderTest {
@Test
public void testLoad() throws Exception {
final CamelContext context = new DefaultCamelContext();
diff --git
a/camel-k-loader-kotlin/camel-k-loader-kotlin/src/test/kotlin/org/apache/camel/k/loader/kotlin/KotlinSourceLoaderTest.kt
b/camel-k-loader-kotlin/camel-k-loader-kotlin/src/test/kotlin/org/apache/camel/k/loader/kotlin/KotlinSourceLoaderTest.kt
new file mode 100644
index 0000000..441c038
--- /dev/null
+++
b/camel-k-loader-kotlin/camel-k-loader-kotlin/src/test/kotlin/org/apache/camel/k/loader/kotlin/KotlinSourceLoaderTest.kt
@@ -0,0 +1,176 @@
+/**
+ * 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.
+ */
+package org.apache.camel.k.loader.kotlin
+
+import org.apache.camel.Predicate
+import org.apache.camel.Processor
+import org.apache.camel.RuntimeCamelException
+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.k.loader.kotlin.support.TestRuntime
+import org.apache.camel.language.bean.BeanLanguage
+import org.apache.camel.model.ProcessDefinition
+import org.apache.camel.model.ToDefinition
+import org.apache.camel.model.rest.GetVerbDefinition
+import org.apache.camel.model.rest.PostVerbDefinition
+import org.apache.camel.processor.FatalFallbackErrorHandler
+import org.apache.camel.support.DefaultHeaderFilterStrategy
+import org.assertj.core.api.Assertions
+import org.assertj.core.api.Assertions.assertThat
+import org.junit.jupiter.api.Test
+import javax.sql.DataSource
+
+class KotlinSourceLoaderTest {
+
+ @Test
+ fun `load routes`() {
+ val runtime = TestRuntime()
+ runtime.loadRoutes("classpath:routes.kts")
+
+ val routes = runtime.context.routeDefinitions
+ assertThat(routes).hasSize(1)
+ assertThat(routes[0].input.endpointUri).isEqualTo("timer:tick")
+
assertThat(routes[0].outputs[0]).isInstanceOf(ProcessDefinition::class.java)
+ assertThat(routes[0].outputs[1]).isInstanceOf(ToDefinition::class.java)
+ }
+
+ @Test
+ fun `load routes with endpoint dsl`() {
+ val runtime = TestRuntime()
+ runtime.loadRoutes("classpath:routes-with-endpoint-dsl.kts")
+
+ val routes = runtime.context.routeDefinitions
+ assertThat(routes).hasSize(1)
+
assertThat(routes[0].input.endpointUri).isEqualTo("timer://tick?period=1s")
+
assertThat(routes[0].outputs[0]).isInstanceOfSatisfying(ToDefinition::class.java)
{
+ assertThat(it.endpointUri).isEqualTo("log://info")
+ }
+ }
+
+
+ @Test
+ fun `load integration with rest`() {
+ val runtime = TestRuntime()
+ runtime.loadRoutes("classpath:routes-with-rest.kts")
+
+ assertThat(runtime.context.restConfiguration.host).isEqualTo("my-host")
+ assertThat(runtime.context.restConfiguration.port).isEqualTo(9192)
+ assertThat(runtime.context.restDefinitions.size).isEqualTo(2)
+
+ with(runtime.context.restDefinitions.find { it.path == "/my/path" }) {
+ assertThat(this?.verbs).hasSize(1)
+
+ with(this?.verbs?.get(0) as GetVerbDefinition) {
+ assertThat(uri).isEqualTo("/get")
+ assertThat(consumes).isEqualTo("application/json")
+ assertThat(produces).isEqualTo("application/json")
+ assertThat(to).hasFieldOrPropertyWithValue("endpointUri",
"direct:get")
+ }
+ }
+
+ with(runtime.context.restDefinitions.find { it.path == "/post" }) {
+ assertThat(this?.verbs).hasSize(1)
+
+ with(this?.verbs?.get(0) as PostVerbDefinition) {
+ assertThat(uri).isNull()
+ assertThat(consumes).isEqualTo("application/json")
+ assertThat(produces).isEqualTo("application/json")
+ assertThat(to).hasFieldOrPropertyWithValue("endpointUri",
"direct:post")
+ }
+ }
+ }
+
+ @Test
+ fun `load integration with beans`() {
+ val runtime = TestRuntime()
+ runtime.loadRoutes("classpath:routes-with-beans.kts")
+
+
assertThat(runtime.context.registry.findByType(DataSource::class.java)).hasSize(1)
+
assertThat(runtime.context.registry.lookupByName("dataSource")).isInstanceOf(DataSource::class.java)
+
assertThat(runtime.context.registry.findByType(DefaultHeaderFilterStrategy::class.java)).hasSize(1)
+
assertThat(runtime.context.registry.lookupByName("filterStrategy")).isInstanceOf(DefaultHeaderFilterStrategy::class.java)
+
assertThat(runtime.context.registry.lookupByName("myProcessor")).isInstanceOf(Processor::class.java)
+
assertThat(runtime.context.registry.lookupByName("myPredicate")).isInstanceOf(Predicate::class.java)
+ }
+
+ @Test
+ fun `load integration with components configuration`() {
+ val runtime = TestRuntime()
+
runtime.loadRoutes("classpath:routes-with-components-configuration.kts")
+
+ val seda = runtime.context.getComponent("seda",
SedaComponent::class.java)
+ val mySeda = runtime.context.getComponent("mySeda",
SedaComponent::class.java)
+ val log = runtime.context.getComponent("log", LogComponent::class.java)
+
+ assertThat(seda.queueSize).isEqualTo(1234)
+ assertThat(seda.concurrentConsumers).isEqualTo(12)
+ assertThat(mySeda.queueSize).isEqualTo(4321)
+ assertThat(mySeda.concurrentConsumers).isEqualTo(21)
+ assertThat(log.exchangeFormatter).isNotNull
+ }
+
+ @Test
+ fun `load integration with components configuration error`() {
+ Assertions.assertThatExceptionOfType(RuntimeCamelException::class.java)
+ .isThrownBy {
TestRuntime().loadRoutes("classpath:routes-with-components-configuration-error.kts")
}
+ .withCauseInstanceOf(IllegalArgumentException::class.java)
+ .withMessageContaining("Type mismatch, expected: class
org.apache.camel.component.log.LogComponent, got: class
org.apache.camel.component.seda.SedaComponent");
+ }
+
+ @Test
+ fun `load integration with languages configuration`() {
+ val runtime = TestRuntime()
+ runtime.loadRoutes("classpath:routes-with-languages-configuration.kts")
+
+ val bean = runtime.context.resolveLanguage("bean") as BeanLanguage
+ assertThat(bean.beanType).isEqualTo(String::class.java)
+ assertThat(bean.method).isEqualTo("toUpperCase")
+
+ val mybean = runtime.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 runtime = TestRuntime()
+
runtime.loadRoutes("classpath:routes-with-dataformats-configuration.kts")
+
+ val jackson = runtime.context.resolveDataFormat("json-jackson") as
JacksonDataFormat
+ assertThat(jackson.unmarshalType).isEqualTo(Map::class.java)
+ assertThat(jackson.isPrettyPrint).isTrue()
+
+ val myjackson = runtime.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 runtime = TestRuntime()
+ runtime.loadRoutes("classpath:routes-with-error-handler.kts")
+ runtime.start()
+
+ try {
+ assertThat(runtime.context.routes).hasSize(1)
+
assertThat(runtime.context.routes[0].getOnException("my-on-exception")).isInstanceOf(FatalFallbackErrorHandler::class.java)
+ } finally {
+ runtime.context.stop()
+ }
+ }
+}
diff --git
a/camel-k-loader-kotlin/camel-k-loader-kotlin/src/test/kotlin/org/apache/camel/k/loader/kotlin/LoaderTest.kt
b/camel-k-loader-kotlin/camel-k-loader-kotlin/src/test/kotlin/org/apache/camel/k/loader/kotlin/LoaderTest.kt
deleted file mode 100644
index d6840fa..0000000
---
a/camel-k-loader-kotlin/camel-k-loader-kotlin/src/test/kotlin/org/apache/camel/k/loader/kotlin/LoaderTest.kt
+++ /dev/null
@@ -1,97 +0,0 @@
-/**
- * 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.
- */
-package org.apache.camel.k.loader.kotlin
-
-import org.apache.camel.CamelContext
-import org.apache.camel.RoutesBuilder
-import org.apache.camel.builder.RouteBuilder
-import org.apache.camel.impl.DefaultCamelContext
-import org.apache.camel.k.Runtime
-import org.apache.camel.k.Sources
-import org.apache.camel.k.listener.RoutesConfigurer
-import org.apache.camel.model.ProcessDefinition
-import org.apache.camel.model.ToDefinition
-import org.assertj.core.api.Assertions.assertThat
-import org.junit.jupiter.api.Test
-import java.util.*
-
-class LoaderTest {
-
- @Test
- fun `load routes`() {
- val runtime = TestRuntime()
- val source = Sources.fromURI("classpath:routes.kts")
- val loader = RoutesConfigurer.load(runtime, source)
-
- assertThat(loader).isInstanceOf(KotlinSourceLoader::class.java)
- assertThat(runtime.builders).hasSize(1)
- assertThat(runtime.builders[0]).isInstanceOf(RouteBuilder::class.java)
-
- val builder = runtime.builders[0] as RouteBuilder
- builder.context = runtime.camelContext
- builder.configure()
-
- val routes = builder.routeCollection.routes
- assertThat(routes).hasSize(1)
- assertThat(routes[0].input.endpointUri).isEqualTo("timer:tick")
-
assertThat(routes[0].outputs[0]).isInstanceOf(ProcessDefinition::class.java)
- assertThat(routes[0].outputs[1]).isInstanceOf(ToDefinition::class.java)
- }
-
- @Test
- fun `load routes with endpoint dsl`() {
- val runtime = TestRuntime()
- val source = Sources.fromURI("classpath:routes-with-endpoint-dsl.kts")
- val loader = RoutesConfigurer.load(runtime, source)
-
- assertThat(loader).isInstanceOf(KotlinSourceLoader::class.java)
- assertThat(runtime.builders).hasSize(1)
- assertThat(runtime.builders[0]).isInstanceOf(RouteBuilder::class.java)
-
- val builder = runtime.builders[0] as RouteBuilder
- builder.context = runtime.camelContext
- builder.configure()
-
- val routes = builder.routeCollection.routes
- assertThat(routes).hasSize(1)
-
assertThat(routes[0].input.endpointUri).isEqualTo("timer://tick?period=1s")
-
assertThat(routes[0].outputs[0]).isInstanceOfSatisfying(ToDefinition::class.java)
{
- assertThat(it.endpointUri).isEqualTo("log://info")
- }
- }
-
- internal class TestRuntime : Runtime {
- private val context: CamelContext
- val builders: MutableList<RoutesBuilder>
-
- init {
- this.context = DefaultCamelContext()
- this.builders = ArrayList()
- }
-
- override fun getCamelContext(): CamelContext {
- return this.context
- }
-
- override fun addRoutes(builder: RoutesBuilder) {
- this.builders.add(builder)
- }
-
- override fun setPropertiesLocations(locations:
MutableCollection<String>?) {
- }
- }
-}
diff --git
a/camel-k-loader-kotlin/camel-k-loader-kotlin/src/test/kotlin/org/apache/camel/k/loader/kotlin/dsl/IntegrationTest.kt
b/camel-k-loader-kotlin/camel-k-loader-kotlin/src/test/kotlin/org/apache/camel/k/loader/kotlin/dsl/IntegrationTest.kt
deleted file mode 100644
index 95c0da7..0000000
---
a/camel-k-loader-kotlin/camel-k-loader-kotlin/src/test/kotlin/org/apache/camel/k/loader/kotlin/dsl/IntegrationTest.kt
+++ /dev/null
@@ -1,166 +0,0 @@
-/**
- * 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.
- */
-package org.apache.camel.k.loader.kotlin.dsl
-
-import org.apache.camel.Predicate
-import org.apache.camel.Processor
-import org.apache.camel.RuntimeCamelException
-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
-import org.apache.camel.processor.FatalFallbackErrorHandler
-import org.apache.camel.support.DefaultHeaderFilterStrategy
-import org.assertj.core.api.Assertions.assertThat
-import org.assertj.core.api.Assertions.assertThatExceptionOfType
-import org.junit.jupiter.api.Test
-import javax.sql.DataSource
-
-class IntegrationTest {
- @Test
- fun `load integration with rest`() {
- val context = DefaultCamelContext()
- val runtime = Runtime.on(context)
-
-
forRoutes("classpath:routes-with-rest.kts").accept(Runtime.Phase.ConfigureRoutes,
runtime)
-
- assertThat(context.restConfiguration.host).isEqualTo("my-host")
- assertThat(context.restConfiguration.port).isEqualTo(9192)
-
assertThat(context.adapt(ModelCamelContext::class.java).restDefinitions.size).isEqualTo(2)
-
- with(context.adapt(ModelCamelContext::class.java).restDefinitions.find
{ it.path == "/my/path" }) {
- assertThat(this?.verbs).hasSize(1)
-
- with(this?.verbs?.get(0) as GetVerbDefinition) {
- assertThat(uri).isEqualTo("/get")
- assertThat(consumes).isEqualTo("application/json")
- assertThat(produces).isEqualTo("application/json")
- assertThat(to).hasFieldOrPropertyWithValue("endpointUri",
"direct:get")
- }
- }
-
- with(context.adapt(ModelCamelContext::class.java).restDefinitions.find
{ it.path == "/post" }) {
- assertThat(this?.verbs).hasSize(1)
-
- with(this?.verbs?.get(0) as PostVerbDefinition) {
- assertThat(uri).isNull()
- assertThat(consumes).isEqualTo("application/json")
- assertThat(produces).isEqualTo("application/json")
- assertThat(to).hasFieldOrPropertyWithValue("endpointUri",
"direct:post")
- }
- }
- }
-
- @Test
- fun `load integration with beans`() {
- val context = DefaultCamelContext()
- val runtime = Runtime.on(context)
-
-
forRoutes("classpath:routes-with-beans.kts").accept(Runtime.Phase.ConfigureRoutes,
runtime)
-
-
assertThat(context.registry.findByType(DataSource::class.java)).hasSize(1)
-
assertThat(context.registry.lookupByName("dataSource")).isInstanceOf(DataSource::class.java)
-
assertThat(context.registry.findByType(DefaultHeaderFilterStrategy::class.java)).hasSize(1)
-
assertThat(context.registry.lookupByName("filterStrategy")).isInstanceOf(DefaultHeaderFilterStrategy::class.java)
-
assertThat(context.registry.lookupByName("myProcessor")).isInstanceOf(Processor::class.java)
-
assertThat(context.registry.lookupByName("myPredicate")).isInstanceOf(Predicate::class.java)
- }
-
- @Test
- fun `load integration with components configuration`() {
- val context = DefaultCamelContext()
- val runtime = Runtime.on(context)
-
-
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)
- val log = context.getComponent("log", LogComponent::class.java)
-
- assertThat(seda.queueSize).isEqualTo(1234)
- assertThat(seda.concurrentConsumers).isEqualTo(12)
- assertThat(mySeda.queueSize).isEqualTo(4321)
- assertThat(mySeda.concurrentConsumers).isEqualTo(21)
- assertThat(log.exchangeFormatter).isNotNull
- }
-
- @Test
- fun `load integration with components configuration error`() {
- val context = DefaultCamelContext()
- val runtime = Runtime.on(context)
-
- assertThatExceptionOfType(RuntimeCamelException::class.java)
- .isThrownBy {
forRoutes("classpath:routes-with-components-configuration-error.kts").accept(Runtime.Phase.ConfigureRoutes,
runtime) }
- .withCauseInstanceOf(IllegalArgumentException::class.java)
- .withMessageContaining("Type mismatch, expected: class
org.apache.camel.component.log.LogComponent, got: class
org.apache.camel.component.seda.SedaComponent");
- }
-
- @Test
- fun `load integration with languages configuration`() {
- val context = DefaultCamelContext()
- val runtime = Runtime.on(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.on(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.on(context)
-
-
forRoutes("classpath:routes-with-error-handler.kts").accept(Runtime.Phase.ConfigureRoutes,
runtime)
-
- context.start()
-
- try {
- assertThat(context.routes).hasSize(1)
-
assertThat(context.routes[0].getOnException("my-on-exception")).isInstanceOf(FatalFallbackErrorHandler::class.java)
- } finally {
- context.stop()
- }
- }
-}
\ No newline at end of file
diff --git
a/camel-k-loader-kotlin/camel-k-loader-kotlin/src/test/kotlin/org/apache/camel/k/loader/kotlin/support/TestRuntime.kt
b/camel-k-loader-kotlin/camel-k-loader-kotlin/src/test/kotlin/org/apache/camel/k/loader/kotlin/support/TestRuntime.kt
new file mode 100644
index 0000000..eefa40f
--- /dev/null
+++
b/camel-k-loader-kotlin/camel-k-loader-kotlin/src/test/kotlin/org/apache/camel/k/loader/kotlin/support/TestRuntime.kt
@@ -0,0 +1,73 @@
+/**
+ * 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.
+ */
+package org.apache.camel.k.loader.kotlin.support
+
+import org.apache.camel.k.Runtime
+import org.apache.camel.CamelContext
+import org.apache.camel.FluentProducerTemplate
+import org.apache.camel.RoutesBuilder
+import org.apache.camel.impl.DefaultCamelContext
+import org.apache.camel.k.CompositeClassloader
+import org.apache.camel.k.listener.RoutesConfigurer.forRoutes
+import org.apache.camel.model.ModelCamelContext
+import java.util.ArrayList
+
+class TestRuntime : Runtime {
+ val context: ModelCamelContext
+ val template: FluentProducerTemplate
+ val builders: MutableList<RoutesBuilder>
+ val configurations: MutableList<Any>
+
+ init {
+ this.context = DefaultCamelContext()
+ this.context.setApplicationContextClassLoader(CompositeClassloader())
+ this.template = this.context.createFluentProducerTemplate()
+ this.builders = ArrayList()
+ this.configurations = ArrayList()
+ }
+
+ override fun getCamelContext(): CamelContext {
+ return this.context
+ }
+
+ override fun addRoutes(builder: RoutesBuilder) {
+ this.builders.add(builder)
+ this.context.addRoutes(builder)
+ }
+
+ override fun addConfiguration(configuration: Any) {
+ this.configurations.add(configuration)
+ }
+
+ fun loadRoutes(vararg routes: String) {
+ for (route in routes) {
+ forRoutes(route).accept(Runtime.Phase.ConfigureRoutes, this)
+ }
+ }
+
+ fun start() {
+ this.context.start()
+ }
+
+ override fun stop() {
+ this.context.stop()
+ }
+
+ override fun close() {
+ stop()
+ }
+}
\ No newline at end of file