Return-Path: Delivered-To: apmail-camel-commits-archive@www.apache.org Received: (qmail 77243 invoked from network); 5 Feb 2009 19:33:12 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 5 Feb 2009 19:33:12 -0000 Received: (qmail 21721 invoked by uid 500); 5 Feb 2009 19:33:12 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 21698 invoked by uid 500); 5 Feb 2009 19:33:12 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 21689 invoked by uid 99); 5 Feb 2009 19:33:12 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Feb 2009 11:33:12 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Feb 2009 19:33:11 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id AD46E238895D; Thu, 5 Feb 2009 19:32:50 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r741254 - /camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ClaimCheckTest.java Date: Thu, 05 Feb 2009 19:32:50 -0000 To: commits@camel.apache.org From: janstey@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090205193250.AD46E238895D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: janstey Date: Thu Feb 5 19:32:49 2009 New Revision: 741254 URL: http://svn.apache.org/viewvc?rev=741254&view=rev Log: CAMEL-1317 - Add example for claim check EIP Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ClaimCheckTest.java (with props) Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ClaimCheckTest.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ClaimCheckTest.java?rev=741254&view=auto ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ClaimCheckTest.java (added) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ClaimCheckTest.java Thu Feb 5 19:32:49 2009 @@ -0,0 +1,100 @@ +/** + * 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 java.util.HashMap; +import java.util.Map; + +import org.apache.camel.Body; +import org.apache.camel.ContextTestSupport; +import org.apache.camel.Exchange; +import org.apache.camel.Header; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.impl.JndiRegistry; +import org.apache.camel.language.XPath; + +public class ClaimCheckTest extends ContextTestSupport { + + // in memory data store for testing only! + public static Map dataStore = new HashMap(); + + @SuppressWarnings("unchecked") + public void testClaimCheck() throws Exception { + String body = ""; + + // check to make sure the message body gets added back in properly + MockEndpoint resultEndpoint = getMockEndpoint("mock:result"); + resultEndpoint.expectedMessageCount(1); + resultEndpoint.message(0).body().equals(body); + + // check to make sure the claim check is added to the message and + // the body is removed + MockEndpoint testCheckpointEndpoint = getMockEndpoint("mock:testCheckpoint"); + testCheckpointEndpoint.expectedMessageCount(1); + testCheckpointEndpoint.expectedHeaderReceived("claimCheck", "123"); + testCheckpointEndpoint.message(0).body().isNull(); + + template.sendBody("direct:start", body); + + assertMockEndpointsSatisfied(); + } + + protected JndiRegistry createRegistry() throws Exception { + JndiRegistry jndi = super.createRegistry(); + jndi.bind("checkLuggage", new CheckLuggageBean()); + jndi.bind("dataEnricher", new DataEnricherBean()); + return jndi; + } + + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + public void configure() { + // START SNIPPET: e1 + from("direct:start").to("bean:checkLuggage", "mock:testCheckpoint", "bean:dataEnricher", "mock:result"); + // END SNIPPET: e1 + } + }; + } + + // START SNIPPET: e2 + public static final class CheckLuggageBean { + public void checkLuggage(Exchange exchange, @Body String body, @XPath("/order/@custId") String custId) { + // store the message body into the data store, using the custId as the claim check + dataStore.put(custId, body); + // add the claim check as a header + exchange.getIn().setHeader("claimCheck", custId); + // remove the body from the message + exchange.getIn().setBody(null); + } + } + // END SNIPPET: e2 + + // START SNIPPET: e3 + public static final class DataEnricherBean { + public void addDataBackIn(Exchange exchange, @Header(name = "claimCheck") String claimCheck) { + // query the data store using the claim check as the key and add the data + // back into the message body + exchange.getIn().setBody(dataStore.get(claimCheck)); + // remove the message data from the data store + dataStore.remove(claimCheck); + // remove the claim check header + exchange.getIn().removeHeader("claimCheck"); + } + } + // END SNIPPET: e3 +} Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ClaimCheckTest.java ------------------------------------------------------------------------------ svn:eol-style = native