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 2010/11/29 13:27:48 UTC
svn commit: r1040085 - in /camel/trunk/tests/camel-itest: ./
src/test/java/org/apache/camel/itest/jaxb/
src/test/resources/org/apache/camel/itest/jaxb/
Author: davsclaus
Date: Mon Nov 29 12:27:48 2010
New Revision: 1040085
URL: http://svn.apache.org/viewvc?rev=1040085&view=rev
Log:
Added test for loading route from XML file and adding to Camel at runtime.
Added:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jaxb/
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jaxb/SpringLoadRouteFromXmlTest.java
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jaxb/
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jaxb/BarRoute.xml
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jaxb/SpringLoadRouteFromXmlTest.xml
Modified:
camel/trunk/tests/camel-itest/ (props changed)
Propchange: camel/trunk/tests/camel-itest/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Mon Nov 29 12:27:48 2010
@@ -7,3 +7,4 @@ target
eclipse-classes
*.i??
activemq-data
+res
Added: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jaxb/SpringLoadRouteFromXmlTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jaxb/SpringLoadRouteFromXmlTest.java?rev=1040085&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jaxb/SpringLoadRouteFromXmlTest.java (added)
+++ camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jaxb/SpringLoadRouteFromXmlTest.java Mon Nov 29 12:27:48 2010
@@ -0,0 +1,78 @@
+/**
+ * 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.itest.jaxb;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Unmarshaller;
+
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.model.Constants;
+import org.apache.camel.model.RoutesDefinition;
+import org.apache.camel.test.junit4.CamelSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+
+/**
+ * @version $Revision$
+ */
+public class SpringLoadRouteFromXmlTest extends CamelSpringTestSupport {
+
+ @Override
+ protected AbstractApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext("org/apache/camel/itest/jaxb/SpringLoadRouteFromXmlTest.xml");
+ }
+
+ @Test
+ public void testLoadRouteFromXml() throws Exception {
+ assertNotNull("Existing foo route should be there", context.getRoute("foo"));
+ 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();
+
+ // load bar route from classpath using JAXB
+ JAXBContext jaxb = JAXBContext.newInstance(Constants.JAXB_CONTEXT_PACKAGES);
+ Unmarshaller unmarshaller = jaxb.createUnmarshaller();
+
+ Resource rs = new ClassPathResource("org/apache/camel/itest/jaxb/BarRoute.xml");
+ Object value = unmarshaller.unmarshal(rs.getInputStream());
+
+ // it should be a RoutesDefinition (we can have multiple routes in the same XML file)
+ RoutesDefinition routes = (RoutesDefinition) value;
+ assertNotNull("Should load routes from XML", routes);
+ assertEquals(1, routes.getRoutes().size());
+
+ // add the routes to existing CamelContext
+ context.addRouteDefinitions(routes.getRoutes());
+
+ assertNotNull("Loaded bar route should be there", context.getRoute("bar"));
+ 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();
+ }
+
+}
Added: camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jaxb/BarRoute.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jaxb/BarRoute.xml?rev=1040085&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jaxb/BarRoute.xml (added)
+++ camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jaxb/BarRoute.xml Mon Nov 29 12:27:48 2010
@@ -0,0 +1,27 @@
+<?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">
+ <!-- this route can be loaded as a file and added to an existing CamelContext -->
+ <route id="bar">
+ <from uri="direct:bar"/>
+ <to uri="mock:bar"/>
+ </route>
+ <!-- we could add more routes if we like -->
+</routes>
+<!-- END SNIPPET: e1 -->
Added: camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jaxb/SpringLoadRouteFromXmlTest.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jaxb/SpringLoadRouteFromXmlTest.xml?rev=1040085&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jaxb/SpringLoadRouteFromXmlTest.xml (added)
+++ camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jaxb/SpringLoadRouteFromXmlTest.xml Mon Nov 29 12:27:48 2010
@@ -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.
+-->
+<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 xmlns="http://camel.apache.org/schema/spring">
+ <route id="foo">
+ <from uri="direct:foo"/>
+ <to uri="mock:foo"/>
+ </route>
+ </camelContext>
+
+</beans>