CamelTestSupport problem
edevera Jul 13, 2012 10:56 AMI am trying to test my camel route builder (which contains endpoints with switchyard as a component) based on the CamelTestSupport class that looks like this:
import org.edevera.model.Entity;
import org.apache.camel.*;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.properties.PropertiesComponent;
import org.apache.camel.model.ProcessorDefinition;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
/**
* @author: Eduardo de Vera
* Date: 6/29/12
* Time: 12:41 AM
*/
public class MyRouterBuilderTest extends CamelTestSupport {
@EndpointInject(uri=MyRouteBuilder.ENDPOINT_MY_SERVICE)
private ProducerTemplate producerTemplate;
protected RouteBuilder createRouteBuilder() throws Exception {
return new MyRouteBuilder();
}
@Test
public void testSendEntityAndSave() throws InterruptedException {
Entity body = new Entity();
producerTemplate.sendBodyAndHeader(body, "operation", "save");
Thread.sleep(1000);
assertTrue(true);
}
protected CamelContext createCamelContext() throws Exception {
CamelContext context = super.createCamelContext();
//Preparing properties
PropertiesComponent prop = context.getComponent("properties", PropertiesComponent.class);
prop.setLocation("classpath:router.properties");
// Substituting switchyard component for a seda.
return context;
}
@Override
protected void debugBefore(Exchange exchange, Processor processor, ProcessorDefinition definition, String id, String label) {
System.out.println("Id:" + id + ", Label:" + label);
}
}
{code}
and I run into the following problem:
{code}
org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[Message: 0-null|]
at org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1237)
at org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:509)
at org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:442)
at org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:438)
at org.apache.camel.impl.DefaultProducerTemplate.sendBodyAndHeader(DefaultProducerTemplate.java:152)
at org.apache.camel.impl.DefaultProducerTemplate.sendBodyAndHeader(DefaultProducerTemplate.java:354)
at com.edevera.services.MyRouterBuilderTest.testSendEntityAndSave(MyRouterBuilderTest.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:47)
at org.junit.rules.RunRules.evaluate(RunRules.java:18)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:76)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.NullPointerException
at org.switchyard.component.camel.SwitchYardProducer.lookupServiceReference(SwitchYardProducer.java:94)
at org.switchyard.component.camel.SwitchYardProducer.process(SwitchYardProducer.java:80)
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
at org.apache.camel.processor.UnitOfWorkProcessor.processAsync(UnitOfWorkProcessor.java:150)
at org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:117)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:99)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:86)
at org.apache.camel.processor.UnitOfWorkProducer.process(UnitOfWorkProducer.java:63)
at org.apache.camel.impl.ProducerCache$2.doInProducer(ProducerCache.java:352)
at org.apache.camel.impl.ProducerCache$2.doInProducer(ProducerCache.java:324)
at org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:223)
at org.apache.camel.impl.ProducerCache.sendExchange(ProducerCache.java:324)
at org.apache.camel.impl.ProducerCache.send(ProducerCache.java:169)
at org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:111)
at org.apache.camel.impl.DefaultProducerTemplate.sendBodyAndHeader(DefaultProducerTemplate.java:150)
... 33 more
Can anyone help me out on this one? I tried using SwitchyardRunner based tests but I can't manage to obtain a reference to the different components that interact during an exchange (as explained here: https://community.jboss.org/thread/202157?tstart=0), so I am trying to at least test the Camel Route Builder.