You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2020/09/02 11:56:24 UTC

[camel-quarkus] 09/13: Add route template integration test

This is an automated email from the ASF dual-hosted git repository.

jamesnetherton pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit 882a0e52f8abd37fa63d4aa19897baef3418b328
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Aug 26 13:57:29 2020 +0200

    Add route template integration test
---
 integration-tests/core/pom.xml                     |  4 ++++
 .../apache/camel/quarkus/core/CoreResource.java    | 15 ++++++++++++
 .../camel/quarkus/core/CoreTemplateRoutes.java     | 28 ++++++++++++++++++++++
 .../org/apache/camel/quarkus/core/CoreTest.java    | 11 ++++++---
 4 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/integration-tests/core/pom.xml b/integration-tests/core/pom.xml
index 85ef4f3..90a75d3 100644
--- a/integration-tests/core/pom.xml
+++ b/integration-tests/core/pom.xml
@@ -42,6 +42,10 @@
     <dependencies>
         <dependency>
             <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-direct</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
             <artifactId>camel-quarkus-log</artifactId>
         </dependency>
         <dependency>
diff --git a/integration-tests/core/src/main/java/org/apache/camel/quarkus/core/CoreResource.java b/integration-tests/core/src/main/java/org/apache/camel/quarkus/core/CoreResource.java
index 34ee80e..44329de 100644
--- a/integration-tests/core/src/main/java/org/apache/camel/quarkus/core/CoreResource.java
+++ b/integration-tests/core/src/main/java/org/apache/camel/quarkus/core/CoreResource.java
@@ -41,6 +41,7 @@ import org.apache.camel.ExtendedCamelContext;
 import org.apache.camel.NoSuchLanguageException;
 import org.apache.camel.Route;
 import org.apache.camel.builder.LambdaRouteBuilder;
+import org.apache.camel.builder.TemplatedRouteBuilder;
 import org.apache.camel.catalog.RuntimeCamelCatalog;
 import org.apache.camel.component.log.LogComponent;
 import org.apache.camel.model.ModelCamelContext;
@@ -85,6 +86,20 @@ public class CoreResource {
         return context.getRoutes().stream().map(Route::getId).sorted().collect(Collectors.joining(","));
     }
 
+    @Path("/routes/template/{id}/{greeting}")
+    @GET
+    @Produces(MediaType.TEXT_PLAIN)
+    public String routeTemplate(@PathParam("id") String id, @PathParam("greeting") String greeting) {
+        String uuid = context.getUuidGenerator().generateUuid();
+        TemplatedRouteBuilder.builder(context, id)
+                .routeId(uuid)
+                .parameter("uuid", uuid)
+                .parameter("greeting", greeting)
+                .add();
+
+        return context.createFluentProducerTemplate().toF("direct:%s", uuid).request(String.class);
+    }
+
     @Path("/registry/lookup-registry")
     @GET
     @Produces(MediaType.TEXT_PLAIN)
diff --git a/integration-tests/core/src/main/java/org/apache/camel/quarkus/core/CoreTemplateRoutes.java b/integration-tests/core/src/main/java/org/apache/camel/quarkus/core/CoreTemplateRoutes.java
new file mode 100644
index 0000000..1a5ad43
--- /dev/null
+++ b/integration-tests/core/src/main/java/org/apache/camel/quarkus/core/CoreTemplateRoutes.java
@@ -0,0 +1,28 @@
+/*
+ * 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.quarkus.core;
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class CoreTemplateRoutes extends RouteBuilder {
+    @Override
+    public void configure() throws Exception {
+        routeTemplate("myTemplate").templateParameter("uuid").templateParameter("greeting")
+                .from("direct:{{uuid}}")
+                .transform().constant("Hello {{greeting}}");
+    }
+}
diff --git a/integration-tests/core/src/test/java/org/apache/camel/quarkus/core/CoreTest.java b/integration-tests/core/src/test/java/org/apache/camel/quarkus/core/CoreTest.java
index f45b7f0..e4ae286 100644
--- a/integration-tests/core/src/test/java/org/apache/camel/quarkus/core/CoreTest.java
+++ b/integration-tests/core/src/test/java/org/apache/camel/quarkus/core/CoreTest.java
@@ -25,8 +25,7 @@ import io.restassured.response.Response;
 import org.apache.camel.support.DefaultLRUCacheFactory;
 import org.junit.jupiter.api.Test;
 
-import static org.hamcrest.Matchers.emptyOrNullString;
-import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.*;
 import static org.hamcrest.core.IsNot.not;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -42,7 +41,13 @@ public class CoreTest {
 
     @Test
     public void testLookupRoutes() {
-        RestAssured.when().get("/test/routes/lookup-routes").then().body(is("bar,timer"));
+        RestAssured.when().get("/test/routes/lookup-routes").then().body(containsString("bar"), containsString("timer"));
+    }
+
+    @Test
+    public void testRouteTemplate() {
+        RestAssured.when().get("/test/routes/template/myTemplate/World").then().body(is("Hello World"));
+        RestAssured.when().get("/test/routes/template/myTemplate/Earth").then().body(is("Hello Earth"));
     }
 
     @Test