java.lang.IncompatibleClassChangeError в тесте верблюда
Я пытаюсь создать простой верблюжий тест-план, но не могу продолжить. Я могу сделать обычный верблюжий тест с маршрутами, но когда я пытаюсь с верблюжьим тестом, я получаю исключение. Я думаю, что некоторые настройки отсутствуют. Я создал этот тест, ссылаясь только на сайт верблюда Apache, но он не работает. Чего-то не хватает.
мой ПОМ:
<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[]
когда я пытаюсь запустить это, я получаю ниже исключения:
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)
В обычном тесте на верблюдах все работает нормально, но в тесте на верблюдах я получаю исключение выше. Любая помощь в преодолении этого очень ценится.
1 ответ
Я столкнулся с той же проблемой при тестировании моего маршрута с поддержкой верблюжьего теста. Как предложил Клаус в комментарии, ошибка исчезла и простой тест прошел после того, как я перешел с osgi core версии 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 и у меня почти такой же тестовый класс, как и у вас.