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 aa7d65d Add unit test based on user issue on gitter
aa7d65d is described below
commit aa7d65d4f71e18a8bc0f88bbe6449f92256eb820
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Mar 22 16:47:39 2018 +0100
Add unit test based on user issue on gitter
---
.../camel/spring/CamelLoadRoutesFromXMLTest.java | 99 ++++++++++++++++++++++
.../camel/spring/camelLoadRoutesFromXMLTest.xml | 31 +++++++
.../resources/org/apache/camel/spring/myRoutes.xml | 32 +++++++
.../org/apache/camel/spring/myUpdatedRoutes.xml | 38 +++++++++
4 files changed, 200 insertions(+)
diff --git
a/components/camel-spring/src/test/java/org/apache/camel/spring/CamelLoadRoutesFromXMLTest.java
b/components/camel-spring/src/test/java/org/apache/camel/spring/CamelLoadRoutesFromXMLTest.java
new file mode 100644
index 0000000..1140637
--- /dev/null
+++
b/components/camel-spring/src/test/java/org/apache/camel/spring/CamelLoadRoutesFromXMLTest.java
@@ -0,0 +1,99 @@
+/**
+ * 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;
+
+import java.io.InputStream;
+
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.model.RoutesDefinition;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class CamelLoadRoutesFromXMLTest extends SpringTestSupport {
+
+ protected AbstractXmlApplicationContext createApplicationContext() {
+ return new
ClassPathXmlApplicationContext("org/apache/camel/spring/camelLoadRoutesFromXMLTest.xml");
+ }
+
+ public void testLoadRoutes() throws Exception {
+ SpringCamelContext camel =
applicationContext.getBean(SpringCamelContext.class);
+ assertEquals(0, camel.getRoutes().size());
+ assertTrue(camel.getStatus().isStarted());
+
+ // load routes from xml file
+ InputStream is = this.getClass().getResourceAsStream("myRoutes.xml");
+ RoutesDefinition routes = camel.loadRoutesDefinition(is);
+ camel.addRouteDefinitions(routes.getRoutes());
+
+ assertEquals(2, camel.getRoutes().size());
+
+ // they should be started
+ assertTrue(camel.getRouteStatus("foo").isStarted());
+ assertTrue(camel.getRouteStatus("bar").isStarted());
+
+ // and they should work
+ MockEndpoint foo = camel.getEndpoint("mock:foo", MockEndpoint.class);
+ foo.expectedBodiesReceived("Hello World");
+
+ MockEndpoint bar = camel.getEndpoint("mock:bar", MockEndpoint.class);
+ bar.expectedBodiesReceived("Bye World");
+
+ ProducerTemplate producer = camel.createProducerTemplate();
+ producer.sendBody("direct:foo", "Hello World");
+ producer.sendBody("direct:bar", "Bye World");
+
+ MockEndpoint.assertIsSatisfied(foo, bar);
+
+ // remove the routes
+ camel.removeRouteDefinitions(routes.getRoutes());
+
+ // they should be removed
+ assertNull(camel.getRouteStatus("foo"));
+ assertNull(camel.getRouteStatus("bar"));
+
+ // you can also do this manually via their route ids
+ //camel.stopRoute("foo");
+ //camel.removeRoute("foo");
+ //camel.stopRoute("bar");
+ //camel.removeRoute("bar");
+
+ // load updated xml
+ is = this.getClass().getResourceAsStream("myUpdatedRoutes.xml");
+ routes = camel.loadRoutesDefinition(is);
+ camel.addRouteDefinitions(routes.getRoutes());
+
+ assertEquals(2, camel.getRoutes().size());
+
+ // they should be started
+ assertTrue(camel.getRouteStatus("foo").isStarted());
+ assertTrue(camel.getRouteStatus("bar").isStarted());
+
+ // and they should work again (need to get new mock endpoint as the
old is gone)
+ foo = camel.getEndpoint("mock:foo", MockEndpoint.class);
+ foo.expectedBodiesReceived("Updated: Hello World");
+
+ bar = camel.getEndpoint("mock:bar", MockEndpoint.class);
+ bar.expectedBodiesReceived("Updated: Bye World");
+
+ producer.sendBody("direct:foo", "Hello World");
+ producer.sendBody("direct:bar", "Bye World");
+
+ MockEndpoint.assertIsSatisfied(foo, bar);
+ }
+
+}
diff --git
a/components/camel-spring/src/test/resources/org/apache/camel/spring/camelLoadRoutesFromXMLTest.xml
b/components/camel-spring/src/test/resources/org/apache/camel/spring/camelLoadRoutesFromXMLTest.xml
new file mode 100644
index 0000000..a30d1ab
--- /dev/null
+++
b/components/camel-spring/src/test/resources/org/apache/camel/spring/camelLoadRoutesFromXMLTest.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.
+
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <camelContext id="myCamel" xmlns="http://camel.apache.org/schema/spring">
+ <!-- empty on purpose -->
+ </camelContext>
+
+</beans>
diff --git
a/components/camel-spring/src/test/resources/org/apache/camel/spring/myRoutes.xml
b/components/camel-spring/src/test/resources/org/apache/camel/spring/myRoutes.xml
new file mode 100644
index 0000000..45bf80f
--- /dev/null
+++
b/components/camel-spring/src/test/resources/org/apache/camel/spring/myRoutes.xml
@@ -0,0 +1,32 @@
+<?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.
+
+-->
+<routes xmlns="http://camel.apache.org/schema/spring">
+
+ <route id="foo">
+ <from uri="direct:foo"/>
+ <to uri="mock:foo"/>
+ </route>
+
+ <route id="bar">
+ <from uri="direct:bar"/>
+ <to uri="mock:bar"/>
+ </route>
+
+</routes>
diff --git
a/components/camel-spring/src/test/resources/org/apache/camel/spring/myUpdatedRoutes.xml
b/components/camel-spring/src/test/resources/org/apache/camel/spring/myUpdatedRoutes.xml
new file mode 100644
index 0000000..aecb8a4
--- /dev/null
+++
b/components/camel-spring/src/test/resources/org/apache/camel/spring/myUpdatedRoutes.xml
@@ -0,0 +1,38 @@
+<?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.
+
+-->
+<routes xmlns="http://camel.apache.org/schema/spring">
+
+ <route id="foo">
+ <from uri="direct:foo"/>
+ <transform>
+ <simple>Updated: ${body}</simple>
+ </transform>
+ <to uri="mock:foo"/>
+ </route>
+
+ <route id="bar">
+ <from uri="direct:bar"/>
+ <transform>
+ <simple>Updated: ${body}</simple>
+ </transform>
+ <to uri="mock:bar"/>
+ </route>
+
+</routes>
--
To stop receiving notification emails like this one, please contact
[email protected].