-
1. Re: Unit test freindly activemqcomponent
njiang Jul 18, 2012 9:13 PM (in response to murray.hughes)If you just want to test route as a unit test, you can use seda component to replace the activemq component by define the jms component like this.
<bean id="jms" class="org.apache.camel.component.seda.SedaComponent">
And you can include this file for testing, it could be much easier for you not to touch the broker configuration staff.
Willem
-
2. Re: Unit test freindly activemqcomponent
murray.hughes Jul 19, 2012 6:36 PM (in response to njiang)That is a clever trick. Thanks. I can now relibably run the unit tests.
I just realised that in order to take advantage of this I needed a separate blueprint file for the jms beans, so I could use a different one in unit test.
I ended up with the following files:
src\main\resources\OSGI-INF\blueprint\jms.xml:
File src\test\java\com\x\RouteTest.java
public class RouteTest extends CamelBlueprintTestSupport {
@Override
protected String getBlueprintDescriptor() {
return "/OSGI-INF/blueprint/jms-test.xml,/OSGI-INF/blueprint/blueprint.xml";
}
-
3. Re: Unit test freindly activemqcomponent
davsclaus Jul 20, 2012 3:32 AM (in response to murray.hughes)I would assume you could have a 2nd blueprint XML file where you setup ActiveMQ, which you then refer from the 1st blueprint XML file, just as you do now with the "seda" trick.
Btw for Camel 2.10 onwards we have a "stub" component instead of seda, its just like seda, but dont validate uri parameters, so you can more easily stub out endpoints that have parameters, that the seda component would otherwise fail to use.
-
4. Re: Unit test freindly activemqcomponent
murray.hughes Jul 22, 2012 5:51 PM (in response to davsclaus)I should clarify my current method of using mutiple blueprint files, as I didn't make it very clear above, and it seems to work:
Production:
src\main\resources\OSGI-INF\blueprint\jms.xml: (in-container activemq as above)src\main\resources\OSGI-INF\blueprint\blueprint.xml: (includes the camel route)
I understand the reason the above two files get utilised when deployed in the container is because they are found in the OSGI-INF\blueprint directory.
Test:
src\test\resources\OSGI-INF\blueprint\jms-test.xml (seda jms as described above)
src\main\resources\OSGI-INF\blueprint\blueprint.xml (includes the camel route)
Note the mix of main & test directories.
I understand there two files get utilised at unit test time because they are in the maven unit test classpath and referred to in the following part of the unit test:
@Override
protected String getBlueprintDescriptor() {
return "/OSGI-INF/blueprint/jms-test.xml,/OSGI-INF/blueprint/blueprint.xml";
}
Please let me know if my understanding of why this works is incorrect.
The above does not rely on one blueprint file referring to another.
Is there a way to refer to one blueprint file from another?
Thanks for the tip about camel 2.10. I see there are a number of camel 2.10 features that enhance unit testing. I'm unsure of the process to upgrade FuseESB to camel 2.10 to take advantage of them, so have avoided that.