camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Henryk Konsek <hekon...@gmail.com>
Subject Re: How to create a message manually for mock testing
Date Mon, 13 Aug 2012 14:27:18 GMT
Hi Gael,

> I am creating a Junit class and would like to create a mock representing a
> message.
> Is there a way to initialize "mockMessage" as a Camel Message using the
> method "setBody", etc... ?

Actually mocking the message is not the best way to test Camel
routing, since by mocking message you test the Camel internals instead
of your routes.

Mocks should be used to verify the interaction with the collaborators.
Since Message is a part of the Camel core API, the Camel framework
will perform a lot of such interaction under the hood. This will lead
to many unexpected results while verifying the mocks.

Remember also that messages can be copied by the Camel while passed to
some EIPs [1] (for example for the multicast). This also makes mocked
message conception a bit missed for Camel.

In general - keep in mind that Camel operates on higher level of
abstraction than POJO objects.

Mocking in Camel is realized via Mock component [2]. It allows you to
focus on the verification of the routing logic without worrying about
the influence of Camel infrastructure on the exchanged messages.

[1] http://camel.apache.org/eip.html
[2] http://camel.apache.org/mock.html

-- 
Henryk Konsek
http://henryk-konsek.blogspot.com

Mime
View raw message