这是使用 mockEndpoint.getExchanges() 解决它的一个示例
public class XmlUnitTest extends CamelTestSupport{
@EndpointInject(uri = "mock:market-out")
MockEndpoint marketOut;
@Override
@Before
public void setUp() throws Exception {
super.setUp();
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:in")
.setBody(constant("<xml>data</xml>"))
.to(marketOut.getEndpointUri());
}
});
}
@Test
public void sameXml() throws Exception {
marketOut.expectedMessageCount(1);
template.sendBody("direct:in", "body");
marketOut.assertIsSatisfied();
final String actual = marketOut.getExchanges().get(0).getIn().getBody(String.class);
final Diff diff = XMLUnit.compareXML("<xml>data</xml>", actual);
assertTrue(diff.similar());
assertTrue(diff.identical());
}
@Test()
public void notSameXml() throws Exception {
marketOut.expectedMessageCount(1);
template.sendBody("direct:in", "body");
marketOut.assertIsSatisfied();
final String actual = marketOut.getExchanges().get(0).getIn().getBody(String.class);
final Diff diff = XMLUnit.compareXML("<xml>invalid</xml>", actual);
assertFalse(diff.similar());
assertFalse(diff.identical());
}
}