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 2019/10/17 19:09:29 UTC
[camel] 08/09: CAMEL-14050: camel-main - Add logic for automatic
RouteBuilder class detection ala camel-spring-boot has
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch route-collector
in repository https://gitbox.apache.org/repos/asf/camel.git
commit cbdcf4d9b8b47419782613b0c7e8d1b562dd4659
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Oct 17 20:38:03 2019 +0200
CAMEL-14050: camel-main - Add logic for automatic RouteBuilder class detection ala camel-spring-boot has
---
.../main/MainRoutesCollectorPackageScanTest.java | 58 ++++++++++++++++++++++
.../camel/main/scan/MyDummyRouteBuilder.java | 27 ++++++++++
.../apache/camel/main/scan/MyScanRouteBuilder.java | 27 ++++++++++
3 files changed, 112 insertions(+)
diff --git a/core/camel-main/src/test/java/org/apache/camel/main/MainRoutesCollectorPackageScanTest.java b/core/camel-main/src/test/java/org/apache/camel/main/MainRoutesCollectorPackageScanTest.java
new file mode 100644
index 0000000..208a5e5
--- /dev/null
+++ b/core/camel-main/src/test/java/org/apache/camel/main/MainRoutesCollectorPackageScanTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.main;
+
+import java.util.Set;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.engine.DefaultPackageScanClassResolver;
+import org.apache.camel.spi.PackageScanClassResolver;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class MainRoutesCollectorPackageScanTest extends Assert {
+
+ @Test
+ public void testMainRoutesCollector() throws Exception {
+ Main main = new Main();
+
+ PackageScanClassResolver resolver = new DefaultPackageScanClassResolver();
+ Set<Class<?>> set = resolver.findImplementations(RouteBuilder.class, "org.apache.camel.main.scan");
+ set.forEach(main::addRouteBuilder);
+ main.start();
+
+ CamelContext camelContext = main.getCamelContext();
+ assertNotNull(camelContext);
+ assertEquals(2, camelContext.getRoutes().size());
+
+ MockEndpoint endpoint = camelContext.getEndpoint("mock:scan", MockEndpoint.class);
+ endpoint.expectedBodiesReceived("Hello World");
+ MockEndpoint endpoint2 = camelContext.getEndpoint("mock:dummy", MockEndpoint.class);
+ endpoint2.expectedBodiesReceived("Bye World");
+
+ main.getCamelTemplate().sendBody("direct:scan", "Hello World");
+ main.getCamelTemplate().sendBody("direct:dummy", "Bye World");
+
+ endpoint.assertIsSatisfied();
+ endpoint2.assertIsSatisfied();
+
+ main.stop();
+ }
+
+}
diff --git a/core/camel-main/src/test/java/org/apache/camel/main/scan/MyDummyRouteBuilder.java b/core/camel-main/src/test/java/org/apache/camel/main/scan/MyDummyRouteBuilder.java
new file mode 100644
index 0000000..d2a5d78
--- /dev/null
+++ b/core/camel-main/src/test/java/org/apache/camel/main/scan/MyDummyRouteBuilder.java
@@ -0,0 +1,27 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.main.scan;
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class MyDummyRouteBuilder extends RouteBuilder {
+
+ @Override
+ public void configure() throws Exception {
+ from("direct:dummy").to("mock:dummy");
+ }
+}
diff --git a/core/camel-main/src/test/java/org/apache/camel/main/scan/MyScanRouteBuilder.java b/core/camel-main/src/test/java/org/apache/camel/main/scan/MyScanRouteBuilder.java
new file mode 100644
index 0000000..ff258c7
--- /dev/null
+++ b/core/camel-main/src/test/java/org/apache/camel/main/scan/MyScanRouteBuilder.java
@@ -0,0 +1,27 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.main.scan;
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class MyScanRouteBuilder extends RouteBuilder {
+
+ @Override
+ public void configure() throws Exception {
+ from("direct:scan").to("mock:scan");
+ }
+}