使用 CamelBlueprintTestSupport 从端点测试某些组件失败
Testing from-Endpoints with CamelBlueprintTestSupport fails with some components
我想测试用 Blueprint-XML 实现的 Camel Routes。当尝试使用简单的 "direct"-from 端点测试路由时,一切正常。
但是将 "from" 端点更改为 netty 或 jetty 组件,测试失败并出现以下异常:
java.lang.RuntimeException:放弃等待来自包 'MyRouteTest'
的 BlueprintContainer
我的路线是这样的:
<route id="test">
<from uri="jetty:http://test:8080/sample/test?matchOnUriPrefix=true" />
<log id="_log1" loggingLevel="INFO" message="Test " />
</route>
我的扩展 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);
}
}
修改路线为
<route id="test">
<from
uri="direct:halloTest" />
<log id="_log1" loggingLevel="INFO" message="Test " />
</route>
通过将 from 部分从 jetty 替换为 direct 可以正常工作(例如,测试运行没有错误,当然由于 assert(true) 检查而最终结果为正)
有人可以帮我吗?
mvn 测试的输出是
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
解决方法是在测试中加入如下代码class:
修改路线为
@Override
public boolean isUseAdviceWith() {
return true;
}
我想测试用 Blueprint-XML 实现的 Camel Routes。当尝试使用简单的 "direct"-from 端点测试路由时,一切正常。
但是将 "from" 端点更改为 netty 或 jetty 组件,测试失败并出现以下异常:
java.lang.RuntimeException:放弃等待来自包 'MyRouteTest'
的 BlueprintContainer我的路线是这样的:
<route id="test">
<from uri="jetty:http://test:8080/sample/test?matchOnUriPrefix=true" />
<log id="_log1" loggingLevel="INFO" message="Test " />
</route>
我的扩展 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);
}
}
修改路线为
<route id="test">
<from
uri="direct:halloTest" />
<log id="_log1" loggingLevel="INFO" message="Test " />
</route>
通过将 from 部分从 jetty 替换为 direct 可以正常工作(例如,测试运行没有错误,当然由于 assert(true) 检查而最终结果为正)
有人可以帮我吗?
mvn 测试的输出是
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
解决方法是在测试中加入如下代码class:
修改路线为
@Override
public boolean isUseAdviceWith() {
return true;
}