5
votes

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;
}

}

2

2 Answers

6
votes

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>
4
votes

After some further research I found a workaround for this. I have to prevent the bundle org.apache.felix.fileinstall from getting started. This can be achieved by override the getBundleFilter() from the CamelBlueprintTestSupport:

@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...