我想用CamelBlueprintTestSupport创建集成测试。 我启动我的Camelcontext,起初看起来还不错:
[main] ingRestJobAdvertApiOfFirstbird INFO跳过CamelContext作为系统属性skipStartingCamelContext设置为true。 [main] BlueprintCamelContext INFO Apache Camel 2.15.1.redhat-620133(CamelContext:camel-1)正在启动
路线也在开始。但后来我在我的控制台中收到了这条消息:
在主循环中,我们遇到了严重的麻烦:java.lang.NullPointerException 显示java.lang.NullPointerException 在org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:303)
骆驼版:2.15.1.redhat-620133
单元测试:
public class WhenUsingRestJobAdvertApiOfdemo extends CamelBlueprintTestSupport {
@Override
protected String getBlueprintDescriptor() {
return "OSGI-INF/blueprint/blueprint.xml";
}
@Override
protected String[] loadConfigAdminConfigurationFile() {
return new String[]{"src/test/resources/jobwebsite.connector.properties", "jobwebsite.connector"};
}
@Test
public void testRoute() throws Exception {
context.addRoutes(new MockServiceEndpoints());
JobRequest jobRequest = readJoData();
template.sendBody("direct:createjobIndemo", jobRequest);
String expectedBody = "<matched/>";
template.sendBodyAndHeader(expectedBody, "foo", "bar");
}
public JobRequest readJoData() throws IOException {
ObjectMapper mapper = new ObjectMapper();
JobRequest jobRequest = mapper.readValue(new File("src/test/resources/demo-data/job-Advert/job-123.json"), JobRequest.class);
return jobRequest;
}
}
答案 0 :(得分:5)
骆驼有一个已知问题: https://issues.apache.org/jira/browse/CAMEL-7985
解决方案,适用于我发布在这里: https://issues.jboss.org/browse/ENTESB-2225。让我们在这里复制有用的评论:
当将项目升级到6.2 GA时 - 我的驼峰测试蓝图单元测试都会过度抛出这个NullPointerException。我查看了错误报告的解决方案,并将其应用于我的poms,并清除了所有NPE。这是我做的:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-blueprint</artifactId>
<scope>test</scope>
<!-- Exclude in order to prevent -->
<!-- java.lang.NullPointerException at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:303) -->
<exclusions>
<exclusion>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.fileinstall</artifactId>
</exclusion>
</exclusions>
</dependency>
此外,我必须添加以下依赖项:
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.utils</artifactId>
<scope>test</scope>
</dependency>
答案 1 :(得分:4)
经过一些进一步的研究后,我找到了解决方法。我必须阻止捆绑org.apache.felix.fileinstall开始。这可以通过覆盖CamelBlueprintTestSupport中的getBundleFilter()来实现:
@Override
protected String getBundleFilter() {
return "(!(Bundle-SymbolicName=org.apache.felix.fileinstall))";
}
我仍然不知道这是一般方法还是我的项目设置有问题......