0
votes

I have a spring boot application with camel. I have a java defined route. I am using selector in that.

 from("jms:Q1?selector=fruit='apple'").process(appleProcessor);
 from("jms:Q1?selector=fruit='orange'").process(orangeProcessor);

I want to write a test case where I need to validate if the selector worked properly and if the correct processor was invoked.

So how to mock the processor. Is it like mocking endpoint.

Or is it like mocking an object (the appleProcessor, defining its bean in a context configuration class) and validating by:

Mockito.verify(appleProcessor, VerificationModeFactory.times(1)).process(Mockito.any());

In my test case I use the ProducerTemplate to send the msg, and my route is being invoked correctly.

Please help.

1

1 Answers

-1
votes

I don't fully understand what you are trying to achieve. JMS selector will work correctly, This is (or should be) guaranteed by Camel's unit tests and Spring JMS unit tests.

If you want to ensure that the selector is working, you should create an integration test, publish some messages in the queue, check the queue and the processors. I don't think it will add any value.

Conversely, if you want to test that an 'apple' message goes to appleProcessor, this is a unit test of your code. Your approach using ProducerTemplate is good. I think that the problem lies in the fact that your processor is the last step in the chain. You could refactor your routes:

from("jms:Q1?selector=fruit='apple'").to("direct:processApple");
from("direct:processApple").process(appleProcessor);

from("jms:Q1?selector=fruit='orange'").to("direct:processOrange")
from("direct:processOrange").process(orangeProcessor);

Now you can mock direct: endpoints and assert that they received the expected message count.

Unit testing each processor is another test, of course.