You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/01/27 13:16:59 UTC

[camel-examples] branch main updated: CAMEL-11834: Add tests for main/main-endpointdsl/reactive-executor-vertx/route-throttling/main-health/main-joor/main-lambda/main-tiny/main-xml/main-yaml (#60)

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-examples.git


The following commit(s) were added to refs/heads/main by this push:
     new 1f4db99  CAMEL-11834: Add tests for main/main-endpointdsl/reactive-executor-vertx/route-throttling/main-health/main-joor/main-lambda/main-tiny/main-xml/main-yaml (#60)
1f4db99 is described below

commit 1f4db99d85e75e7288cf433963fdf37619d331f6
Author: Nicolas Filotto <es...@users.noreply.github.com>
AuthorDate: Thu Jan 27 14:16:55 2022 +0100

    CAMEL-11834: Add tests for main/main-endpointdsl/reactive-executor-vertx/route-throttling/main-health/main-joor/main-lambda/main-tiny/main-xml/main-yaml (#60)
---
 .../org/apache/camel/example/any23/Any23Test.java  |  5 ++
 .../org/apache/camel/example/kafka/KafkaTest.java  |  5 ++
 examples/main-endpointdsl/pom.xml                  |  7 ++-
 .../apache/camel/example/MainEndpointDSLTest.java} | 39 ++++++------
 examples/main-health/README.adoc                   | 15 ++++-
 examples/main-health/pom.xml                       |  7 ++-
 .../org/apache/camel/example/MainHealthTest.java}  | 41 +++++++++----
 examples/main-joor/README.adoc                     | 11 +++-
 examples/main-joor/pom.xml                         |  7 ++-
 .../org/apache/camel/example/MyRouteBuilder.java   |  2 +-
 .../src/main/resources/application.properties      |  3 +-
 .../org/apache/camel/example/MainJOORTest.java}    | 38 ++++++------
 examples/main-lambda/README.adoc                   | 11 +++-
 examples/main-lambda/pom.xml                       |  7 ++-
 .../org/apache/camel/example/MainLambdaTest.java   | 66 ++++++++++++++++++++
 examples/main-tiny/README.adoc                     |  9 +++
 examples/main-tiny/pom.xml                         |  7 ++-
 examples/main-tiny/src/main/data/foo.properties    | 18 ------
 .../org/apache/camel/example/MainTinyTest.java     | 62 +++++++++++++++++++
 examples/main-xml/README.adoc                      | 14 ++++-
 examples/main-xml/pom.xml                          |  7 ++-
 .../java/org/apache/camel/example/MainXMLTest.java | 70 ++++++++++++++++++++++
 examples/main-yaml/README.adoc                     | 14 ++++-
 examples/main-yaml/pom.xml                         |  7 ++-
 .../org/apache/camel/example/MainYAMLTest.java     | 69 +++++++++++++++++++++
 examples/main/README.adoc                          |  6 +-
 examples/main/pom.xml                              |  7 ++-
 .../org/apache/camel/example/StandaloneCamel.java  | 42 +++++++------
 .../java/org/apache/camel/example/MainTest.java    | 61 +++++++++++++++++++
 .../apache/camel/example/mongodb/MongoDBTest.java  |  1 -
 examples/reactive-executor-vertx/README.adoc       | 10 +++-
 examples/reactive-executor-vertx/pom.xml           |  7 ++-
 .../java/org/apache/camel/example/VertxTest.java   | 63 +++++++++++++++++++
 examples/route-throttling/README.adoc              | 22 +++----
 examples/route-throttling/pom.xml                  |  8 +--
 .../apache/camel/example/client/CamelClient.java   | 52 ++++++++--------
 .../camel/example/client/CamelFileClient.java      | 25 ++++----
 .../resources/META-INF/spring/camel-server.xml     |  1 -
 .../camel/example/client/RouteThrottlingTest.java  | 68 +++++++++++++++++++++
 39 files changed, 745 insertions(+), 169 deletions(-)

diff --git a/examples/any23/src/test/java/org/apache/camel/example/any23/Any23Test.java b/examples/any23/src/test/java/org/apache/camel/example/any23/Any23Test.java
index 7d1c724..105fbd4 100644
--- a/examples/any23/src/test/java/org/apache/camel/example/any23/Any23Test.java
+++ b/examples/any23/src/test/java/org/apache/camel/example/any23/Any23Test.java
@@ -26,6 +26,11 @@ import org.junit.jupiter.api.Test;
  */
 class Any23Test extends CamelTestSupport {
 
+    @Override
+    public boolean isUseAdviceWith() {
+        return true;
+    }
+
     @Test
     void should_extract_data_from_rdf() throws Exception {
         // Mock the endpoint log:result
diff --git a/examples/kafka/src/test/java/org/apache/camel/example/kafka/KafkaTest.java b/examples/kafka/src/test/java/org/apache/camel/example/kafka/KafkaTest.java
index 074fbf0..07679cd 100644
--- a/examples/kafka/src/test/java/org/apache/camel/example/kafka/KafkaTest.java
+++ b/examples/kafka/src/test/java/org/apache/camel/example/kafka/KafkaTest.java
@@ -56,6 +56,11 @@ class KafkaTest extends CamelTestSupport {
     }
 
     @Override
+    public boolean isUseAdviceWith() {
+        return true;
+    }
+
+    @Override
     protected CamelContext createCamelContext() throws Exception {
         CamelContext camelContext = super.createCamelContext();
         // Set the location of the configuration
diff --git a/examples/main-endpointdsl/pom.xml b/examples/main-endpointdsl/pom.xml
index 1e16b94..072b894 100644
--- a/examples/main-endpointdsl/pom.xml
+++ b/examples/main-endpointdsl/pom.xml
@@ -82,7 +82,12 @@
             <artifactId>logback-classic</artifactId>
             <version>${logback-version}</version>
         </dependency>
-
+        <!-- for testing -->
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test-junit5</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/examples/any23/src/test/java/org/apache/camel/example/any23/Any23Test.java b/examples/main-endpointdsl/src/test/java/org/apache/camel/example/MainEndpointDSLTest.java
similarity index 52%
copy from examples/any23/src/test/java/org/apache/camel/example/any23/Any23Test.java
copy to examples/main-endpointdsl/src/test/java/org/apache/camel/example/MainEndpointDSLTest.java
index 7d1c724..e081d4f 100644
--- a/examples/any23/src/test/java/org/apache/camel/example/any23/Any23Test.java
+++ b/examples/main-endpointdsl/src/test/java/org/apache/camel/example/MainEndpointDSLTest.java
@@ -14,35 +14,40 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.example.any23;
+package org.apache.camel.example;
 
 import org.apache.camel.RoutesBuilder;
-import org.apache.camel.builder.AdviceWith;
+import org.apache.camel.builder.NotifyBuilder;
 import org.apache.camel.test.junit5.CamelTestSupport;
 import org.junit.jupiter.api.Test;
 
-/**
- * A unit test checking that we can extract data from a page with RDF content using Apache Anything To Triples.
- */
-class Any23Test extends CamelTestSupport {
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
 
-    @Test
-    void should_extract_data_from_rdf() throws Exception {
-        // Mock the endpoint log:result
-        AdviceWith.adviceWith(context, "result", ad -> ad.mockEndpoints("log:result"));
+import static org.apache.camel.util.PropertiesHelper.asProperties;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
-        // must start Camel after we are done using advice-with
-        context.start();
-
-        getMockEndpoint("mock:log:result").expectedMinimumMessageCount(1);
+/**
+ * A unit test checking that Camel supports routes with endpoints built with the endpoint DSL.
+ */
+class MainEndpointDSLTest extends CamelTestSupport {
 
-        template.sendBody("direct:start", "This is a test message to run the example");
+    @Override
+    protected Properties useOverridePropertiesWithPropertiesComponent() {
+        return asProperties("myPeriod", Integer.toString(500));
+    }
 
-        assertMockEndpointsSatisfied();
+    @Test
+    void should_support_routes_built_with_endpoint_dsl() {
+        NotifyBuilder notify = new NotifyBuilder(context)
+            .whenCompleted(1).whenBodiesDone("Davs how are you? I am called 1 times").create();
+        assertTrue(
+            notify.matches(20, TimeUnit.SECONDS), "1 message should be completed"
+        );
     }
 
     @Override
     protected RoutesBuilder createRouteBuilder() {
-        return new Any23RouteBuilder();
+        return new MyRouteBuilder();
     }
 }
diff --git a/examples/main-health/README.adoc b/examples/main-health/README.adoc
index a273379..20ba4ad 100644
--- a/examples/main-health/README.adoc
+++ b/examples/main-health/README.adoc
@@ -10,11 +10,20 @@ causes the custom health check to be in either UP or DOWN state.
 The 2nd route is on purpose made to fail on startup by configuring netty to an unknown host.
 Camel supervising route controller will attempt to restart the route up till 10 times before exhausting.
 
-The routes health check will therefore report this route as DOWN until its exhausted
+The route's health check will therefore report this route as DOWN until its exhausted
 where the states are changed to UNKNOWN.
 
 The details can be seen at runtime via JMX.
 
+=== Build
+
+First compile the example by executing:
+
+[source,sh]
+----
+$ mvn compile
+----
+
 === How to run
 
 You can run this example using
@@ -26,8 +35,8 @@ $ mvn camel:run
 
 === JMX Management
 
-You can from JMX see the health-check status in the Camel tree under health and
-find the DefaultHealthCheck MBean.
+You can see from JMX the health-check status in the Camel tree under `health` and
+find the `DefaultHealthCheck` MBean.
 
 === Help and contributions
 
diff --git a/examples/main-health/pom.xml b/examples/main-health/pom.xml
index 49a7ac4..4ca670d 100644
--- a/examples/main-health/pom.xml
+++ b/examples/main-health/pom.xml
@@ -90,7 +90,12 @@
             <artifactId>logback-classic</artifactId>
             <version>${logback-version}</version>
         </dependency>
-
+        <!-- for testing -->
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test-junit5</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/examples/any23/src/test/java/org/apache/camel/example/any23/Any23Test.java b/examples/main-health/src/test/java/org/apache/camel/example/MainHealthTest.java
similarity index 50%
copy from examples/any23/src/test/java/org/apache/camel/example/any23/Any23Test.java
copy to examples/main-health/src/test/java/org/apache/camel/example/MainHealthTest.java
index 7d1c724..d757629 100644
--- a/examples/any23/src/test/java/org/apache/camel/example/any23/Any23Test.java
+++ b/examples/main-health/src/test/java/org/apache/camel/example/MainHealthTest.java
@@ -14,35 +14,52 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.example.any23;
+package org.apache.camel.example;
 
 import org.apache.camel.RoutesBuilder;
 import org.apache.camel.builder.AdviceWith;
+import org.apache.camel.builder.NotifyBuilder;
 import org.apache.camel.test.junit5.CamelTestSupport;
 import org.junit.jupiter.api.Test;
 
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.camel.util.PropertiesHelper.asProperties;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
 /**
- * A unit test checking that we can extract data from a page with RDF content using Apache Anything To Triples.
+ * A unit test checking that Camel supports custom health-checks.
  */
-class Any23Test extends CamelTestSupport {
+class MainHealthTest extends CamelTestSupport {
+
+    @Override
+    public boolean isUseAdviceWith() {
+        return true;
+    }
+
+    @Override
+    protected Properties useOverridePropertiesWithPropertiesComponent() {
+        return asProperties("myPeriod", Integer.toString(500));
+    }
 
     @Test
-    void should_extract_data_from_rdf() throws Exception {
-        // Mock the endpoint log:result
-        AdviceWith.adviceWith(context, "result", ad -> ad.mockEndpoints("log:result"));
+    void should_support_custom_health_checks() throws Exception {
+        // Prevent failure by replacing the failing endpoint
+        AdviceWith.adviceWith(context, "netty", ad -> ad.replaceFromWith("direct:foo"));
 
         // must start Camel after we are done using advice-with
         context.start();
 
-        getMockEndpoint("mock:log:result").expectedMinimumMessageCount(1);
-
-        template.sendBody("direct:start", "This is a test message to run the example");
-
-        assertMockEndpointsSatisfied();
+        NotifyBuilder notify = new NotifyBuilder(context)
+            .whenCompleted(2).whenBodiesDone("Chaos monkey was here", "All is okay").create();
+        assertTrue(
+            notify.matches(20, TimeUnit.SECONDS), "2 messages should be completed"
+        );
     }
 
     @Override
     protected RoutesBuilder createRouteBuilder() {
-        return new Any23RouteBuilder();
+        return new MyRouteBuilder();
     }
 }
diff --git a/examples/main-joor/README.adoc b/examples/main-joor/README.adoc
index c9aa3bf..6bfb2aa 100644
--- a/examples/main-joor/README.adoc
+++ b/examples/main-joor/README.adoc
@@ -1,7 +1,16 @@
 == Camel Example Main jOOR
 
 This example shows using the new jOOR language in the Camel DSL.
-The jOOR language is very performant, as it is compiled to Java code once during startup (runtime).
+The jOOR language is very performant, as it is compiled once to Java code during startup (runtime).
+
+=== Build
+
+First compile the example by executing:
+
+[source,sh]
+----
+$ mvn compile
+----
 
 === How to run
 
diff --git a/examples/main-joor/pom.xml b/examples/main-joor/pom.xml
index ec490a2..3834eff 100644
--- a/examples/main-joor/pom.xml
+++ b/examples/main-joor/pom.xml
@@ -81,7 +81,12 @@
             <artifactId>logback-classic</artifactId>
             <version>${logback-version}</version>
         </dependency>
-
+        <!-- for testing -->
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test-junit5</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/examples/main-joor/src/main/java/org/apache/camel/example/MyRouteBuilder.java b/examples/main-joor/src/main/java/org/apache/camel/example/MyRouteBuilder.java
index da4f671..941f88c 100644
--- a/examples/main-joor/src/main/java/org/apache/camel/example/MyRouteBuilder.java
+++ b/examples/main-joor/src/main/java/org/apache/camel/example/MyRouteBuilder.java
@@ -22,7 +22,7 @@ public class MyRouteBuilder extends RouteBuilder {
 
     @Override
     public void configure() throws Exception {
-        from("timer:foo?period=2s")
+        from("timer:foo?period={{myPeriod}}")
             .bean(UserFactoryBean.class, "createUser")
             .choice()
                 .when(joor("var user = bodyAs(MyUser); return user.getName() != null && user.getAge() > 21"))
diff --git a/examples/main-joor/src/main/resources/application.properties b/examples/main-joor/src/main/resources/application.properties
index 93324db..1915ce7 100644
--- a/examples/main-joor/src/main/resources/application.properties
+++ b/examples/main-joor/src/main/resources/application.properties
@@ -19,5 +19,6 @@
 # here you can configure options on camel main (see MainConfigurationProperties class)
 camel.main.name = MyCamel
 
-
+# properties used in the route
+myPeriod = 2s
 
diff --git a/examples/any23/src/test/java/org/apache/camel/example/any23/Any23Test.java b/examples/main-joor/src/test/java/org/apache/camel/example/MainJOORTest.java
similarity index 55%
copy from examples/any23/src/test/java/org/apache/camel/example/any23/Any23Test.java
copy to examples/main-joor/src/test/java/org/apache/camel/example/MainJOORTest.java
index 7d1c724..83dbff4 100644
--- a/examples/any23/src/test/java/org/apache/camel/example/any23/Any23Test.java
+++ b/examples/main-joor/src/test/java/org/apache/camel/example/MainJOORTest.java
@@ -14,35 +14,39 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.example.any23;
+package org.apache.camel.example;
 
 import org.apache.camel.RoutesBuilder;
-import org.apache.camel.builder.AdviceWith;
+import org.apache.camel.builder.NotifyBuilder;
 import org.apache.camel.test.junit5.CamelTestSupport;
 import org.junit.jupiter.api.Test;
 
-/**
- * A unit test checking that we can extract data from a page with RDF content using Apache Anything To Triples.
- */
-class Any23Test extends CamelTestSupport {
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
 
-    @Test
-    void should_extract_data_from_rdf() throws Exception {
-        // Mock the endpoint log:result
-        AdviceWith.adviceWith(context, "result", ad -> ad.mockEndpoints("log:result"));
+import static org.apache.camel.util.PropertiesHelper.asProperties;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
-        // must start Camel after we are done using advice-with
-        context.start();
-
-        getMockEndpoint("mock:log:result").expectedMinimumMessageCount(1);
+/**
+ * A unit test checking that Camel supports jOOR language in the Camel DSL.
+ */
+class MainJOORTest extends CamelTestSupport {
 
-        template.sendBody("direct:start", "This is a test message to run the example");
+    @Override
+    protected Properties useOverridePropertiesWithPropertiesComponent() {
+        return asProperties("myPeriod", Integer.toString(500));
+    }
 
-        assertMockEndpointsSatisfied();
+    @Test
+    void should_support_joor_in_dsl() {
+        NotifyBuilder notify = new NotifyBuilder(context).whenCompleted(10).create();
+        assertTrue(
+            notify.matches(20, TimeUnit.SECONDS), "10 messages should be completed"
+        );
     }
 
     @Override
     protected RoutesBuilder createRouteBuilder() {
-        return new Any23RouteBuilder();
+        return new MyRouteBuilder();
     }
 }
diff --git a/examples/main-lambda/README.adoc b/examples/main-lambda/README.adoc
index 9dd6be8..c2ce843 100644
--- a/examples/main-lambda/README.adoc
+++ b/examples/main-lambda/README.adoc
@@ -12,10 +12,19 @@ The `LambdaRouteBuilder` is a functional interface that makes defining routes wi
 easy. All you need to do is to create a method that returns `LambdaRouteBuilder` and mark
 the method with `@BindToRegistry` or if using Spring Boot `@Bean` or `@Produce` for CDI/Quarkus.
 
-See the `MyConfiguration.java` for the configuration and Camel routes are setup.
+See the `MyConfiguration.java` for the configuration and Camel routes are set up.
 
 Multiple routes can be defined by having multiple methods.
 
+=== Build
+
+First compile the example by executing:
+
+[source,sh]
+----
+$ mvn compile
+----
+
 === How to run
 
 You can run this example using
diff --git a/examples/main-lambda/pom.xml b/examples/main-lambda/pom.xml
index aebe3f5..a0b91ed 100644
--- a/examples/main-lambda/pom.xml
+++ b/examples/main-lambda/pom.xml
@@ -81,7 +81,12 @@
             <artifactId>logback-classic</artifactId>
             <version>${logback-version}</version>
         </dependency>
-
+        <!-- for testing -->
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test-junit5</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/examples/main-lambda/src/test/java/org/apache/camel/example/MainLambdaTest.java b/examples/main-lambda/src/test/java/org/apache/camel/example/MainLambdaTest.java
new file mode 100644
index 0000000..db6fb8b
--- /dev/null
+++ b/examples/main-lambda/src/test/java/org/apache/camel/example/MainLambdaTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.example;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.LambdaRouteBuilder;
+import org.apache.camel.builder.NotifyBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * A unit test checking that {@code LambdaRouteBuilder} can be used to define routes
+ * using lambda style.
+ */
+class MainLambdaTest extends CamelTestSupport {
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext camelContext = super.createCamelContext();
+        camelContext.getPropertiesComponent().setLocation("classpath:application.properties");
+        return camelContext;
+    }
+
+    @Override
+    protected void postProcessTest() throws Exception {
+        super.postProcessTest();
+        context.getInjector().newInstance(MyConfiguration.class);
+    }
+
+    @Test
+    void should_support_routes_defined_using_a_lambda() throws Exception {
+        // We need to add the route manually for the test
+        LambdaRouteBuilder builder = context.getRegistry().findByType(LambdaRouteBuilder.class).iterator().next();
+        context.addRoutes(new RouteBuilder(context) {
+            @Override
+            public void configure() throws Exception {
+                builder.accept(this);
+            }
+        });
+        context.start();
+        NotifyBuilder notify = new NotifyBuilder(context)
+            .whenCompleted(1).whenBodiesDone("Bye World").create();
+        assertTrue(
+            notify.matches(20, TimeUnit.SECONDS), "1 message should be completed"
+        );
+    }
+}
diff --git a/examples/main-tiny/README.adoc b/examples/main-tiny/README.adoc
index 1558239..292aa3f 100644
--- a/examples/main-tiny/README.adoc
+++ b/examples/main-tiny/README.adoc
@@ -7,6 +7,15 @@ This example shows how to run Camel standalone via the built-in Main class.
 
 Notice how you can configure Camel in the `application.properties` file.
 
+=== Build
+
+First compile the example by executing:
+
+[source,sh]
+----
+$ mvn compile
+----
+
 === How to run
 
 You can run this example using
diff --git a/examples/main-tiny/pom.xml b/examples/main-tiny/pom.xml
index e33c0ca..3fe4052 100644
--- a/examples/main-tiny/pom.xml
+++ b/examples/main-tiny/pom.xml
@@ -77,7 +77,12 @@
             <artifactId>logback-classic</artifactId>
             <version>${logback-version}</version>
         </dependency>
-
+        <!-- for testing -->
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test-junit5</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/examples/main-tiny/src/main/data/foo.properties b/examples/main-tiny/src/main/data/foo.properties
deleted file mode 100644
index b43e6bc..0000000
--- a/examples/main-tiny/src/main/data/foo.properties
+++ /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.
-## ---------------------------------------------------------------------------
-
-bye = Bye
\ No newline at end of file
diff --git a/examples/main-tiny/src/test/java/org/apache/camel/example/MainTinyTest.java b/examples/main-tiny/src/test/java/org/apache/camel/example/MainTinyTest.java
new file mode 100644
index 0000000..3b211cf
--- /dev/null
+++ b/examples/main-tiny/src/test/java/org/apache/camel/example/MainTinyTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.example;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.NotifyBuilder;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.camel.util.PropertiesHelper.asProperties;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * A unit test checking that Camel can work in tiny mode.
+ */
+class MainTinyTest extends CamelTestSupport {
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext camelContext = super.createCamelContext();
+        MyBean myBean = new MyBean();
+        myBean.setHi("Hello");
+        camelContext.getRegistry().bind("myBean", myBean);
+        return camelContext;
+    }
+
+    @Override
+    protected Properties useOverridePropertiesWithPropertiesComponent() {
+        return asProperties("myPeriod", Integer.toString(500));
+    }
+
+    @Test
+    void should_support_tiny_mode() {
+        NotifyBuilder notify = new NotifyBuilder(context).whenCompleted(1).whenBodiesDone("Hello how are you?").create();
+        assertTrue(
+            notify.matches(20, TimeUnit.SECONDS), "1 message should be completed"
+        );
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() {
+        return new MyRouteBuilder();
+    }
+}
diff --git a/examples/main-xml/README.adoc b/examples/main-xml/README.adoc
index b7ca179..dd99b5b 100644
--- a/examples/main-xml/README.adoc
+++ b/examples/main-xml/README.adoc
@@ -10,11 +10,23 @@ and when saved Camel will auto update the route(s).
 
 The application is configured in the `application.properties` file.
 
+=== Build
+
+First compile the example by executing:
+
+[source,sh]
+----
+$ mvn compile
+----
+
 === How to run
 
 You can run this example using
 
-    mvn camel:run
+[source,sh]
+----
+$ mvn camel:run
+----
 
 === Help and contributions
 
diff --git a/examples/main-xml/pom.xml b/examples/main-xml/pom.xml
index cf2b8b8..6254b0f 100644
--- a/examples/main-xml/pom.xml
+++ b/examples/main-xml/pom.xml
@@ -92,7 +92,12 @@
             <artifactId>logback-classic</artifactId>
             <version>${logback-version}</version>
         </dependency>
-
+        <!-- for testing -->
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test-junit5</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/examples/main-xml/src/test/java/org/apache/camel/example/MainXMLTest.java b/examples/main-xml/src/test/java/org/apache/camel/example/MainXMLTest.java
new file mode 100644
index 0000000..f565b89
--- /dev/null
+++ b/examples/main-xml/src/test/java/org/apache/camel/example/MainXMLTest.java
@@ -0,0 +1,70 @@
+/*
+ * 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.example;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ExtendedCamelContext;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.NotifyBuilder;
+import org.apache.camel.spi.PackageScanResourceResolver;
+import org.apache.camel.spi.Resource;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
+/**
+ * A unit test checking that Camel supports XML routes.
+ */
+class MainXMLTest extends CamelTestSupport {
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext camelContext = super.createCamelContext();
+        camelContext.getPropertiesComponent().setLocation("classpath:application.properties");
+        return camelContext;
+    }
+
+    @Override
+    protected void postProcessTest() throws Exception {
+        super.postProcessTest();
+        context.getInjector().newInstance(MyConfiguration.class);
+    }
+
+    @Test
+    void should_support_xml_routes() {
+        NotifyBuilder notify = new NotifyBuilder(context).whenCompleted(1).whenBodiesDone("Bye World").create();
+        assertTrue(
+            notify.matches(20, TimeUnit.SECONDS), "1 message should be completed"
+        );
+    }
+
+    @Override
+    protected RoutesBuilder[] createRouteBuilders() throws Exception {
+        final ExtendedCamelContext ecc = context.adapt(ExtendedCamelContext.class);
+        final PackageScanResourceResolver resolver = ecc.getPackageScanResourceResolver();
+        for (Resource resource : resolver.findResources("/routes/my-route.xml")) {
+            // Only one file is expected
+            return ecc.getRoutesLoader().findRoutesBuilders(resource).toArray(RoutesBuilder[]::new);
+        }
+        fail("Should find the routes");
+        return null;
+    }
+}
diff --git a/examples/main-yaml/README.adoc b/examples/main-yaml/README.adoc
index f8432bf..b968800 100644
--- a/examples/main-yaml/README.adoc
+++ b/examples/main-yaml/README.adoc
@@ -10,11 +10,23 @@ and when saved Camel will auto update the route(s).
 
 The application is configured in the `application.properties` file.
 
+=== Build
+
+First compile the example by executing:
+
+[source,sh]
+----
+$ mvn compile
+----
+
 === How to run
 
 You can run this example using
 
-    mvn camel:run
+[source,sh]
+----
+$ mvn camel:run
+----
 
 === Help and contributions
 
diff --git a/examples/main-yaml/pom.xml b/examples/main-yaml/pom.xml
index e019f2e..5f8d9d1 100644
--- a/examples/main-yaml/pom.xml
+++ b/examples/main-yaml/pom.xml
@@ -91,7 +91,12 @@
             <artifactId>logback-classic</artifactId>
             <version>${logback-version}</version>
         </dependency>
-
+        <!-- for testing -->
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test-junit5</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/examples/main-yaml/src/test/java/org/apache/camel/example/MainYAMLTest.java b/examples/main-yaml/src/test/java/org/apache/camel/example/MainYAMLTest.java
new file mode 100644
index 0000000..d9d2d1c
--- /dev/null
+++ b/examples/main-yaml/src/test/java/org/apache/camel/example/MainYAMLTest.java
@@ -0,0 +1,69 @@
+/*
+ * 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.example;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ExtendedCamelContext;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.NotifyBuilder;
+import org.apache.camel.spi.PackageScanResourceResolver;
+import org.apache.camel.spi.Resource;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
+/**
+ * A unit test checking that Camel supports YAML routes.
+ */
+class MainYAMLTest extends CamelTestSupport {
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext camelContext = super.createCamelContext();
+        camelContext.getPropertiesComponent().setLocation("classpath:application.properties");
+        return camelContext;
+    }
+
+    @Override
+    protected void postProcessTest() throws Exception {
+        super.postProcessTest();
+        context.getInjector().newInstance(MyConfiguration.class);
+    }
+
+    @Test
+    void should_support_yaml_routes() {
+        NotifyBuilder notify = new NotifyBuilder(context).whenCompleted(1).whenBodiesDone("Bye World").create();
+        assertTrue(
+            notify.matches(20, TimeUnit.SECONDS), "1 message should be completed"
+        );
+    }
+
+    @Override
+    protected RoutesBuilder[] createRouteBuilders() throws Exception {
+        final ExtendedCamelContext ecc = context.adapt(ExtendedCamelContext.class);
+        final PackageScanResourceResolver resolver = ecc.getPackageScanResourceResolver();
+        for (Resource resource : resolver.findResources("/routes/my-route.yaml")) {
+            return ecc.getRoutesLoader().findRoutesBuilders(resource).toArray(RoutesBuilder[]::new);
+        }
+        fail("Should find the routes");
+        return null;
+    }
+}
diff --git a/examples/main/README.adoc b/examples/main/README.adoc
index e3404d5..85c9aa5 100644
--- a/examples/main/README.adoc
+++ b/examples/main/README.adoc
@@ -9,9 +9,9 @@ Also notice how you can configure Camel in the `application.properties` file.
 
 === Alternative example
 
-The class `StandaloneCamel` is an alternative example that uses a
-_public static void main_ class and where you manually setup Camel without
-any help from Camel's built-in Main class. However it shows how to do this
+The class `StandaloneCamel` is an alternative example that provides a
+_public static void main_ method and where you manually set up Camel without
+any help from Camel's built-in Main class. However, it shows how to do this
 in a _raw style_ without using any _magic_.
 
 === Build
diff --git a/examples/main/pom.xml b/examples/main/pom.xml
index 2a5954a..6757d2a 100644
--- a/examples/main/pom.xml
+++ b/examples/main/pom.xml
@@ -85,7 +85,12 @@
             <artifactId>logback-classic</artifactId>
             <version>${logback-version}</version>
         </dependency>
-
+        <!-- for testing -->
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test-junit5</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/examples/main/src/main/java/org/apache/camel/example/StandaloneCamel.java b/examples/main/src/main/java/org/apache/camel/example/StandaloneCamel.java
index f01c5b6..5ecbf12 100644
--- a/examples/main/src/main/java/org/apache/camel/example/StandaloneCamel.java
+++ b/examples/main/src/main/java/org/apache/camel/example/StandaloneCamel.java
@@ -20,12 +20,12 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.impl.DefaultCamelContext;
 
 /**
- * This is an alternative example to show how you can use a public static void main class
+ * This is an alternative example to show how you can use a public static void main method
  * to run Camel standalone (without help from its Main class). This is to demonstrate
- * what code you need to write to startup Camel without any help (or magic).
+ * what code you need to write to start up Camel without any help (or magic).
  * <p/>
  * Compare this example with {@link MyApplication} which uses Camel's main class to
- * run Camel standalone in a easier way.
+ * run Camel standalone in an easier way.
  */
 public final class StandaloneCamel {
 
@@ -34,29 +34,27 @@ public final class StandaloneCamel {
 
     public static void main(String[] args) throws Exception {
         // create a new CamelContext
-        CamelContext camelContext = new DefaultCamelContext();
+        try (CamelContext camelContext = new DefaultCamelContext()) {
 
-        // configure where to load properties file in the properties component
-        camelContext.getPropertiesComponent().setLocation("classpath:application.properties");
-        // resolve property placeholder
-        String hello = camelContext.resolvePropertyPlaceholders("{{hi}}");
+            // configure where to load properties file in the properties component
+            camelContext.getPropertiesComponent().setLocation("classpath:application.properties");
+            // resolve property placeholder
+            String hello = camelContext.resolvePropertyPlaceholders("{{hi}}");
 
-        // and create bean with the placeholder
-        MyBean myBean = new MyBean(hello, "Bye");
-        // register bean to Camel
-        camelContext.getRegistry().bind("myBean", myBean);
+            // and create bean with the placeholder
+            MyBean myBean = new MyBean(hello, "Bye");
+            // register bean to Camel
+            camelContext.getRegistry().bind("myBean", myBean);
 
-        // add routes to Camel
-        camelContext.addRoutes(new MyRouteBuilder());
+            // add routes to Camel
+            camelContext.addRoutes(new MyRouteBuilder());
 
-        // start Camel
-        camelContext.start();
+            // start Camel
+            camelContext.start();
 
-        // just run for 10 seconds and stop
-        System.out.println("Running for 10 seconds and then stopping");
-        Thread.sleep(10000);
-
-        // stop and shutdown Camel
-        camelContext.stop();
+            // just run for 10 seconds and stop
+            System.out.println("Running for 10 seconds and then stopping");
+            Thread.sleep(10000);
+        }
     }
 }
diff --git a/examples/main/src/test/java/org/apache/camel/example/MainTest.java b/examples/main/src/test/java/org/apache/camel/example/MainTest.java
new file mode 100644
index 0000000..7316f1f
--- /dev/null
+++ b/examples/main/src/test/java/org/apache/camel/example/MainTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.example;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.NotifyBuilder;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * A unit test checking that Camel supports binding via annotations.
+ */
+class MainTest extends CamelTestSupport {
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext camelContext = super.createCamelContext();
+        camelContext.getPropertiesComponent().setLocation("classpath:application.properties");
+        camelContext.getPropertiesComponent().addLocation("file:src/main/data/foo.properties");
+        return camelContext;
+    }
+
+    @Override
+    protected void postProcessTest() throws Exception {
+        super.postProcessTest();
+        context.getInjector().newInstance(MyConfiguration.class);
+    }
+
+    @Test
+    void should_support_binding_via_annotations() {
+        NotifyBuilder notify = new NotifyBuilder(context)
+            .whenCompleted(1).whenBodiesDone("Bye World").create();
+        assertTrue(
+            notify.matches(20, TimeUnit.SECONDS), "1 message should be completed"
+        );
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() {
+        return new MyRouteBuilder();
+    }
+}
diff --git a/examples/mongodb/src/test/java/org/apache/camel/example/mongodb/MongoDBTest.java b/examples/mongodb/src/test/java/org/apache/camel/example/mongodb/MongoDBTest.java
index c3562a7..a071dae 100644
--- a/examples/mongodb/src/test/java/org/apache/camel/example/mongodb/MongoDBTest.java
+++ b/examples/mongodb/src/test/java/org/apache/camel/example/mongodb/MongoDBTest.java
@@ -32,7 +32,6 @@ import java.util.regex.Pattern;
 
 import static io.restassured.RestAssured.given;
 import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.is;
 import static org.hamcrest.Matchers.matchesPattern;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
diff --git a/examples/reactive-executor-vertx/README.adoc b/examples/reactive-executor-vertx/README.adoc
index d9cfaeb..0a2f06d 100644
--- a/examples/reactive-executor-vertx/README.adoc
+++ b/examples/reactive-executor-vertx/README.adoc
@@ -1,9 +1,17 @@
 == Camel Example Reactive Executor VertX
 
 This example uses VertX as the reactive executor for routing messages with Camel.
-By default Camel uses its own reactive engine for routing messages, but you can plugin
+By default, Camel uses its own reactive engine for routing messages, but you can plug in
 different engines via a SPI interface. This example uses VertX as the engine.
 
+=== Build
+
+You will need to compile this example first:
+
+----
+$ mvn compile
+----
+
 === How to run
 
 You can run this example using
diff --git a/examples/reactive-executor-vertx/pom.xml b/examples/reactive-executor-vertx/pom.xml
index 0bd8030..2b36706 100644
--- a/examples/reactive-executor-vertx/pom.xml
+++ b/examples/reactive-executor-vertx/pom.xml
@@ -93,7 +93,12 @@
             <version>${log4j2-version}</version>
             <scope>runtime</scope>
         </dependency>
-
+        <!-- for testing -->
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test-junit5</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/examples/reactive-executor-vertx/src/test/java/org/apache/camel/example/VertxTest.java b/examples/reactive-executor-vertx/src/test/java/org/apache/camel/example/VertxTest.java
new file mode 100644
index 0000000..830e0be
--- /dev/null
+++ b/examples/reactive-executor-vertx/src/test/java/org/apache/camel/example/VertxTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.example;
+
+import io.vertx.core.Vertx;
+import org.apache.camel.CamelContext;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.NotifyBuilder;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * A unit test checking that Camel can use VertX as reactive executor.
+ */
+class VertxTest extends CamelTestSupport {
+
+    @AfterEach
+    void destroy() {
+        Vertx vertx = context.getRegistry().lookupByNameAndType("vertx", Vertx.class);
+        if (vertx != null) {
+            vertx.close();
+        }
+    }
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext camelContext = super.createCamelContext();
+        camelContext.getRegistry().bind("vertx", Vertx.vertx());
+        return camelContext;
+    }
+
+    @Test
+    void should_use_vertx_as_reactive_executor() {
+        NotifyBuilder notify = new NotifyBuilder(context).from("timer:*").whenCompleted(15).create();
+        assertTrue(
+            notify.matches(30, TimeUnit.SECONDS), "15 messages should be completed"
+        );
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() {
+        return new MyRouteBuilder();
+    }
+}
diff --git a/examples/route-throttling/README.adoc b/examples/route-throttling/README.adoc
index 89de065..dd89ecc 100644
--- a/examples/route-throttling/README.adoc
+++ b/examples/route-throttling/README.adoc
@@ -3,19 +3,19 @@
 === Introduction
 
 This example shows how to use the new feature in Camel 2.1 which is
-RoutePolicy. A route policy allows you to associate a route with a
+`RoutePolicy`. A route policy allows you to associate a route with a
 policy. Camel provides a throttling policy which allows Camel to dynamic
 throttle the route consumer depending on the number of concurrent
 messages current in flight.
 
 The Server is required to be running when you start the client. You can
-see on the server it should log in the console how it adjust the
+see on the server it should log in the console how it adjusts the
 throttling dynamically.
 
 The goal of this example is to illustrate that Camel throttles the JMS
 queue to be on same pace with the rest of the Camel routing. When
 running the example you should observe that the JMS route and the SEDA
-route completes nearly in sync.
+route complete nearly in sync.
 
 === Build
 
@@ -30,35 +30,35 @@ $ mvn compile
 The example has 3 maven goals to run the example
 
 ----
-$ mvn compile exec:java -PCamelServer
+$ mvn exec:java -PCamelServer
 ----
 
 Starts the Camel Server which contains the 3 routes and where you should
 check its log output for how it goes.
 
 ----
-$ mvn compile exec:java -PCamelClient
+$ mvn exec:java -PCamelClient
 ----
 
 Is a client that sends 10000 JMS messages to the JMS broker which is
 consumed by route1. The Server must be started beforehand.
 
 ----
-$ mvn compile exec:java -PCamelFileClient
+$ mvn exec:java -PCamelFileClient
 ----
 
 Is a client that creates 5000 files that are consumed by route2. The
-server may be started beforehand, but its not required.
+server may be started beforehand, but it's not required.
 
 So at first you start the server. Then at any time you can run a client
-at will. For example you can run the JMS client and let it run to
+at will. For example, you can run the JMS client and let it run to
 completion at the server. You can see at the server console logging that
-it reports the progress. And at sometime it will reach 10000 messages
+it reports the progress. And at some time it will reach 10000 messages
 processed. You can then start the client again if you like. You can also
 start the other client to create the files which then let the example be
 a bit more complicated as we have concurrent processing of JMS messages
-and files at the same time. And where as both of these should be dynamic
-throttled so we wont go too fast.
+and files at the same time. And as both of these should be dynamic
+throttled, so we won't go too fast.
 
 To stop the example hit ctrl+c
 
diff --git a/examples/route-throttling/pom.xml b/examples/route-throttling/pom.xml
index 3ee49ae..89e054b 100644
--- a/examples/route-throttling/pom.xml
+++ b/examples/route-throttling/pom.xml
@@ -112,13 +112,7 @@
         <!-- for testing -->
         <dependency>
             <groupId>org.apache.camel</groupId>
-            <artifactId>camel-test</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <version>${junit-version}</version>
+            <artifactId>camel-test-spring-junit5</artifactId>
             <scope>test</scope>
         </dependency>
 
diff --git a/examples/route-throttling/src/main/java/org/apache/camel/example/client/CamelClient.java b/examples/route-throttling/src/main/java/org/apache/camel/example/client/CamelClient.java
index 86139b3..0e316e2 100644
--- a/examples/route-throttling/src/main/java/org/apache/camel/example/client/CamelClient.java
+++ b/examples/route-throttling/src/main/java/org/apache/camel/example/client/CamelClient.java
@@ -22,8 +22,7 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.ProducerTemplate;
-import org.apache.camel.util.IOHelper;
-import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 /**
@@ -43,38 +42,37 @@ public final class CamelClient {
     public static void main(final String[] args) throws Exception {
         System.out.println("Notice this client requires that the CamelServer is already running!");
 
-        AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-client.xml");
+        try (ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("camel-client.xml")) {
 
-        // get the camel template for Spring template style sending of messages (= producer)
-        final ProducerTemplate producer = context.getBean("camelTemplate", ProducerTemplate.class);
+            // get the camel template for Spring template style sending of messages (= producer)
+            try (final ProducerTemplate producer = context.getBean("camelTemplate", ProducerTemplate.class)) {
 
-        // now send a lot of messages
-        System.out.println("Sending ...");
+                // now send a lot of messages
+                System.out.println("Sending ...");
 
-        final CountDownLatch latch = new CountDownLatch(POOL);
+                final CountDownLatch latch = new CountDownLatch(POOL);
 
-        ExecutorService executors = Executors.newFixedThreadPool(POOL);
-        for (int i = 0; i < POOL; i++) {
-            final int idx = i;
-            executors.execute(new Runnable() {
-                public void run() {
-                    try {
-                        for (int j = 0; j < SIZE / POOL; j++) {
-                            producer.sendBody("jms:queue:inbox", "Message " + idx * j + j);
+                ExecutorService executors = Executors.newFixedThreadPool(POOL);
+                for (int i = 0; i < POOL; i++) {
+                    final int idx = i;
+                    executors.execute(new Runnable() {
+                        public void run() {
+                            try {
+                                for (int j = 0; j < SIZE / POOL; j++) {
+                                    producer.sendBody("jms:queue:inbox", "Message " + idx * j + j);
+                                }
+                            } finally {
+                                latch.countDown();
+                            }
                         }
-                    } finally {
-                        latch.countDown();
-                    }
+                    });
                 }
-            });
-        }
-
-        latch.await(300, TimeUnit.SECONDS);
-        System.out.println("... Send " + SIZE + " message to JMS broker");
-        executors.shutdownNow();
 
-        // we're done so let's properly close the application context
-        IOHelper.close(context);
+                latch.await(300, TimeUnit.SECONDS);
+                System.out.println("... Send " + SIZE + " message to JMS broker");
+                executors.shutdownNow();
+            }
+        }
     }
 
 }
diff --git a/examples/route-throttling/src/main/java/org/apache/camel/example/client/CamelFileClient.java b/examples/route-throttling/src/main/java/org/apache/camel/example/client/CamelFileClient.java
index 26c1169..202c5a1 100644
--- a/examples/route-throttling/src/main/java/org/apache/camel/example/client/CamelFileClient.java
+++ b/examples/route-throttling/src/main/java/org/apache/camel/example/client/CamelFileClient.java
@@ -18,8 +18,7 @@ package org.apache.camel.example.client;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.ProducerTemplate;
-import org.apache.camel.util.IOHelper;
-import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 /**
@@ -34,22 +33,20 @@ public final class CamelFileClient {
     }
 
     public static void main(final String[] args) throws Exception {
-        AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-file-client.xml");
+        try (ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("camel-file-client.xml")) {
+            // get the camel template for Spring template style sending of messages (= producer)
+            try (final ProducerTemplate producer = context.getBean("camelTemplate", ProducerTemplate.class)) {
 
-        // get the camel template for Spring template style sending of messages (= producer)
-        final ProducerTemplate producer = context.getBean("camelTemplate", ProducerTemplate.class);
+                // now send a lot of messages
+                System.out.println("Writing files ...");
 
-        // now send a lot of messages
-        System.out.println("Writing files ...");
+                for (int i = 0; i < SIZE; i++) {
+                    producer.sendBodyAndHeader("file:target//inbox", "File " + i, Exchange.FILE_NAME, i + ".txt");
+                }
 
-        for (int i = 0; i < SIZE; i++) {
-            producer.sendBodyAndHeader("file:target//inbox", "File " + i, Exchange.FILE_NAME, i + ".txt");
+                System.out.println("... Wrote " + SIZE + " files");
+            }
         }
-
-        System.out.println("... Wrote " + SIZE + " files");
-
-        // we're done so let's properly close the application context
-        IOHelper.close(context);
     }
 
 }
\ No newline at end of file
diff --git a/examples/route-throttling/src/main/resources/META-INF/spring/camel-server.xml b/examples/route-throttling/src/main/resources/META-INF/spring/camel-server.xml
index a7f45ac..42c2895 100644
--- a/examples/route-throttling/src/main/resources/META-INF/spring/camel-server.xml
+++ b/examples/route-throttling/src/main/resources/META-INF/spring/camel-server.xml
@@ -19,7 +19,6 @@
 -->
 <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xmlns:camel="http://camel.apache.org/schema/spring"
        xmlns:broker="http://activemq.apache.org/schema/core"
        xsi:schemaLocation="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
diff --git a/examples/route-throttling/src/test/java/org/apache/camel/example/client/RouteThrottlingTest.java b/examples/route-throttling/src/test/java/org/apache/camel/example/client/RouteThrottlingTest.java
new file mode 100644
index 0000000..d653e38
--- /dev/null
+++ b/examples/route-throttling/src/test/java/org/apache/camel/example/client/RouteThrottlingTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.example.client;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.NotifyBuilder;
+import org.apache.camel.model.ModelCamelContext;
+import org.apache.camel.test.spring.junit5.CamelSpringTest;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * A unit test allowing to check that the route throttling works as expected.
+ */
+@CamelSpringTest
+@ContextConfiguration("/META-INF/spring/camel-server.xml")
+class RouteThrottlingTest {
+
+    @Autowired
+    ProducerTemplate template;
+    @Autowired
+    ModelCamelContext context;
+
+    @Test
+    void should_support_route_throttling() {
+        int totalMessages = 1_000;
+        NotifyBuilder notify = new NotifyBuilder(context).wereSentTo("log:+++SEDA+++*")
+                .whenCompleted(totalMessages).create();
+        List<CompletableFuture<Void>> futures = IntStream.range(0, totalMessages)
+                .mapToObj(i -> CompletableFuture.runAsync(() -> sendMessage(i)))
+                .collect(Collectors.toUnmodifiableList());
+
+        CompletableFuture.allOf(futures.toArray(CompletableFuture[]::new)).join();
+        assertTrue(notify.matches(20, TimeUnit.SECONDS), "100 messages should be completed");
+    }
+
+    private void sendMessage(int i) {
+        if (i % 2 == 0) {
+            template.sendBodyAndHeader("file:target//inbox", "File " + i, Exchange.FILE_NAME, i + ".txt");
+        } else {
+            template.sendBody("jms:queue:inbox", "Message " + i);
+        }
+    }
+}