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 2021/03/03 07:15:54 UTC

[camel] branch master updated: core: move route builder loader tests from core to dsl (#5159)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 885f8d5  core: move route builder loader tests from core to dsl (#5159)
885f8d5 is described below

commit 885f8d57826f12a52cca4f6823a9d60ec01ab824
Author: Luca Burgazzoli <lb...@users.noreply.github.com>
AuthorDate: Wed Mar 3 08:15:36 2021 +0100

    core: move route builder loader tests from core to dsl (#5159)
---
 .../DefaultPackageScanResourceResolverTest.java    | 61 ++++++------------
 .../apache/camel/model/LoadRestFromXmlTest.java    | 29 ---------
 .../apache/camel/model/LoadRouteFromXmlTest.java   | 31 ----------
 .../apache/camel/dsl/xml/io/XmlLoadRestTest.java   | 72 ++++++++++++++++++++++
 .../org/apache/camel/dsl/xml/io/XmlLoadTest.java   | 72 ++++++++++++++++++++++
 .../org/apache/camel/dsl/xml/io/XmlMainTest.java   | 10 +--
 .../org/apache/camel/dsl/xml/io/barRest.xml        | 26 ++++++++
 .../org/apache/camel/dsl/xml/io/barRoute.xml       | 31 ++++++++++
 .../camel/dsl/xml/jaxb/JaxbXmlLoadRestTest.java    | 72 ++++++++++++++++++++++
 .../apache/camel/dsl/xml/jaxb/JaxbXmlLoadTest.java | 72 ++++++++++++++++++++++
 .../apache/camel/dsl/xml/jaxb/JaxbXmlMainTest.java | 10 +--
 .../org/apache/camel/dsl/xml/jaxb/barRest.xml      | 26 ++++++++
 .../org/apache/camel/dsl/xml/jaxb/barRoute.xml     | 31 ++++++++++
 13 files changed, 431 insertions(+), 112 deletions(-)

diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/engine/DefaultPackageScanResourceResolverTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/engine/DefaultPackageScanResourceResolverTest.java
index a69224a..5c8efcb 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/engine/DefaultPackageScanResourceResolverTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/engine/DefaultPackageScanResourceResolverTest.java
@@ -16,56 +16,33 @@
  */
 package org.apache.camel.impl.engine;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.ExtendedCamelContext;
-import org.apache.camel.RoutesBuilder;
 import org.apache.camel.impl.DefaultCamelContext;
-import org.apache.camel.model.RouteDefinition;
-import org.apache.camel.spi.Resource;
+import org.apache.camel.spi.PackageScanResourceResolver;
 import org.junit.jupiter.api.Test;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
 public class DefaultPackageScanResourceResolverTest {
-    private static Set<String> loadRouteIDs(String path) throws Exception {
-        DefaultCamelContext ctx = new DefaultCamelContext(false);
-        for (RoutesBuilder builder : loadRouteDefinitions(ctx, path)) {
-            ctx.addRoutes(builder);
-        }
-        return ctx.getRouteDefinitions().stream().map(RouteDefinition::getId).collect(Collectors.toSet());
-    }
-
-    private static List<RoutesBuilder> loadRouteDefinitions(CamelContext context, String path) {
-        List<RoutesBuilder> answer = new ArrayList<>();
-
-        ExtendedCamelContext ecc = context.adapt(ExtendedCamelContext.class);
-        try {
-            for (Resource resource : ecc.getPackageScanResourceResolver().findResources(path)) {
-                answer.addAll(
-                        ecc.getRoutesLoader().findRoutesBuilders(resource));
-            }
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
-
-        return answer;
-    }
-
     @Test
     public void testFileResourcesScan() throws Exception {
-
-        assertThat(loadRouteIDs("file:src/test/resources/org/apache/camel/impl/engine/**/*.xml"))
-                .containsOnly("dummy-a", "scan-a", "dummy-b", "scan-b");
-        assertThat(loadRouteIDs("file:src/test/resources/org/apache/camel/impl/engine/a?/*.xml"))
-                .containsOnly("dummy-a", "scan-a");
-        assertThat(loadRouteIDs("file:src/test/resources/org/apache/camel/impl/engine/b?/*.xml"))
-                .containsOnly("dummy-b", "scan-b");
-        assertThat(loadRouteIDs("file:src/test/resources/org/apache/camel/impl/engine/c?/*.xml"))
+        final DefaultCamelContext ctx = new DefaultCamelContext();
+        final PackageScanResourceResolver resolver = ctx.getPackageScanResourceResolver();
+
+        assertThat(resolver.findResources("file:src/test/resources/org/apache/camel/impl/engine/**/*.xml"))
+                .hasSize(4)
+                .anyMatch(r -> r.getLocation().contains("ar/camel-scan.xml"))
+                .anyMatch(r -> r.getLocation().contains("ar/camel-dummy.xml"))
+                .anyMatch(r -> r.getLocation().contains("br/camel-scan.xml"))
+                .anyMatch(r -> r.getLocation().contains("br/camel-dummy.xml"));
+        assertThat(resolver.findResources("file:src/test/resources/org/apache/camel/impl/engine/a?/*.xml"))
+                .hasSize(2)
+                .anyMatch(r -> r.getLocation().contains("ar/camel-scan.xml"))
+                .anyMatch(r -> r.getLocation().contains("ar/camel-dummy.xml"));
+        assertThat(resolver.findResources("file:src/test/resources/org/apache/camel/impl/engine/b?/*.xml"))
+                .hasSize(2)
+                .anyMatch(r -> r.getLocation().contains("br/camel-scan.xml"))
+                .anyMatch(r -> r.getLocation().contains("br/camel-dummy.xml"));
+        assertThat(resolver.findResources("file:src/test/resources/org/apache/camel/impl/engine/c?/*.xml"))
                 .isEmpty();
     }
 }
diff --git a/core/camel-core/src/test/java/org/apache/camel/model/LoadRestFromXmlTest.java b/core/camel-core/src/test/java/org/apache/camel/model/LoadRestFromXmlTest.java
index cb099cf..024cbc1 100644
--- a/core/camel-core/src/test/java/org/apache/camel/model/LoadRestFromXmlTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/model/LoadRestFromXmlTest.java
@@ -26,7 +26,6 @@ import org.apache.camel.component.rest.DummyRestConsumerFactory;
 import org.apache.camel.component.rest.DummyRestProcessorFactory;
 import org.apache.camel.model.rest.RestsDefinition;
 import org.apache.camel.spi.Registry;
-import org.apache.camel.spi.Resource;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -70,34 +69,6 @@ public class LoadRestFromXmlTest extends ContextTestSupport {
         bar.assertIsSatisfied();
     }
 
-    @Test
-    public void testLoadRoutesBuilderFromXml() throws Exception {
-        assertNotNull(context.getRoute("foo"), "Existing foo route should be there");
-
-        assertEquals(2, context.getRoutes().size());
-
-        // test that existing route works
-        MockEndpoint foo = getMockEndpoint("mock:foo");
-        foo.expectedBodiesReceived("Hello World");
-        template.sendBody("direct:foo", "Hello World");
-        foo.assertIsSatisfied();
-
-        // load rest from XML and add them to the existing camel context
-        ExtendedCamelContext ecc = context.adapt(ExtendedCamelContext.class);
-        Resource resource = Resource.fromClasspath(LoadRouteFromXmlTest.class, "barRest.xml");
-
-        ecc.getRoutesLoader().loadRoutes(resource);
-
-        assertNotNull(context.getRoute("route1"), "Loaded rest route should be there");
-        assertEquals(3, context.getRoutes().size());
-
-        // test that loaded route works
-        MockEndpoint bar = getMockEndpoint("mock:bar");
-        bar.expectedBodiesReceived("Bye World");
-        template.sendBody("seda:get-say-hello-bar", "Bye World");
-        bar.assertIsSatisfied();
-    }
-
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
diff --git a/core/camel-core/src/test/java/org/apache/camel/model/LoadRouteFromXmlTest.java b/core/camel-core/src/test/java/org/apache/camel/model/LoadRouteFromXmlTest.java
index d8e47b9..f3e01ac 100644
--- a/core/camel-core/src/test/java/org/apache/camel/model/LoadRouteFromXmlTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/model/LoadRouteFromXmlTest.java
@@ -22,7 +22,6 @@ import org.apache.camel.ContextTestSupport;
 import org.apache.camel.ExtendedCamelContext;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.spi.Resource;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -59,36 +58,6 @@ public class LoadRouteFromXmlTest extends ContextTestSupport {
         bar.assertIsSatisfied();
     }
 
-    @Test
-    public void testLoadRoutesBuilderFromXml() throws Exception {
-        assertNotNull(context.getRoute("foo"), "Existing foo route should be there");
-        assertEquals(1, context.getRoutes().size());
-
-        // test that existing route works
-        MockEndpoint foo = getMockEndpoint("mock:foo");
-        foo.expectedBodiesReceived("Hello World");
-        template.sendBody("direct:foo", "Hello World");
-        foo.assertIsSatisfied();
-
-        // START SNIPPET: e1
-        // load route from XML and add them to the existing camel context
-        ExtendedCamelContext ecc = context.adapt(ExtendedCamelContext.class);
-        Resource resource = Resource.fromClasspath(LoadRouteFromXmlTest.class, "barRoute.xml");
-
-        ecc.getRoutesLoader().loadRoutes(resource);
-
-        // END SNIPPET: e1
-
-        assertNotNull(context.getRoute("bar"), "Loaded bar route should be there");
-        assertEquals(2, context.getRoutes().size());
-
-        // test that loaded route works
-        MockEndpoint bar = getMockEndpoint("mock:bar");
-        bar.expectedBodiesReceived("Bye World");
-        template.sendBody("direct:bar", "Bye World");
-        bar.assertIsSatisfied();
-    }
-
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
diff --git a/dsl/camel-xml-io-dsl/src/test/java/org/apache/camel/dsl/xml/io/XmlLoadRestTest.java b/dsl/camel-xml-io-dsl/src/test/java/org/apache/camel/dsl/xml/io/XmlLoadRestTest.java
new file mode 100644
index 0000000..3d14a68
--- /dev/null
+++ b/dsl/camel-xml-io-dsl/src/test/java/org/apache/camel/dsl/xml/io/XmlLoadRestTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.dsl.xml.io;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.rest.DummyRestConsumerFactory;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.model.LoadRouteFromXmlTest;
+import org.apache.camel.spi.Resource;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+public class XmlLoadRestTest {
+    @Test
+    public void testLoadRoutesBuilderFromXml() throws Exception {
+        try (DefaultCamelContext context = new DefaultCamelContext()) {
+            context.getRegistry().bind("dummy-rest", new DummyRestConsumerFactory());
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    restConfiguration()
+                            .host("localhost")
+                            .component("dummy-rest");
+
+                    from("direct:foo")
+                            .routeId("foo")
+                            .to("mock:foo");
+                }
+            });
+
+            context.start();
+
+            assertNotNull(context.getRoute("foo"), "Existing foo route should be there");
+            assertEquals(1, context.getRoutes().size());
+
+            // test that existing route works
+            MockEndpoint foo = context.getEndpoint("mock:foo", MockEndpoint.class);
+            foo.expectedBodiesReceived("Hello World");
+            context.createProducerTemplate().sendBody("direct:foo", "Hello World");
+            foo.assertIsSatisfied();
+
+            // load rest from XML and add them to the existing camel context
+            Resource resource = Resource.fromClasspath(LoadRouteFromXmlTest.class, "barRest.xml");
+            context.getRoutesLoader().loadRoutes(resource);
+
+            assertEquals(2, context.getRoutes().size());
+
+            // test that loaded route works
+            MockEndpoint bar = context.getEndpoint("mock:bar", MockEndpoint.class);
+            bar.expectedBodiesReceived("Bye World");
+            context.createProducerTemplate().sendBody("seda:get-say-hello-bar", "Bye World");
+            bar.assertIsSatisfied();
+        }
+    }
+}
diff --git a/dsl/camel-xml-io-dsl/src/test/java/org/apache/camel/dsl/xml/io/XmlLoadTest.java b/dsl/camel-xml-io-dsl/src/test/java/org/apache/camel/dsl/xml/io/XmlLoadTest.java
new file mode 100644
index 0000000..b11b75b
--- /dev/null
+++ b/dsl/camel-xml-io-dsl/src/test/java/org/apache/camel/dsl/xml/io/XmlLoadTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.dsl.xml.io;
+
+import org.apache.camel.ExtendedCamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.model.LoadRouteFromXmlTest;
+import org.apache.camel.spi.Resource;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+public class XmlLoadTest {
+    @Test
+    public void testLoadRoutesBuilderFromXml() throws Exception {
+        try (DefaultCamelContext context = new DefaultCamelContext()) {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    from("direct:foo")
+                        .routeId("foo")
+                        .to("mock:foo");
+                }
+            });
+
+            context.start();
+
+            assertNotNull(context.getRoute("foo"), "Existing foo route should be there");
+            assertEquals(1, context.getRoutes().size());
+
+            // test that existing route works
+            MockEndpoint foo = context.getEndpoint("mock:foo", MockEndpoint.class);
+            foo.expectedBodiesReceived("Hello World");
+            context.createProducerTemplate().sendBody("direct:foo", "Hello World");
+            foo.assertIsSatisfied();
+
+            // START SNIPPET: e1
+            // load route from XML and add them to the existing camel context
+            ExtendedCamelContext ecc = context.adapt(ExtendedCamelContext.class);
+            Resource resource = Resource.fromClasspath(LoadRouteFromXmlTest.class, "barRoute.xml");
+
+            ecc.getRoutesLoader().loadRoutes(resource);
+
+            // END SNIPPET: e1
+            assertNotNull(context.getRoute("bar"), "Loaded bar route should be there");
+            assertEquals(2, context.getRoutes().size());
+
+            // test that loaded route works
+            MockEndpoint bar =  context.getEndpoint("mock:bar", MockEndpoint.class);
+            bar.expectedBodiesReceived("Bye World");
+            context.createProducerTemplate().sendBody("direct:bar", "Bye World");
+            bar.assertIsSatisfied();
+        }
+    }
+}
diff --git a/dsl/camel-xml-io-dsl/src/test/java/org/apache/camel/dsl/xml/io/XmlMainTest.java b/dsl/camel-xml-io-dsl/src/test/java/org/apache/camel/dsl/xml/io/XmlMainTest.java
index d689c61..60ebf97 100644
--- a/dsl/camel-xml-io-dsl/src/test/java/org/apache/camel/dsl/xml/io/XmlMainTest.java
+++ b/dsl/camel-xml-io-dsl/src/test/java/org/apache/camel/dsl/xml/io/XmlMainTest.java
@@ -40,7 +40,7 @@ public class XmlMainTest {
         // will load XML from target/classes when testing
         doTestMain(
                 "org/apache/camel/main/xml/camel-*.xml",
-                "**/camel-rests.xml,**/camel-template.xml");
+                "**/org/apache/camel/dsl/**,**/camel-rests.xml,**/camel-template.xml");
     }
 
     @Test
@@ -48,7 +48,7 @@ public class XmlMainTest {
         // will load XML from target/classes when testing
         doTestMain(
                 "org/apache/camel/main/**/*.xml",
-                "**/camel-rests.xml,**/camel-template.xml");
+                "**/org/apache/camel/dsl/**,**/camel-rests.xml,**/camel-template.xml");
     }
 
     @Test
@@ -56,7 +56,7 @@ public class XmlMainTest {
         // will load XML from target/classes when testing
         doTestMain(
                 "classpath:org/apache/camel/main/xml/camel-*.xml",
-                "**/camel-rests.xml,**/camel-template.xml");
+                "**/org/apache/camel/dsl/**,**/camel-rests.xml,**/camel-template.xml");
     }
 
     @Test
@@ -71,14 +71,14 @@ public class XmlMainTest {
     public void testMainRoutesCollectorScanInDir() throws Exception {
         doTestMain(
                 "file:src/test/resources/org/apache/camel/main/xml/camel-*.xml",
-                "**/camel-rests.xml,**/camel-template.xml");
+                "**/org/apache/camel/dsl/**,**/camel-rests.xml,**/camel-template.xml");
     }
 
     @Test
     public void testMainRoutesCollectorScanWildcardDirFilePath() throws Exception {
         doTestMain(
                 "file:src/test/resources/**/*.xml",
-                "**/camel-rests.xml,**/camel-template.xml");
+                "**/org/apache/camel/dsl/**,**/camel-rests.xml,**/camel-template.xml");
     }
 
     @Test
diff --git a/dsl/camel-xml-io-dsl/src/test/resources/org/apache/camel/dsl/xml/io/barRest.xml b/dsl/camel-xml-io-dsl/src/test/resources/org/apache/camel/dsl/xml/io/barRest.xml
new file mode 100644
index 0000000..dc50305
--- /dev/null
+++ b/dsl/camel-xml-io-dsl/src/test/resources/org/apache/camel/dsl/xml/io/barRest.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<rests xmlns="http://camel.apache.org/schema/spring">
+	<rest id="bar" path="/say/hello">
+	    <get uri="/bar">
+	      <to uri="mock:bar"/>
+	    </get>
+    </rest>
+</rests>
\ No newline at end of file
diff --git a/dsl/camel-xml-io-dsl/src/test/resources/org/apache/camel/dsl/xml/io/barRoute.xml b/dsl/camel-xml-io-dsl/src/test/resources/org/apache/camel/dsl/xml/io/barRoute.xml
new file mode 100644
index 0000000..e96c1f2
--- /dev/null
+++ b/dsl/camel-xml-io-dsl/src/test/resources/org/apache/camel/dsl/xml/io/barRoute.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<!-- START SNIPPET: e1 -->
+<routes xmlns="http://camel.apache.org/schema/spring">
+    <!-- here we define the bar route -->
+    <route id="bar">
+        <from uri="direct:bar"/>
+        <to uri="mock:bar"/>
+    </route>
+
+    <!-- we could add more routes if we like,
+         but in this example we stick to one route only -->
+</routes>
+<!-- END SNIPPET: e1 -->
\ No newline at end of file
diff --git a/dsl/camel-xml-jaxb-dsl/src/test/java/org/apache/camel/dsl/xml/jaxb/JaxbXmlLoadRestTest.java b/dsl/camel-xml-jaxb-dsl/src/test/java/org/apache/camel/dsl/xml/jaxb/JaxbXmlLoadRestTest.java
new file mode 100644
index 0000000..c4476e9
--- /dev/null
+++ b/dsl/camel-xml-jaxb-dsl/src/test/java/org/apache/camel/dsl/xml/jaxb/JaxbXmlLoadRestTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.dsl.xml.jaxb;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.rest.DummyRestConsumerFactory;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.model.LoadRouteFromXmlTest;
+import org.apache.camel.spi.Resource;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+public class JaxbXmlLoadRestTest {
+    @Test
+    public void testLoadRoutesBuilderFromXml() throws Exception {
+        try (DefaultCamelContext context = new DefaultCamelContext()) {
+            context.getRegistry().bind("dummy-rest", new DummyRestConsumerFactory());
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    restConfiguration()
+                            .host("localhost")
+                            .component("dummy-rest");
+
+                    from("direct:foo")
+                            .routeId("foo")
+                            .to("mock:foo");
+                }
+            });
+
+            context.start();
+
+            assertNotNull(context.getRoute("foo"), "Existing foo route should be there");
+            assertEquals(1, context.getRoutes().size());
+
+            // test that existing route works
+            MockEndpoint foo = context.getEndpoint("mock:foo", MockEndpoint.class);
+            foo.expectedBodiesReceived("Hello World");
+            context.createProducerTemplate().sendBody("direct:foo", "Hello World");
+            foo.assertIsSatisfied();
+
+            // load rest from XML and add them to the existing camel context
+            Resource resource = Resource.fromClasspath(LoadRouteFromXmlTest.class, "barRest.xml");
+            context.getRoutesLoader().loadRoutes(resource);
+
+            assertEquals(2, context.getRoutes().size());
+
+            // test that loaded route works
+            MockEndpoint bar = context.getEndpoint("mock:bar", MockEndpoint.class);
+            bar.expectedBodiesReceived("Bye World");
+            context.createProducerTemplate().sendBody("seda:get-say-hello-bar", "Bye World");
+            bar.assertIsSatisfied();
+        }
+    }
+}
diff --git a/dsl/camel-xml-jaxb-dsl/src/test/java/org/apache/camel/dsl/xml/jaxb/JaxbXmlLoadTest.java b/dsl/camel-xml-jaxb-dsl/src/test/java/org/apache/camel/dsl/xml/jaxb/JaxbXmlLoadTest.java
new file mode 100644
index 0000000..72a73eb
--- /dev/null
+++ b/dsl/camel-xml-jaxb-dsl/src/test/java/org/apache/camel/dsl/xml/jaxb/JaxbXmlLoadTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.dsl.xml.jaxb;
+
+import org.apache.camel.ExtendedCamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.model.LoadRouteFromXmlTest;
+import org.apache.camel.spi.Resource;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+public class JaxbXmlLoadTest {
+    @Test
+    public void testLoadRoutesBuilderFromXml() throws Exception {
+        try (DefaultCamelContext context = new DefaultCamelContext()) {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    from("direct:foo")
+                        .routeId("foo")
+                        .to("mock:foo");
+                }
+            });
+
+            context.start();
+
+            assertNotNull(context.getRoute("foo"), "Existing foo route should be there");
+            assertEquals(1, context.getRoutes().size());
+
+            // test that existing route works
+            MockEndpoint foo = context.getEndpoint("mock:foo", MockEndpoint.class);
+            foo.expectedBodiesReceived("Hello World");
+            context.createProducerTemplate().sendBody("direct:foo", "Hello World");
+            foo.assertIsSatisfied();
+
+            // START SNIPPET: e1
+            // load route from XML and add them to the existing camel context
+            ExtendedCamelContext ecc = context.adapt(ExtendedCamelContext.class);
+            Resource resource = Resource.fromClasspath(LoadRouteFromXmlTest.class, "barRoute.xml");
+
+            ecc.getRoutesLoader().loadRoutes(resource);
+
+            // END SNIPPET: e1
+            assertNotNull(context.getRoute("bar"), "Loaded bar route should be there");
+            assertEquals(2, context.getRoutes().size());
+
+            // test that loaded route works
+            MockEndpoint bar =  context.getEndpoint("mock:bar", MockEndpoint.class);
+            bar.expectedBodiesReceived("Bye World");
+            context.createProducerTemplate().sendBody("direct:bar", "Bye World");
+            bar.assertIsSatisfied();
+        }
+    }
+}
diff --git a/dsl/camel-xml-jaxb-dsl/src/test/java/org/apache/camel/dsl/xml/jaxb/JaxbXmlMainTest.java b/dsl/camel-xml-jaxb-dsl/src/test/java/org/apache/camel/dsl/xml/jaxb/JaxbXmlMainTest.java
index 5d885ca..203516f 100644
--- a/dsl/camel-xml-jaxb-dsl/src/test/java/org/apache/camel/dsl/xml/jaxb/JaxbXmlMainTest.java
+++ b/dsl/camel-xml-jaxb-dsl/src/test/java/org/apache/camel/dsl/xml/jaxb/JaxbXmlMainTest.java
@@ -40,7 +40,7 @@ public class JaxbXmlMainTest {
         // will load XML from target/classes when testing
         doTestMain(
                 "org/apache/camel/main/xml/camel-*.xml",
-                "**/camel-rests.xml,**/camel-template.xml");
+                "**/org/apache/camel/dsl/**,**/camel-rests.xml,**/camel-template.xml");
     }
 
     @Test
@@ -48,7 +48,7 @@ public class JaxbXmlMainTest {
         // will load XML from target/classes when testing
         doTestMain(
                 "org/apache/camel/main/**/*.xml",
-                "**/camel-rests.xml,**/camel-template.xml");
+                "**/org/apache/camel/dsl/**,**/camel-rests.xml,**/camel-template.xml");
     }
 
     @Test
@@ -56,7 +56,7 @@ public class JaxbXmlMainTest {
         // will load XML from target/classes when testing
         doTestMain(
                 "classpath:org/apache/camel/main/xml/camel-*.xml",
-                "**/camel-rests.xml,**/camel-template.xml");
+                "**/org/apache/camel/dsl/**,**/camel-rests.xml,**/camel-template.xml");
     }
 
     @Test
@@ -71,14 +71,14 @@ public class JaxbXmlMainTest {
     public void testMainRoutesCollectorScanInDir() throws Exception {
         doTestMain(
                 "file:src/test/resources/org/apache/camel/main/xml/camel-*.xml",
-                "**/camel-rests.xml,**/camel-template.xml");
+                "**/org/apache/camel/dsl/**,**/camel-rests.xml,**/camel-template.xml");
     }
 
     @Test
     public void testMainRoutesCollectorScanWildcardDirFilePath() throws Exception {
         doTestMain(
                 "file:src/test/resources/**/*.xml",
-                "**/camel-rests.xml,**/camel-template.xml");
+                "**/org/apache/camel/dsl/**,**/camel-rests.xml,**/camel-template.xml");
     }
 
     @Test
diff --git a/dsl/camel-xml-jaxb-dsl/src/test/resources/org/apache/camel/dsl/xml/jaxb/barRest.xml b/dsl/camel-xml-jaxb-dsl/src/test/resources/org/apache/camel/dsl/xml/jaxb/barRest.xml
new file mode 100644
index 0000000..dc50305
--- /dev/null
+++ b/dsl/camel-xml-jaxb-dsl/src/test/resources/org/apache/camel/dsl/xml/jaxb/barRest.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<rests xmlns="http://camel.apache.org/schema/spring">
+	<rest id="bar" path="/say/hello">
+	    <get uri="/bar">
+	      <to uri="mock:bar"/>
+	    </get>
+    </rest>
+</rests>
\ No newline at end of file
diff --git a/dsl/camel-xml-jaxb-dsl/src/test/resources/org/apache/camel/dsl/xml/jaxb/barRoute.xml b/dsl/camel-xml-jaxb-dsl/src/test/resources/org/apache/camel/dsl/xml/jaxb/barRoute.xml
new file mode 100644
index 0000000..e96c1f2
--- /dev/null
+++ b/dsl/camel-xml-jaxb-dsl/src/test/resources/org/apache/camel/dsl/xml/jaxb/barRoute.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<!-- START SNIPPET: e1 -->
+<routes xmlns="http://camel.apache.org/schema/spring">
+    <!-- here we define the bar route -->
+    <route id="bar">
+        <from uri="direct:bar"/>
+        <to uri="mock:bar"/>
+    </route>
+
+    <!-- we could add more routes if we like,
+         but in this example we stick to one route only -->
+</routes>
+<!-- END SNIPPET: e1 -->
\ No newline at end of file