camel-test-blueprint中的java.lang.IncompatibleClassChangeError

时间:2017-07-26 09:32:11

标签: apache-camel camel-blueprint

我正在尝试创建简单的camel-test-blueprint,但无法继续。我可以使用路线进行正常的驼峰测试,但是当我尝试使用驼峰测试蓝图时,我会遇到异常。我认为缺少一些配置。我通过仅引用Apache camel站点创建了这个测试用例,但它不起作用。有些东西不见了。

我的POM:

Argument of type '(items: any) => void' is not assignable to parameter of type '(value: any, index: number) => ObservableInput<{}>'.
  Type 'void' is not assignable to type 'ObservableInput<{}>'.

我的测试班:

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

当我尝试运行此操作时,我遇到异常:

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[]

在正常的驼峰测试中,它工作正常,但在骆驼蓝图测试中,我得到了上述例外。非常感谢任何克服这一点的帮助。

1 个答案:

答案 0 :(得分:1)

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

<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

顺便说一句,我也正在运行骆驼2.17,并且具有与您几乎相同的测试类。

相关问题