Hi If you use OSGi you should use Pax Exam or something like that for unit testing with OSGi. Its frankly a bit more complicated and we will most likely add a camel-osgi-test component which makes testing Camel routes easier with OSGi.
You can take a look at some of the camel source in tests/camel-itest-osgi for some examples how it can be done. On Wed, Apr 20, 2011 at 9:56 AM, janne postilista <jannepostilis...@gmail.com> wrote: > I'm trying to unit/integration test my Spring DSL refined route with > CamelSpringTestSupport. I have camel-context.xml which defines my > routes. I try to initialize tests with that, and mock some endpoints > using test-routes.xml which looks like: > > <interceptSendToEndpoint uri="activemq://something-that-ends-my-route"> > <to uri="mock:mock-endpoint"/> > </interceptSendToEndpoint> > > and my test class then looks like > > public class SomeTest extends CamelSpringTestSupport { > > @Override > protected AbstractApplicationContext createApplicationContext() { > return new ClassPathXmlApplicationContext(new String[]{ > "test-routes.xml", > "META-INF/spring/camel-context.xml" > }); > } > > @Test > public void testSomething() throws Exception { > MockEndpoint mock = getMockEndpoint("mock:mock-endpoint"); > mock.expectedMessageCount(1); > template.sendBody("someendpointwhichstartsmyroute", SOMETHING); > mock.assertIsSatisfied(); > } > > Problem is that CamelSpringTestSupport refuses to use my route > definition, which uses osgi for configuring variables: > > org.springframework.beans.factory.parsing.BeanDefinitionParsingException: > Configuration problem: Unable to locate Spring NamespaceHandler for > XML schema namespace > [http://www.springframework.org/schema/osgi-compendium] > Offending resource: class path resource [META-INF/spring/camel-context.xml] > > at > org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68) > > Start of my camel-context.xml: > > <beans xmlns="http://www.springframework.org/schema/beans" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xmlns:osgi="http://camel.apache.org/schema/osgi" > xmlns:osgix="http://www.springframework.org/schema/osgi-compendium" > xmlns:ctx="http://www.springframework.org/schema/context" > xsi:schemaLocation=" > http://www.springframework.org/schema/beans > http://www.springframework.org/schema/beans/spring-beans-2.0.xsd > http://camel.apache.org/schema/spring > http://camel.apache.org/schema/spring/camel-spring.xsd > http://camel.apache.org/schema/osgi > http://camel.apache.org/schema/osgi/camel-osgi.xsd > http://www.springframework.org/schema/osgi-compendium > http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd > http://www.springframework.org/schema/context > http://www.springframework.org/schema/context/spring-context.xsd > "> > > <osgix:cm-properties id="someProperties" persistent-id="com.something" /> > -- Claus Ibsen ----------------- FuseSource Email: cib...@fusesource.com Web: http://fusesource.com CamelOne 2011: http://fusesource.com/camelone2011/ Twitter: davsclaus Blog: http://davsclaus.blogspot.com/ Author of Camel in Action: http://www.manning.com/ibsen/