简体   繁体   English

使用 CamelBlueprintTestSupport 从端点测试某些组件失败

[英]Testing from-Endpoints with CamelBlueprintTestSupport fails with some components

I'd like to test Camel Routes implemented with Blueprint-XML.我想测试用 Blueprint-XML 实现的骆驼路线。 When trying to test a route with a simple "direct"-from endpoint, everything works fine.当尝试使用简单的“直接”端点测试路由时,一切正常。

But changing the "from" endpoint to the netty or jetty component, the test fails with the following exception:但是将“from”端点更改为 netty 或 jetty 组件,测试失败,但出现以下异常:

java.lang.RuntimeException: Gave up waiting for BlueprintContainer from bundle 'MyRouteTest' java.lang.RuntimeException: 放弃等待来自 bundle 'MyRouteTest' 的 BlueprintContainer

The route I have looks like this:我的路线如下所示:

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

My test class which extends CamelBlueprintTestSupport looks like this:我的扩展 CamelBlueprintTestSupport 的测试 class 如下所示:

// 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);

    }
}

Modifying the route to修改路由到

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

by replacing the from part from jetty to direct works fine (eg the test runs without errors and of course ends up positive beccause of the assert(true) check)通过将 from 部分从 jetty 替换为 direct 可以正常工作(例如,测试运行没有错误,当然由于 assert(true) 检查而最终是肯定的)

Can anybody help me?有谁能够帮我?

The output of mvn test is mvn测试的output是

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

The soultion is to add the following code to the test class:解决方案是将以下代码添加到测试 class 中:

Modifying the route to修改路由到

    @Override
    public boolean isUseAdviceWith() {
        return true;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM