我正在尝试在 Spring Boot 中测试 Camel 处理器。然而,即使遵循 Camel in Action 和其他答案的指导,我也会遇到很多异常。
我使用的是骆驼3.0.0-M4
例如,这是我的测试:
@SpringBootTest
@BootstrapWith(SpringBootTestContextBootstrapper.class)
public class MyProcessorTest extends CamelTestSupport {
@Produce
ProducerTemplate template;
@EndpointInject(uri = "mock:out")
private MockEndpoint resultEndpoint;
@Before
public void setUp() throws Exception {
super.setUp();
}
@BeforeClass
public static void stopCamelStart() {
SpringCamelContext.setNoStart(true);
}
@AfterClass
public static void enableCamelStart() {
SpringCamelContext.setNoStart(false);
}
@Before
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("seda:test")
.process(new MyProcessor())
.to("mock:out");
}
};
}
@Test
public void testPrepend() throws Exception {
Map<String, String> body = new HashMap<String, String>();
body.put("test", "body");
template.sendBody("seda:test", body);
String result = resultEndpoint.getExchanges().get(0).getIn().getBody(String.class);
}
}
我得到一个java.lang.ArrayIndexOutOfBoundsException
如果我尝试启动骆驼上下文,context.start();我会得到一个java.lang.NullPointerException
如果我交换发送正文的路线,则template.sendBody("mock:out", body);不会发生任何处理。
如果我从 改为 ,seda:test我direct:test会得到一个非常慢的运行测试并且org.apache.camel.component.direct.DirectConsumerNotAvailableException: No consumers available on endpoint: direct://test
我哪里错了??
MMMHUHU
相关分类