3

JUnit を使用してルート ビルダーをテストする必要があり、java.lang.NoSuchMethodError が発生します。構成が不足しているか、ルート ビルダーへのアクセス方法を変更する必要があります。ここで RouteBuilder、コンテキスト、および Junit クラスを見つけてください

@Component
public class MyRouteBuilder extends SpringRouteBuilder {

@Autowired
private SourcePoint sourcePoint;

@Autowired
private DestinationPoint    destinationPoint;

@Override
public void configure() throws Exception {

    from(sourcePoint.getString()).to(destinationPoint.getString());
}

JUnit テスト ケースを作成しました。これは、以下のような適切な Maven の場所にあるコンテキストです

src/test/java/org/apache/camel/spring/patterns/MyRouteBuilderTest.java
src/test/resources/org/apache/camel/spring/patterns/MyRouteBuilderTest-context.xml

ここでは、両方のファイルを添付しています

***** MyRouteBuilderTest-context.xml ***
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
   http://www.springframework.org/schema/beans 
   http://www.springframework.org/schema/beans/spring-beans.xsd
   http://www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context.xsd
   http://camel.apache.org/schema/spring 
   http://camel.apache.org/schema/spring/camel-spring.xsd">

<camelContext xmlns="http://camel.apache.org/schema/spring">
    <routeBuilder ref="MyRouteBuilder" />
</camelContext>

<context:component-scan base-package="com.myroute" />

***** MyRouteBuilderTest.class ***
@RunWith(CamelSpringJUnit4ClassRunner.class)
@BootstrapWith(CamelTest.class)
@ContextConfiguration
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@MockEndpoints("log:*")
@DisableJmx(false)
public class EmypaRouteBuilderTest extends CamelSpringTestSupport {

private static final Logger logger              = LoggerFactory.getLogger(MyRouteBuilderTest.class);

@Autowired
private MyRouteBuilder  myRouteBuilder  = null;

@Override
protected AbstractApplicationContext createApplicationContext() {

    return new ClassPathXmlApplicationContext("Application-context.xml");
}
@Test
public void testRead throws exception(){
    context.start();
    Thread.sleep(10 * 60 * 1000);
   }
}

確認のために、ログも添付します

java.lang.NoSuchMethodError: org.springframework.test.context.TestContextManager.<init>(Ljava/lang/Class;Ljava/lang/String;)V
at org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner$CamelTestContextManager.<init>(CamelSpringJUnit4ClassRunner.java:68)
at org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner.createTestContextManager(CamelSpringJUnit4ClassRunner.java:47)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:114)
at org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner.<init>(CamelSpringJUnit4ClassRunner.java:36)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
4

1 に答える 1