This is an automated email from the ASF dual-hosted git repository. ppalaga pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit ac2d18335dc2c4e075487e81caad3338caa2ffda Author: aldettinger <aldettin...@gmail.com> AuthorDate: Thu Jun 10 15:27:05 2021 +0200 Kamelet extension: added test for kamelet discovery mechanism #2652 --- .../component/kamelet/it/KameletResource.java | 7 ++++++ .../component/kamelet/it/KameletRoutes.java | 28 ++++++++++++++++++++++ .../resources/kamelets/auto-discovery.kamelet.yaml | 18 ++++++++++++++ .../quarkus/component/kamelet/it/KameletTest.java | 11 +++++++++ 4 files changed, 64 insertions(+) diff --git a/integration-tests/kamelet/src/main/java/org/apache/camel/quarkus/component/kamelet/it/KameletResource.java b/integration-tests/kamelet/src/main/java/org/apache/camel/quarkus/component/kamelet/it/KameletResource.java index bf61c5b..7ef58e1 100644 --- a/integration-tests/kamelet/src/main/java/org/apache/camel/quarkus/component/kamelet/it/KameletResource.java +++ b/integration-tests/kamelet/src/main/java/org/apache/camel/quarkus/component/kamelet/it/KameletResource.java @@ -72,4 +72,11 @@ public class KameletResource { public String invoke(@PathParam("name") String name, String message) throws Exception { return fluentProducerTemplate.toF("kamelet:%s", name).withBody(message).request(String.class); } + + @Path("/auto-discovery") + @POST + @Produces(MediaType.TEXT_PLAIN) + public String autoDiscovery(String message) { + return fluentProducerTemplate.toF("kamelet:auto-discovery?message=%s", message).request(String.class); + } } diff --git a/integration-tests/kamelet/src/main/java/org/apache/camel/quarkus/component/kamelet/it/KameletRoutes.java b/integration-tests/kamelet/src/main/java/org/apache/camel/quarkus/component/kamelet/it/KameletRoutes.java index 7062b0a..1505a1b 100644 --- a/integration-tests/kamelet/src/main/java/org/apache/camel/quarkus/component/kamelet/it/KameletRoutes.java +++ b/integration-tests/kamelet/src/main/java/org/apache/camel/quarkus/component/kamelet/it/KameletRoutes.java @@ -18,11 +18,18 @@ package org.apache.camel.quarkus.component.kamelet.it; import java.util.Locale; +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Named; + import io.quarkus.runtime.annotations.RegisterForReflection; import org.apache.camel.Exchange; import org.apache.camel.Processor; +import org.apache.camel.RoutesBuilder; import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.spi.Resource; +import org.apache.camel.support.RoutesBuilderLoaderSupport; +@ApplicationScoped public class KameletRoutes extends RouteBuilder { @Override @@ -71,4 +78,25 @@ public class KameletRoutes extends RouteBuilder { exchange.getMessage().getBody(String.class).toUpperCase(Locale.US)); } } + + @Named("routes-builder-loader-kamelet.yaml") + RoutesBuilderLoaderSupport routesBuilderLoaderKameletYaml() { + return new RoutesBuilderLoaderSupport() { + @Override + public String getSupportedExtension() { + return "kamelet.yaml"; + } + + @Override + public RoutesBuilder loadRoutesBuilder(Resource resource) { + return new RouteBuilder() { + @Override + public void configure() { + routeTemplate("auto-discovery").templateParameter("message").from("kamelet:source").setBody() + .constant("Auto-discovered {{message}}"); + } + }; + } + }; + } } diff --git a/integration-tests/kamelet/src/main/resources/kamelets/auto-discovery.kamelet.yaml b/integration-tests/kamelet/src/main/resources/kamelets/auto-discovery.kamelet.yaml new file mode 100644 index 0000000..d48d285 --- /dev/null +++ b/integration-tests/kamelet/src/main/resources/kamelets/auto-discovery.kamelet.yaml @@ -0,0 +1,18 @@ +# +# 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. +# + +# Fake kamelet definition to be loaded by "routes-builder-loader-kamelet.yaml" bean from registry \ No newline at end of file diff --git a/integration-tests/kamelet/src/test/java/org/apache/camel/quarkus/component/kamelet/it/KameletTest.java b/integration-tests/kamelet/src/test/java/org/apache/camel/quarkus/component/kamelet/it/KameletTest.java index 77a6607..c27c06f 100644 --- a/integration-tests/kamelet/src/test/java/org/apache/camel/quarkus/component/kamelet/it/KameletTest.java +++ b/integration-tests/kamelet/src/test/java/org/apache/camel/quarkus/component/kamelet/it/KameletTest.java @@ -84,4 +84,15 @@ class KameletTest { .statusCode(200) .body(is("KAMELET2")); } + + @Test + public void testAutoDiscovery() { + RestAssured.given() + .contentType(ContentType.TEXT) + .body("Kamelet") + .post("/kamelet/auto-discovery") + .then() + .statusCode(200) + .body(is("Auto-discovered Kamelet")); + } }