Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NPE when using CamelBlueprintTestSupport

I want to create an integration test with CamelBlueprintTestSupport. I start my Camelcontext which looks ok at first:

[ 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

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)

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

}

like image 442
daniel Avatar asked Jul 27 '15 10:07

daniel


1 Answers

There is a known issue in camel: https://issues.apache.org/jira/browse/CAMEL-7985

Solution, which works for me posted here: 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. 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>
like image 173
Yury Bich Avatar answered Oct 24 '22 06:10

Yury Bich