Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-5494

Camel's JavaConfigContextLoader class lacks support for Camel's testing annotations

    XMLWordPrintableJSON

Details

    • Patch Available
    • Unknown

    Description

      While implementing a Camel route in a new project which uses Spring's JavaConfig I ran into some issues with tests I had written.

      Originally I implemented the tests using the old XML-based appContext, then once I had everything working I started converting it all to JavaConfig. After some research, I found that to do this I had to use

      @ContextConfiguration(
              locations = {"blah.EsbConfig", ... },
              loader = JavaConfigContextLoader.class
      )
      

      Which was fine, except it completely broke the functionality of the @MockEndpoints annotation on my tests. I tried adding a org.apache.camel.impl.InterceptSendToMockEndpointStrategy bean to my JavaConfig context, but that didn't change anything. To fix it I ended up making a new (Smart)ContextLoader called CamelSpringDelegatingTestContextLoader, which extends Spring's DelegatingSmartContextLoader and is based on CamelSpringTestContextLoader. It handles both XML and JavaConfig style Spring configuration, and so far seems to have fixed everything.

      You must use CamelSpringJUnit4ClassRunner for this to work, and change @ContextConfiguration's "locations" to "classes" (and specify them as Class instances). See example below.

      @RunWith(CamelSpringJUnit4ClassRunner.class)
      @ContextConfiguration(
              classes = {TestCamelSpringDelegatingTestContextLoader.TestConfig.class},
              loader = CamelSpringDelegatingTestContextLoader.class
      )
      @MockEndpoints
      public class TestSomethingWithCamel { ... }
      

      Attachments

        Activity

          People

            njiang Willem Jiang
            mprowler Joshua Ecklund
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: