A simple route
We are using 3 queues: seda:groceries, seda:fruits and seda:vegetables. In case you're wondering what SEDA is, it's just an in-memory queue provided by Camel and it can be replaced by anything else like JMS or RabbitMQ, the principle stays the same.
The type of objects pushed into the groceries queue is checked via Camel's choice() construct and the fruits are redirected into the fruits queue, while the vegetables are redirected into the vegetables queue. The fruits queue is processed by FruitProcessor and the vegetable queue is processed by VegetableProcessor.
The type of objects pushed into the groceries queue is checked via Camel's choice() construct and the fruits are redirected into the fruits queue, while the vegetables are redirected into the vegetables queue. The fruits queue is processed by FruitProcessor and the vegetable queue is processed by VegetableProcessor.
The test setup
In order to test the routes, we need to start Camel, which is not possible using the production configuration, considering the fact that Camel will connect to various third party services. Also, we need to make sure that we don't run the real processors, because we only want to test the routes.
This is the test setup, which is actually the complicated part of all this:
This is the test setup, which is actually the complicated part of all this:
A few essential points for the test setup:
- We are using CamelSpringJUnit4ClassRunner to run the tests
- The test has its own configuration, defined in the ContextConfig inner class, which extends SingleRouteCamelConfiguration
- The route() method in ContextConfig() defines the route builder class that we are testing
- All the processors are defined as beans and they are mocked by using Camel's MockEndpoint. That allows us to replace the actual processors with mocks and make assertions on how the messages are travelling through the routes.
- The mock processors are autowired into the test class so that assertions can be made against them
The tests
After the setup is complete, the actual tests are quite straightforward:
- When I push a Fruit object into the groceries queue, I would like the FruitProcessor to process the message
- When I push a Vegetable object into the groceries queue, I would like the VegetableProcessor to process the message
This is the actual code:
There are many ways to go about testing the routes, but the setup and test strategy remain the same. I hope you found this useful, if you did then please share. The maven project is available here.
nice blog keep it up Hindbiz
ReplyDeletePretty! This was a really wonderful post. Thank you for providing these details.
ReplyDeleteBanfield Pet Hospital
Famous Dave's
HuHot
Xero Customer service is available 24/7 for all types of issues related to Xero. We help people to manage their financial Account for future used.
ReplyDeleteShadow Creation is the process to change the color of an image or video..Shadow Creation It means correcting the lighting, white color balance, red or blue color balance, so that the image looks more clear or natural
ReplyDeleteSafe moving of your stock just with us, In the blink of an eye you require not worry over damage to the stock in the midst of moving. We have a gathering of capable workers who pack your stock appropriately. We know the estimation of your things in this way we move your stock precisely that does not hurt your items. So if you are in Faridabad and need to move then Relocato Removals, Delhi is the best option for you. You can see each one of your stock moved in an astoundingly shielded route with no damage done. In case you are in Faridabad and hunting down a place change then after organizations are open for you in Delhi.
ReplyDeleteBest Packers and Movers in Delhi
ReplyDeleteBudgetary moving our specialty, Do you assume that? We finish moving in an especially mild way. That is our specialty. We understand that it has ended up being difficult to administer step by step costs nowadays. However, our expenses will make you feel like the cool twist in the blazing warmth. So now loosen up. Do whatever it takes not to think twice and totally depend on upon us. The organizations gave by us indicated underneath. We have phenomenal expenses for our organizations which will make you smile.
Best Packers and Movers in Noida
Thanks on your marvelous posting! I really enjoyed reading it, you’re a great author.Please visit here: Local Packers And Movers Bangalore
ReplyDelete