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/09/03 20:17:05 UTC

[camel-k-runtime] 01/08: chore(test): remove dependencies on runtime from camel-k-loader-js

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 7a5d455eeeea0ea5b940483193089e08b7ed9639
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Tue Sep 3 13:53:18 2019 +0200

    chore(test): remove dependencies on runtime from camel-k-loader-js
---
 camel-k-loader-js/pom.xml                          |   5 -
 .../camel/k/loader/js/dsl/IntegrationTest.java     | 128 +++++++++++----------
 2 files changed, 68 insertions(+), 65 deletions(-)

diff --git a/camel-k-loader-js/pom.xml b/camel-k-loader-js/pom.xml
index 89c6eee..34f1acc 100644
--- a/camel-k-loader-js/pom.xml
+++ b/camel-k-loader-js/pom.xml
@@ -53,11 +53,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-undertow</artifactId>
             <scope>test</scope>
diff --git a/camel-k-loader-js/src/test/java/org/apache/camel/k/loader/js/dsl/IntegrationTest.java b/camel-k-loader-js/src/test/java/org/apache/camel/k/loader/js/dsl/IntegrationTest.java
index 4e14a29..156f0af 100644
--- a/camel-k-loader-js/src/test/java/org/apache/camel/k/loader/js/dsl/IntegrationTest.java
+++ b/camel-k-loader-js/src/test/java/org/apache/camel/k/loader/js/dsl/IntegrationTest.java
@@ -18,11 +18,12 @@ package org.apache.camel.k.loader.js.dsl;
 
 import java.util.List;
 
+import org.apache.camel.CamelContext;
 import org.apache.camel.ProducerTemplate;
 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.FromDefinition;
 import org.apache.camel.model.ModelCamelContext;
 import org.apache.camel.model.RouteDefinition;
@@ -30,91 +31,98 @@ import org.apache.camel.model.TransformDefinition;
 import org.apache.camel.model.rest.GetVerbDefinition;
 import org.apache.camel.model.rest.RestDefinition;
 import org.apache.camel.spi.RestConfiguration;
+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 IntegrationTest {
-    @Test
-    public void testComponentConfiguration() throws Exception {
-        ApplicationRuntime runtime = new ApplicationRuntime();
-        runtime.addListener(RoutesConfigurer.forRoutes("classpath:routes-with-component-configuration.js"));
-        runtime.addListener(Runtime.Phase.Started, r -> {
-            SedaComponent seda = r.getCamelContext().getComponent("seda", SedaComponent.class);
+    private CamelContext context;
+    private Runtime runtime;
 
-            assertThat(seda).isNotNull();
-            assertThat(seda).hasFieldOrPropertyWithValue("queueSize", 1234);
+    @BeforeEach
+    public void setUp() {
+        this.context = new DefaultCamelContext();
+        this.runtime = Runtime.of(context);
+    }
 
-            runtime.stop();
-        });
+    @AfterEach
+    public void shutDown() {
+        if (this.context != null) {
+            this.context.stop();
+        }
+    }
 
-        runtime.run();
+    private void configureRoutes(String... routes) {
+        RoutesConfigurer.forRoutes(routes).accept(Runtime.Phase.ConfigureRoutes, runtime);
     }
 
     @Test
-    public void testRestConfiguration() throws Exception {
-        ApplicationRuntime runtime = new ApplicationRuntime();
-        runtime.addListener(RoutesConfigurer.forRoutes("classpath:routes-with-rest-configuration.js"));
-        runtime.addListener(Runtime.Phase.Started, r -> {
-            RestConfiguration conf = r.getCamelContext().getRestConfiguration();
+    public void testComponentConfiguration() {
+        configureRoutes(
+            "classpath:routes-with-component-configuration.js"
+        );
 
-            assertThat(conf).isNotNull();
-            assertThat(conf).hasFieldOrPropertyWithValue("component", "undertow");
-            assertThat(conf).hasFieldOrPropertyWithValue("port", 1234);
+        SedaComponent seda = context.getComponent("seda", SedaComponent.class);
 
-            runtime.stop();
-        });
+        assertThat(seda).isNotNull();
+        assertThat(seda).hasFieldOrPropertyWithValue("queueSize", 1234);
+    }
+    @Test
+    public void testRestConfiguration() {
+        configureRoutes(
+            "classpath:routes-with-rest-configuration.js"
+        );
+
+        RestConfiguration conf = context.getRestConfiguration();
 
-        runtime.run();
+        assertThat(conf).isNotNull();
+        assertThat(conf).hasFieldOrPropertyWithValue("component", "undertow");
+        assertThat(conf).hasFieldOrPropertyWithValue("port", 1234);
     }
 
     @Test
-    public void testRestDSL() throws Exception {
-        ApplicationRuntime runtime = new ApplicationRuntime();
-        runtime.addListener(RoutesConfigurer.forRoutes("classpath:routes-with-rest-dsl.js"));
-        runtime.addListener(Runtime.Phase.Started, r -> {
-            ModelCamelContext mcc = r.getCamelContext().adapt(ModelCamelContext.class);
-            List<RestDefinition> rests = mcc.getRestDefinitions();
-            List<RouteDefinition> routes = mcc.getRouteDefinitions();
-
-            assertThat(rests).hasSize(1);
-            assertThat(rests).first().hasFieldOrPropertyWithValue("produces", "text/plain");
-            assertThat(rests).first().satisfies(definition -> {
-                assertThat(definition.getVerbs()).hasSize(1);
-                assertThat(definition.getVerbs()).first().isInstanceOfSatisfying(GetVerbDefinition.class, get -> {
-                    assertThat(get).hasFieldOrPropertyWithValue("uri", "/say/hello");
-                });
+    public void testRestDSL() {
+        configureRoutes(
+            "classpath:routes-with-rest-dsl.js"
+        );
+
+        ModelCamelContext mcc = context.adapt(ModelCamelContext.class);
+        List<RestDefinition> rests = mcc.getRestDefinitions();
+        List<RouteDefinition> routes = mcc.getRouteDefinitions();
+
+        assertThat(rests).hasSize(1);
+        assertThat(rests).first().hasFieldOrPropertyWithValue("produces", "text/plain");
+        assertThat(rests).first().satisfies(definition -> {
+            assertThat(definition.getVerbs()).hasSize(1);
+            assertThat(definition.getVerbs()).first().isInstanceOfSatisfying(GetVerbDefinition.class, get -> {
+                assertThat(get).hasFieldOrPropertyWithValue("uri", "/say/hello");
             });
+        });
 
-            assertThat(routes).hasSize(1);
-            assertThat(routes).first().satisfies(definition -> {
-                assertThat(definition.getInput()).isInstanceOf(FromDefinition.class);
-                assertThat(definition.getOutputs()).hasSize(1);
-                assertThat(definition.getOutputs()).first().satisfies(output -> {
-                    assertThat(output).isInstanceOf(TransformDefinition.class);
-                });
+        assertThat(routes).hasSize(1);
+        assertThat(routes).first().satisfies(definition -> {
+            assertThat(definition.getInput()).isInstanceOf(FromDefinition.class);
+            assertThat(definition.getOutputs()).hasSize(1);
+            assertThat(definition.getOutputs()).first().satisfies(output -> {
+                assertThat(output).isInstanceOf(TransformDefinition.class);
             });
-
-            runtime.stop();
         });
-
-        runtime.run();
     }
 
     @Test
-    public void testProcessors() throws Exception {
-        ApplicationRuntime runtime = new ApplicationRuntime();
-        runtime.addListener(RoutesConfigurer.forRoutes("classpath:routes-with-processors.js"));
-        runtime.addListener(Runtime.Phase.Started, r -> {
-            ProducerTemplate template = r.getCamelContext().createProducerTemplate();
+    public void testProcessors() {
+        configureRoutes(
+            "classpath:routes-with-processors.js"
+        );
 
-            assertThat(template.requestBody("direct:arrow", "")).isEqualTo("arrow");
-            assertThat(template.requestBody("direct:wrapper", "")).isEqualTo("wrapper");
-            assertThat(template.requestBody("direct:function", "")).isEqualTo("function");
+        context.start();
 
-            runtime.stop();
-        });
+        ProducerTemplate template = context.createProducerTemplate();
 
-        runtime.run();
+        assertThat(template.requestBody("direct:arrow", "")).isEqualTo("arrow");
+        assertThat(template.requestBody("direct:wrapper", "")).isEqualTo("wrapper");
+        assertThat(template.requestBody("direct:function", "")).isEqualTo("function");
     }
 }