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/07/25 06:40:24 UTC

[camel-k-runtime] branch master updated: chore(js): add test for rest dsl/definition

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 9f3c3ca  chore(js): add test for rest dsl/definition
9f3c3ca is described below

commit 9f3c3cae86705ba198c11fdf0883c71c2914856f
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Thu Jul 25 08:30:58 2019 +0200

    chore(js): add test for rest dsl/definition
---
 .../camel/k/loader/js/dsl/IntegrationTest.java     | 59 ++++++++++++++++++++++
 .../resources/routes-with-rest-configuration.js    |  4 ++
 .../src/test/resources/routes-with-rest-dsl.js     |  7 +++
 3 files changed, 70 insertions(+)

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 c5e0aed..a881b3a 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
@@ -16,10 +16,19 @@
  */
 package org.apache.camel.k.loader.js.dsl;
 
+import java.util.List;
+
 import org.apache.camel.component.seda.SedaComponent;
 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;
+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.Test;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -40,4 +49,54 @@ public class IntegrationTest {
 
         runtime.run();
     }
+
+    @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();
+
+            assertThat(conf).isNotNull();
+            assertThat(conf).hasFieldOrPropertyWithValue("component", "undertow");
+            assertThat(conf).hasFieldOrPropertyWithValue("port", 1234);
+
+            runtime.stop();
+        });
+
+        runtime.run();
+    }
+
+    @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");
+                });
+            });
+
+            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();
+    }
 }
diff --git a/camel-k-loader-js/src/test/resources/routes-with-rest-configuration.js b/camel-k-loader-js/src/test/resources/routes-with-rest-configuration.js
new file mode 100644
index 0000000..c54a31b
--- /dev/null
+++ b/camel-k-loader-js/src/test/resources/routes-with-rest-configuration.js
@@ -0,0 +1,4 @@
+
+c = restConfiguration()
+c.setComponent('undertow')
+c.setPort('1234')
diff --git a/camel-k-loader-js/src/test/resources/routes-with-rest-dsl.js b/camel-k-loader-js/src/test/resources/routes-with-rest-dsl.js
new file mode 100644
index 0000000..195fca6
--- /dev/null
+++ b/camel-k-loader-js/src/test/resources/routes-with-rest-dsl.js
@@ -0,0 +1,7 @@
+
+rest('/')
+    .produces("text/plain")
+    .get('/say/hello')
+    .route()
+        .transform().constant("Hello World");
+