You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by janne postilista <ja...@gmail.com> on 2011/04/20 09:56:38 UTC

Testing Spring DSL camel routes with CamelSpringTestSupport, osgix namespace problem

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" />

Re: Testing Spring DSL camel routes with CamelSpringTestSupport, osgix namespace problem

Posted by Claus Ibsen <cl...@gmail.com>.
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
<ja...@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: cibsen@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/

Re: Testing Spring DSL camel routes with CamelSpringTestSupport, osgix namespace problem

Posted by Willem Jiang <wi...@gmail.com>.
"http://www.springframework.org/schema/osgi-compendium" namespace 
handler is a part of Spring-DM. You need to deploy the spring 
application into OSGi platform.

If you just want to test spring DSL without OSGi. you may consider to 
put the
  <osgix:cm-properties id="someProperties" persistent-id="com.something" />
into META-INF/spring/osgi-context.xml and import actuate camel context 
from other directory such as META-INF/camel/camel-context.xml.

In this way you can test your Spring DSL with sample 
CamelSpringTestSupport with the application context "test-routes.xml", 
"META-INF/camel/camel-context.xml".

Willem

On 4/20/11 3:56 PM, janne postilista 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" />
>


-- 
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
          http://jnn.javaeye.com (Chinese)
Twitter: willemjiang

Connect at CamelOne May 24-26
The Open Source Integration Conference
http://camelone.com