L.S.,
At first glance, it seems to me that the correct result is returned. Only the order of the attributes within the XML element has changed, but everything is there. I don't think that there is a way to enforce this order of attributes, it's probably being rearranged while parsing the XML document for the XPath splitter.
One possible solution is to check the id attribute in your test afterwards using the DOM API instead of using the expectedBodies(...): resultEndpoint.assertIsSatisfied(); assertEquals("2909509", resultEndpoint.assertExchangeReceived(0).getIn().getBody(Element.class).getAttribute("id")); assertEquals("2866397", resultEndpoint.assertExchangeReceived(1).getIn().getBody(Element.class).getAttribute("id"));
Regards, Gert arjanm wrote:
With this simple example the test is passing indeed. But when I feed a slightly more complicated xml it is failing. Maybe it's just something simple I'm overlooking... public void testXPathWithRUFixtures() throws Exception { log.debug("testXPathWithRUFixtures()"); context.addRoutes( new RouteBuilder() { @Override public void configure() {from("direct:xpathrufix").splitter(xpath("/rugbyFixtures/rugbyFixture")).to("mock:result");} } );final String fixture1 = "<rugbyFixture id=\"2909509\" venue=\"Parc des Princes\" "+"date=\"2007-10-19\" time=\"20:00:00\">"+ "<homeTeam id=\"33176\" name=\"France\" />"+ "<awayTeam id=\"33085\" name=\"Argentina\" />"+ "<competition id=\"700\" name=\"World Cup\" />"+ "</rugbyFixture>";final String fixture2 = "<rugbyFixture id=\"2866397\" venue=\"Kingston Park\" "+"date=\"2007-10-21\" time=\"14:00:00\">"+ "<homeTeam id=\"34698\" name=\"Newcastle\" />"+ "<awayTeam id=\"33094\" name=\"Bath\" />"+ "<competition id=\"100\" name=\"Guinness Premiership\" />"+ "</rugbyFixture>";resultEndpoint.expectedBodiesReceived(fixture1, fixture2);template.send("direct:xpathrufix", new Processor() { public void process(Exchange exchange) { Message in = exchange.getIn(); in.setBody(//"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+"<rugbyFixtures>"+fixture1+fixture2+"</rugbyFixtures>");} });resultEndpoint.assertIsSatisfied();} The error is: java.lang.AssertionError: mock:result Body of message: 0. Expected: <<rugbyFixture id="2909509" venue="Parc des Princes" date="2007-10-19" time="20:00:00"><homeTeam id="33176" name="France" /><awayTeam id="33085" name="Argentina" /><competition id="700" name="World Cup" /></rugbyFixture>> but was: <<rugbyFixture date="2007-10-19" id="2909509" time="20:00:00" venue="Parc des Princes"><homeTeam id="33176" name="France"/><awayTeam id="33085" name="Argentina"/><competition id="700" name="World Cup"/></rugbyFixture>> at org.apache.camel.component.mock.MockEndpoint.fail(MockEndpoint.java:531) at org.apache.camel.component.mock.MockEndpoint.assertEquals(MockEndpoint.java:513) at org.apache.camel.component.mock.MockEndpoint$2.run(MockEndpoint.java:252) at org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied(MockEndpoint.java:179) at org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied(MockEndpoint.java:144) at com.bbc.newsi.feeds.common.dslroutes.CamelTest.testXPathWithRUFixtures(CamelTest.java:101)
