From 0e198c8f415437a606d525ee2f9bc1bcf9b26122 Mon Sep 17 00:00:00 2001 From: Andrea Tarocchi Date: Tue, 15 Jun 2021 16:47:26 +0200 Subject: [PATCH] fix #2733 : Native support for kamelet.yaml discovery. --- .../pages/reference/extensions/kamelet.adoc | 18 ++-- extensions/kamelet/deployment/pom.xml | 4 - .../kamelet/deployment/KameletProcessor.java | 92 ++++++------------- .../kamelet/deployment/KameletResolver.java | 21 ++++- .../deployment/KameletResolverBuildItem.java | 18 +++- .../kamelet/runtime/src/main/doc/usage.adoc | 12 +-- .../kamelet/KameletConfiguration.java | 10 +- .../component/kamelet/KameletRecorder.java | 9 +- integration-tests/kamelet/pom.xml | 13 +++ .../component/kamelet/it/KameletResource.java | 9 +- .../component/kamelet/it/KameletRoutes.java | 25 ----- .../src/main/resources/application.properties | 5 +- .../kamelets/auto-discovery.kamelet.yaml | 18 ---- .../resources/kamelets/injector.kamelet.yaml | 4 +- .../resources/kamelets/logger.kamelet.yaml | 3 +- .../component/kamelet/it/KameletTest.java | 33 +++---- 16 files changed, 126 insertions(+), 168 deletions(-) delete mode 100644 integration-tests/kamelet/src/main/resources/kamelets/auto-discovery.kamelet.yaml diff --git a/docs/modules/ROOT/pages/reference/extensions/kamelet.adoc b/docs/modules/ROOT/pages/reference/extensions/kamelet.adoc index cf3e036b27c0..c335a61646d6 100644 --- a/docs/modules/ROOT/pages/reference/extensions/kamelet.adoc +++ b/docs/modules/ROOT/pages/reference/extensions/kamelet.adoc @@ -42,24 +42,22 @@ Check the xref:user-guide/index.adoc[User guide] for more information about writ === Pre-load Kamelets at build-time -This extension allow to pre-load a set of Kamelets at build time through the following two options. The kamelet to pre-load can be listed using the `quarkus.camel.kamelet.names` property. +This extension allows to pre-load a set of Kamelets at build time using the `quarkus.camel.kamelet.identifiers` property. === Using the Kamelet Catalog -//TODO: does not yet exist - A set of pre-made Kamelets can be found on the https://camel.apache.org/camel-kamelets/latest[Kamelet Catalog]. -To use the Kamelet from the catalog you either need to copy them on your project in the classpath location defined by the `quarkus.camel.kamelet.location` property, or you can add the `camel-quarkus-kamelets-catalog` artifact to your `pom.xml`: +To use the Kamelet from the catalog you need to copy their yaml definition (that you can find https://github.com/apache/camel-kamelets/[in the camel-kamelet repo]) on your project in the classpath. Alternatively you can add the `camel-quarkus-kamelets-catalog` artifact to your `pom.xml`: [source,xml] ---- - org.apache.camel.quarkus - camel-quarkus-kamelets-catalog + org.apache.camel.kamelets + camel-kamelets-catalog ---- -This artifact makes all the kamelets available in the catalog available to Camel Quarkus for build time processing, the artefact is not part of the runtime classpath. +This artifact add all the kamelets available in the catalog to your Camel Quarkus application for build time processing. If you include it with the scope `provided` the artifact should not be part of the runtime classpath, but at build time, all the kamelets listed via `quarkus.camel.kamelet.identifiers` property should be preloaded. == Additional Camel Quarkus configuration @@ -69,10 +67,10 @@ This artifact makes all the kamelets available in the catalog available to Camel | Configuration property | Type | Default -|icon:lock[title=Fixed at build time] [[quarkus.camel.kamelet.names]]`link:#quarkus.camel.kamelet.names[quarkus.camel.kamelet.names]` +|icon:lock[title=Fixed at build time] [[quarkus.camel.kamelet.identifiers]]`link:#quarkus.camel.kamelet.identifiers[quarkus.camel.kamelet.identifiers]` -List of kamelets names to pre-load at build time. - Each individual name is used to set the related `org.apache.camel.model.RouteTemplateDefinition` id. TODO: find a better name for this configuration option +List of kamelets identifiers to pre-load at build time. + Each individual identifier is used to set the related `org.apache.camel.model.RouteTemplateDefinition` id. | `string` | |=== diff --git a/extensions/kamelet/deployment/pom.xml b/extensions/kamelet/deployment/pom.xml index 9a79c82d5813..462b0e2de223 100644 --- a/extensions/kamelet/deployment/pom.xml +++ b/extensions/kamelet/deployment/pom.xml @@ -38,10 +38,6 @@ org.apache.camel.quarkus camel-quarkus-kamelet - - com.fasterxml.jackson.dataformat - jackson-dataformat-yaml - org.apache.camel camel-yaml-dsl diff --git a/extensions/kamelet/deployment/src/main/java/org/apache/camel/quarkus/component/kamelet/deployment/KameletProcessor.java b/extensions/kamelet/deployment/src/main/java/org/apache/camel/quarkus/component/kamelet/deployment/KameletProcessor.java index e7ad076ad6ff..071f43042acc 100644 --- a/extensions/kamelet/deployment/src/main/java/org/apache/camel/quarkus/component/kamelet/deployment/KameletProcessor.java +++ b/extensions/kamelet/deployment/src/main/java/org/apache/camel/quarkus/component/kamelet/deployment/KameletProcessor.java @@ -16,35 +16,29 @@ */ package org.apache.camel.quarkus.component.kamelet.deployment; -import java.io.InputStream; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.Comparator; -import java.util.Iterator; import java.util.List; -import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.annotations.ExecutionTime; import io.quarkus.deployment.annotations.Record; import io.quarkus.deployment.builditem.FeatureBuildItem; +import org.apache.camel.CamelContext; +import org.apache.camel.ExtendedCamelContext; import org.apache.camel.Ordered; +import org.apache.camel.RoutesBuilder; import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.dsl.yaml.YamlRoutesBuilderLoader; import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.model.RouteTemplateDefinition; import org.apache.camel.quarkus.component.kamelet.KameletConfiguration; import org.apache.camel.quarkus.component.kamelet.KameletRecorder; import org.apache.camel.quarkus.core.deployment.spi.CamelContextCustomizerBuildItem; import org.apache.camel.spi.Resource; -import org.apache.camel.support.ResourceHelper; class KameletProcessor { private static final String FEATURE = "camel-kamelet"; @@ -58,10 +52,10 @@ FeatureBuildItem feature() { KameletResolverBuildItem defaultResolver() { return new KameletResolverBuildItem(new KameletResolver() { @Override - public Optional resolve(String id) throws Exception { + public Optional resolve(String id, CamelContext context) throws Exception { + ExtendedCamelContext ecc = context.adapt(ExtendedCamelContext.class); return Optional.ofNullable( - Thread.currentThread().getContextClassLoader() - .getResourceAsStream("/kamelets/" + id + ".kamelet.yaml")); + ecc.getResourceLoader().resolveResource("/kamelets/" + id + ".kamelet.yaml")); } }); } @@ -73,65 +67,39 @@ CamelContextCustomizerBuildItem configureTemplates( KameletConfiguration configuration, KameletRecorder recorder) throws Exception { - ObjectMapper mapper = new ObjectMapper(new YAMLFactory()) - .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - List definitions = new ArrayList<>(); List kameletResolvers = resolvers.stream() .map(KameletResolverBuildItem::getResolver) .sorted(Comparator.comparingInt(Ordered::getOrder)) .collect(Collectors.toList()); - try (YamlRoutesBuilderLoader ybl = new YamlRoutesBuilderLoader()) { - ybl.setCamelContext(new DefaultCamelContext()); - ybl.start(); + CamelContext context = new DefaultCamelContext(); + ExtendedCamelContext ecc = context.adapt(ExtendedCamelContext.class); - for (String name : configuration.names.orElse(Collections.emptyList())) { + for (String id : configuration.identifiers.orElse(Collections.emptyList())) { + for (KameletResolver resolver : kameletResolvers) { + final Optional resource = resolver.resolve(id, ecc); + if (!resource.isPresent()) { + continue; + } - for (KameletResolver resolver : kameletResolvers) { - final Optional is = resolver.resolve(name); - if (!is.isPresent()) { - continue; + Collection rbs = ecc.getRoutesLoader().findRoutesBuilders(resource.get()); + for (RoutesBuilder rb : rbs) { + RouteBuilder routeBuilder = (RouteBuilder) rb; + routeBuilder.configure(); + if (routeBuilder.getRouteTemplateCollection().getRouteTemplates().size() == 0) { + throw new IllegalStateException( + "No kamelet template was created for " + + "kamelet:" + id + "might be the kamelet was malformed?"); + } else if (routeBuilder.getRouteTemplateCollection().getRouteTemplates().size() > 1) { + throw new IllegalStateException( + "A kamelet is not supposed to create more than one route (" + + "kamelet:" + id + "," + + "routes: " + routeBuilder.getRouteTemplateCollection().getRouteTemplates().size() + + ")"); } - try { - final ObjectNode definition = (ObjectNode) mapper.readTree(is.get()); - final JsonNode properties = definition.requiredAt("/spec/definition/properties"); - final JsonNode flow = mapper.createArrayNode().add(definition.requiredAt("/spec/flow")); - final Resource res = ResourceHelper.fromBytes(name + ".yaml", mapper.writeValueAsBytes(flow)); - - RouteTemplateDefinition rt = new RouteTemplateDefinition(); - rt.setId(name); - - Iterator> it = properties.fields(); - while (it.hasNext()) { - final Map.Entry property = it.next(); - final String key = property.getKey(); - final JsonNode def = property.getValue().at("/default"); - - if (def.isMissingNode()) { - rt.templateParameter(key); - } else { - rt.templateParameter(key, def.asText()); - } - } - - RouteBuilder rb = (RouteBuilder) ybl.loadRoutesBuilder(res); - rb.configure(); - if (rb.getRouteCollection().getRoutes().size() != 1) { - throw new IllegalStateException( - "A kamelet is not supposed to create more than one route (" - + "kamelet:" + name + "," - + "routes: " + rb.getRouteCollection().getRoutes().size() - + ")"); - } - - rt.setRoute(rb.getRouteCollection().getRoutes().get(0)); - - definitions.add(rt); - } finally { - is.get().close(); - } + definitions.add(routeBuilder.getRouteTemplateCollection().getRouteTemplates().get(0)); } } } diff --git a/extensions/kamelet/deployment/src/main/java/org/apache/camel/quarkus/component/kamelet/deployment/KameletResolver.java b/extensions/kamelet/deployment/src/main/java/org/apache/camel/quarkus/component/kamelet/deployment/KameletResolver.java index ebfc61f2a14a..a32305f72614 100644 --- a/extensions/kamelet/deployment/src/main/java/org/apache/camel/quarkus/component/kamelet/deployment/KameletResolver.java +++ b/extensions/kamelet/deployment/src/main/java/org/apache/camel/quarkus/component/kamelet/deployment/KameletResolver.java @@ -1,12 +1,29 @@ +/* + * 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.component.kamelet.deployment; -import java.io.InputStream; import java.util.Optional; +import org.apache.camel.CamelContext; import org.apache.camel.Ordered; +import org.apache.camel.spi.Resource; public interface KameletResolver extends Ordered { - Optional resolve(String id) throws Exception; + Optional resolve(String id, CamelContext context) throws Exception; @Override default int getOrder() { diff --git a/extensions/kamelet/deployment/src/main/java/org/apache/camel/quarkus/component/kamelet/deployment/KameletResolverBuildItem.java b/extensions/kamelet/deployment/src/main/java/org/apache/camel/quarkus/component/kamelet/deployment/KameletResolverBuildItem.java index 79ac1a388ed7..f463f0bbf8a5 100644 --- a/extensions/kamelet/deployment/src/main/java/org/apache/camel/quarkus/component/kamelet/deployment/KameletResolverBuildItem.java +++ b/extensions/kamelet/deployment/src/main/java/org/apache/camel/quarkus/component/kamelet/deployment/KameletResolverBuildItem.java @@ -1,3 +1,19 @@ +/* + * 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.component.kamelet.deployment; import io.quarkus.builder.item.MultiBuildItem; @@ -5,7 +21,7 @@ /** * Build item used by kamelet providers to plug their own way of resolving kamelets giving a name. This could be * leveraged by a future camel-quarkus-kamelet-catalog extension to resolve kamelets as they may have a different naming - * structure or location int the classpath. + * structure or location in the classpath. */ public final class KameletResolverBuildItem extends MultiBuildItem { private final KameletResolver resolver; diff --git a/extensions/kamelet/runtime/src/main/doc/usage.adoc b/extensions/kamelet/runtime/src/main/doc/usage.adoc index 8263cd36c860..a435ff380daa 100644 --- a/extensions/kamelet/runtime/src/main/doc/usage.adoc +++ b/extensions/kamelet/runtime/src/main/doc/usage.adoc @@ -1,20 +1,18 @@ === Pre-load Kamelets at build-time -This extension allow to pre-load a set of Kamelets at build time through the following two options. The kamelet to pre-load can be listed using the `quarkus.camel.kamelet.names` property. +This extension allows to pre-load a set of Kamelets at build time using the `quarkus.camel.kamelet.identifiers` property. === Using the Kamelet Catalog -//TODO: does not yet exist - A set of pre-made Kamelets can be found on the https://camel.apache.org/camel-kamelets/latest[Kamelet Catalog]. -To use the Kamelet from the catalog you either need to copy them on your project in the classpath location defined by the `quarkus.camel.kamelet.location` property, or you can add the `camel-quarkus-kamelets-catalog` artifact to your `pom.xml`: +To use the Kamelet from the catalog you need to copy their yaml definition (that you can find https://github.com/apache/camel-kamelets/[in the camel-kamelet repo]) on your project in the classpath. Alternatively you can add the `camel-quarkus-kamelets-catalog` artifact to your `pom.xml`: [source,xml] ---- - org.apache.camel.quarkus - camel-quarkus-kamelets-catalog + org.apache.camel.kamelets + camel-kamelets-catalog ---- -This artifact makes all the kamelets available in the catalog available to Camel Quarkus for build time processing, the artefact is not part of the runtime classpath. \ No newline at end of file +This artifact add all the kamelets available in the catalog to your Camel Quarkus application for build time processing. If you include it with the scope `provided` the artifact should not be part of the runtime classpath, but at build time, all the kamelets listed via `quarkus.camel.kamelet.identifiers` property should be preloaded. diff --git a/extensions/kamelet/runtime/src/main/java/org/apache/camel/quarkus/component/kamelet/KameletConfiguration.java b/extensions/kamelet/runtime/src/main/java/org/apache/camel/quarkus/component/kamelet/KameletConfiguration.java index c3c0febd12bd..58a1eb8a4221 100644 --- a/extensions/kamelet/runtime/src/main/java/org/apache/camel/quarkus/component/kamelet/KameletConfiguration.java +++ b/extensions/kamelet/runtime/src/main/java/org/apache/camel/quarkus/component/kamelet/KameletConfiguration.java @@ -26,12 +26,10 @@ @ConfigRoot(name = "camel.kamelet", phase = ConfigPhase.BUILD_TIME) public class KameletConfiguration { /** - * List of kamelets names to pre-load at build time. - * - *

- * Each individual name is used to set the related {@link org.apache.camel.model.RouteTemplateDefinition} id. - * TODO: find a better name for this configuration option + * List of kamelets identifiers to pre-load at build time. + *

+ * Each individual identifier is used to set the related {@link org.apache.camel.model.RouteTemplateDefinition} id. */ @ConfigItem - public Optional> names; + public Optional> identifiers; } diff --git a/extensions/kamelet/runtime/src/main/java/org/apache/camel/quarkus/component/kamelet/KameletRecorder.java b/extensions/kamelet/runtime/src/main/java/org/apache/camel/quarkus/component/kamelet/KameletRecorder.java index 064a1f7fcae0..1f59eadb942a 100644 --- a/extensions/kamelet/runtime/src/main/java/org/apache/camel/quarkus/component/kamelet/KameletRecorder.java +++ b/extensions/kamelet/runtime/src/main/java/org/apache/camel/quarkus/component/kamelet/KameletRecorder.java @@ -20,17 +20,20 @@ import io.quarkus.runtime.RuntimeValue; import io.quarkus.runtime.annotations.Recorder; +import io.quarkus.runtime.annotations.RelaxedValidation; import org.apache.camel.CamelContext; import org.apache.camel.model.Model; import org.apache.camel.model.RouteTemplateDefinition; -import org.apache.camel.quarkus.core.CamelContextCustomizer; +import org.apache.camel.spi.CamelContextCustomizer; @Recorder public class KameletRecorder { - public RuntimeValue createTemplateLoaderCustomizer(List definitions) { + public RuntimeValue createTemplateLoaderCustomizer( + @RelaxedValidation List definitions) { + return new RuntimeValue<>(new CamelContextCustomizer() { @Override - public void customize(CamelContext context) { + public void configure(CamelContext context) { try { context.getExtension(Model.class).addRouteTemplateDefinitions(definitions); } catch (Exception e) { diff --git a/integration-tests/kamelet/pom.xml b/integration-tests/kamelet/pom.xml index 9b2450df68ea..d0fd1ea9341e 100644 --- a/integration-tests/kamelet/pom.xml +++ b/integration-tests/kamelet/pom.xml @@ -81,6 +81,19 @@ + + org.apache.camel.quarkus + camel-quarkus-bean-deployment + ${project.version} + pom + test + + + * + * + + + org.apache.camel.quarkus camel-quarkus-direct-deployment 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 5ceb99dfce5f..d899853cf095 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 @@ -82,16 +82,9 @@ public String invoke(@PathParam("name") String name, String message) throws Exce 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); - } - @Path("/list") @GET - @Produces(MediaType.TEXT_PLAIN) + @Produces(MediaType.APPLICATION_JSON) public JsonArray list() { JsonArrayBuilder builder = Json.createArrayBuilder(); 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 e7eb13495c4d..7cbc1408b2d3 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 @@ -17,15 +17,11 @@ package org.apache.camel.quarkus.component.kamelet.it; 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 { @@ -75,25 +71,4 @@ public void process(Exchange exchange) { exchange.getMessage().setBody(exchange.getMessage().getBody(String.class) + "-suffix"); } } - - @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/application.properties b/integration-tests/kamelet/src/main/resources/application.properties index 51c16ca1fbcb..dd2333ec1810 100644 --- a/integration-tests/kamelet/src/main/resources/application.properties +++ b/integration-tests/kamelet/src/main/resources/application.properties @@ -16,4 +16,7 @@ ## --------------------------------------------------------------------------- camel.kamelet.setBodyFromProperties.bodyValueFromProperty=Camel Quarkus Kamelet Property -quarkus.camel.kamelet.names = injector,logger \ No newline at end of file +quarkus.camel.kamelet.identifiers = injector,logger + +# this is needed to actually test that kamelet are preloaded at build time: +camel.component.kamelet.location = file:/invalid \ No newline at end of file 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 deleted file mode 100644 index d48d28546b69..000000000000 --- a/integration-tests/kamelet/src/main/resources/kamelets/auto-discovery.kamelet.yaml +++ /dev/null @@ -1,18 +0,0 @@ -# -# 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/main/resources/kamelets/injector.kamelet.yaml b/integration-tests/kamelet/src/main/resources/kamelets/injector.kamelet.yaml index 0bf2f62b936f..5ebd22463888 100644 --- a/integration-tests/kamelet/src/main/resources/kamelets/injector.kamelet.yaml +++ b/integration-tests/kamelet/src/main/resources/kamelets/injector.kamelet.yaml @@ -18,7 +18,7 @@ apiVersion: camel.apache.org/v1alpha1 kind: Kamelet metadata: - name: injector-source-v1alpha1 + name: injector labels: camel.apache.org/kamelet.type: "source" camel.apache.org/kamelet.name: "injector" @@ -42,7 +42,7 @@ spec: flow: from: uri: timer - properties: + parameters: timerName: "{{routeId}}" period: "{{delay}}" steps: diff --git a/integration-tests/kamelet/src/main/resources/kamelets/logger.kamelet.yaml b/integration-tests/kamelet/src/main/resources/kamelets/logger.kamelet.yaml index 86b072f6dad6..d974eef64fa7 100644 --- a/integration-tests/kamelet/src/main/resources/kamelets/logger.kamelet.yaml +++ b/integration-tests/kamelet/src/main/resources/kamelets/logger.kamelet.yaml @@ -18,6 +18,7 @@ apiVersion: camel.apache.org/v1alpha1 kind: Kamelet metadata: + name: logger labels: camel.apache.org/kamelet.type: "sink" camel.apache.org/kamelet.name: "log" @@ -50,7 +51,7 @@ spec: steps: - to: uri: "log" - properties: + parameters: loggerName: "{{loggerName}}" showAll: "{{showAll}}" multiline: "{{multiLine}}" 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 649585896f19..8d497063ab45 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 @@ -16,13 +16,17 @@ */ package org.apache.camel.quarkus.component.kamelet.it; +import java.util.ArrayList; +import java.util.Map; + import io.quarkus.test.junit.QuarkusTest; import io.restassured.RestAssured; import io.restassured.http.ContentType; +import io.restassured.response.Response; import org.junit.jupiter.api.Test; -import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertTrue; @QuarkusTest class KameletTest { @@ -86,24 +90,17 @@ public void testInvoke() { .body(is("Kamelet2-suffix")); } - @Test - public void testAutoDiscovery() { - RestAssured.given() - .contentType(ContentType.TEXT) - .body("Kamelet") - .post("/kamelet/auto-discovery") - .then() - .statusCode(200) - .body(is("Auto-discovered Kamelet")); - } - @Test public void testDiscovered() { - RestAssured.given() - .contentType(ContentType.TEXT) - .get("/kamelet/list") - .then() - .statusCode(200) - .body(hasItem("injector"), hasItem("logger")); + + Response resp = RestAssured.given() + .contentType(ContentType.JSON) + .when().get("/kamelet/list"); + resp.then().statusCode(200); + + ArrayList> jsonAsArrayList = resp.body() + .jsonPath().get(""); + assertTrue(jsonAsArrayList.contains("injector")); + assertTrue(jsonAsArrayList.contains("logger")); } }