gpt4 book ai didi

java - 使用 CamelBlueprintTestSupport 时的 NPE

转载 作者:搜寻专家 更新时间:2023-11-01 01:33:13 24 4
gpt4 key购买 nike

我想用 CamelBlueprintTestSupport 创建一个集成测试。我开始我的 Camelcontext,起初看起来还不错:

[ main] ingRestJobAdvertApiOfFirstbird INFO Skipping starting CamelContext as system property skipStartingCamelContext is set to be true. [ main] BlueprintCamelContext INFO Apache Camel 2.15.1.redhat-620133 (CamelContext: camel-1) is starting

路线也开始了。但是后来我在我的控制台中收到了这条消息:

In main loop, we have serious trouble: java.lang.NullPointerException java.lang.NullPointerException at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:303)

Camel 版本: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;
}

最佳答案

camel 中有一个已知问题: https://issues.apache.org/jira/browse/CAMEL-7985

对我有用的解决方案发布在这里: https://issues.jboss.org/browse/ENTESB-2225 .让我们在这里复制有用的评论:

When stepping up projects to 6.2 GA - my camel-test-blueprint unit tests all throw this NullPointerException excessively. I looked at the resolution of the bug report and applied that to my poms, and it cleared up all the NPEs. 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>

关于java - 使用 CamelBlueprintTestSupport 时的 NPE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31651255/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com