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 2011/01/14 07:06:33 UTC
svn commit: r1058858 - in /camel/trunk/camel-core/src/test:
java/org/apache/camel/model/ resources/org/apache/camel/model/
Author: davsclaus
Date: Fri Jan 14 06:06:32 2011
New Revision: 1058858
URL: http://svn.apache.org/viewvc?rev=1058858&view=rev
Log:
Added some tests
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/model/LoadRouteFromXmlWithInterceptTest.java
- copied, changed from r1058661, camel/trunk/camel-core/src/test/java/org/apache/camel/model/LoadRouteFromXmlTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/model/LoadRouteFromXmlWithOnExceptionTest.java
camel/trunk/camel-core/src/test/resources/org/apache/camel/model/barInterceptorRoute.xml
- copied, changed from r1058661, camel/trunk/camel-core/src/test/resources/org/apache/camel/model/barRoute.xml
camel/trunk/camel-core/src/test/resources/org/apache/camel/model/barOnExceptionRoute.xml
Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/model/LoadRouteFromXmlWithInterceptTest.java (from r1058661, camel/trunk/camel-core/src/test/java/org/apache/camel/model/LoadRouteFromXmlTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/model/LoadRouteFromXmlWithInterceptTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/model/LoadRouteFromXmlWithInterceptTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/model/LoadRouteFromXmlTest.java&r1=1058661&r2=1058858&rev=1058858&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/model/LoadRouteFromXmlTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/model/LoadRouteFromXmlWithInterceptTest.java Fri Jan 14 06:06:32 2011
@@ -19,49 +19,32 @@ package org.apache.camel.model;
import java.io.InputStream;
import org.apache.camel.ContextTestSupport;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
/**
* @version $Revision$
*/
-public class LoadRouteFromXmlTest extends ContextTestSupport {
+public class LoadRouteFromXmlWithInterceptTest extends ContextTestSupport {
- public void testLoadRouteFromXml() throws Exception {
- assertNotNull("Existing foo route should be there", context.getRoute("foo"));
- assertEquals(1, context.getRoutes().size());
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
- // 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
- InputStream is = getClass().getResourceAsStream("barRoute.xml");
+ public void testLoadRouteFromXmlWithIntercept() throws Exception {
+ InputStream is = getClass().getResourceAsStream("barInterceptorRoute.xml");
RoutesDefinition routes = context.loadRoutesDefinition(is);
context.addRouteDefinitions(routes.getRoutes());
- // END SNIPPET: e1
+ context.start();
assertNotNull("Loaded bar route should be there", context.getRoute("bar"));
- assertEquals(2, context.getRoutes().size());
+ assertEquals(1, context.getRoutes().size());
// test that loaded route works
- MockEndpoint bar = getMockEndpoint("mock:bar");
- bar.expectedBodiesReceived("Bye World");
+ getMockEndpoint("mock:bar").expectedBodiesReceived("Bye World");
+ getMockEndpoint("mock:intercept").expectedBodiesReceived("Bye World");
+
template.sendBody("direct:bar", "Bye World");
- bar.assertIsSatisfied();
- }
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- from("direct:foo").routeId("foo")
- .to("mock:foo");
- }
- };
+ assertMockEndpointsSatisfied();
}
}
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/model/LoadRouteFromXmlWithOnExceptionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/model/LoadRouteFromXmlWithOnExceptionTest.java?rev=1058858&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/model/LoadRouteFromXmlWithOnExceptionTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/model/LoadRouteFromXmlWithOnExceptionTest.java Fri Jan 14 06:06:32 2011
@@ -0,0 +1,71 @@
+/**
+ * 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.model;
+
+import java.io.InputStream;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.impl.JndiRegistry;
+
+/**
+ * @version $Revision$
+ */
+public class LoadRouteFromXmlWithOnExceptionTest extends ContextTestSupport {
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry jndi = super.createRegistry();
+ jndi.bind("myProcessor", new MyProcessor());
+ return jndi;
+ }
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ public void testLoadRouteFromXmlWitOnException() throws Exception {
+ InputStream is = getClass().getResourceAsStream("barOnExceptionRoute.xml");
+ RoutesDefinition routes = context.loadRoutesDefinition(is);
+ context.addRouteDefinitions(routes.getRoutes());
+ context.start();
+
+ assertNotNull("Loaded bar route should be there", context.getRoute("bar"));
+ assertEquals(1, context.getRoutes().size());
+
+ // test that loaded route works
+ getMockEndpoint("mock:bar").expectedBodiesReceived("Bye World");
+ getMockEndpoint("mock:error").expectedBodiesReceived("Kabom");
+
+ template.sendBody("direct:bar", "Bye World");
+ template.sendBody("direct:bar", "Kabom");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ private final class MyProcessor implements Processor {
+
+ public void process(Exchange exchange) throws Exception {
+ String body = exchange.getIn().getBody(String.class);
+ if ("Kabom".equals(body)) {
+ throw new IllegalArgumentException("Damn");
+ }
+ }
+ }
+}
Copied: camel/trunk/camel-core/src/test/resources/org/apache/camel/model/barInterceptorRoute.xml (from r1058661, camel/trunk/camel-core/src/test/resources/org/apache/camel/model/barRoute.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/resources/org/apache/camel/model/barInterceptorRoute.xml?p2=camel/trunk/camel-core/src/test/resources/org/apache/camel/model/barInterceptorRoute.xml&p1=camel/trunk/camel-core/src/test/resources/org/apache/camel/model/barRoute.xml&r1=1058661&r2=1058858&rev=1058858&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/resources/org/apache/camel/model/barRoute.xml (original)
+++ camel/trunk/camel-core/src/test/resources/org/apache/camel/model/barInterceptorRoute.xml Fri Jan 14 06:06:32 2011
@@ -15,15 +15,15 @@
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"/>
+ <intercept>
+ <to uri="log:intercept"/>
+ <to uri="mock:intercept"/>
+ </intercept>
<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
Added: camel/trunk/camel-core/src/test/resources/org/apache/camel/model/barOnExceptionRoute.xml
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/resources/org/apache/camel/model/barOnExceptionRoute.xml?rev=1058858&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/resources/org/apache/camel/model/barOnExceptionRoute.xml (added)
+++ camel/trunk/camel-core/src/test/resources/org/apache/camel/model/barOnExceptionRoute.xml Fri Jan 14 06:06:32 2011
@@ -0,0 +1,33 @@
+<?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="bar">
+ <from uri="direct:bar"/>
+ <onException>
+ <exception>java.lang.Exception</exception>
+ <handled>
+ <constant>true</constant>
+ </handled>
+ <to uri="mock:error"/>
+ </onException>
+ <process ref="myProcessor"/>
+ <to uri="mock:bar"/>
+ </route>
+
+</routes>