Hello,

I'm having some problems when using a pure spring-test test with CamelSpringJUnit4ClassRunner. When I add additional TestExecutionListeners with the default settings (inheritListeners=true) the listeners added by my test class apparently get added before CamelSpringTestContextLoaderTestExecutionListener and running such a test ends with the following error:

java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157)
    ...
Caused by: java.lang.NullPointerException
at org.apache.camel.test.spring.CamelSpringTestContextLoader.cleanup(CamelSpringTestContextLoader.java:177)

It is the order of the listeners that causes this behaviour because when I declare the listeners explicitly like this:

@ContextConfiguration
@RunWith(CamelSpringJUnit4ClassRunner.class)
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@TestExecutionListeners(inheritListeners = false, listeners = {
        CamelSpringTestContextLoaderTestExecutionListener.class,
        DependencyInjectionTestExecutionListener.class,
        DirtiesContextTestExecutionListener.class,
        TransactionalTestExecutionListener.class,
        DisableJmxTestExecutionListener.class,
        StopWatchTestExecutionListener.class,
        DbUnitTestExecutionListener.class })
public class MyTestClass {
  ...
}

Nullpointer is not thrown and the tests pass. When I put the DbUnitTestExecutionListener before CamelSpringTestContextLoaderTestExecutionListener I get the exception again. I'd like to use it like the following (much more compact) and not be forced to redeclare all the listeners.
@ContextConfiguration
@RunWith(CamelSpringJUnit4ClassRunner.class)
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@TestExecutionListeners({ DbUnitTestExecutionListener.class })
public class MyTestClass {
  ...
}

I guess this qualifies as a bug as I haven't found any remarks on such behaviour on camel site / documentation. I guess the behaviour should not change when the order of listeners change. Please confirm that this in fact qualifies as a bug and I'll create a ticket for it in the camel's issue tracker.

Regards,
Tom

Reply via email to