On Fri, Feb 4, 2011 at 10:01 AM, Claus Ibsen <[email protected]> wrote:
> Hi
>
> Using a registry.
>
> Map map = new HashMap();
> map.put("beanId", beanInstance);
>
Ah was a bit to quick, you need to use SimpleRegistry instead of the
Map. But it extends HashMap.
> this.context = new DefaultCamelContext(map);
>
>
> See details about registry in chapter 4 in the Camel book.
> Or google the website.
>
> There is also a ton of unit tests in camel-core you can take a look
> at, eg for the bean component.
>
> If you use the Camel test kit then you can override the
> createJndiContext method, which is automatic used by Camel if you dont
> instantiate a CamelContext yourself.
>
> protected Context createJndiContext() throws Exception {
> JndiContext answer = new JndiContext();
> answer.bind("foo", new FooBean());
> answer.bind("bar", new BarBean());
> answer.bind("baz", new BazBean());
> return answer;
> }
>
>
>
> On Fri, Feb 4, 2011 at 9:57 AM, xdevroey <[email protected]>
> wrote:
>>
>> Hello,
>>
>> I am currently trying to write a unit test for a camel route which contains
>> a .method("beanId","methodName") component:
>>
>> from(this.incomingSource)
>> .split().method("splitterBean", "splitMessages")
>> .choice()
>> .when(isValid)
>> .marshal(jaxb).to(this.outgoingDestination)
>> .otherwise()
>> .processRef("errorReportingProcessor").to(this.invalidDestination)
>> .end();
>>
>> In the Test class I have the following lines for the @Before method :
>>
>> @Before
>> public void beforeTest() throws Exception {
>> this.context = new DefaultCamelContext();
>>
>> this.route = new SplittingMainRoute();
>> this.route.setIncomingSource("mokc:in");
>> this.route.setOutgoingDestination(""mock:out);
>> this.route.setInvalidDestination("mock:isValid");
>>
>> this.context.addRoutes(this.route);
>> this.context.start();
>>
>> this.producer = this.context.createProducerTemplate();
>> }
>>
>> I'm actually running Camel on Fuse-Servicemix and the "splitterBean" bean is
>> defined in the bundle-context.xml as <bean id="splitterBean"
>> class="com.foo.MySplitterBean" />
>>
>> My question is: How do I instantiate the splitterBean in my unit test so the
>> route can access it ? And BTW, how do I do that for the
>> errorReportingProcessor, which is also declared in the bundle-context.xml,
>> too ?
>>
>> Many thanks in advance,
>>
>> Xavier
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/Camel-route-with-method-Unit-Testing-tp3370644p3370644.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
>
>
> --
> Claus Ibsen
> -----------------
> FuseSource
> Email: [email protected]
> Web: http://fusesource.com
> Twitter: davsclaus
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/
>
--
Claus Ibsen
-----------------
FuseSource
Email: [email protected]
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/