Updated Branches: refs/heads/master ee1fd85a1 -> 3f4f8e9dd
CAMEL-6650: AggregationStrategy - Allow to use a pojo with no Camel API dependencies. Work in progress. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/aea2127e Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/aea2127e Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/aea2127e Branch: refs/heads/master Commit: aea2127ed35f1d6f112fe0d2bd5b56bce1c7f88c Parents: 5aa3ba6 Author: Claus Ibsen <davscl...@apache.org> Authored: Mon Aug 19 16:23:21 2013 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Tue Aug 20 08:29:57 2013 +0200 ---------------------------------------------------------------------- .../apache/camel/model/AggregateDefinition.java | 32 ++++++++- .../apache/camel/model/EnrichDefinition.java | 34 ++++++++-- .../apache/camel/model/MulticastDefinition.java | 48 ++++++++++++-- .../camel/model/PollEnrichDefinition.java | 34 ++++++++-- .../camel/model/RecipientListDefinition.java | 44 ++++++++++-- .../org/apache/camel/model/SplitDefinition.java | 33 ++++++++- .../AggregationStrategyBeanAdapter.java | 2 - ...ionStrategyBeanAdapterRefMethodNameTest.java | 70 ++++++++++++++++++++ .../AggregationStrategyBeanAdapterRefTest.java | 66 ++++++++++++++++++ ...ionStrategyBeanAdapterRefMethodNameTest.java | 32 +++++++++ ...ngAggregationStrategyBeanAdapterRefTest.java | 32 +++++++++ ...tionStrategyBeanAdapterRefMethodNameTest.xml | 41 ++++++++++++ ...ingAggregationStrategyBeanAdapterRefTest.xml | 41 ++++++++++++ 13 files changed, 480 insertions(+), 29 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/aea2127e/camel-core/src/main/java/org/apache/camel/model/AggregateDefinition.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/AggregateDefinition.java b/camel-core/src/main/java/org/apache/camel/model/AggregateDefinition.java index a0dc593..62cf08d 100644 --- a/camel-core/src/main/java/org/apache/camel/model/AggregateDefinition.java +++ b/camel-core/src/main/java/org/apache/camel/model/AggregateDefinition.java @@ -20,7 +20,6 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.ScheduledExecutorService; - import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; @@ -37,6 +36,7 @@ import org.apache.camel.model.language.ExpressionDefinition; import org.apache.camel.processor.CamelInternalProcessor; import org.apache.camel.processor.aggregate.AggregateProcessor; import org.apache.camel.processor.aggregate.AggregationStrategy; +import org.apache.camel.processor.aggregate.AggregationStrategyBeanAdapter; import org.apache.camel.processor.aggregate.GroupedExchangeAggregationStrategy; import org.apache.camel.processor.aggregate.OptimisticLockRetryPolicy; import org.apache.camel.spi.AggregationRepository; @@ -88,6 +88,8 @@ public class AggregateDefinition extends ProcessorDefinition<AggregateDefinition @XmlAttribute private String strategyRef; @XmlAttribute + private String strategyMethodName; + @XmlAttribute private Integer completionSize; @XmlAttribute private Long completionInterval; @@ -277,7 +279,14 @@ public class AggregateDefinition extends ProcessorDefinition<AggregateDefinition private AggregationStrategy createAggregationStrategy(RouteContext routeContext) { AggregationStrategy strategy = getAggregationStrategy(); if (strategy == null && strategyRef != null) { - strategy = routeContext.mandatoryLookup(strategyRef, AggregationStrategy.class); + Object aggStrategy = routeContext.lookup(strategyRef, Object.class); + if (aggStrategy instanceof AggregationStrategy) { + strategy = (AggregationStrategy) aggStrategy; + } else if (aggStrategy != null) { + strategy = new AggregationStrategyBeanAdapter(aggStrategy, getAggregationStrategyMethodName()); + } else { + throw new IllegalArgumentException("Cannot find AggregationStrategy in Registry with name: " + strategyRef); + } } if (groupExchanges != null && groupExchanges) { @@ -323,6 +332,14 @@ public class AggregateDefinition extends ProcessorDefinition<AggregateDefinition this.strategyRef = aggregationStrategyRef; } + public String getAggregationStrategyMethodName() { + return strategyMethodName; + } + + public void setAggregationStrategyMethodName(String strategyMethodName) { + this.strategyMethodName = strategyMethodName; + } + public Integer getCompletionSize() { return completionSize; } @@ -681,6 +698,17 @@ public class AggregateDefinition extends ProcessorDefinition<AggregateDefinition } /** + * Sets the method name to use when using a POJO as {@link AggregationStrategy}. + * + * @param methodName the method name to call + * @return the builder + */ + public AggregateDefinition aggregationStrategyMethodName(String methodName) { + setAggregationStrategyMethodName(methodName); + return this; + } + + /** * Sets the custom aggregate repository to use. * <p/> * Will by default use {@link org.apache.camel.processor.aggregate.MemoryAggregationRepository} http://git-wip-us.apache.org/repos/asf/camel/blob/aea2127e/camel-core/src/main/java/org/apache/camel/model/EnrichDefinition.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/EnrichDefinition.java b/camel-core/src/main/java/org/apache/camel/model/EnrichDefinition.java index 465b1ff..bcb6f01 100644 --- a/camel-core/src/main/java/org/apache/camel/model/EnrichDefinition.java +++ b/camel-core/src/main/java/org/apache/camel/model/EnrichDefinition.java @@ -26,6 +26,7 @@ import org.apache.camel.Endpoint; import org.apache.camel.Processor; import org.apache.camel.processor.Enricher; import org.apache.camel.processor.aggregate.AggregationStrategy; +import org.apache.camel.processor.aggregate.AggregationStrategyBeanAdapter; import org.apache.camel.spi.RouteContext; import org.apache.camel.util.ObjectHelper; @@ -44,6 +45,8 @@ public class EnrichDefinition extends NoOutputDefinition<EnrichDefinition> { private String resourceRef; @XmlAttribute(name = "strategyRef") private String aggregationStrategyRef; + @XmlAttribute(name = "strategyMethodName") + private String aggregationStrategyMethodName; @XmlTransient private AggregationStrategy aggregationStrategy; @@ -94,17 +97,30 @@ public class EnrichDefinition extends NoOutputDefinition<EnrichDefinition> { } Enricher enricher = new Enricher(null, endpoint.createProducer()); - if (aggregationStrategyRef != null) { - aggregationStrategy = routeContext.mandatoryLookup(aggregationStrategyRef, AggregationStrategy.class); - } - if (aggregationStrategy == null) { + AggregationStrategy strategy = createAggregationStrategy(routeContext); + if (strategy == null) { enricher.setDefaultAggregationStrategy(); } else { - enricher.setAggregationStrategy(aggregationStrategy); + enricher.setAggregationStrategy(strategy); } return enricher; } + private AggregationStrategy createAggregationStrategy(RouteContext routeContext) { + AggregationStrategy strategy = getAggregationStrategy(); + if (strategy == null && aggregationStrategyRef != null) { + Object aggStrategy = routeContext.lookup(aggregationStrategyRef, Object.class); + if (aggStrategy instanceof AggregationStrategy) { + strategy = (AggregationStrategy) aggStrategy; + } else if (aggStrategy != null) { + strategy = new AggregationStrategyBeanAdapter(aggStrategy, getAggregationStrategyMethodName()); + } else { + throw new IllegalArgumentException("Cannot find AggregationStrategy in Registry with name: " + aggregationStrategyRef); + } + } + return strategy; + } + public String getResourceUri() { return resourceUri; } @@ -129,6 +145,14 @@ public class EnrichDefinition extends NoOutputDefinition<EnrichDefinition> { this.aggregationStrategyRef = aggregationStrategyRef; } + public String getAggregationStrategyMethodName() { + return aggregationStrategyMethodName; + } + + public void setAggregationStrategyMethodName(String aggregationStrategyMethodName) { + this.aggregationStrategyMethodName = aggregationStrategyMethodName; + } + public AggregationStrategy getAggregationStrategy() { return aggregationStrategy; } http://git-wip-us.apache.org/repos/asf/camel/blob/aea2127e/camel-core/src/main/java/org/apache/camel/model/MulticastDefinition.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/MulticastDefinition.java b/camel-core/src/main/java/org/apache/camel/model/MulticastDefinition.java index b0e65a2..c9a152e 100644 --- a/camel-core/src/main/java/org/apache/camel/model/MulticastDefinition.java +++ b/camel-core/src/main/java/org/apache/camel/model/MulticastDefinition.java @@ -28,6 +28,7 @@ import org.apache.camel.Processor; import org.apache.camel.processor.CamelInternalProcessor; import org.apache.camel.processor.MulticastProcessor; import org.apache.camel.processor.aggregate.AggregationStrategy; +import org.apache.camel.processor.aggregate.AggregationStrategyBeanAdapter; import org.apache.camel.processor.aggregate.UseLatestAggregationStrategy; import org.apache.camel.spi.RouteContext; import org.apache.camel.util.CamelContextHelper; @@ -44,6 +45,8 @@ public class MulticastDefinition extends OutputDefinition<MulticastDefinition> i private Boolean parallelProcessing; @XmlAttribute private String strategyRef; + @XmlAttribute + private String strategyMethodName; @XmlTransient private ExecutorService executorService; @XmlAttribute @@ -111,6 +114,17 @@ public class MulticastDefinition extends OutputDefinition<MulticastDefinition> i } /** + * Sets the method name to use when using a POJO as {@link AggregationStrategy}. + * + * @param methodName the method name to call + * @return the builder + */ + public MulticastDefinition aggregationStrategyMethodName(String methodName) { + setStrategyMethodName(methodName); + return this; + } + + /** * Uses the {@link java.util.concurrent.ExecutorService} to do the multicasting work * * @return the builder @@ -207,12 +221,10 @@ public class MulticastDefinition extends OutputDefinition<MulticastDefinition> i } protected Processor createCompositeProcessor(RouteContext routeContext, List<Processor> list) throws Exception { - if (strategyRef != null) { - aggregationStrategy = routeContext.mandatoryLookup(strategyRef, AggregationStrategy.class); - } - if (aggregationStrategy == null) { + AggregationStrategy strategy = createAggregationStrategy(routeContext); + if (strategy == null) { // default to use latest aggregation strategy - aggregationStrategy = new UseLatestAggregationStrategy(); + strategy = new UseLatestAggregationStrategy(); } boolean shutdownThreadPool = ProcessorDefinitionHelper.willCreateNewThreadPool(routeContext, this, isParallelProcessing()); @@ -226,7 +238,7 @@ public class MulticastDefinition extends OutputDefinition<MulticastDefinition> i onPrepare = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), onPrepareRef, Processor.class); } - MulticastProcessor answer = new MulticastProcessor(routeContext.getCamelContext(), list, aggregationStrategy, isParallelProcessing(), + MulticastProcessor answer = new MulticastProcessor(routeContext.getCamelContext(), list, strategy, isParallelProcessing(), threadPool, shutdownThreadPool, isStreaming(), isStopOnException(), timeout, onPrepare, isShareUnitOfWork()); if (isShareUnitOfWork()) { // wrap answer in a sub unit of work, since we share the unit of work @@ -237,6 +249,22 @@ public class MulticastDefinition extends OutputDefinition<MulticastDefinition> i return answer; } + private AggregationStrategy createAggregationStrategy(RouteContext routeContext) { + AggregationStrategy strategy = getAggregationStrategy(); + if (strategy == null && strategyRef != null) { + Object aggStrategy = routeContext.lookup(strategyRef, Object.class); + if (aggStrategy instanceof AggregationStrategy) { + strategy = (AggregationStrategy) aggStrategy; + } else if (aggStrategy != null) { + strategy = new AggregationStrategyBeanAdapter(aggStrategy, getStrategyMethodName()); + } else { + throw new IllegalArgumentException("Cannot find AggregationStrategy in Registry with name: " + strategyRef); + } + } + return strategy; + } + + public AggregationStrategy getAggregationStrategy() { return aggregationStrategy; } @@ -298,6 +326,14 @@ public class MulticastDefinition extends OutputDefinition<MulticastDefinition> i this.strategyRef = strategyRef; } + public String getStrategyMethodName() { + return strategyMethodName; + } + + public void setStrategyMethodName(String strategyMethodName) { + this.strategyMethodName = strategyMethodName; + } + public String getExecutorServiceRef() { return executorServiceRef; } http://git-wip-us.apache.org/repos/asf/camel/blob/aea2127e/camel-core/src/main/java/org/apache/camel/model/PollEnrichDefinition.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/PollEnrichDefinition.java b/camel-core/src/main/java/org/apache/camel/model/PollEnrichDefinition.java index 660064b..38310a6 100644 --- a/camel-core/src/main/java/org/apache/camel/model/PollEnrichDefinition.java +++ b/camel-core/src/main/java/org/apache/camel/model/PollEnrichDefinition.java @@ -26,6 +26,7 @@ import org.apache.camel.Endpoint; import org.apache.camel.Processor; import org.apache.camel.processor.PollEnricher; import org.apache.camel.processor.aggregate.AggregationStrategy; +import org.apache.camel.processor.aggregate.AggregationStrategyBeanAdapter; import org.apache.camel.spi.RouteContext; import org.apache.camel.util.ObjectHelper; @@ -46,6 +47,8 @@ public class PollEnrichDefinition extends NoOutputDefinition<PollEnrichDefinitio private Long timeout; @XmlAttribute(name = "strategyRef") private String aggregationStrategyRef; + @XmlAttribute(name = "strategyMethodName") + private String aggregationStrategyMethodName; @XmlTransient private AggregationStrategy aggregationStrategy; @@ -99,18 +102,31 @@ public class PollEnrichDefinition extends NoOutputDefinition<PollEnrichDefinitio enricher = new PollEnricher(null, endpoint.createPollingConsumer(), -1); } - if (aggregationStrategyRef != null) { - aggregationStrategy = routeContext.mandatoryLookup(aggregationStrategyRef, AggregationStrategy.class); - } - if (aggregationStrategy == null) { + AggregationStrategy strategy = createAggregationStrategy(routeContext); + if (strategy == null) { enricher.setDefaultAggregationStrategy(); } else { - enricher.setAggregationStrategy(aggregationStrategy); + enricher.setAggregationStrategy(strategy); } return enricher; } + private AggregationStrategy createAggregationStrategy(RouteContext routeContext) { + AggregationStrategy strategy = getAggregationStrategy(); + if (strategy == null && aggregationStrategyRef != null) { + Object aggStrategy = routeContext.lookup(aggregationStrategyRef, Object.class); + if (aggStrategy instanceof AggregationStrategy) { + strategy = (AggregationStrategy) aggStrategy; + } else if (aggStrategy != null) { + strategy = new AggregationStrategyBeanAdapter(aggStrategy, getAggregationStrategyMethodName()); + } else { + throw new IllegalArgumentException("Cannot find AggregationStrategy in Registry with name: " + aggregationStrategyRef); + } + } + return strategy; + } + public String getResourceUri() { return resourceUri; } @@ -143,6 +159,14 @@ public class PollEnrichDefinition extends NoOutputDefinition<PollEnrichDefinitio this.aggregationStrategyRef = aggregationStrategyRef; } + public String getAggregationStrategyMethodName() { + return aggregationStrategyMethodName; + } + + public void setAggregationStrategyMethodName(String aggregationStrategyMethodName) { + this.aggregationStrategyMethodName = aggregationStrategyMethodName; + } + public AggregationStrategy getAggregationStrategy() { return aggregationStrategy; } http://git-wip-us.apache.org/repos/asf/camel/blob/aea2127e/camel-core/src/main/java/org/apache/camel/model/RecipientListDefinition.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/RecipientListDefinition.java b/camel-core/src/main/java/org/apache/camel/model/RecipientListDefinition.java index e44e235..ee99d55 100644 --- a/camel-core/src/main/java/org/apache/camel/model/RecipientListDefinition.java +++ b/camel-core/src/main/java/org/apache/camel/model/RecipientListDefinition.java @@ -33,6 +33,7 @@ import org.apache.camel.processor.EvaluateExpressionProcessor; import org.apache.camel.processor.Pipeline; import org.apache.camel.processor.RecipientList; import org.apache.camel.processor.aggregate.AggregationStrategy; +import org.apache.camel.processor.aggregate.AggregationStrategyBeanAdapter; import org.apache.camel.processor.aggregate.UseLatestAggregationStrategy; import org.apache.camel.spi.RouteContext; import org.apache.camel.util.CamelContextHelper; @@ -56,6 +57,8 @@ public class RecipientListDefinition<Type extends ProcessorDefinition<Type>> ext @XmlAttribute private String strategyRef; @XmlAttribute + private String strategyMethodName; + @XmlAttribute private String executorServiceRef; @XmlAttribute private Boolean stopOnException; @@ -161,16 +164,24 @@ public class RecipientListDefinition<Type extends ProcessorDefinition<Type>> ext } }; } - + private AggregationStrategy createAggregationStrategy(RouteContext routeContext) { - if (aggregationStrategy == null && strategyRef != null) { - aggregationStrategy = routeContext.mandatoryLookup(strategyRef, AggregationStrategy.class); + AggregationStrategy strategy = getAggregationStrategy(); + if (strategy == null && strategyRef != null) { + Object aggStrategy = routeContext.lookup(strategyRef, Object.class); + if (aggStrategy instanceof AggregationStrategy) { + strategy = (AggregationStrategy) aggStrategy; + } else if (aggStrategy != null) { + strategy = new AggregationStrategyBeanAdapter(aggStrategy, getStrategyMethodName()); + } else { + throw new IllegalArgumentException("Cannot find AggregationStrategy in Registry with name: " + strategyRef); + } } - if (aggregationStrategy == null) { + if (strategy == null) { // fallback to use latest - aggregationStrategy = new UseLatestAggregationStrategy(); + strategy = new UseLatestAggregationStrategy(); } - return aggregationStrategy; + return strategy; } // Fluent API @@ -215,7 +226,18 @@ public class RecipientListDefinition<Type extends ProcessorDefinition<Type>> ext setStrategyRef(aggregationStrategyRef); return this; } - + + /** + * Sets the method name to use when using a POJO as {@link AggregationStrategy}. + * + * @param methodName the method name to call + * @return the builder + */ + public RecipientListDefinition<Type> aggregationStrategyMethodName(String methodName) { + setStrategyMethodName(methodName); + return this; + } + /** * Ignore the invalidate endpoint exception when try to create a producer with that endpoint * @@ -353,6 +375,14 @@ public class RecipientListDefinition<Type extends ProcessorDefinition<Type>> ext this.strategyRef = strategyRef; } + public String getStrategyMethodName() { + return strategyMethodName; + } + + public void setStrategyMethodName(String strategyMethodName) { + this.strategyMethodName = strategyMethodName; + } + public String getExecutorServiceRef() { return executorServiceRef; } http://git-wip-us.apache.org/repos/asf/camel/blob/aea2127e/camel-core/src/main/java/org/apache/camel/model/SplitDefinition.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/SplitDefinition.java b/camel-core/src/main/java/org/apache/camel/model/SplitDefinition.java index f6ea616..77d55d3 100644 --- a/camel-core/src/main/java/org/apache/camel/model/SplitDefinition.java +++ b/camel-core/src/main/java/org/apache/camel/model/SplitDefinition.java @@ -30,6 +30,7 @@ import org.apache.camel.model.language.ExpressionDefinition; import org.apache.camel.processor.CamelInternalProcessor; import org.apache.camel.processor.Splitter; import org.apache.camel.processor.aggregate.AggregationStrategy; +import org.apache.camel.processor.aggregate.AggregationStrategyBeanAdapter; import org.apache.camel.spi.RouteContext; import org.apache.camel.util.CamelContextHelper; @@ -50,6 +51,8 @@ public class SplitDefinition extends ExpressionNode implements ExecutorServiceAw @XmlAttribute private String strategyRef; @XmlAttribute + private String strategyMethodName; + @XmlAttribute private String executorServiceRef; @XmlAttribute private Boolean streaming; @@ -123,10 +126,17 @@ public class SplitDefinition extends ExpressionNode implements ExecutorServiceAw private AggregationStrategy createAggregationStrategy(RouteContext routeContext) { AggregationStrategy strategy = getAggregationStrategy(); if (strategy == null && strategyRef != null) { - strategy = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), strategyRef, AggregationStrategy.class); + Object aggStrategy = routeContext.lookup(strategyRef, Object.class); + if (aggStrategy instanceof AggregationStrategy) { + strategy = (AggregationStrategy) aggStrategy; + } else if (aggStrategy != null) { + strategy = new AggregationStrategyBeanAdapter(aggStrategy, strategyMethodName); + } else { + throw new IllegalArgumentException("Cannot find AggregationStrategy in Registry with name: " + strategyRef); + } } return strategy; - } + } // Fluent API // ------------------------------------------------------------------------- @@ -153,6 +163,17 @@ public class SplitDefinition extends ExpressionNode implements ExecutorServiceAw } /** + * Sets the method name to use when using a POJO as {@link AggregationStrategy}. + * + * @param methodName the method name to call + * @return the builder + */ + public SplitDefinition aggregationStrategyMethodName(String methodName) { + setStrategyMethodName(methodName); + return this; + } + + /** * Doing the splitting work in parallel * * @return the builder @@ -319,6 +340,14 @@ public class SplitDefinition extends ExpressionNode implements ExecutorServiceAw this.strategyRef = strategyRef; } + public String getStrategyMethodName() { + return strategyMethodName; + } + + public void setStrategyMethodName(String strategyMethodName) { + this.strategyMethodName = strategyMethodName; + } + public String getExecutorServiceRef() { return executorServiceRef; } http://git-wip-us.apache.org/repos/asf/camel/blob/aea2127e/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregationStrategyBeanAdapter.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregationStrategyBeanAdapter.java b/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregationStrategyBeanAdapter.java index 21d8199..5cf55ba 100644 --- a/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregationStrategyBeanAdapter.java +++ b/camel-core/src/main/java/org/apache/camel/processor/aggregate/AggregationStrategyBeanAdapter.java @@ -40,8 +40,6 @@ public final class AggregationStrategyBeanAdapter extends ServiceSupport impleme // TODO: Add parameter bindings for: // - @Header / @Property / @XPath etc // - CamelContext, Registry, etc. - // TODO: Add DSL support in Java DSL - // TODO: Add DSL support in XML DSL private static final List<Method> EXCLUDED_METHODS = new ArrayList<Method>(); private CamelContext camelContext; http://git-wip-us.apache.org/repos/asf/camel/blob/aea2127e/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregationStrategyBeanAdapterRefMethodNameTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregationStrategyBeanAdapterRefMethodNameTest.java b/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregationStrategyBeanAdapterRefMethodNameTest.java new file mode 100644 index 0000000..1c42a9c --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregationStrategyBeanAdapterRefMethodNameTest.java @@ -0,0 +1,70 @@ +/** + * 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.aggregator; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.impl.JndiRegistry; + +public class AggregationStrategyBeanAdapterRefMethodNameTest extends ContextTestSupport { + + @Override + protected JndiRegistry createRegistry() throws Exception { + JndiRegistry jndi = super.createRegistry(); + jndi.bind("myAppender", new AggregationStrategyBeanAdapterRefMethodNameTest.MyBodyAppender()); + return jndi; + } + + public void testAggregate() throws Exception { + getMockEndpoint("mock:result").expectedBodiesReceived("ABC"); + + template.sendBody("direct:start", "A"); + template.sendBody("direct:start", "B"); + template.sendBody("direct:start", "C"); + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .aggregate(constant(true)).aggregationStrategyRef("myAppender").aggregationStrategyMethodName("append") + .completionSize(3) + .to("mock:result"); + } + }; + } + + public static final class MyBodyAppender { + + public String append(String existing, String next) { + if (next != null) { + return existing + next; + } else { + return existing; + } + } + + public String foo(String foo, String bar) { + return "foobar"; + } + + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/aea2127e/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregationStrategyBeanAdapterRefTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregationStrategyBeanAdapterRefTest.java b/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregationStrategyBeanAdapterRefTest.java new file mode 100644 index 0000000..9c5ea32 --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregationStrategyBeanAdapterRefTest.java @@ -0,0 +1,66 @@ +/** + * 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.aggregator; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.impl.JndiRegistry; + +public class AggregationStrategyBeanAdapterRefTest extends ContextTestSupport { + + @Override + protected JndiRegistry createRegistry() throws Exception { + JndiRegistry jndi = super.createRegistry(); + jndi.bind("myAppender", new AggregationStrategyBeanAdapterTest.MyBodyAppender()); + return jndi; + } + + public void testAggregate() throws Exception { + getMockEndpoint("mock:result").expectedBodiesReceived("ABC"); + + template.sendBody("direct:start", "A"); + template.sendBody("direct:start", "B"); + template.sendBody("direct:start", "C"); + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .aggregate(constant(true)).aggregationStrategyRef("myAppender") + .completionSize(3) + .to("mock:result"); + } + }; + } + + public static final class MyBodyAppender { + + public String append(String existing, String next) { + if (next != null) { + return existing + next; + } else { + return existing; + } + } + + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/aea2127e/components/camel-spring/src/test/java/org/apache/camel/spring/processor/aggregator/SpringAggregationStrategyBeanAdapterRefMethodNameTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/aggregator/SpringAggregationStrategyBeanAdapterRefMethodNameTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/aggregator/SpringAggregationStrategyBeanAdapterRefMethodNameTest.java new file mode 100644 index 0000000..546aac6 --- /dev/null +++ b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/aggregator/SpringAggregationStrategyBeanAdapterRefMethodNameTest.java @@ -0,0 +1,32 @@ +/** + * 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.aggregator; + +import org.apache.camel.CamelContext; +import org.apache.camel.processor.aggregator.AggregationStrategyBeanAdapterRefMethodNameTest; + +import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext; + +/** + * @version + */ +public class SpringAggregationStrategyBeanAdapterRefMethodNameTest extends AggregationStrategyBeanAdapterRefMethodNameTest { + + protected CamelContext createCamelContext() throws Exception { + return createSpringCamelContext(this, "org/apache/camel/spring/processor/aggregator/SpringAggregationStrategyBeanAdapterRefMethodNameTest.xml"); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/aea2127e/components/camel-spring/src/test/java/org/apache/camel/spring/processor/aggregator/SpringAggregationStrategyBeanAdapterRefTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/aggregator/SpringAggregationStrategyBeanAdapterRefTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/aggregator/SpringAggregationStrategyBeanAdapterRefTest.java new file mode 100644 index 0000000..626861a --- /dev/null +++ b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/aggregator/SpringAggregationStrategyBeanAdapterRefTest.java @@ -0,0 +1,32 @@ +/** + * 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.aggregator; + +import org.apache.camel.CamelContext; +import org.apache.camel.processor.aggregator.AggregationStrategyBeanAdapterRefTest; + +import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext; + +/** + * @version + */ +public class SpringAggregationStrategyBeanAdapterRefTest extends AggregationStrategyBeanAdapterRefTest { + + protected CamelContext createCamelContext() throws Exception { + return createSpringCamelContext(this, "org/apache/camel/spring/processor/aggregator/SpringAggregationStrategyBeanAdapterRefTest.xml"); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/aea2127e/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator/SpringAggregationStrategyBeanAdapterRefMethodNameTest.xml ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator/SpringAggregationStrategyBeanAdapterRefMethodNameTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator/SpringAggregationStrategyBeanAdapterRefMethodNameTest.xml new file mode 100644 index 0000000..1bcb061 --- /dev/null +++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator/SpringAggregationStrategyBeanAdapterRefMethodNameTest.xml @@ -0,0 +1,41 @@ +<?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: e1 --> + <camelContext xmlns="http://camel.apache.org/schema/spring"> + <route> + <from uri="direct:start"/> + <aggregate strategyRef="myAppender" strategyMethodName="append" completionSize="3"> + <correlationExpression> + <constant>true</constant> + </correlationExpression> + <to uri="mock:result"/> + </aggregate> + </route> + </camelContext> + + <bean id="myAppender" class="org.apache.camel.processor.aggregator.AggregationStrategyBeanAdapterRefMethodNameTest.MyBodyAppender"/> + <!-- END SNIPPET: e1 --> + +</beans> http://git-wip-us.apache.org/repos/asf/camel/blob/aea2127e/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator/SpringAggregationStrategyBeanAdapterRefTest.xml ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator/SpringAggregationStrategyBeanAdapterRefTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator/SpringAggregationStrategyBeanAdapterRefTest.xml new file mode 100644 index 0000000..535c01d --- /dev/null +++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aggregator/SpringAggregationStrategyBeanAdapterRefTest.xml @@ -0,0 +1,41 @@ +<?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: e1 --> + <camelContext xmlns="http://camel.apache.org/schema/spring"> + <route> + <from uri="direct:start"/> + <aggregate strategyRef="myAppender" completionSize="3"> + <correlationExpression> + <constant>true</constant> + </correlationExpression> + <to uri="mock:result"/> + </aggregate> + </route> + </camelContext> + + <bean id="myAppender" class="org.apache.camel.processor.aggregator.AggregationStrategyBeanAdapterRefTest.MyBodyAppender"/> + <!-- END SNIPPET: e1 --> + +</beans>