You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2007/09/04 17:51:09 UTC
svn commit: r572720 - in /activemq/camel/trunk/camel-core/src:
main/java/org/apache/camel/model/ChoiceType.java
test/java/org/apache/camel/processor/FaultRouteTest.java
Author: jstrachan
Date: Tue Sep 4 08:51:08 2007
New Revision: 572720
URL: http://svn.apache.org/viewvc?rev=572720&view=rev
Log:
added more helper methods to ChoiceType to make it easier to use more of the DSL within a when() clause; also added a test case showing routing using faults
Added:
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRouteTest.java (with props)
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ChoiceType.java
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ChoiceType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ChoiceType.java?rev=572720&r1=572719&r2=572720&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ChoiceType.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ChoiceType.java Tue Sep 4 08:51:08 2007
@@ -17,10 +17,12 @@
package org.apache.camel.model;
import org.apache.camel.Endpoint;
+import org.apache.camel.Expression;
import org.apache.camel.Predicate;
import org.apache.camel.Processor;
import org.apache.camel.impl.RouteContext;
import org.apache.camel.processor.ChoiceProcessor;
+import org.apache.camel.processor.DelegateProcessor;
import org.apache.camel.processor.FilterProcessor;
import org.apache.camel.util.CollectionStringBuffer;
@@ -105,6 +107,162 @@
public ChoiceType to(String... uris) {
super.to(uris);
+ return this;
+ }
+
+ @Override
+ public ChoiceType bean(Object bean) {
+ super.bean(bean);
+ return this;
+ }
+
+ @Override
+ public ChoiceType bean(Object bean, String method) {
+ super.bean(bean, method);
+ return this;
+ }
+
+ @Override
+ public ChoiceType beanRef(String ref) {
+ super.beanRef(ref);
+ return this;
+ }
+
+ @Override
+ public ChoiceType beanRef(String ref, String method) {
+ super.beanRef(ref, method);
+ return this;
+ }
+
+ @Override
+ public ChoiceType convertBodyTo(Class type) {
+ super.convertBodyTo(type);
+ return this;
+ }
+
+ @Override
+ public ChoiceType convertFaultBodyTo(Class type) {
+ super.convertFaultBodyTo(type);
+ return this;
+ }
+
+ @Override
+ public ChoiceType convertOutBodyTo(Class type) {
+ super.convertOutBodyTo(type);
+ return this;
+ }
+
+ @Override
+ public ChoiceType inheritErrorHandler(boolean condition) {
+ super.inheritErrorHandler(condition);
+ return this;
+ }
+
+ @Override
+ public ChoiceType intercept(DelegateProcessor interceptor) {
+ super.intercept(interceptor);
+ return this;
+ }
+
+ @Override
+ public ChoiceType interceptor(String ref) {
+ super.interceptor(ref);
+ return this;
+ }
+
+ @Override
+ public ChoiceType interceptors(String... refs) {
+ super.interceptors(refs);
+ return this;
+ }
+
+ @Override
+ public ChoiceType pipeline(Collection<Endpoint> endpoints) {
+ super.pipeline(endpoints);
+ return this;
+ }
+
+ @Override
+ public ChoiceType pipeline(Endpoint... endpoints) {
+ super.pipeline(endpoints);
+ return this;
+ }
+
+ @Override
+ public ChoiceType pipeline(String... uris) {
+ super.pipeline(uris);
+ return this;
+ }
+
+ @Override
+ public ChoiceType process(Processor processor) {
+ super.process(processor);
+ return this;
+ }
+
+ @Override
+ public ChoiceType recipientList(Expression receipients) {
+ super.recipientList(receipients);
+ return this;
+ }
+
+ @Override
+ public ChoiceType removeHeader(String name) {
+ super.removeHeader(name);
+ return this;
+ }
+
+ @Override
+ public ChoiceType removeOutHeader(String name) {
+ super.removeOutHeader(name);
+ return this;
+ }
+
+ @Override
+ public ChoiceType removeProperty(String name) {
+ super.removeProperty(name);
+ return this;
+ }
+
+ @Override
+ public ChoiceType setBody(Expression expression) {
+ super.setBody(expression);
+ return this;
+ }
+
+ @Override
+ public ChoiceType setHeader(String name, Expression expression) {
+ super.setHeader(name, expression);
+ return this;
+ }
+
+ @Override
+ public ChoiceType setOutBody(Expression expression) {
+ super.setOutBody(expression);
+ return this;
+ }
+
+ @Override
+ public ChoiceType setOutHeader(String name, Expression expression) {
+ super.setOutHeader(name, expression);
+ return this;
+ }
+
+ @Override
+ public ChoiceType setProperty(String name, Expression expression) {
+ super.setProperty(name, expression);
+ return this;
+ }
+
+ @Override
+ public ChoiceType trace() {
+ super.trace();
+ return this;
+ }
+
+ @Override
+ public ChoiceType trace(String category) {
+ super.trace(category);
return this;
}
Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRouteTest.java?rev=572720&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRouteTest.java (added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRouteTest.java Tue Sep 4 08:51:08 2007
@@ -0,0 +1,105 @@
+/**
+ *
+ * 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.processor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class FaultRouteTest extends ContextTestSupport {
+ protected MockEndpoint a;
+ protected MockEndpoint b;
+ protected MockEndpoint c;
+ protected boolean shouldWork = true;
+
+ public void testWithOut() throws Exception {
+/*
+ a.whenExchangeReceived(1, new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ exchange.getOut().setBody("out");
+ }
+ });
+*/
+ a.expectedMessageCount(1);
+ b.expectedBodiesReceived("out");
+ c.expectedMessageCount(0);
+
+ template.sendBody("direct:start", "in");
+
+ MockEndpoint.assertIsSatisfied(a, b, c);
+ }
+
+ public void testWithFault() throws Exception {
+ shouldWork = false;
+
+/*
+ a.whenExchangeReceived(1, new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ exchange.getFault().setBody("fault");
+ }
+ });
+*/
+ a.expectedMessageCount(1);
+ b.expectedMessageCount(0);
+ c.expectedBodiesReceived("fault");
+
+ template.sendBody("direct:start", "in");
+
+ MockEndpoint.assertIsSatisfied(a, b, c);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ a = resolveMandatoryEndpoint("mock:a", MockEndpoint.class);
+ b = resolveMandatoryEndpoint("mock:b", MockEndpoint.class);
+ c = resolveMandatoryEndpoint("mock:c", MockEndpoint.class);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:start")
+ .process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ if (shouldWork) {
+ exchange.getOut().setBody("out");
+ }
+ else {
+ exchange.getFault().setBody("fault");
+ }
+ }
+ })
+ .to("mock:a")
+ .choice()
+ .when(faultBody().isNull())
+ .to("mock:b")
+ .otherwise()
+ .setBody(faultBody()).to("mock:c");
+ }
+ };
+ }
+
+}
\ No newline at end of file
Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FaultRouteTest.java
------------------------------------------------------------------------------
svn:eol-style = native