0

我想测试用 Blueprint-XML 实现的骆驼路线。当尝试使用简单的“直接”端点测试路由时,一切正常。

但是将“from”端点更改为 netty 或 jetty 组件,测试失败,但出现以下异常:

java.lang.RuntimeException:放弃等待来自 bundle 'MyRouteTest' 的 BlueprintContainer

我的路线如下所示:

<route id="test">
 <from uri="jetty:http://test:8080/sample/test?matchOnUriPrefix=true" />
 <log id="_log1" loggingLevel="INFO" message="Test " />
</route>

我扩展 CamelBlueprintTestSupport 的测试类如下所示:

// imports...

public class MyRouteTest extends CamelBlueprintTestSupport {


    @Override
    protected String getBlueprintDescriptor() {
        return "/OSGI-INF/blueprint/blueprint2.xml";
    }

    @Test
    public void testRoute() throws Exception {

        context.getRouteDefinition("test").adviceWith(context, new AdviceWithRouteBuilder() {
            @Override
            public void configure() throws Exception {
                replaceFromWith("direct:myMock");
            }
        });
        assert (true);

    }
}

修改路由到

<route id="test">
  <from
    uri="direct:halloTest" />
  <log id="_log1" loggingLevel="INFO" message="Test " />
</route>

通过将 from 部分从 jetty 替换为 direct 可以正常工作(例如,测试运行没有错误,当然由于 assert(true) 检查而最终是肯定的)

有谁能够帮我?

mvn test 的输出是

ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 31.843 s <<< FAILURE! - myPackage.MyRouteTest
[ERROR] testRoute(myPackage.MyRouteTest)  Time elapsed: 31.544 s  <<< ERROR!
java.lang.RuntimeException: Gave up waiting for BlueprintContainer from bundle "MyRouteTest"

[INFO]
[INFO] Results:
[INFO]
[ERROR] Errors:
[ERROR]   MyRouteTest>CamelBlueprintTestSupport.setUp:241->CamelBlueprintTestSupport.createBundleContext:175 ▒ Runtime
[INFO]
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
4

1 回答 1

0

解决方案是将以下代码添加到测试类中:

修改路由到

    @Override
    public boolean isUseAdviceWith() {
        return true;
    }
于 2019-10-08T06:26:03.213 回答