I tried some of mock.expect* methods, but I couldnt write the assert with
one of them. Is this possible?

Jan

-----Ursprüngliche Nachricht-----
Von: Jan Matèrne (jhm) [mailto:apa...@materne.de] 
Gesendet: Montag, 4. Februar 2013 14:24
An: users@camel.apache.org
Betreff: AW: Calling count function in the camel route

Played a little bit with that.
This example works for me.

cheers
Jan


public class XpathCountTest extends CamelTestSupport {

        @Test
        public void count() {
                final MockEndpoint mock = getMockEndpoint("mock:result");
        mock.expectedMessageCount(1);
        
        template.sendBody("direct:in", "<root><A/><A/><B/><A/></root>");
        
        assertEquals(
                "Wrong count",
                3,
                mock.getExchanges().get(0).getIn().getHeader("count"));
        }
        
        @Override
        protected RouteBuilder createRouteBuilder() throws Exception {
                return new RouteBuilder() {
                        public void configure() {
                                from("direct:in")
                                    .setHeader("count",
xpath("count(//A)").resultType(Integer.class))
                                    .to("mock:result");
                        }
                };
        }
        
}

-----Ursprüngliche Nachricht-----
Von: Claus Ibsen [mailto:claus.ib...@gmail.com]
Gesendet: Montag, 4. Februar 2013 14:07
An: users@camel.apache.org
Betreff: Re: Calling count function in the camel route

On Mon, Feb 4, 2013 at 1:45 PM, dkum003 <dhananjay.ku...@amadeus.com> wrote:
> Hi Claus,
>
> The xml is pretty simple.. say a list of tags...
>
>
> So i need to get the count of h3 tags and store it in the exchange header.
>

Hi

See this page
http://camel.apache.org/xpath

About namespace auditing. If your xml has namespaces, then your xpath
expression must have that as well.
And then its not so easy to get working.

There may be some xpath tools / tutorials you can take a look at to make the
count work

Maybe something like
"count(//h3)"

Mind that if you have namesapces, you need to add that to the count
"count(//foo:h3)"

Where foo is your namespace "key".



> Thanks.
>
>
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/Calling-count-function-in-the-camel-
> route-tp5726886p5726891.html Sent from the Camel - Users mailing list 
> archive at Nabble.com.



--
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cib...@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen


Reply via email to