Sunday, 24 July 2016

Testing Apache Camel routes

Running Apache Camel on top of Spring is quite popular nowadays and there is a multitude of resources on how to create the routes. However, sooner or later you will want to test the routes and this is where people usually hit a brick wall, because the documentation is a bit confusing. If you're still trying to find a good way to test your routes, then read on.

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 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:



A few essential points for the test setup:
  1. We are using CamelSpringJUnit4ClassRunner to run the tests
  2. The test has its own configuration, defined in the ContextConfig inner class, which extends SingleRouteCamelConfiguration
  3. The route() method in ContextConfig() defines the route builder class that we are testing
  4. 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.
  5. 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:
  1. When I push a Fruit object into the groceries queue, I would like the FruitProcessor to process the message
  2. 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.

Share on Twitter | Share on Facebook | Share on Google+

31 comments:

  1. I regard something truly interesting about your web blog so I saved to favorites .
    Packers And Movers in Bangalore

    ReplyDelete
  2. It has always been my belief that very good writing such as this takes researching and also talent. It’s very apparent you have performed your homework.Good job!Also visit my web blog …
    Packers And Movers Bangalore

    ReplyDelete
  3. I must be thankful for sharing your ideas.Thank you for the good writeup.its a brellint job.please visit here for more detail:
    Packers and Movers Delhi
    http://packers-and-movers-delhi.in/packers-and-movers-noida

    ReplyDelete

  4. Manish Packers and Movers Pvt Ltd as a Services providing company can make all the difference to your Home Relocation experience. Indore based Company which offers versatile solutions, Right team that easily reduce the stress associated with a Household Shifting, Vehicle Transportation. we help things run smoothly and reduce breakages and offer you seamless, Affordable, Reliable Shifting Services, Compare Shifting Charges, Visit :
    https://www.manishpackersmoversindore.in/
    https://www.manishpackersmoversindore.in/packers-and-movers-indore.html
    https://www.manishpackersmoversindore.in/manish-packers-and-movers-indore.html
    https://www.manishpackersmoversindore.in/packers-movers-gurgaon.html
    https://www.manishpackersmoversindore.in/packers-movers-kolkata.html
    https://www.manishpackersmoversindore.in/packers-movers-mumbai.html
    https://www.manishpackersmoversindore.in/packers-movers-bhopal.html
    https://www.manishpackersmoversindore.in/packers-movers-nagpur.html
    https://www.manishpackersmoversindore.in/packers-movers-raipur.html
    https://www.manishpackersmoversindore.in/packers-movers-ahmedabad.html

    ReplyDelete
  5. Hire Manish Packers and Movers Pvt Ltd in India for hassle-free Household Shifting, Office Relocation, Car Transporation, Loading Unloading, packing Unpacking at affordable Price Quotation. Top Rated Safe and Secure Service Providers who can help you with 24x7 and make sure a Untroubled Relocation Services at Cheapest/Lowest Rate. Visit More :-
    Manish Packers and Movers Pvt Ltd
    Packers and Movers Bangalore
    Packers and Movers Gurgaon
    Packers and Movers Indore
    Packers and Movers Kolkata
    Packers and Movers Mumbai
    Packers and Movers Nagpur
    Packers and Movers Ahmedabad
    Manish Packers in Indore
    Manish Packers and Movers Pvt Ltd Sitemap

    ReplyDelete

  6. اننا في شركة الرائد للخدمات المنزلية نقدم خدمات ممتازة في الدمام بافضل الاسعار بجودة عالية لمزيد من الخدمات تفضل بزيارة

    شركة مكافحة حشرات بالدمام شركة مكافحة حشرات بالدمام
    شركة تنظيف سجاد بالدمام شركة تنظيف سجاد بالدمام
    شركة تسليك مجاري بالدمام شركة تسليك مجاري بالدمام
    افضل شركة تنظيف بالدمام افضل شركة تنظيف بالدمام
    شركة مكافحة الفئران بالدمام شركة مكافحة الفئران بالدمام
    ارخص شركة نقل عفش بالدمام ارخص شركة نقل عفش بالدمام

    ReplyDelete
  7. Packers and Movers Chennai Give Safe and Reliable ***Household Shifting Services in Chennai with Reasonable ###Packers and Movers Price Quotation. We Provide Household Shifting, Office Relocation, ✔✔✔Local and Domestic Transportation Services, Affordable and Reliable Shifting Service Charges @
    Packers And Movers Chennai

    ReplyDelete
  8. Background Removal Services (BRS) is one of the best Clipping path service provider around the world. We offer our global customers: Raster to Vector Services, Photo Restoration Services Prices, Photo Neck Joint Service, Exposure Color Correction Service, Jewelry Photo, Retouching Services, Photo Color Correction Service, Image Mirror Effect Service, Cheap Retouching Services, Deep Etching Service,

    ReplyDelete
  9. أفضل شركة نقل في الطائف والنجارين في إعمار في تفكيك وتركيب الأثاث

    ReplyDelete
  10. أفضل شركة نقل في المدينة المنورة والنجارين المبهرين في تفكيك وتركيب الأثاث والمفروشات.

    ReplyDelete
  11. Turbo Steam is a powerful, yet portable, fabric and clothes steamer for all of your steaming needs. Our Turbo Steam takes only 45 seconds to heat up and to start generating steam and its steam delivery system evenly distributes steam across fabrics to remove even the worst wrinkles.

    ReplyDelete
  12. Best Photo Retouch Services information is here for you go our site to read the ultimate guide to photo retouching service and image retouch

    ReplyDelete
  13. Packers and Movers Indore - Call 09303355424, Local Household Shifting in Indore, Domestic Home Relocation from Indore. International Home Relocation from Indore, Office Shifting within Indore, Car and Bike Transportation from Indore, Safe Packing and Moving Services,
    Best Packers and Movers Indore
    Best Packers and Movers Gurgaon
    Best Packers and Movers Kolkata
    Best Packers and Movers Mumbai
    Best Packers and Movers Bhopal
    Best Packers and Movers Delhi
    Best Packers and Movers Jaipur
    Best Packers and Movers Raipur
    Best Packers and Movers Pune
    Best Packers and Movers Ahmedabad

    ReplyDelete
  14. Using the Images Background Remover service, you can get the best possible solutions. The photos will be livelier and you can use them anywhere. The importance of Background Remover Online is undeniable for every photo. Before we move to the benefits of having the service, it is better to know about the service.

    ReplyDelete
  15. In other sense, the clipping path is like creating a path that will remove the bars from the photo. As the name suggests, it clips a path. It points that the path that you not need gets clipped. The ClippingPath Service Provider is able to bring the change in the photos. Applying the Photoshop tool, the provider does the task.

    ReplyDelete

  16. Hire Best Packers And Movers Mumbai for hassle-free Household Shifting, ***Office Relocation, ###Car Transporation, Loading Unloading, packing Unpacking at affordable ✔✔✔ Price Quotation. Top Rated, Safe and Secure Service Providers who can help you with 24x7 and make sure a Untroubled Relocation Services at Cheapest/Lowest Rate
    Packers And Movers Mumbai

    ReplyDelete
  17. Prom Dress Hut is a prom dresses company. If you are looking for a prom dress, check out our Latest Prom Dress Collection. You can order from Prom Dresses USA, Prom Dresses UK, Prom Dresses Australia, Prom Dresses Canada, and Prom Dresses Germany.

    ReplyDelete
  18. Packers and Movers Hyderabad Give Certified and Verified Service Providers, Cheap and Best ###Office Relocation Charges, ***Home Shifting, ✔ ✔ ✔ Goods Insurance worth Rs. 10,000, Assurance for Local and Domestic House Shifting. Safe and Reliable Household Shifting Services in Hyderabad with Reasonable Packers and Movers Price Quotation @
    Packers And Movers Hyderabad

    ReplyDelete
  19. Read the best Foot Massager Reviews of 2019 Inthe following article, we present the top 8 models available today and revealtheir pros and cons.

    ReplyDelete
  20. Pretty! This was a really wonderful post. Thank you for providing these details.

    Banfield Pet Hospital

    Famous Dave's
    HuHot

    ReplyDelete
  21. Packers and Movers Bangalore as a Services providing company can make all the difference to your ###Home Relocation experience. Bangalore based Company which offers versatile solutions, Right team that easily reduce the stress associated with a ✔✔✔Household Shifting, ***Vehicle Transportation. we help things run smoothly and reduce breakages and offer you seamless, Affordable, Reliable Shifting Services, Compare Shifting Charges @
    Packers And Movers Bangalore

    ReplyDelete
  22. Packers and Movers Pune Provide High Quality ***Household Shifting, Home/Office Relocation, Insurance, Packing, Loading, ###Car Transportation Service Pune and High experiences, Top Rated, Safe and Reliable, Best and Secure Packers and Movers Pune Team List. Get ✔✔✔ Affordable Rate Charts and Compare Quotation and Save Money and Time .
    Packers And Movers Pune

    ReplyDelete
  23. Packers and Movers Gurgaon Provide Reliable, Safe and Certified Service Provider list, Get Free ***Best Price Quotaition and Compare Charges. ✔✔✔ Hassle free Household Shifting Services, High Quality packing Material, Office Relocation, Car Transportaion, ###Local and Domestic Shifting Service @
    Packers And Movers Gurgaon

    ReplyDelete
  24. Clipping path is a must for any kinds of product images. Clipping Path Service can provide you with your desired product with a high-end view which will help you to attract both the organic customers and paid to add customers. Do clipping path for your business growth and show your customers what you have!

    ReplyDelete