Daniel
Daniel

Reputation: 2500

How to test a route using CamelJmsDestinationName?

I have a processor where I'm using the CamelJmsDestinationName header to dynamically determine to destination in one of my routes (details here).

So in my processor I'm setting the header

exchange.getIn().setHeader("CamelJmsDestinationName",messageExport.getEndpoint());

Then in my route, I have the following clause

.when(header("CamelJmsDestinationName").isNotNull())
   //Set to dummy, actual queue name will be set by processor (CamelJmsDestinationName)
   .to("activemq:queue:dummy")
.otherwise()
   .to("{{message.export.no_type_match}}")
   .log(LoggingLevel.ERROR, "Message could not be matched to an existing route");

This works exactly as I expect. However I'm struggling with writing unit test for this route. How can I test that the message ends up in whatever value I set for CamelJmsDestinationName?

Upvotes: 0

Views: 938

Answers (1)

vikingsteve
vikingsteve

Reputation: 40378

I suggest the easiest approach is to use a property for the "activemq:queue:" part and set it to "mock:activemq" in your testing.

.when(header("CamelJmsDestinationName").isNotNull())
   //Set to dummy, actual queue name will be set by processor (CamelJmsDestinationName)
   .to("{{activemq.endpoint}}:dummy")
.otherwise()
   .to("{{message.export.no_type_match}}")
   .log(LoggingLevel.ERROR, "Message could not be matched to an existing route");

And then you can write tests where "activemq.endpoint" property is "mock", therefore you can test versus mock endpoints named mock:dummy, etc.

There is another approach where you can write a mock version of the activemq component, but it is more involved.

Upvotes: 2

Related Questions