Using Pax Exam to test Camel Spring module
Environment
- JBoss Fuse 6.0
Issue
-
User would like to test Camel Spring module with the Pax Exam. The test should include using properties managed by the OSGi Compendium Configuration Admin Service.
-
When browsing through some examples on how to do integration tests, I came accross 2 examples:
One is https://access.redhat.com/documentation/en-US/Red_Hat_JBoss_Fuse/6.2/html/Deploying_into_the_Container/PaxExam-Sample.html
and the other is
http://blog.christianposta.com/testing/integration-testing-jboss-fuse-6-x-with-pax-exam-part-i/
Both seem to be using pax exam, but the setup is completly different.
What is the difference between both approaches? - I'm trying to test some camel routes in an osgi bundle context using Pax Exam, but I can't get my test to work.
- org.osgi.framework.BundleException: pojosr can't do that
- I'm trying to test some camel routes in an osgi bundle context using Pax Exam, but I can't get my test to work
Resolution
The documentation is not up to the date. There is a jira raised to fix it, refer: https://issues.jboss.org/browse/ENTESB-1020
The complete working Maven project demonstrating the solution is attached to this KCS entry. The most important pieces of the latter example are emphasized below.
The META-INF/spring/camel-context.xml file fill be picked up by the Karaf container managed by Pax Exam. It is important to include xmlns:osgix="http://www.springframework.org/schema/osgi-compendium" namespace declaration there if we want to use properties managed by container OSGi Compendium Configuration Admin Service.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ctx="http://www.springframework.org/schema/context"
xmlns:osgix="http://www.springframework.org/schema/osgi-compendium"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/osgi-compendium http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd">
...
<bean id="prefixer" class="fuse.pocs.camel.spring.properties.Prefixer">
<constructor-arg value="${prefix}"/>
</bean>
<!-- Properties configuration -->
<ctx:property-placeholder properties-ref="properties"/>
<osgix:cm-properties id="properties" persistent-id="my.persistent.id">
<prop key="prefix">MyPrefix</prop>
</osgix:cm-properties>
</beans>
Keep in mind that Pax Exam test should load camel-spring Karaf feature in order to recognize the tested Camel Spring module.
@RunWith(PaxExam.class)
public class SpringPropertiesTest extends Assert {
@Inject
CamelContext camelContext;
@Configuration
public Option[] configuration() {
return new Option[]{
...
features(
maven().groupId("org.apache.camel.karaf").artifactId("apache-camel").
type("xml").classifier("features").versionAsInProject(),
"camel-spring"),
// Tested module
mavenBundle().groupId("fuse-pocs").artifactId("fuse-pocs-camel-spring-properties-bundle").versionAsInProject(),
};
}
...
}
Attachments
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
