camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Henryk Konsek <>
Subject Re: Question about using message headers/Exchange properties and route testing
Date Mon, 30 Dec 2013 09:21:21 GMT
Hi Stephan,

> My problem arised in the route tests where I mock away the whole bean. I
> can mock the method call, but I cannot add entries to the header- or
> property-maps. So if the header or property entry is expected later in the
> route, it fails.

Keep in mind that in tests you can send messages via ProducerTemplate
with some arbitatry headers/properties. Since headers and properties
are propagated with the messages down the route, you can set test
fixtures this way.

producerTemplate.sendBodyAndHeader("direct:test", "message",
"expected_header_key", "expected_header_value");

In production environment "expected_header_key" could be set by your
bean, but for unit tests you would pass it explicitly as a fixture to
the producer template initiating the test.

This approach usually works for me. For more complicated cases (for
example when you need to alter the header within the route), you can
use AdviceWith [1] or interceptors [2].



Henryk Konsek

View raw message