camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Babak Vahdat <babak.vah...@swissonline.ch>
Subject Re: Splitter + aggregator + dynamic timeout
Date Mon, 13 Aug 2012 10:18:36 GMT
Hi

the sample unit-test Alek has already provided by this thread puzzles me a
bit, so I changed it to a minimum (without parallel processing) which I
expect it to pass but it doesn't as "mock:result" is not satisfied:

    java.lang.AssertionError: mock://result Body of message: 0. Expected:
<1+2+3> but was: <A,B,C>

However "mock:result2" is satisfied, which is as expected.

Can someone please advice me about the point I'm missing, or could it maybe
a bug?

public class SplitterWithAggregatorTest extends CamelTestSupport {

    @Test
    public void shouldProcessCorrectlyOnBothSources() throws Exception {
        getMockEndpoint("mock:result").expectedBodiesReceived("1+2+3");
        getMockEndpoint("mock:result2").expectedBodiesReceived("1+2+3");

        template.requestBody("direct:start", "A,B,C");

        assertMockEndpointsSatisfied();
    }

    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("direct:start").to("direct:process").to("mock:result");

                from("direct:process").split(body()).bean(new
Responder()).aggregate(header("myId"), new
MyAggregationStrategy()).completionSize(3).to("mock:result2");
            }
        };
    }

    public static class Responder {

        public String translate(Exchange exchange, String body) {
            exchange.getIn().setHeader("myId", "myValue");

            if ("A".equals(body)) {
                return "1";
            } else if ("B".equals(body)) {
                return "2";
            } else if ("C".equals(body)) {
                return "3";
            } else {
                throw new IllegalArgumentException("bla bla");
            }
        }

    }

    public static class MyAggregationStrategy implements AggregationStrategy
{

        public Exchange aggregate(Exchange oldExchange, Exchange
newExchange) {
            if (oldExchange == null) {
                return newExchange;
            }

            String oldBody = oldExchange.getIn().getBody(String.class);
            String newBody = newExchange.getIn().getBody(String.class);
            oldExchange.getIn().setBody(oldBody + "+" + newBody);
            return oldExchange;
        }

    }
}


Thanks, Babak



--
View this message in context: http://camel.465427.n5.nabble.com/Splitter-aggregator-dynamic-timeout-tp5717166p5717221.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message