Just define it as a spring bean
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?
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>
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
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);
Will the same works for Camel 1.6.1?
Yeah you can use the Jndi code I showed.