首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >camel中的java.lang.IncompatibleClassChangeError -测试-蓝图

camel中的java.lang.IncompatibleClassChangeError -测试-蓝图
EN

Stack Overflow用户
提问于 2017-07-26 17:32:11
回答 1查看 600关注 0票数 0

我正在尝试创建简单的camel-test-blueprint,但无法继续。我可以对路由进行正常的camel-test,但是当我尝试camel-test-blueprint时,我得到了异常。我想有些配置丢失了。我只通过引用Apache camel站点来创建此测试用例,但它不起作用。少了点什么。

我的POM:

代码语言:javascript
复制
<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>

我的测试类:

代码语言:javascript
复制
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[]

当我尝试运行这段代码时,我得到以下异常:

代码语言:javascript
复制
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)

在正常的驼峰测试中,它工作得很好,但在驼峰蓝图测试中,我得到了上面的异常。任何帮助克服这一点的人都会非常感谢。

EN

回答 1

Stack Overflow用户

发布于 2018-09-14 22:36:36

在使用camel blueprint测试支持测试我的路线时,我遇到了同样的问题。正如Claus在评论中建议的那样,在我从osgi核心版本4.3.1切换到5.0.0之后,错误消失了,简单的测试通过了:

代码语言:javascript
复制
<dependency>
    <groupId>org.osgi</groupId>
    <artifactId>org.osgi.core</artifactId>
    <version>5.0.0</version>
</dependency>

我非常确定这是因为功能接口是在osgi版本5中引入的:

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

顺便说一句,我也在运行camel 2.17,并且和你的测试类几乎一样。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45322935

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档