Hi I guess its a bit expected as the output from jackson is streaming based and even so when stream caching is enabled - then when you convert the payload the 2nd time in the expectation then the payload has not been reset prior and therefore is eol, and the assertion fails.
Camel will automatic reset stream caching (when possible) during routing, so if you had 2 mock endpoints mock:a and mock:b, and each had one assertion like yours, then it would work. However as Gregor writes it seems we have improved something somewhere in 2.20 > 2.19 that mitigates this problem. It could be in camel-jackson or Camel data formats, or in some stream caching type converter, etc. I haven't looked deeper or tried to run this test / debug it etc. You can just add a .convertBodyTo(String.class) before your mock endpoint and your test on 2.19.x would work. An alternative is to consider making mock endpoint reset the stream caching for each expectation it evaluations (which would be like some kind of root fix). On Fri, Nov 10, 2017 at 7:12 PM, Minhtri Tran <mtran7...@gmail.com> wrote: > Hello, > > I am currently having an issue with setting up multiple expectations > in a test case when streamCaching is enabled and json marshalling is > used. Every expectation except the first one fails. > > Here’s my test class: > > @RunWith(CamelSpringBootRunner.class) > > @SpringBootTest(classes = MyApplication.class) > > public class MyTest extends CamelTestSupport { > > > > @Test > > public void test() throws Exception { > > class Hello { > > Hello(String value) { > > this.value = value; > > } > > > > private String value; > > > > public String getValue() { > > return value; > > } > > > > public void setValue(String value) { > > this.value = value; > > } > > } > > > > MockEndpoint mock = getMockEndpoint("mock:dest"); > > mock.message(0).body().convertToString().contains("hello"); > > mock.message(0).body().convertToString().contains("world"); > > template.sendBody("direct:source", new Hello("hello world")); > > mock.assertIsSatisfied(); } > > > > @Override > > protected RoutesBuilder createRouteBuilder() throws Exception { > > return new RouteBuilder() { > > @Override > > public void configure() throws Exception { > > from("direct:source") > > .streamCaching() > > .marshal().json(JsonLibrary.Jackson) > > .to("mock:dest"); > > } > > }; > > } > > } > > > > This is the assertion error that I’m getting: > > java.lang.AssertionError: Assertion error at index 0 on mock > mock://dest with predicate: Simple: body contains world evaluated as: > contains world on Exchange[ID-A1504214-60132-1508506055845-1-2] > > > > Why is this happening? How can I set multiple expectations on the > same message body in this case? > > > > Thanks, > > Minhtri -- Claus Ibsen ----------------- http://davsclaus.com @davsclaus Camel in Action 2: https://www.manning.com/ibsen2