有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

直接组件的javacamel-Junit测试

我正在Fuse 6.3上运行一个camel应用程序,它工作正常。 我正在尝试为Camel组件编写JUnit测试用例,结果发现错误是java。lang.CompatibleClassChangeError:找到类组织。springframework。测验上下文TestContext,但需要接口。附加maven依赖项屏幕截图

我正在使用下面的依赖项版本

<dependency>
                <groupId>org.jboss.fuse.bom</groupId>
                <artifactId>jboss-fuse-parent</artifactId>
                <version>6.3.0.redhat-262</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

JUnit stacktrace:

java.lang.IncompatibleClassChangeError: Found class org.springframework.test.context.TestContext, but interface was expected
    at org.apache.camel.test.spring.CamelSpringTestContextLoaderTestExecutionListener.prepareTestInstance(CamelSpringTestContextLoaderTestExecutionListener.java:47)
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:284)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

JUnit类

package com.company.integration;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.impl.DefaultExchange;
import org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;

@RunWith(CamelSpringJUnit4ClassRunner.class)
@ContextConfiguration(locations  = {
         "classpath:/META-INF/spring/camel-context.xml" ,
         "classpath:/META-INF/spring/policyHolderRoute.xml" ,
         "classpath:/META-INF/spring/policyRoute.xml" 
})
public class ComponentTest {

    private static final Logger LOGGER = LoggerFactory.getLogger(ComponentTest.class);

    private Exchange exchange;

    @Autowired
    private CamelContext context;

    @Autowired
    private ProducerTemplate template;

    @Produce(uri = "direct:policyHolderLoad")
    protected ProducerTemplate directPolicyHolderTemplate;

    @Produce(uri = "direct:policyLoad")
    protected ProducerTemplate directPolicyTemplate;

    @Before
    public void setUp() throws Exception {
        exchange = createExchange();
    }

    protected Exchange createExchange() {
        return new DefaultExchange(context);
    }

    @Test
    public void testDirectPolicyHolderRoute() throws Exception {

        try {
            String pathToImportPolicyHolderResponse = "componenttest/success/mock/importpolicy/response.json";
            String requestJson = "componenttest/success/input/importpolicy/request.json";
            exchange.getIn().setBody(readFile(requestJson));
            Exchange responseExchange = directPolicyHolderTemplate.send(exchange);
            Thread.sleep(2000);

        } catch (Exception e) {
            Assert.fail("Unexpected error performing XML comparison: " + e.getMessage());
            LOGGER.error(e.getMessage());
            ;

        }
    }

    protected String readFile(String fileName) throws IOException {
        StringBuilder fileContent = new StringBuilder();
        InputStream content = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
        if (content == null)
            return null;
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(content));
            String s = reader.readLine();
            while (s != null) {
                fileContent.append(s);
                s = reader.readLine();
            }
        } finally {
            if (content != null)
                content.close();
        }
        return fileContent.toString();

    }

}

输出:mvn依赖项:tree-Dscope=runtime

[INFO] com.company.esb.online.in:Online:war:0.0.1-SNAPSHOT
[INFO] +- org.apache.camel:camel-jolt:jar:2.17.0.redhat-630262:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.6.3:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.6.3:compile
[INFO] |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.6.3:compile
[INFO] |  +- com.bazaarvoice.jolt:jolt-core:jar:0.0.20:compile
[INFO] |  +- com.bazaarvoice.jolt:json-utils:jar:0.0.20:compile
[INFO] |  +- com.sun.xml.bind:jaxb-core:jar:2.2.11:compile
[INFO] |  \- com.sun.xml.bind:jaxb-impl:jar:2.2.11.redhat-2:compile
[INFO] +- org.apache.camel:camel-jackson:jar:2.17.0.redhat-630262:compile
[INFO] |  \- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.6.3:compile
[INFO] +- org.apache.camel:camel-jms:jar:2.17.0.redhat-630262:compile
[INFO] |  +- org.springframework:spring-jms:jar:3.2.16.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:3.2.16.RELEASE:compile
[INFO] |  +- org.springframework:spring-tx:jar:3.2.16.RELEASE:compile
[INFO] |  \- org.springframework:spring-beans:jar:3.2.16.RELEASE:compile
[INFO] +- org.apache.camel:camel-cxf:jar:2.17.0.redhat-630262:compile
[INFO] |  +- org.apache.camel:camel-cxf-transport:jar:2.17.0.redhat-630262:compile
[INFO] |  |  \- javax.servlet:javax.servlet-api:jar:3.1.0.redhat-1:compile
[INFO] |  +- org.apache.cxf:cxf-rt-frontend-jaxrs:jar:3.1.5.redhat-630262:compile
[INFO] |  |  +- org.apache.cxf:cxf-core:jar:3.1.5.redhat-630262:compile
[INFO] |  |  |  +- org.codehaus.woodstox:woodstox-core-asl:jar:4.4.1:compile
[INFO] |  |  |  |  \- org.codehaus.woodstox:stax2-api:jar:3.1.4:compile
[INFO] |  |  |  \- org.apache.ws.xmlschema:xmlschema-core:jar:2.2.1.redhat-1:compile
[INFO] |  |  +- javax.ws.rs:javax.ws.rs-api:jar:2.0.1:compile
[INFO] |  |  +- javax.annotation:javax.annotation-api:jar:1.2:compile
[INFO] |  |  \- org.apache.cxf:cxf-rt-transports-http:jar:3.1.5.redhat-630262:compile
[INFO] |  +- org.apache.cxf:cxf-rt-frontend-jaxws:jar:3.1.5.redhat-630262:compile
[INFO] |  |  +- xml-resolver:xml-resolver:jar:1.2.0.redhat-10:compile
[INFO] |  |  +- org.ow2.asm:asm:jar:5.0.4:compile
[INFO] |  |  +- org.apache.cxf:cxf-rt-bindings-xml:jar:3.1.5.redhat-630262:compile
[INFO] |  |  +- org.apache.cxf:cxf-rt-frontend-simple:jar:3.1.5.redhat-630262:compile
[INFO] |  |  \- org.apache.cxf:cxf-rt-ws-addr:jar:3.1.5.redhat-630262:compile
[INFO] |  |     \- org.apache.cxf:cxf-rt-ws-policy:jar:3.1.5.redhat-630262:compile
[INFO] |  |        \- org.apache.neethi:neethi:jar:3.0.3.redhat-1:compile
[INFO] |  +- org.apache.cxf:cxf-rt-rs-security-oauth:jar:3.1.5.redhat-630262:compile
[INFO] |  |  +- org.apache.cxf:cxf-rt-rs-client:jar:3.1.5.redhat-630262:compile
[INFO] |  |  \- net.oauth.core:oauth-provider:jar:20100527:compile
[INFO] |  |     \- net.oauth.core:oauth:jar:20100527:compile
[INFO] |  +- org.springframework:spring-core:jar:3.2.16.RELEASE:compile
[INFO] |  |  \- commons-logging:commons-logging:jar:1.2:compile
[INFO] |  \- org.apache.cxf:cxf-rt-bindings-soap:jar:3.1.5.redhat-630262:compile
[INFO] |     +- org.apache.cxf:cxf-rt-wsdl:jar:3.1.5.redhat-630262:compile
[INFO] |     |  \- wsdl4j:wsdl4j:jar:1.6.3.redhat-1:compile
[INFO] |     \- org.apache.cxf:cxf-rt-databinding-jaxb:jar:3.1.5.redhat-630262:compile
[INFO] +- org.apache.camel:camel-jsonpath:jar:2.17.0.redhat-630262:compile
[INFO] |  +- com.jayway.jsonpath:json-path:jar:2.1.0:compile
[INFO] |  \- net.minidev:json-smart:jar:2.2.1:compile
[INFO] |     \- net.minidev:accessors-smart:jar:1.1:compile
[INFO] +- org.apache.camel:camel-core:jar:2.17.0.redhat-630262:compile
[INFO] +- org.apache.camel:camel-spring:jar:2.17.0.redhat-630262:compile
[INFO] |  +- org.springframework:spring-aop:jar:3.2.16.RELEASE:compile
[INFO] |  |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  \- org.springframework:spring-expression:jar:3.2.16.RELEASE:compile
[INFO] +- xmlunit:xmlunit:jar:1.6:compile
[INFO] +- javax.inject:javax.inject:jar:1.0.0.redhat-6:compile
[INFO] +- javax.enterprise:cdi-api:jar:1.2.0.redhat-2:compile
[INFO] |  +- javax.el:javax.el-api:jar:3.0.0:compile
[INFO] |  \- javax.interceptor:javax.interceptor-api:jar:1.2:compile
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.7.7.redhat-2:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.7.redhat-2:compile
[INFO] +- log4j:log4j:jar:1.2.17.redhat-1:compile
[INFO] \- org.springframework:spring-web:jar:3.2.16.RELEASE:compile
[INFO] ------------------------------------------------------------------------

我做了一些分析,发现默认的spring版本用于camel 2.17.0。redhat-630262为3.2.16。在camel父pom xml中发布

<!-- default springframework version used in Fuse 6.2.1 and 6.3 -->
    <spring-version>${spring32-version}</spring-version>
    <!-- we don't have to declare versions for SMX spring bundles -->
    <spring32-version>3.2.16.RELEASE</spring32-version>
    <spring40-version>4.0.9.RELEASE</spring40-version>
    <spring41-version>4.1.9.RELEASE</spring41-version>
    <spring42-version>4.2.5.RELEASE</spring42-version>

Iam在带有JDK1.8的EAP上运行fuse 6.3,我是否应该将spring框架升级到4。x来解决这个问题


共 (0) 个答案