You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by PaSik <to...@poczta.fm> on 2013/02/09 18:20:10 UTC
CamelSpringJUnit4ClassRunner and additional TestExecutionListeners
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
Re: CamelSpringJUnit4ClassRunner and additional TestExecutionListeners
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
Yeah its a bug, though those listeners is often not used, and hence
why its not seen before.
As we love contributions, fell free to fix the issue and provide a
patch and/or log a JIRA ticket
http://camel.apache.org/contributing.html
On Sat, Feb 9, 2013 at 6:20 PM, PaSik <to...@poczta.fm> wrote:
> 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
--
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen