You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Joshua Ecklund (JIRA)" <ji...@apache.org> on 2012/08/09 17:54:19 UTC
[jira] [Updated] (CAMEL-5494) Camel's JavaConfigContextLoader class
lacks support for Camel's testing annotations
[ https://issues.apache.org/jira/browse/CAMEL-5494?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Joshua Ecklund updated CAMEL-5494:
----------------------------------
Attachment: TestCamelSpringDelegatingTestContextLoader.java
CamelSpringDelegatingTestContextLoader.java
Attached source and test case.
> Camel's JavaConfigContextLoader class lacks support for Camel's testing annotations
> -----------------------------------------------------------------------------------
>
> Key: CAMEL-5494
> URL: https://issues.apache.org/jira/browse/CAMEL-5494
> Project: Camel
> Issue Type: Improvement
> Components: camel-spring
> Affects Versions: 2.10.0
> Reporter: Joshua Ecklund
> Labels: annotations, javaconfig, mocks, spring, test
> Attachments: CamelSpringDelegatingTestContextLoader.java, TestCamelSpringDelegatingTestContextLoader.java
>
>
> 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
> {code:java}
> @ContextConfiguration(
> locations = {"blah.EsbConfig", ... },
> loader = JavaConfigContextLoader.class
> )
> {code}
> 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.
> {code:java}
> @RunWith(CamelSpringJUnit4ClassRunner.class)
> @ContextConfiguration(
> classes = {TestCamelSpringDelegatingTestContextLoader.TestConfig.class},
> loader = CamelSpringDelegatingTestContextLoader.class
> )
> @MockEndpoints
> public class TestSomethingWithCamel { ... }
> {code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira