[英]NPE when using CamelBlueprintTestSupport
I want to create an integration test with CamelBlueprintTestSupport. 我想用CamelBlueprintTestSupport创建集成测试。 I start my Camelcontext which looks ok at first: 我启动我的Camelcontext,起初看起来还不错:
[ main] ingRestJobAdvertApiOfFirstbird INFO Skipping starting CamelContext as system property skipStartingCamelContext is set to be true. [main] ingRestJobAdvertApiOfFirstbird INFO跳过CamelContext作为系统属性skipStartingCamelContext设置为true。 [ main] BlueprintCamelContext INFO Apache Camel 2.15.1.redhat-620133 (CamelContext: camel-1) is starting [main] BlueprintCamelContext INFO Apache Camel 2.15.1.redhat-620133(CamelContext:camel-1)即将开始
Routes are also starting. 路线也开始了。 But then I just get this message within my console: 但是我只是在我的控制台中收到此消息:
In main loop, we have serious trouble: java.lang.NullPointerException java.lang.NullPointerException at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:303) 在主循环中,我们遇到了严重问题:org.apache.felix.fileinstall.internal.DirectoryWatcher.run中的java.lang.NullPointerException java.lang.NullPointerException(DirectoryWatcher.java:303)
Camel Version: 2.15.1.redhat-620133 骆驼版:2.15.1.redhat-620133
The Unit Test: 单元测试:
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;
}
} }
There is a known issue in camel: https://issues.apache.org/jira/browse/CAMEL-7985 骆驼有一个已知问题: https : //issues.apache.org/jira/browse/CAMEL-7985
Solution, which works for me posted here: https://issues.jboss.org/browse/ENTESB-2225 . 解决方案,适用于我发布在这里: https : //issues.jboss.org/browse/ENTESB-2225 。 Let's copy useful comment here: 我们在这里复制有用的评论:
When stepping up projects to 6.2 GA - my camel-test-blueprint unit tests all throw this NullPointerException excessively. 当将项目升级到6.2 GA时 - 我的驼峰测试蓝图单元测试都会过度抛出这个NullPointerException。 I looked at the resolution of the bug report and applied that to my poms, and it cleared up all the NPEs. 我查看了错误报告的解决方案,并将其应用于我的poms,并清除了所有NPE。 Here is what I did: 这是我做的:
<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>
Additionally, I had to add the following dependency: 另外,我必须添加以下依赖项:
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.utils</artifactId>
<scope>test</scope>
</dependency>
After some further research I found a workaround for this. 经过一些进一步的研究后,我找到了解决方法。 I have to prevent the bundle org.apache.felix.fileinstall from getting started. 我必须阻止捆绑org.apache.felix.fileinstall开始。 This can be achieved by override the getBundleFilter() from the CamelBlueprintTestSupport: 这可以通过覆盖CamelBlueprintTestSupport中的getBundleFilter()来实现:
@Override
protected String getBundleFilter() {
return "(!(Bundle-SymbolicName=org.apache.felix.fileinstall))";
}
I still don't know if this is the general approach or if I problem with my project setup... 我仍然不知道这是一般方法还是我的项目设置问题...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.