Chapter 6. Testing with Camel

 

This chapter covers

  • Introducing and using the Camel Test Kit
  • Testing using multiple environments
  • Using mocks
  • Simulating real components
  • Simulating errors
  • Testing without mocks

In the last chapter, we covered error handling and learned that it’s hard to handle and cater for all difficulties that can possibly arise. To help address this problem, you can test as many situations as possible. In this chapter, we’ll look at how to test with Camel—not only testing your projects when everything goes well, but also simulating errors and testing whether your error handling strategies are up to the job.

Testing is vital to ensuring that your integration projects are successful. JUnit has become the standard API for unit testing, and the Camel Test Kit builds on top of JUnit, leveraging the existing JUnit tooling. If you aren’t familiar with JUnit, you can read about it in JUnit in Action, second edition (http://www.manning.com/tahchiev).

A good way to perform unit testing on a Camel application is to start the application, send messages to the application, and verify that the messages are routed as expected. This is illustrated in figure 6.1. You send a message to the application, which transforms the message to another format and returns the output. You can then verify that the output is as expected.

Figure 6.1. Testing a Camel application by sending a message to the application and then verifying the returned output

6.1. Introducing the Camel Test Kit

6.2. Using the Mock component

6.3. Simulating errors

6.4. Testing without mocks

6.5. Summary and best practices

sitemap