You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by "J. Ecklund" <m....@gmail.com> on 2012/08/09 02:11:10 UTC

Issues with JavaConfigContextLoader

Hello,

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).

In case it helps anyone in this situation, I am attaching the source.

Regards,

-Joshua

Re: Issues with JavaConfigContextLoader

Posted by mProwler <m....@gmail.com>.
Willem,

I've created  https://issues.apache.org/jira/browse/CAMEL-5494 CAMEL-5494 
for this and attached the code and a test case.

Thanks,

-Joshua


Willem.Jiang wrote
> 
> It look like your attachment does't show in mail.
> Can you create a small test case and attached the files to the Camel
> JIRA[1]?
> 
> It could be great, if you patch can be a part of Camel Spring Test
> framework.
> 




--
View this message in context: http://camel.465427.n5.nabble.com/Issues-with-JavaConfigContextLoader-tp5717034p5717081.html
Sent from the Camel Development mailing list archive at Nabble.com.

Re: Issues with JavaConfigContextLoader

Posted by Willem jiang <wi...@gmail.com>.
It look like your attachment does't show in mail.
Can you create a small test case and attached the files to the Camel JIRA[1]?

It could be great, if you patch can be a part of Camel Spring Test framework.

[1]https://issues.apache.org/jira/browse/CAMEL 

-- 
Willem Jiang

FuseSource
Web: http://www.fusesource.com (http://www.fusesource.com/)
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.javaeye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang 
Weibo: willemjiang


Sent with Sparrow (http://www.sparrowmailapp.com/?sig)


On Thursday, August 9, 2012 at 8:11 AM, J. Ecklund wrote:

> Hello,
> 
> 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). 
> 
> In case it helps anyone in this situation, I am attaching the source.
> 
> Regards,
> 
> -Joshua 



Re: Issues with JavaConfigContextLoader

Posted by Willem jiang <wi...@gmail.com>.
Thanks for sharing this with us. 

-- 
Willem Jiang

FuseSource
Web: http://www.fusesource.com (http://www.fusesource.com/)
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.javaeye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang 
Weibo: willemjiang


Sent with Sparrow (http://www.sparrowmailapp.com/?sig)


On Thursday, August 9, 2012 at 8:11 AM, J. Ecklund wrote:

> Hello,
> 
> 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). 
> 
> In case it helps anyone in this situation, I am attaching the source.
> 
> Regards,
> 
> -Joshua 



Re: Issues with JavaConfigContextLoader

Posted by Willem jiang <wi...@gmail.com>.
Hi Joshua,

It looks like I massed the Spring 3.0.x and 3.1.x in different module. When I clean up the dependency issue, the test works for me now. I will commit the patch shortly. 

-- 
Willem Jiang

FuseSource
Web: http://www.fusesource.com (http://www.fusesource.com/)
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.javaeye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang 
Weibo: willemjiang





On Friday, August 24, 2012 at 12:55 AM, mProwler wrote:

> Willem,
> 
> This was written for Spring 3.1.1 which is what I'm currently using. Can
> you send me details on the problem(s) you encountered?
> 
> Thanks,
> 
> Joshua Ecklund
> Web Developer
> m.prowler@gmail.com (mailto:m.prowler@gmail.com)
> 
> 
> On Sat, Aug 11, 2012 at 2:22 AM, Willem.Jiang [via Camel] <
> ml-node+s465427n5717151h8@n5.nabble.com (mailto:ml-node+s465427n5717151h8@n5.nabble.com)> wrote:
> 
> > Hi Joshua,
> > 
> > I tried to apply your patch into the Camel trunk. But it looks like there
> > a huge change on the Spring test between 3.0.x and 3.1.x. And Camel 2.11 is
> > using the Spring 3.1.x by default.
> > 
> > Can you try to create new a patch for it ?
> > 
> > --
> > Willem Jiang
> > 
> > FuseSource
> > Web: http://www.fusesource.com (http://www.fusesource.com/)
> > Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/)
> > (English)
> > http://jnn.javaeye.com (http://jnn.javaeye.com/) (Chinese)
> > Twitter: willemjiang
> > Weibo: willemjiang
> > 
> > 
> > Sent with Sparrow (http://www.sparrowmailapp.com/?sig)
> > 
> > 
> > On Friday, August 10, 2012 at 3:43 AM, J. Ecklund wrote:
> > 
> > > Willem,
> > > 
> > > I've created CAMEL-5494 <
> > https://issues.apache.org/jira/browse/CAMEL-5494> for
> > > this and attached the code and a test case.
> > > 
> > > Thanks,
> > > 
> > > -Joshua
> > > 
> > > Willem.Jiang wrote
> > > It look like your attachment does't show in mail.
> > > Can you create a small test case and attached the files to the Camel
> > > JIRA[1]?
> > > 
> > > It could be great, if you patch can be a part of Camel Spring Test
> > > framework.
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > ------------------------------
> > If you reply to this email, your message will be added to the discussion
> > below:
> > 
> > http://camel.465427.n5.nabble.com/Issues-with-JavaConfigContextLoader-tp5717034p5717151.html
> > To unsubscribe from Issues with JavaConfigContextLoader, click here<http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5717034&code=bS5wcm93bGVyQGdtYWlsLmNvbXw1NzE3MDM0fC05NzEyNzQ0MzU=>
> > .
> > NAML<http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
> 
> 
> 
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/Issues-with-JavaConfigContextLoader-tp5717034p5717964.html
> Sent from the Camel Development mailing list archive at Nabble.com (http://Nabble.com).




Re: Issues with JavaConfigContextLoader

Posted by mProwler <m....@gmail.com>.
Willem,

This was written for Spring 3.1.1 which is what I'm currently using.  Can
you send me details on the problem(s) you encountered?

Thanks,

Joshua Ecklund
Web Developer
m.prowler@gmail.com


On Sat, Aug 11, 2012 at 2:22 AM, Willem.Jiang [via Camel] <
ml-node+s465427n5717151h8@n5.nabble.com> wrote:

> Hi Joshua,
>
> I tried to apply your patch into the Camel trunk. But it looks like there
> a huge change on the Spring test between 3.0.x and 3.1.x. And Camel 2.11 is
> using the Spring 3.1.x by default.
>
> Can you try to create new a patch for it ?
>
> --
> Willem Jiang
>
> FuseSource
> Web: http://www.fusesource.com (http://www.fusesource.com/)
> Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/)
> (English)
>           http://jnn.javaeye.com (http://jnn.javaeye.com/) (Chinese)
> Twitter: willemjiang
> Weibo: willemjiang
>
>
> Sent with Sparrow (http://www.sparrowmailapp.com/?sig)
>
>
> On Friday, August 10, 2012 at 3:43 AM, J. Ecklund wrote:
>
> > Willem,
> >
> > I've created CAMEL-5494 <
> https://issues.apache.org/jira/browse/CAMEL-5494> for
> > this and attached the code and a test case.
> >
> > Thanks,
> >
> > -Joshua
> >
> > Willem.Jiang wrote
> > It look like your attachment does't show in mail.
> > Can you create a small test case and attached the files to the Camel
> > JIRA[1]?
> >
> > It could be great, if you patch can be a part of Camel Spring Test
> > framework.
> >
>
>
>
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://camel.465427.n5.nabble.com/Issues-with-JavaConfigContextLoader-tp5717034p5717151.html
>  To unsubscribe from Issues with JavaConfigContextLoader, click here<http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5717034&code=bS5wcm93bGVyQGdtYWlsLmNvbXw1NzE3MDM0fC05NzEyNzQ0MzU=>
> .
> NAML<http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://camel.465427.n5.nabble.com/Issues-with-JavaConfigContextLoader-tp5717034p5717964.html
Sent from the Camel Development mailing list archive at Nabble.com.