On 11/16/10 9:46 PM, serega wrote:
The fundamental question is how do I test my routes with mock endpoints on
both ends?
The following code works.
public class CamelTest extends CamelTestSupport {
@EndpointInject(uri = "mock:result")
protected MockEndpoint resultEndpoint;
@Produce(uri = "direct:start")
protected ProducerTemplate template;
public static class MyBean1 {
public void doIt(Exchange exchange) {
System.out.println(this.getClass());
}
}
public static class MyBean2 {
public void doIt(Exchange exchange) {
System.out.println(this.getClass());
}
}
@Override
protected Context createJndiContext() throws Exception {
Context context = super.createJndiContext();
context.bind("bean1", new MyBean1());
context.bind("bean2", new MyBean2());
return context;
}
@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
from("direct:start")
.beanRef("bean1")
.beanRef("bean2")
.to("mock:result");
}
};
}
@Test
public void test1() throws InterruptedException {
resultEndpoint.expectedBodiesReceived("Hello World");
template.sendBody("direct:start", "Hello World");
resultEndpoint.assertIsSatisfied();
}
}
1. How can I replicate the same test, with route configured using XML?
@Produce can work with or without the spring configured.
Here is spring configure example[1] that you can take a look.
2. I commented out line @Produce(uri = "direct:start")
and added line
template = this.context.getRegistry().lookup("template",
ProducerTemplate.class);
in createRouteBuilder(), but the template ended to be null.
oh, if you don't create the camel context from spring config, you need
create the template from camelcontext yourself.
template = context.createProducerTemplate();
[1]https://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/produce/ProduceTemplateTest.java
[2]https://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/produce/ProduceTemplateTest-context.xml
--
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.javaeye.com (Chinese)
Twitter: willemjiang