-
1. Re: JUnit test and bean endpoint in route
davsclaus Nov 15, 2009 4:06 AM (in response to mfatafta)Just define it as a spring bean
-
2. Re: JUnit test and bean endpoint in route
mfatafta Nov 15, 2009 12:31 PM (in response to davsclaus)It is.
My route is defined in a RouteBuilder java file, the route looks something like this:
from ( sourceUri )
.inOut ( "validator:xsd/validateRequest.xsd" )
.inOut( "bean:myRequestBean" )
.inOut ( internalSourceDirectEndPoint )
;
myRequestBean is defined as a spring bean in an xml file like this:
I am trying to create JUnit test case for my route. How do I load the bean into my JUnit test camelContext?
Does anyone have an sample code that I can follow?
-
3. Re: JUnit test and bean endpoint in route
njiang Nov 15, 2009 8:19 PM (in response to mfatafta)You can try to let spring load the route rule just like this
<camelContext id="camel5" xmlns="http://camel.apache.org/schema/spring"> <routeBuilder ref="myBuilder"></routeBuilder> </camelContext> <bean id="myBuilder" class="org.apache.camel.spring.example.test1.MyRouteBuilder"></bean>
-
4. Re: JUnit test and bean endpoint in route
mfatafta Nov 15, 2009 10:00 PM (in response to njiang)I don't think you understand my question.
In my JUnit test, I am trying to load a camel route. That camel route references a java bean in one of its endpoint.
When I run my JUnit test I get the following exception:
org.apache.camel.component.bean.NoBeanAvailableException: No bean available for endpoint: myRequestBean
-
5. Re: JUnit test and bean endpoint in route
davsclaus Nov 16, 2009 1:03 AM (in response to mfatafta)If its a pure junit test, eg extending TestCase or the likes you need to bind your bean to the Camel Registry so it knows how to find it.
for example using JNDI
Or creating your own implementation of Camel Registry.
In Camel 2.1 there is a SimpleRegistry out of the box that is based on a Map so its easy to bind using put.
You can do it something like this:
JndiContext ctx = new org.apache.camel.util.jndi.JndiContext(); cxt.bind("foo", new MyFooBean(); CamelContext context = new DefaultCameContext(ctx);
-
6. Re: JUnit test and bean endpoint in route
mfatafta Nov 16, 2009 10:35 AM (in response to davsclaus)Will the same works for Camel 1.6.1?
Thanks
-
7. Re: JUnit test and bean endpoint in route
davsclaus Nov 16, 2009 11:13 AM (in response to mfatafta)Yeah you can use the Jndi code I showed.