9 Testing

 

This chapter covers

  • Introducing and using the Camel Test Kit
  • Unit-testing Camel
  • Testing with mocks
  • Simulating components and errors
  • Amending routes before testing
  • Integration and system testing
  • Using third-party test frameworks with Camel

Integrated systems are notoriously difficult to test. Systems being built and integrated today often involve a myriad of systems ranging from legacy systems, closed source commercial products, homegrown applications, and so on. These systems often have no built-in support for automated testing.

The poor folks who are tasked with testing such integrated systems often have no other choice than to play through manual use cases—triggering events from one window/terminal and then crossing their fingers and watching the results in the affected systems. And by watching, we mean looking at log files, checking databases, or any other manual procedure to verify the results. When they move on to the next use case, they have to reset the system to ensure its correct state before carrying on with the testing.

During development, the systems being integrated are often test systems that are from other teams or are available only in production. If the systems aren’t network connected, internal company procedures may hold back a speedy resolution. With the higher number of systems involved, it becomes more difficult for developers to build and test their work.

9.1 Introducing the Camel Test Kit

9.1.1 Using the Camel JUnit extensions

9.1.2 Using camel-test to test Java Camel routes

9.1.3 Unit testing an existing RouteBuilder class

9.2 Testing Camel with Spring, OSGi, and CDI

9.2.1 Camel testing with Spring XML

9.2.2 Camel testing with Spring Java Config

9.2.3 Camel testing with Spring Boot

9.2.4 Camel testing with OSGi Blueprint XML

9.2.5 Camel testing with CDI

9.2.6 Camel testing with WildFly Swarm

9.2.7 Camel testing with WildFly

9.3 Using the mock component

9.3.1 Introducing the mock component

9.3.2 Unit-testing with the mock component

9.3.3 Verifying that the correct message arrives

9.3.4 Using expressions with mocks

9.3.5 Using mocks to simulate real components

9.4 Simulating errors

9.4.1 Simulating errors using a processor

9.4.2 Simulating errors using mocks

9.4.3 Simulating errors using interceptors

9.4.4 Using adviceWith to add interceptors to an existing route

9.4.5 Using adviceWith to manipulate routes for testing

9.4.6 Using weave with adviceWith to amend routes

9.5 Camel integration testing