java.lang.IncompatibleClassChangeError in camel-test-blueprint

803 views Asked by At

I am trying to create simple camel-test-blueprint, but can not proceed. I am able to do normal camel-test with the routes , but when I am trying with camel-test-blueprint I am getting exception. I think Some configuration is missing. I have created this test cases by referring Apache camel site only, but it's not working. Something is missing.

my POM:

<properties>
    <camel-version>2.17.0</camel-version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-test-blueprint</artifactId>
        <version>${camel-version}</version>
        <scope>test</scope>
    </dependency>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <extensions>true</extensions>
            <version>2.4.0</version>
        </plugin>
    </plugins>
</build>

My test class:

package com.test.routes;

import org.apache.camel.Exchange;
import org.apache.camel.model.ProcessorDefinition;
import org.apache.camel.test.blueprint.CamelBlueprintTestSupport;
import org.junit.Test;

//tag::example[]
//to use camel-test-blueprint, then extend the CamelBlueprintTestSupport class,    
//and add your unit tests methods as shown below.
public class DebugBlueprintTest extends CamelBlueprintTestSupport {

    private boolean debugBeforeMethodCalled;
    private boolean debugAfterMethodCalled;

    // override this method, and return the location of our Blueprint XML file to be used for testing
    @Override
    protected String getBlueprintDescriptor() {
        return "OSGI-INF/blueprint/route.xml";
    }

    // here we have regular JUnit @Test method
    @Test
    public void testRoute() throws Exception {
        System.out.println("*** Entering testRoute() ***");

        // set mock expectations
        //getMockEndpoint("mock:a").expectedMessageCount(1);
        getMockEndpoint("mock:vm:inputFile1").expectedMessageCount(1);

        // send a message
        //template.sendBody("direct:start", "World");
        template.sendBody("vm:inputFileEndpointTest", "Hello World");

        // assert mocks
        assertMockEndpointsSatisfied();

        // assert on the debugBefore/debugAfter methods below being called as we've 
        enabled the debugger
        assertTrue(debugBeforeMethodCalled);
        assertTrue(debugAfterMethodCalled);
    }

    @Override
    public boolean isUseDebugger() {
        // must enable debugger
        return true;
    }

    @Override
    protected void debugBefore(Exchange exchange, org.apache.camel.Processor processor, ProcessorDefinition<?> definition, String id, String label) {
        log.info("Before " + definition + " with body " + exchange.getIn().getBody());
        debugBeforeMethodCalled = true;
    }

    @Override
    protected void debugAfter(Exchange exchange, org.apache.camel.Processor processor, ProcessorDefinition<?> definition, String id, String label, long timeTaken) {
        log.info("After " + definition + " with body " + exchange.getIn().getBody());
        debugAfterMethodCalled = true;
    }
}
//end::example[]

when I am trying to run this, I am getting below exception:

java.lang.IncompatibleClassChangeError: Class   org.apache.felix.connect.felix.framework.ServiceRegistrationImpl$ServiceReferenceImpl 
does not implement the requested interface org.osgi.resource.Capability
at org.apache.felix.connect.felix.framework.capabilityset.CapabilitySet.addCapability(CapabilitySet.java:63)
at org.apache.felix.connect.felix.framework.ServiceRegistry.registerService(ServiceRegistry.java:124)

In normal camel-test it's working fine, but in camel-blueprint test I'm getting the exception above. Any help in overcoming this is greatly appreciated.

1

There are 1 answers

0
Bubzsan On

I ran into the same problem when testing my route with camel blueprint test support. As Claus suggested in the comment, the error went away and the simple test passed after i switched from osgi core version 4.3.1 to 5.0.0:

<dependency>
    <groupId>org.osgi</groupId>
    <artifactId>org.osgi.core</artifactId>
    <version>5.0.0</version>
</dependency>

I'm pretty sure that's because the Capability Interface was introduced in osgi release 5:

https://osgi.org/javadoc/r5/core/org/osgi/resource/Capability.html

Btw, I'm also running camel 2.17 and have an almost identical test class as yours.