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/06/04 08:18:52 UTC
[camel] 03/05: CAMEL-13608: Add route filter to model camel context
so you can filter out unwanted routes, such as from unit testing.
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
commit bb0570880bfd2f3e93440292c1dd57631b1363a7
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Jun 4 06:54:18 2019 +0200
CAMEL-13608: Add route filter to model camel context so you can filter out unwanted routes, such as from unit testing.
---
.../camel/spring/boot/routefilter/BarRoute.java | 2 +-
.../camel/spring/boot/routefilter/FooRoute.java | 2 +-
.../boot/routefilter/RoutePatternFilterTest.java | 60 ++++++++++++++++++++++
3 files changed, 62 insertions(+), 2 deletions(-)
diff --git a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/routefilter/BarRoute.java b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/routefilter/BarRoute.java
index 9326321..b1412d1 100644
--- a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/routefilter/BarRoute.java
+++ b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/routefilter/BarRoute.java
@@ -24,7 +24,7 @@ public class BarRoute extends RouteBuilder {
@Override
public void configure() throws Exception {
- from("direct:start")
+ from("direct:start").routeId("bar")
.to("mock:bar");
}
}
diff --git a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/routefilter/FooRoute.java b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/routefilter/FooRoute.java
index 2a22281..f241783 100644
--- a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/routefilter/FooRoute.java
+++ b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/routefilter/FooRoute.java
@@ -24,7 +24,7 @@ public class FooRoute extends RouteBuilder {
@Override
public void configure() throws Exception {
- from("direct:start")
+ from("direct:start").routeId("foo")
.to("mock:foo");
}
}
diff --git a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/routefilter/RoutePatternFilterTest.java b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/routefilter/RoutePatternFilterTest.java
new file mode 100644
index 0000000..aa06a57
--- /dev/null
+++ b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/routefilter/RoutePatternFilterTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.spring.boot.routefilter;
+
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.model.ModelCamelContext;
+import org.apache.camel.test.spring.CamelSpringBootRunner;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@RunWith(CamelSpringBootRunner.class)
+@SpringBootApplication
+@SpringBootTest(classes = RoutePatternFilterTest.class,
+ properties = {"camel.springboot.route-filter-pattern=bar*"})
+public class RoutePatternFilterTest {
+
+ @Autowired
+ ProducerTemplate producerTemplate;
+
+ @Autowired
+ ModelCamelContext camelContext;
+
+ @Test
+ public void shouldSendToBar() throws Exception {
+ // should only be 1 route
+ Assert.assertEquals(1, camelContext.getRoutes().size());
+ Assert.assertEquals(1, camelContext.getRouteDefinitions().size());
+ Assert.assertEquals("bar", camelContext.getRouteDefinitions().get(0).getId());
+
+ // Given
+ MockEndpoint mock = camelContext.getEndpoint("mock:bar", MockEndpoint.class);
+ mock.expectedBodiesReceived("Hello Bar");
+
+ // When
+ producerTemplate.sendBody("direct:start", "Hello Bar");
+
+ // Then
+ mock.assertIsSatisfied();
+ }
+
+}