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 6339b52498d671f28b95965d39e41206324eda4f Author: lburgazzoli <lburgazz...@gmail.com> AuthorDate: Tue Sep 3 14:42:38 2019 +0200 chore(test): move runtime test to camel-k-runtime-main --- .../src/main/java/org/apache/camel/k/Runtime.java | 8 ++ camel-k-runtime-main/pom.xml | 26 ++++++ .../test/java/org/apache/camel/k/main}/MyBean.java | 2 +- .../apache/camel/k/main}/MyRoutesWithBeans.java | 6 +- .../java/org/apache/camel/k/main/RuntimeTest.java | 103 ++++++++++++++------- .../src/test/resources/MyRoutesWithBeans.java | 4 +- camel-k-runtime-main/src/test/resources/rests.xml | 27 ++++++ .../src/test/resources/routes-with-expression.xml | 28 ++++++ camel-k-runtime-main/src/test/resources/routes.xml | 25 +++++ 9 files changed, 191 insertions(+), 38 deletions(-) diff --git a/camel-k-runtime-core/src/main/java/org/apache/camel/k/Runtime.java b/camel-k-runtime-core/src/main/java/org/apache/camel/k/Runtime.java index 34ca0d2..c90fb5c 100644 --- a/camel-k-runtime-core/src/main/java/org/apache/camel/k/Runtime.java +++ b/camel-k-runtime-core/src/main/java/org/apache/camel/k/Runtime.java @@ -16,6 +16,7 @@ */ package org.apache.camel.k; +import java.util.Map; import java.util.Properties; import org.apache.camel.CamelContext; @@ -41,6 +42,13 @@ public interface Runtime extends HasCamelContext { getRegistry().bind("properties", pc); } + default void setProperties(Map<String, String> properties) { + Properties p = new Properties(); + p.putAll(properties); + + setProperties(p); + } + default void addRoutes(RoutesBuilder builder) { try { getCamelContext().addRoutes(builder); diff --git a/camel-k-runtime-main/pom.xml b/camel-k-runtime-main/pom.xml index 2953855..87a55a7 100644 --- a/camel-k-runtime-main/pom.xml +++ b/camel-k-runtime-main/pom.xml @@ -104,6 +104,32 @@ <artifactId>camel-properties</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-endpointdsl</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bean</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.camel.k</groupId> + <artifactId>camel-k-loader-js</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel.k</groupId> + <artifactId>camel-k-loader-xml</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel.k</groupId> + <artifactId>camel-k-loader-java</artifactId> + <scope>test</scope> + </dependency> <dependency> <groupId>org.junit.jupiter</groupId> diff --git a/camel-k-loader-java/src/test/java/org/apache/camel/k/loader/java/MyBean.java b/camel-k-runtime-main/src/test/java/org/apache/camel/k/main/MyBean.java similarity index 96% rename from camel-k-loader-java/src/test/java/org/apache/camel/k/loader/java/MyBean.java rename to camel-k-runtime-main/src/test/java/org/apache/camel/k/main/MyBean.java index 94a1834..2069e08 100644 --- a/camel-k-loader-java/src/test/java/org/apache/camel/k/loader/java/MyBean.java +++ b/camel-k-runtime-main/src/test/java/org/apache/camel/k/main/MyBean.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.k.loader.java; +package org.apache.camel.k.main; public class MyBean { private final String name; diff --git a/camel-k-loader-java/src/test/java/org/apache/camel/k/loader/java/MyRoutesWithBeans.java b/camel-k-runtime-main/src/test/java/org/apache/camel/k/main/MyRoutesWithBeans.java similarity index 86% rename from camel-k-loader-java/src/test/java/org/apache/camel/k/loader/java/MyRoutesWithBeans.java rename to camel-k-runtime-main/src/test/java/org/apache/camel/k/main/MyRoutesWithBeans.java index 15db22b..a42b9f1 100644 --- a/camel-k-loader-java/src/test/java/org/apache/camel/k/loader/java/MyRoutesWithBeans.java +++ b/camel-k-runtime-main/src/test/java/org/apache/camel/k/main/MyRoutesWithBeans.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.k.loader.java; +package org.apache.camel.k.main; import org.apache.camel.BindToRegistry; import org.apache.camel.builder.RouteBuilder; @@ -28,7 +28,7 @@ public class MyRoutesWithBeans extends RouteBuilder { } @BindToRegistry("my-bean") - public org.apache.camel.k.loader.java.MyBean createMyBean() { - return new org.apache.camel.k.loader.java.MyBean("my-bean-name"); + public org.apache.camel.k.main.MyBean createMyBean() { + return new org.apache.camel.k.main.MyBean("my-bean-name"); } } \ No newline at end of file diff --git a/camel-k-runtime-main/src/test/java/org/apache/camel/k/main/RuntimeTest.java b/camel-k-runtime-main/src/test/java/org/apache/camel/k/main/RuntimeTest.java index b5eca85..13abd05 100644 --- a/camel-k-runtime-main/src/test/java/org/apache/camel/k/main/RuntimeTest.java +++ b/camel-k-runtime-main/src/test/java/org/apache/camel/k/main/RuntimeTest.java @@ -24,57 +24,96 @@ import org.apache.camel.k.Runtime; import org.apache.camel.k.listener.ContextConfigurer; import org.apache.camel.k.listener.RoutesConfigurer; import org.apache.camel.model.ModelCamelContext; +import org.apache.camel.util.CollectionHelper; import org.apache.camel.util.ObjectHelper; -import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; public class RuntimeTest { - @Disabled + private ApplicationRuntime runtime; + + @BeforeEach + public void setUp() { + runtime = new ApplicationRuntime(); + } + + @AfterEach + public void cleanUp() throws Exception { + if (runtime != null) { + runtime.stop(); + } + } @Test void testLoadMultipleRoutes() throws Exception { - ApplicationRuntime runtime = new ApplicationRuntime(); + runtime.addListener(new ContextConfigurer()); + runtime.addListener(RoutesConfigurer.forRoutes("classpath:r1.js", "classpath:r2.mytype?language=js")); + runtime.addListener(Runtime.Phase.Started, r -> { + CamelContext context = r.getCamelContext(); + List<Route> routes = context.getRoutes(); - try { - runtime.addListener(new ContextConfigurer()); - runtime.addListener(RoutesConfigurer.forRoutes("classpath:r1.js", "classpath:r2.mytype?language=js")); - runtime.addListener(Runtime.Phase.Started, r -> { - CamelContext context = r.getCamelContext(); - List<Route> routes = context.getRoutes(); + assertThat(routes).hasSize(2); + assertThat(routes).anyMatch(p -> ObjectHelper.equal("r1", p.getId())); + assertThat(routes).anyMatch(p -> ObjectHelper.equal("r2", p.getId())); - assertThat(routes).hasSize(2); - assertThat(routes).anyMatch(p -> ObjectHelper.equal("r1", p.getId())); - assertThat(routes).anyMatch(p -> ObjectHelper.equal("r2", p.getId())); + runtime.stop(); + }); + + runtime.run(); + } + + @Test + void testLoadRouteAndRest() throws Exception { + runtime.addListener(new ContextConfigurer()); + runtime.addListener(RoutesConfigurer.forRoutes("classpath:routes.xml", "classpath:rests.xml")); + runtime.addListener(Runtime.Phase.Started, r -> { + CamelContext context = r.getCamelContext(); - runtime.stop(); - }); + assertThat(context.adapt(ModelCamelContext.class).getRouteDefinitions()).isNotEmpty(); + assertThat(context.adapt(ModelCamelContext.class).getRestDefinitions()).isNotEmpty(); - runtime.run(); - } finally { runtime.stop(); - } + }); + + runtime.run(); } - @Disabled @Test - void testLoadRouteAndRest() throws Exception { + void testLoadRouteWithExpression() throws Exception { + runtime.setProperties(CollectionHelper.mapOf( + "the.body", "10" + )); + + runtime.addListener(new ContextConfigurer()); + runtime.addListener(RoutesConfigurer.forRoutes("classpath:routes-with-expression.xml")); + runtime.addListener(Runtime.Phase.Started, r -> runtime.stop()); + runtime.run(); + } + + + @Test + public void testLoadJavaClassWithBeans() throws Exception { ApplicationRuntime runtime = new ApplicationRuntime(); - try { - runtime.addListener(new ContextConfigurer()); - runtime.addListener(RoutesConfigurer.forRoutes("classpath:routes.xml", "classpath:rests.xml")); - runtime.addListener(Runtime.Phase.Started, r -> { - CamelContext context = r.getCamelContext(); + runtime.addListener(RoutesConfigurer.forRoutes("classpath:" + MyRoutesWithBeans.class.getName() + ".class")); + runtime.addListener(Runtime.Phase.Started, r -> runtime.stop()); + runtime.run(); - assertThat(context.adapt(ModelCamelContext.class).getRouteDefinitions()).isNotEmpty(); - assertThat(context.adapt(ModelCamelContext.class).getRestDefinitions()).isNotEmpty(); + assertThat(runtime.getRegistry().lookupByName("my-bean")).isInstanceOfSatisfying(MyBean.class, b -> { + assertThat(b).hasFieldOrPropertyWithValue("name", "my-bean-name"); + }); + } - runtime.stop(); - }); + @Test + public void testLoadJavaSourceWithBeans() throws Exception { + ApplicationRuntime runtime = new ApplicationRuntime(); + runtime.addListener(RoutesConfigurer.forRoutes("classpath:MyRoutesWithBeans.java")); + runtime.addListener(Runtime.Phase.Started, r -> runtime.stop()); + runtime.run(); - runtime.run(); - } finally { - runtime.stop(); - } + assertThat(runtime.getRegistry().lookupByName("my-bean")).isInstanceOfSatisfying(MyBean.class, b -> { + assertThat(b).hasFieldOrPropertyWithValue("name", "my-bean-name"); + }); } } diff --git a/camel-k-loader-java/src/test/resources/MyRoutesWithBeans.java b/camel-k-runtime-main/src/test/resources/MyRoutesWithBeans.java similarity index 89% rename from camel-k-loader-java/src/test/resources/MyRoutesWithBeans.java rename to camel-k-runtime-main/src/test/resources/MyRoutesWithBeans.java index f232dd6..530fe17 100644 --- a/camel-k-loader-java/src/test/resources/MyRoutesWithBeans.java +++ b/camel-k-runtime-main/src/test/resources/MyRoutesWithBeans.java @@ -27,7 +27,7 @@ public class MyRoutesWithBeans extends RouteBuilder { } @BindToRegistry("my-bean") - public org.apache.camel.k.loader.java.MyBean createMyBean() { - return new org.apache.camel.k.loader.java.MyBean("my-bean-name"); + public org.apache.camel.k.main.MyBean createMyBean() { + return new org.apache.camel.k.main.MyBean("my-bean-name"); } } \ No newline at end of file diff --git a/camel-k-runtime-main/src/test/resources/rests.xml b/camel-k-runtime-main/src/test/resources/rests.xml new file mode 100644 index 0000000..40ecfb1 --- /dev/null +++ b/camel-k-runtime-main/src/test/resources/rests.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<!-- + + 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. + +--> +<rests xmlns="http://camel.apache.org/schema/spring"> + <rest path="/camel/"> + <get id="greeting-api" uri="/greetings/{name}"> + <param dataType="string" name="name" required="true" type="path"/> + <to uri="direct:greeting-api"/> + </get> + </rest> +</rests> diff --git a/camel-k-runtime-main/src/test/resources/routes-with-expression.xml b/camel-k-runtime-main/src/test/resources/routes-with-expression.xml new file mode 100644 index 0000000..dc1090d --- /dev/null +++ b/camel-k-runtime-main/src/test/resources/routes-with-expression.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<routes xmlns="http://camel.apache.org/schema/spring"> + <route> + <from uri="timer:tick"/> + <filter> + <simple>in.body == {{the.body}}</simple> + <to uri="log:info"/> + </filter> + </route> +</routes> \ No newline at end of file diff --git a/camel-k-runtime-main/src/test/resources/routes.xml b/camel-k-runtime-main/src/test/resources/routes.xml new file mode 100644 index 0000000..2dbe048 --- /dev/null +++ b/camel-k-runtime-main/src/test/resources/routes.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<routes xmlns="http://camel.apache.org/schema/spring"> + <route> + <from uri="timer:tick"/> + <to uri="log:info"/> + </route> +</routes> \ No newline at end of file