You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ge...@apache.org on 2008/10/28 14:10:08 UTC
svn commit: r708565 -
/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutCamelErrorHandlingTest.java
Author: gertv
Date: Tue Oct 28 06:10:07 2008
New Revision: 708565
URL: http://svn.apache.org/viewvc?rev=708565&view=rev
Log:
SM-1665,SM-1629: Add a test for error handling with the new Camel 1.5 handleFault
Added:
servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutCamelErrorHandlingTest.java
Added: servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutCamelErrorHandlingTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutCamelErrorHandlingTest.java?rev=708565&view=auto
==============================================================================
--- servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutCamelErrorHandlingTest.java (added)
+++ servicemix/components/engines/servicemix-camel/trunk/src/test/java/org/apache/servicemix/camel/JbiInOutCamelErrorHandlingTest.java Tue Oct 28 06:10:07 2008
@@ -0,0 +1,81 @@
+/*
+ * 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.servicemix.camel;
+
+import java.util.List;
+
+import javax.jbi.messaging.Fault;
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.namespace.QName;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.converter.jaxp.StringSource;
+import org.apache.servicemix.client.DefaultServiceMixClient;
+import org.apache.servicemix.client.ServiceMixClient;
+import org.apache.servicemix.jbi.FaultException;
+import org.apache.servicemix.jbi.container.ActivationSpec;
+
+/**
+ * Tests on handling fault messages with the Camel Exception handler
+ */
+public class JbiInOutCamelErrorHandlingTest extends JbiTestSupport {
+
+ private static final String MESSAGE = "<just><a>test</a></just>";
+
+ public void testInOnlyExchangeConvertBody() throws Exception {
+ MockEndpoint errors = getMockEndpoint("mock:errors");
+ errors.expectedMessageCount(1);
+
+ ServiceMixClient client = new DefaultServiceMixClient(jbiContainer);
+ InOut exchange = client.createInOutExchange();
+ exchange.setService(new QName("urn:test", "service"));
+ exchange.getInMessage().setContent(new StringSource(MESSAGE));
+ client.sendSync(exchange);
+
+ errors.assertIsSatisfied();
+ }
+
+ @Override
+ protected void appendJbiActivationSpecs(List<ActivationSpec> activationSpecList) {
+ // no additional activation specs required
+ ActivationSpec spec = new ActivationSpec(new MyEchoComponent() {
+ protected boolean transform(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws MessagingException {
+ Fault f = exchange.createFault();
+ f.setContent(new StringSource("<fault/>"));
+ throw new FaultException("Error", exchange, f);
+ }
+ });
+ spec.setService(new QName("urn:test", "faulty-service"));
+ spec.setEndpoint("endpoint");
+ activationSpecList.add(spec);
+ }
+
+ @Override
+ protected RouteBuilder createRoutes() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ errorHandler(deadLetterChannel("mock:errors"));
+ from("jbi:service:urn:test:service").handleFault().to("jbi:service:urn:test:faulty-service");
+ }
+ };
+ }
+}