Updated Branches: refs/heads/master 7f8a295af -> f1ead1197
CAMEL-6658 Added more unit test for it Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f1ead119 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f1ead119 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f1ead119 Branch: refs/heads/master Commit: f1ead1197987b63cd4d61ee34f270d5a239b04a0 Parents: 7f8a295 Author: Willem Jiang <[email protected]> Authored: Fri Aug 23 16:15:01 2013 +0800 Committer: Willem Jiang <[email protected]> Committed: Fri Aug 23 16:15:29 2013 +0800 ---------------------------------------------------------------------- .../SpringMulticastAggregatorTest.java | 44 +++++++++++++++++ .../SpringMulticastAggregatorTest-context.xml | 51 ++++++++++++++++++++ .../BankResponseAggregationStrategy.java | 25 +++------- 3 files changed, 102 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/f1ead119/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringMulticastAggregatorTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringMulticastAggregatorTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringMulticastAggregatorTest.java new file mode 100644 index 0000000..bdc54ec --- /dev/null +++ b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringMulticastAggregatorTest.java @@ -0,0 +1,44 @@ +/** + * 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.spring.processor; + +import org.apache.camel.EndpointInject; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.component.mock.MockEndpoint; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration +public class SpringMulticastAggregatorTest { + @Autowired + protected ProducerTemplate producer; + + @EndpointInject(uri = "mock:result") + protected MockEndpoint result; + + @Test + public void multicastAggreatorTest() throws Exception { + result.expectedBodiesReceived("directA directB"); + producer.sendBody("direct:start", "test"); + result.assertIsSatisfied(); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/f1ead119/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringMulticastAggregatorTest-context.xml ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringMulticastAggregatorTest-context.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringMulticastAggregatorTest-context.xml new file mode 100644 index 0000000..2291e77 --- /dev/null +++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringMulticastAggregatorTest-context.xml @@ -0,0 +1,51 @@ +<?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 + "> + + <!-- START SNIPPET: example --> + <camelContext xmlns="http://camel.apache.org/schema/spring"> + <route> + <from uri="direct:start"/> + <multicast strategyRef="aggregatorStrategy" > + <to uri="direct:A"/> + <to uri="direct:B"/> + </multicast> + <to uri="mock:result"/> + </route> + <route> + <from uri="direct:A" /> + <transform> + <simple>directA</simple> + </transform> + </route> + <route> + <from uri="direct:B" /> + <transform> + <simple>directB</simple> + </transform> + </route> + </camelContext> + + <bean id="aggregatorStrategy" class="org.apache.camel.spring.processor.MyAggregator"/> + <!-- END SNIPPET: example --> +</beans> http://git-wip-us.apache.org/repos/asf/camel/blob/f1ead119/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/BankResponseAggregationStrategy.java ---------------------------------------------------------------------- diff --git a/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/BankResponseAggregationStrategy.java b/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/BankResponseAggregationStrategy.java index 953afe1..848b5db 100644 --- a/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/BankResponseAggregationStrategy.java +++ b/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/BankResponseAggregationStrategy.java @@ -16,28 +16,17 @@ */ package org.apache.camel.loanbroker.webservice.version; -import org.apache.camel.Exchange; import org.apache.camel.loanbroker.webservice.version.bank.BankQuote; -import org.apache.camel.processor.aggregate.AggregationStrategy; //START SNIPPET: aggregating -public class BankResponseAggregationStrategy implements AggregationStrategy { - - @Override - public Exchange aggregate(Exchange oldExchange, Exchange newExchange) { - // the first time we only have the new exchange - if (oldExchange == null) { - return newExchange; - } - - BankQuote oldQuote = oldExchange.getIn().getBody(BankQuote.class); - BankQuote newQuote = newExchange.getIn().getBody(BankQuote.class); - - // return the winner with the lowest rate - if (oldQuote.getRate() <= newQuote.getRate()) { - return oldExchange; +// This POJO aggregator is supported since Camel 2.12 +public class BankResponseAggregationStrategy { + + public BankQuote aggregate(BankQuote oldQuote, BankQuote newQuote) { + if (oldQuote != null && oldQuote.getRate() <= newQuote.getRate()) { + return oldQuote; } else { - return newExchange; + return newQuote; } }
