Say I have the following route:
from(rabbitMQUri)
.to(myCustomerProcessor)
.choice()
.when(shouldGotoA)
.to(fizz)
.when(shouldGotoB)
.to(buzz)
.otherwise()
.to(foo);
Let's pretend that myCustomProcessor
tunes shouldGotoA
and shouldGotoB
according to the message consumed from RabbitMQ.
I would like to unit test 3 scenarios:
- A "fizz" message is consumed and
shouldGotoA
is set to true, which executes the firstwhen(...)
. - A "buzz" message is consumed and
shouldGotoB
is set to true, which executes the secondwhen(...)
. - A "foo" message is consumed and the
otherwise()
is executed.
My question is: how do I mock/stub the RabbitMQ endpoint so that the route executes as it normally will in production, but so that I don't have to actually connect the test to a RabbitMQ server? I need some kind of "mock message" producer.
A code example or snippet would be extremely helpful and very much so appreciated!
See Question&Answers more detail:os