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 bdaf98221352716d1098e6a511a5aa774d506d33 Author: Luca Burgazzoli <[email protected]> AuthorDate: Mon Nov 23 18:40:14 2020 +0100 camel-kamelet: improve global properties handling #560 --- components/camel-kamelet/pom.xml | 2 + .../kamelet/KameletComponentConfigurer.java | 3 + .../kamelet/KameletConfigurationConfigurer.java | 66 ++++++++++++++++++++++ .../kamelet/KameletEndpointConfigurer.java | 5 -- ...he.camel.component.kamelet.KameletConfiguration | 2 + .../apache/camel/component/kamelet/kamelet.json | 2 +- .../apache/camel/component/kamelet/Kamelet.java | 3 +- .../camel/component/kamelet/KameletComponent.java | 65 ++++++++++++++++++--- .../component/kamelet/KameletConfiguration.java | 44 +++++++++++++++ .../camel/component/kamelet/KameletEndpoint.java | 4 +- .../kamelet/support/PropertiesConfigurer.java | 30 ++++++++++ .../apache/camel/configurer/java.util.Properties | 18 ++++++ .../component/kamelet/KameletComponentTest.java | 55 ++++++++++++++++++ 13 files changed, 281 insertions(+), 18 deletions(-) diff --git a/components/camel-kamelet/pom.xml b/components/camel-kamelet/pom.xml index 2f5b0ee..2441ff2 100644 --- a/components/camel-kamelet/pom.xml +++ b/components/camel-kamelet/pom.xml @@ -92,6 +92,7 @@ <build> <plugins> + <!-- <plugin> <groupId>org.jboss.jandex</groupId> <artifactId>jandex-maven-plugin</artifactId> @@ -104,6 +105,7 @@ </execution> </executions> </plugin> + --> <plugin> <groupId>org.apache.camel</groupId> <artifactId>camel-component-maven-plugin</artifactId> diff --git a/components/camel-kamelet/src/generated/java/org/apache/camel/component/kamelet/KameletComponentConfigurer.java b/components/camel-kamelet/src/generated/java/org/apache/camel/component/kamelet/KameletComponentConfigurer.java index 32acfce..9013d36 100644 --- a/components/camel-kamelet/src/generated/java/org/apache/camel/component/kamelet/KameletComponentConfigurer.java +++ b/components/camel-kamelet/src/generated/java/org/apache/camel/component/kamelet/KameletComponentConfigurer.java @@ -18,6 +18,7 @@ public class KameletComponentConfigurer extends PropertyConfigurerSupport implem private static final Map<String, Object> ALL_OPTIONS; static { Map<String, Object> map = new CaseInsensitiveMap(); + map.put("configuration", org.apache.camel.component.kamelet.KameletConfiguration.class); map.put("bridgeErrorHandler", boolean.class); map.put("block", boolean.class); map.put("lazyStartProducer", boolean.class); @@ -35,6 +36,7 @@ public class KameletComponentConfigurer extends PropertyConfigurerSupport implem case "block": target.setBlock(property(camelContext, boolean.class, value)); return true; case "bridgeerrorhandler": case "bridgeErrorHandler": target.setBridgeErrorHandler(property(camelContext, boolean.class, value)); return true; + case "configuration": target.setConfiguration(property(camelContext, org.apache.camel.component.kamelet.KameletConfiguration.class, value)); return true; case "lazystartproducer": case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true; case "timeout": target.setTimeout(property(camelContext, long.class, value)); return true; @@ -56,6 +58,7 @@ public class KameletComponentConfigurer extends PropertyConfigurerSupport implem case "block": return target.isBlock(); case "bridgeerrorhandler": case "bridgeErrorHandler": return target.isBridgeErrorHandler(); + case "configuration": return target.getConfiguration(); case "lazystartproducer": case "lazyStartProducer": return target.isLazyStartProducer(); case "timeout": return target.getTimeout(); diff --git a/components/camel-kamelet/src/generated/java/org/apache/camel/component/kamelet/KameletConfigurationConfigurer.java b/components/camel-kamelet/src/generated/java/org/apache/camel/component/kamelet/KameletConfigurationConfigurer.java new file mode 100644 index 0000000..956450f --- /dev/null +++ b/components/camel-kamelet/src/generated/java/org/apache/camel/component/kamelet/KameletConfigurationConfigurer.java @@ -0,0 +1,66 @@ +/* Generated by camel build tools - do NOT edit this file! */ +package org.apache.camel.component.kamelet; + +import java.util.Map; + +import org.apache.camel.CamelContext; +import org.apache.camel.spi.GeneratedPropertyConfigurer; +import org.apache.camel.spi.PropertyConfigurerGetter; +import org.apache.camel.util.CaseInsensitiveMap; +import org.apache.camel.component.kamelet.KameletConfiguration; + +/** + * Generated by camel build tools - do NOT edit this file! + */ +@SuppressWarnings("unchecked") +public class KameletConfigurationConfigurer extends org.apache.camel.support.component.PropertyConfigurerSupport implements GeneratedPropertyConfigurer, PropertyConfigurerGetter { + + private static final Map<String, Object> ALL_OPTIONS; + static { + Map<String, Object> map = new CaseInsensitiveMap(); + map.put("RouteProperties", java.util.Map.class); + map.put("TemplateProperties", java.util.Map.class); + ALL_OPTIONS = map; + } + + @Override + public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) { + org.apache.camel.component.kamelet.KameletConfiguration target = (org.apache.camel.component.kamelet.KameletConfiguration) obj; + switch (ignoreCase ? name.toLowerCase() : name) { + case "routeproperties": + case "RouteProperties": target.setRouteProperties(property(camelContext, java.util.Map.class, value)); return true; + case "templateproperties": + case "TemplateProperties": target.setTemplateProperties(property(camelContext, java.util.Map.class, value)); return true; + default: return false; + } + } + + @Override + public Map<String, Object> getAllOptions(Object target) { + return ALL_OPTIONS; + } + + @Override + public Object getOptionValue(Object obj, String name, boolean ignoreCase) { + org.apache.camel.component.kamelet.KameletConfiguration target = (org.apache.camel.component.kamelet.KameletConfiguration) obj; + switch (ignoreCase ? name.toLowerCase() : name) { + case "routeproperties": + case "RouteProperties": return target.getRouteProperties(); + case "templateproperties": + case "TemplateProperties": return target.getTemplateProperties(); + default: return null; + } + } + + @Override + public Object getCollectionValueType(Object target, String name, boolean ignoreCase) { + switch (ignoreCase ? name.toLowerCase() : name) { + case "routeproperties": + case "RouteProperties": return java.util.Properties.class; + case "templateproperties": + case "TemplateProperties": return java.util.Properties.class; + default: return null; + } + } +} + diff --git a/components/camel-kamelet/src/generated/java/org/apache/camel/component/kamelet/KameletEndpointConfigurer.java b/components/camel-kamelet/src/generated/java/org/apache/camel/component/kamelet/KameletEndpointConfigurer.java index cdbc56e..0af67b2 100644 --- a/components/camel-kamelet/src/generated/java/org/apache/camel/component/kamelet/KameletEndpointConfigurer.java +++ b/components/camel-kamelet/src/generated/java/org/apache/camel/component/kamelet/KameletEndpointConfigurer.java @@ -25,7 +25,6 @@ public class KameletEndpointConfigurer extends PropertyConfigurerSupport impleme map.put("exchangePattern", org.apache.camel.ExchangePattern.class); map.put("block", boolean.class); map.put("failIfNoConsumers", boolean.class); - map.put("kameletProperties", java.util.Map.class); map.put("lazyStartProducer", boolean.class); map.put("timeout", long.class); map.put("basicPropertyBinding", boolean.class); @@ -48,8 +47,6 @@ public class KameletEndpointConfigurer extends PropertyConfigurerSupport impleme case "exchangePattern": target.setExchangePattern(property(camelContext, org.apache.camel.ExchangePattern.class, value)); return true; case "failifnoconsumers": case "failIfNoConsumers": target.setFailIfNoConsumers(property(camelContext, boolean.class, value)); return true; - case "kameletproperties": - case "kameletProperties": target.setKameletProperties(property(camelContext, java.util.Map.class, value)); return true; case "lazystartproducer": case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true; case "synchronous": target.setSynchronous(property(camelContext, boolean.class, value)); return true; @@ -78,8 +75,6 @@ public class KameletEndpointConfigurer extends PropertyConfigurerSupport impleme case "exchangePattern": return target.getExchangePattern(); case "failifnoconsumers": case "failIfNoConsumers": return target.isFailIfNoConsumers(); - case "kameletproperties": - case "kameletProperties": return target.getKameletProperties(); case "lazystartproducer": case "lazyStartProducer": return target.isLazyStartProducer(); case "synchronous": return target.isSynchronous(); diff --git a/components/camel-kamelet/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.component.kamelet.KameletConfiguration b/components/camel-kamelet/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.component.kamelet.KameletConfiguration new file mode 100644 index 0000000..7b71d91 --- /dev/null +++ b/components/camel-kamelet/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.component.kamelet.KameletConfiguration @@ -0,0 +1,2 @@ +# Generated by camel build tools - do NOT edit this file! +class=org.apache.camel.component.kamelet.KameletConfigurationConfigurer diff --git a/components/camel-kamelet/src/generated/resources/org/apache/camel/component/kamelet/kamelet.json b/components/camel-kamelet/src/generated/resources/org/apache/camel/component/kamelet/kamelet.json index 91854be..948fa42 100644 --- a/components/camel-kamelet/src/generated/resources/org/apache/camel/component/kamelet/kamelet.json +++ b/components/camel-kamelet/src/generated/resources/org/apache/camel/component/kamelet/kamelet.json @@ -22,6 +22,7 @@ "lenientProperties": true }, "componentProperties": { + "configuration": { "kind": "property", "displayName": "Configuration", "group": "common", "label": "", "required": false, "type": "object", "javaType": "org.apache.camel.component.kamelet.KameletConfiguration", "deprecated": false, "secret": false, "description": "The configuration." }, "bridgeErrorHandler": { "kind": "property", "displayName": "Bridge Error Handler", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by [...] "block": { "kind": "property", "displayName": "Block", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": true, "description": "If sending a message to a kamelet endpoint which has no active consumer, then we can tell the producer to block and wait for the consumer to become active." }, "lazyStartProducer": { "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the r [...] @@ -36,7 +37,6 @@ "exchangePattern": { "kind": "parameter", "displayName": "Exchange Pattern", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.ExchangePattern", "enum": [ "InOnly", "InOut", "InOptionalOut" ], "deprecated": false, "secret": false, "description": "Sets the exchange pattern when the consumer creates an exchange." }, "block": { "kind": "parameter", "displayName": "Block", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": true, "description": "If sending a message to a direct endpoint which has no active consumer, then we can tell the producer to block and wait for the consumer to become active." }, "failIfNoConsumers": { "kind": "parameter", "displayName": "Fail If No Consumers", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": true, "description": "Whether the producer should fail by throwing an exception, when sending to a kamelet endpoint with no active consumers." }, - "kameletProperties": { "kind": "parameter", "displayName": "Kamelet Properties", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "java.util.Map<java.lang.String, java.lang.Object>", "deprecated": false, "secret": false, "description": "Custom properties for kamelet" }, "lazyStartProducer": { "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the [...] "timeout": { "kind": "parameter", "displayName": "Timeout", "group": "producer", "label": "producer", "required": false, "type": "integer", "javaType": "long", "deprecated": false, "secret": false, "defaultValue": 30000, "description": "The timeout value to use if block is enabled." }, "basicPropertyBinding": { "kind": "parameter", "displayName": "Basic Property Binding", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the endpoint should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities" }, diff --git a/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/Kamelet.java b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/Kamelet.java index 14ecc43..2823bf5 100644 --- a/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/Kamelet.java +++ b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/Kamelet.java @@ -87,9 +87,8 @@ public final class Kamelet { return answer; } - public static Map<String, Object> extractKameletProperties(CamelContext context, String... elements) { + public static Map<String, Object> extractKameletProperties(CamelContext context, Map<String, Object> properties, String... elements) { PropertiesComponent pc = context.getPropertiesComponent(); - Map<String, Object> properties = new HashMap<>(); String prefix = Kamelet.PROPERTIES_PREFIX; for (String element: elements) { diff --git a/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletComponent.java b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletComponent.java index ea4767c..c60ae71 100644 --- a/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletComponent.java +++ b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletComponent.java @@ -70,6 +70,9 @@ public class KameletComponent extends DefaultComponent { @Metadata(label = "producer", defaultValue = "30000") private long timeout = 30000L; + @Metadata + private KameletConfiguration configuration; + public KameletComponent() { } @@ -225,20 +228,56 @@ public class KameletComponent extends DefaultComponent { endpoint.setBlock(block); endpoint.setTimeout(timeout); - // set endpoint specific properties + // set and remove endpoint specific properties setProperties(endpoint, parameters); + Map<String, Object> kameletProperties = new HashMap<>(); + // - // The properties for the kamelets are determined by global properties - // and local endpoint parameters, + // Load properties from the component configuration. Template and route specific properties + // can be set through properties, as example: + // + // camel.component.kamelet.configuration.template-properties[templateId].key = val + // camel.component.kamelet.configuration.route-properties[templateId].key = val + // + if (configuration != null && configuration.getTemplateProperties() != null) { + Properties props = configuration.getTemplateProperties().get(routeId); + if (props != null) { + props.stringPropertyNames().forEach(name -> kameletProperties.put(name, props.get(name))); + } + } + if (configuration != null && configuration.getRouteProperties() != null) { + Properties props = configuration.getRouteProperties().get(routeId); + if (props != null) { + props.stringPropertyNames().forEach(name -> kameletProperties.put(name, props.get(name))); + } + } + // - // Global parameters are loaded in the following order: + // We can't mix configuration styles so if properties are not configured through the component, + // then fallback to the old - deprecated - style. // - // camel.kamelet." + templateId - // camel.kamelet." + templateId + "." routeId + if (kameletProperties.isEmpty()) { + // + // The properties for the kamelets are determined by global properties + // and local endpoint parameters, + // + // Global parameters are loaded in the following order: + // + // camel.kamelet." + templateId + // camel.kamelet." + templateId + "." routeId + // + Kamelet.extractKameletProperties(getCamelContext(), kameletProperties, templateId, routeId); + } + + // + // Uri params have the highest precedence // - Map<String, Object> kameletProperties = Kamelet.extractKameletProperties(getCamelContext(), templateId, routeId); kameletProperties.putAll(parameters); + + // + // And finally we have some specific properties that cannot be changed by the user. + // kameletProperties.put(PARAM_TEMPLATE_ID, templateId); kameletProperties.put(PARAM_ROUTE_ID, routeId); @@ -272,6 +311,17 @@ public class KameletComponent extends DefaultComponent { this.timeout = timeout; } + public KameletConfiguration getConfiguration() { + return configuration; + } + + /** + * The configuration. + */ + public void setConfiguration(KameletConfiguration configuration) { + this.configuration = configuration; + } + int getStateCounter() { return stateCounter; } @@ -415,4 +465,5 @@ public class KameletComponent extends DefaultComponent { LOGGER.debug("Route with id={} created from template={}", id, endpoint.getTemplateId()); } } + } diff --git a/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletConfiguration.java b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletConfiguration.java new file mode 100644 index 0000000..4a73226 --- /dev/null +++ b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletConfiguration.java @@ -0,0 +1,44 @@ +/* + * 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.component.kamelet; + +import java.util.Map; +import java.util.Properties; + +import org.apache.camel.spi.Configurer; + +@Configurer +public class KameletConfiguration { + private Map<String, Properties> templateProperties; + private Map<String, Properties> routeProperties; + + public Map<String, Properties> getTemplateProperties() { + return templateProperties; + } + + public void setTemplateProperties(Map<String, Properties> templateProperties) { + this.templateProperties = templateProperties; + } + + public Map<String, Properties> getRouteProperties() { + return routeProperties; + } + + public void setRouteProperties(Map<String, Properties> routeProperties) { + this.routeProperties = routeProperties; + } +} diff --git a/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletEndpoint.java b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletEndpoint.java index 415fba7..05e8013 100644 --- a/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletEndpoint.java +++ b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletEndpoint.java @@ -39,8 +39,8 @@ import org.apache.camel.util.ObjectHelper; lenientProperties = true, category = Category.CORE) public class KameletEndpoint extends DefaultEndpoint { - private final String key; + private final Map<String, Object> kameletProperties; @Metadata(required = true) @UriPath(description = "The Route Template ID") @@ -53,8 +53,6 @@ public class KameletEndpoint extends DefaultEndpoint { private boolean block = true; @UriParam(label = "producer", defaultValue = "30000") private long timeout = 30000L; - @UriParam(label = "producer") - private final Map<String, Object> kameletProperties; @UriParam(label = "producer", defaultValue = "true") private boolean failIfNoConsumers = true; diff --git a/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/support/PropertiesConfigurer.java b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/support/PropertiesConfigurer.java new file mode 100644 index 0000000..50fff27 --- /dev/null +++ b/components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/support/PropertiesConfigurer.java @@ -0,0 +1,30 @@ +/* + * 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.component.kamelet.support; + +import java.util.Properties; + +import org.apache.camel.CamelContext; +import org.apache.camel.spi.GeneratedPropertyConfigurer; + +public class PropertiesConfigurer implements GeneratedPropertyConfigurer { + @Override + public boolean configure(CamelContext camelContext, Object target, String name, Object value, boolean ignoreCase) { + ((Properties) target).put(name, value); + return true; + } +} diff --git a/components/camel-kamelet/src/main/resources/META-INF/services/org/apache/camel/configurer/java.util.Properties b/components/camel-kamelet/src/main/resources/META-INF/services/org/apache/camel/configurer/java.util.Properties new file mode 100644 index 0000000..f308c08 --- /dev/null +++ b/components/camel-kamelet/src/main/resources/META-INF/services/org/apache/camel/configurer/java.util.Properties @@ -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. +# + +class=org.apache.camel.component.kamelet.support.PropertiesConfigurer \ No newline at end of file diff --git a/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletComponentTest.java b/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletComponentTest.java new file mode 100644 index 0000000..9382e58 --- /dev/null +++ b/components/camel-kamelet/src/test/java/org/apache/camel/component/kamelet/KameletComponentTest.java @@ -0,0 +1,55 @@ +/* + * 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.component.kamelet; + +import java.util.Map; + +import org.apache.camel.CamelContext; +import org.apache.camel.impl.DefaultCamelContext; +import org.apache.camel.support.PropertyBindingSupport; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class KameletComponentTest { + @Test + public void testComponent() { + CamelContext context = new DefaultCamelContext(); + KameletComponent component = context.getComponent(Kamelet.SCHEME, KameletComponent.class); + + PropertyBindingSupport.build() + .withIgnoreCase(true) + .withReflection(false) + .withRemoveParameters(false) + .withCamelContext(context) + .withTarget(component) + .withConfigurer(component.getComponentPropertyConfigurer()) + .withProperties(Map.of( + "configuration.template-properties[myTemplate].foo", "bar", + "configuration.route-properties[myRoute].foo", "baz" + )) + .bind(); + + + assertThat(component.getConfiguration().getTemplateProperties()).isNotEmpty(); + assertThat(component.getConfiguration().getTemplateProperties()).containsKey("myTemplate"); + assertThat(component.getConfiguration().getTemplateProperties().get("myTemplate")).containsEntry("foo", "bar"); + assertThat(component.getConfiguration().getRouteProperties()).isNotEmpty(); + assertThat(component.getConfiguration().getRouteProperties()).containsKey("myRoute"); + assertThat(component.getConfiguration().getRouteProperties().get("myRoute")).containsEntry("foo", "baz"); + } +}
