-
1. Re: how to mock blueprint beans?
jasonnh Aug 8, 2012 11:28 AM (in response to jasonnh)I have solved this by changing the bean to a Processor and using adviceWith:
-
2. Re: how to mock blueprint beans?
shenzy_shency.revindran Apr 15, 2013 7:01 AM (in response to jasonnh)hi Jason,
how do I convert a bean definition to pocessor in blueprint?
I have the below and want to be able to mock the classA for my test.
Thanks
Edited by: shenzy on Apr 15, 2013 11:01 AM
-
3. Re: how to mock blueprint beans?
shenzy_shency.revindran Apr 15, 2013 7:47 AM (in response to shenzy_shency.revindran)Noticed that the bean should implement the org.apache.camel.Processor for this to work.
But I don't want to make my spring bean a processor just for the unit test.
Is there any other way of mocking beans inside blueprint? I have tried the spring extension springockito ( <mockito:mock/> ) - blueprint is not liking it.
-
4. Re: how to mock blueprint beans?
timgstewart Apr 16, 2013 1:17 PM (in response to shenzy_shency.revindran)#1.
You might be able to use a special blueprint.xml file for testing.
In your class that extends CamelBlueprintTestSupport, you can do:
@Override
protected String getBlueprintDescriptor() {
return "OSGI-INF/blueprint/test-blueprint.xml,OSGI-INF/blueprint/blueprint.xml";
}
So that it reads both files in order. I'm not sure if you want the test-blueprint.xml first or last. In the end you want the mock bean to be the one that is in the registry so camel picks it up as the processor rather than the actual.
In this case you'd have to write a test processor and mock the methods yourself, or at the very least as a wrapper around some mock object that you inject before you run the routes.
You might also be able to programatically register the mock processor using the bundle context.
I have done this with services that my routes are expecting, but not with processors (using the registerService method).
#2.
You might be able to change the ProcessorFactory in the camel context, and return a different processor when camel requests it.
http://camel.apache.org/processorfactory.html
I haven't tried this.
#3.
I've done this:
route.adviceWith(context, new RouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("myProcessor").
skipSendToOriginalEndpoint().
process(new Processor() {
@Override
public void process(Exchange exchng) throws Exception {
// do something different here.
}
}).
to("mock:myMockEndpoint");
Intercepting camel before it sends to the processor, tell it not to send to the original endpoint, do something else in a mock fashion, and send it to a mock endpoint to count exchanges. You could also send it onto a live endpoint if you wanted.