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

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 04428ed47f2c CAMEL-27535: camel-kamelet - document how a Kamelet is 
configured and tested (#30753)
04428ed47f2c is described below

commit 04428ed47f2c17e7a2a86c913bb5237898b50d77
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Nov 24 22:34:52 2026 +0100

    CAMEL-27535: camel-kamelet - document how a Kamelet is configured and 
tested (#30753)
    
    * CAMEL-27535: camel-kamelet - document how a Kamelet is configured and 
tested
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    
    * CAMEL-27535: camel-kamelet - correct the javadoc of the environment 
variable lookup
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    
    * CAMEL-27535: camel-kamelet - link the catalog pages with xref
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    
    * CAMEL-27535: camel-kamelet - name the catalog pages without a link, the 
xref check cannot resolve other repositories
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    
    * CAMEL-27535: regen the catalog copies of the camel-kamelet docs
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    
    ---------
    
    Co-authored-by: Claude Opus 5.5 <[email protected]>
---
 .../camel/catalog/docs/kamelet-component.adoc      | 52 ++++++++++++++++++++++
 .../apache/camel/catalog/docs/kamelet-custom.adoc  | 45 +++++++++++++++++++
 .../src/main/docs/kamelet-component.adoc           | 52 ++++++++++++++++++++++
 .../src/main/docs/kamelet-custom.adoc              | 45 +++++++++++++++++++
 .../apache/camel/component/kamelet/Kamelet.java    | 16 ++++---
 5 files changed, 205 insertions(+), 5 deletions(-)

diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/kamelet-component.adoc
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/kamelet-component.adoc
index 2fd776e2bb9b..b2bdbb8620f7 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/kamelet-component.adoc
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/kamelet-component.adoc
@@ -39,6 +39,58 @@ The *kamelet* endpoint is *lenient*, which means that the 
endpoint accepts addit
 
 If a xref:manual::route-template.adoc[Route Template] is not found, the 
*kamelet* endpoint tries to load the related *kamelet* definition from the file 
system (by default `classpath:kamelets`). The default resolution mechanism 
expects _Kamelets_ files to have the extension `.kamelet.yaml`.
 
+=== Configuring a Kamelet
+
+The parameters of a Kamelet can be set in four places. When a parameter is set 
in more than one, the one higher in
+this list wins:
+
+. The endpoint parameters: `kamelet:timer-source?message=Hello`, or 
`parameters` in YAML.
+. An environment variable `CAMEL_KAMELET_<NAME>_<PARAMETER>`. The name of the 
Kamelet and of the parameter are
+  written in capitals, with `_` between the words: the parameter 
`bucketNameOrArn` of `aws-s3-source` is
+  `CAMEL_KAMELET_AWS_S3_SOURCE_BUCKET_NAME_OR_ARN`.
+. A property `camel.kamelet.<name>.<parameter>`, such as 
`camel.kamelet.timer-source.message=Hello`, for every use
+  of the Kamelet.
+. The default of the parameter, in the Kamelet.
+
+A use of a Kamelet can be given an id after its name, `kamelet:<name>/<id>`. 
The property
+`camel.kamelet.<name>.<id>.<parameter>` and the environment variable 
`CAMEL_KAMELET_<NAME>_<ID>_<PARAMETER>` then
+apply to that use only, and win over the ones for every use:
+
+[source,properties]
+----
+camel.kamelet.timer-source.message=Hello
+camel.kamelet.timer-source.fast.period=1000
+----
+
+[source,yaml]
+----
+- route:
+    from:
+      uri: kamelet:timer-source/fast
+      steps:
+        - to:
+            uri: kamelet:log-sink
+----
+
+The component options `template-properties` and `route-properties` hold 
parameters too:
+`camel.component.kamelet.template-properties[<name>].<parameter>` for every 
use and
+`camel.component.kamelet.route-properties[<id>].<parameter>` for one use. Use 
one style or the other: once any
+`template-properties` or `route-properties` value applies to a Kamelet, no 
`camel.kamelet.*` property is read for it,
+and those parameters fall back to their defaults. The environment variables 
and the endpoint parameters still apply.
+
+A required parameter that is not set fails the route when it starts, such as
+`Route template timer-source the following mandatory parameters must be 
provided: message`.
+
+These names belong to the `kamelet` endpoint and are never passed to the 
Kamelet: `templateId`, `routeId`,
+`location`, `uuid`, and the endpoint options `block`, `timeout`, 
`failIfNoConsumers`, `noErrorHandler`,
+`advancedOptions`, `bridgeErrorHandler`, `exceptionHandler`, `exchangePattern` 
and `lazyStartProducer`. A Kamelet
+should not have a parameter with one of these names.
+
+NOTE: An optional parameter that is not set, written `+{{?user}}+` in the 
template, is still looked up as a property
+placeholder, and so also in the environment under its name in capitals: an 
unset `user` takes the value of `USER`.
+
+For the Kamelets of the catalog, see also the page Using Kamelets in the 
Kamelet Catalog documentation.
+
 === Writing a custom Kamelet
 
 You can write your own Kamelets, for a piece of an integration that several 
routes need. A Kamelet is a
diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/kamelet-custom.adoc
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/kamelet-custom.adoc
index 6b966009b2d9..0a7ea367a5c0 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/kamelet-custom.adoc
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/kamelet-custom.adoc
@@ -240,3 +240,48 @@ line in the template.
 ----
 camel validate yaml content-filter-action.kamelet.yaml
 ----
+
+== Testing a Kamelet
+
+A Kamelet is tested by running a route that uses it and checking what it does. 
The
+xref:manual::camel-jbang-test.adoc[Camel CLI testing plugin] runs such tests, 
written with
+https://citrusframework.org/[Citrus]. This test runs the route above with the 
three Kamelets, and checks that the
+order is logged with only the allowed fields:
+
+.test/orders.citrus.it.yaml
+[source,yaml]
+----
+name: orders-test
+actions:
+  # Run the route with the three Kamelets
+  - camel:
+      cli:
+        run:
+          resources:
+            - "order-source.kamelet.yaml"
+            - "content-filter-action.kamelet.yaml"
+            - "archive-sink.kamelet.yaml"
+          integration:
+            file: "../orders.camel.yaml"
+
+  # The order is logged with only the allowed fields
+  - camel:
+      cli:
+        verify:
+          integration: "orders.camel"
+          logMessage: '"country" : "DK"'
+----
+
+The `resources` are the files the route needs next to it, relative to the 
route file. The integration is named after
+the route file, without `.yaml`. Run the test from the directory of the route:
+
+[source,bash]
+----
+camel plugin add test
+camel test run test/orders.citrus.it.yaml
+----
+
+A test that only checks that something was logged also passes when a Kamelet 
does nothing. Check what the Kamelet
+changes, as the allowed field here, and the body and headers it gives. The 
tests of the Kamelet catalog show more
+ways to check a source, a sink and an action, such as with an HTTP server or a 
database in a container; see the
+page Testing a Kamelet in the Kamelet Catalog documentation.
diff --git a/components/camel-kamelet/src/main/docs/kamelet-component.adoc 
b/components/camel-kamelet/src/main/docs/kamelet-component.adoc
index 2fd776e2bb9b..b2bdbb8620f7 100644
--- a/components/camel-kamelet/src/main/docs/kamelet-component.adoc
+++ b/components/camel-kamelet/src/main/docs/kamelet-component.adoc
@@ -39,6 +39,58 @@ The *kamelet* endpoint is *lenient*, which means that the 
endpoint accepts addit
 
 If a xref:manual::route-template.adoc[Route Template] is not found, the 
*kamelet* endpoint tries to load the related *kamelet* definition from the file 
system (by default `classpath:kamelets`). The default resolution mechanism 
expects _Kamelets_ files to have the extension `.kamelet.yaml`.
 
+=== Configuring a Kamelet
+
+The parameters of a Kamelet can be set in four places. When a parameter is set 
in more than one, the one higher in
+this list wins:
+
+. The endpoint parameters: `kamelet:timer-source?message=Hello`, or 
`parameters` in YAML.
+. An environment variable `CAMEL_KAMELET_<NAME>_<PARAMETER>`. The name of the 
Kamelet and of the parameter are
+  written in capitals, with `_` between the words: the parameter 
`bucketNameOrArn` of `aws-s3-source` is
+  `CAMEL_KAMELET_AWS_S3_SOURCE_BUCKET_NAME_OR_ARN`.
+. A property `camel.kamelet.<name>.<parameter>`, such as 
`camel.kamelet.timer-source.message=Hello`, for every use
+  of the Kamelet.
+. The default of the parameter, in the Kamelet.
+
+A use of a Kamelet can be given an id after its name, `kamelet:<name>/<id>`. 
The property
+`camel.kamelet.<name>.<id>.<parameter>` and the environment variable 
`CAMEL_KAMELET_<NAME>_<ID>_<PARAMETER>` then
+apply to that use only, and win over the ones for every use:
+
+[source,properties]
+----
+camel.kamelet.timer-source.message=Hello
+camel.kamelet.timer-source.fast.period=1000
+----
+
+[source,yaml]
+----
+- route:
+    from:
+      uri: kamelet:timer-source/fast
+      steps:
+        - to:
+            uri: kamelet:log-sink
+----
+
+The component options `template-properties` and `route-properties` hold 
parameters too:
+`camel.component.kamelet.template-properties[<name>].<parameter>` for every 
use and
+`camel.component.kamelet.route-properties[<id>].<parameter>` for one use. Use 
one style or the other: once any
+`template-properties` or `route-properties` value applies to a Kamelet, no 
`camel.kamelet.*` property is read for it,
+and those parameters fall back to their defaults. The environment variables 
and the endpoint parameters still apply.
+
+A required parameter that is not set fails the route when it starts, such as
+`Route template timer-source the following mandatory parameters must be 
provided: message`.
+
+These names belong to the `kamelet` endpoint and are never passed to the 
Kamelet: `templateId`, `routeId`,
+`location`, `uuid`, and the endpoint options `block`, `timeout`, 
`failIfNoConsumers`, `noErrorHandler`,
+`advancedOptions`, `bridgeErrorHandler`, `exceptionHandler`, `exchangePattern` 
and `lazyStartProducer`. A Kamelet
+should not have a parameter with one of these names.
+
+NOTE: An optional parameter that is not set, written `+{{?user}}+` in the 
template, is still looked up as a property
+placeholder, and so also in the environment under its name in capitals: an 
unset `user` takes the value of `USER`.
+
+For the Kamelets of the catalog, see also the page Using Kamelets in the 
Kamelet Catalog documentation.
+
 === Writing a custom Kamelet
 
 You can write your own Kamelets, for a piece of an integration that several 
routes need. A Kamelet is a
diff --git a/components/camel-kamelet/src/main/docs/kamelet-custom.adoc 
b/components/camel-kamelet/src/main/docs/kamelet-custom.adoc
index 6b966009b2d9..0a7ea367a5c0 100644
--- a/components/camel-kamelet/src/main/docs/kamelet-custom.adoc
+++ b/components/camel-kamelet/src/main/docs/kamelet-custom.adoc
@@ -240,3 +240,48 @@ line in the template.
 ----
 camel validate yaml content-filter-action.kamelet.yaml
 ----
+
+== Testing a Kamelet
+
+A Kamelet is tested by running a route that uses it and checking what it does. 
The
+xref:manual::camel-jbang-test.adoc[Camel CLI testing plugin] runs such tests, 
written with
+https://citrusframework.org/[Citrus]. This test runs the route above with the 
three Kamelets, and checks that the
+order is logged with only the allowed fields:
+
+.test/orders.citrus.it.yaml
+[source,yaml]
+----
+name: orders-test
+actions:
+  # Run the route with the three Kamelets
+  - camel:
+      cli:
+        run:
+          resources:
+            - "order-source.kamelet.yaml"
+            - "content-filter-action.kamelet.yaml"
+            - "archive-sink.kamelet.yaml"
+          integration:
+            file: "../orders.camel.yaml"
+
+  # The order is logged with only the allowed fields
+  - camel:
+      cli:
+        verify:
+          integration: "orders.camel"
+          logMessage: '"country" : "DK"'
+----
+
+The `resources` are the files the route needs next to it, relative to the 
route file. The integration is named after
+the route file, without `.yaml`. Run the test from the directory of the route:
+
+[source,bash]
+----
+camel plugin add test
+camel test run test/orders.citrus.it.yaml
+----
+
+A test that only checks that something was logged also passes when a Kamelet 
does nothing. Check what the Kamelet
+changes, as the allowed field here, and the body and headers it gives. The 
tests of the Kamelet catalog show more
+ways to check a source, a sink and an action, such as with an HTTP server or a 
database in a container; see the
+page Testing a Kamelet in the Kamelet Catalog documentation.
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 3d87c1319b66..427192c06c5d 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
@@ -168,12 +168,18 @@ public final class Kamelet {
     }
 
     /**
-     * Looking for OS environment variables that match the properties of the 
given Kamelet. At first lookup attempt is
-     * made without considering camelCase keys in the elements. The second 
lookup is converting camelCase to
-     * underscores.
+     * Looking for OS environment variables that match the properties of the 
given Kamelet. The elements (the Kamelet
+     * name, and the route id) are upper-cased, with dashes and dots replaced 
by underscores. The first lookup keeps a
+     * camelCase element as one word, the second lookup splits it with 
underscores.
      *
-     * For example given an ENV variable in either format: - 
CAMEL_KAMELET_AWSS3SOURCE_BUCKETNAMEORARN=myArn -
-     * CAMEL_KAMELET_AWS_S3_SOURCE_BUCKET_NAME_OR_ARN=myArn
+     * For example, given the Kamelet aws-s3-source used with the route id 
myRoute, these ENV variables all match:
+     * <ul>
+     * <li>CAMEL_KAMELET_AWS_S3_SOURCE_BUCKET_NAME_OR_ARN=myArn</li>
+     * <li>CAMEL_KAMELET_AWS_S3_SOURCE_BUCKETNAMEORARN=myArn</li>
+     * <li>CAMEL_KAMELET_AWS_S3_SOURCE_MYROUTE_BUCKET_NAME_OR_ARN=myArn</li>
+     * <li>CAMEL_KAMELET_AWS_S3_SOURCE_MY_ROUTE_BUCKET_NAME_OR_ARN=myArn</li>
+     * </ul>
+     * The dashes of the Kamelet name always become underscores: 
CAMEL_KAMELET_AWSS3SOURCE_... does not match.
      */
     public static void extractKameletEnvironmentVariables(Map<String, Object> 
properties, String... elements) {
         StringBuilder prefixBuffer = new StringBuilder(Kamelet.ENV_VAR_PREFIX);

Reply via email to