Apache camel 如何在Apache Camel中模拟cxfbean调用?

Apache camel 如何在Apache Camel中模拟cxfbean调用?,apache-camel,Apache Camel,我有一条叫cxfbean的路线: .to("cxfbean:reservationService") 在我的测试中试着用 @EndpointInject(uri = "mock:reservationService") MockEndpoint reservationSystemMock; @BeforeMethod private void setUpContext() throws Exception { context.getRouteDefinition( "send.to

我有一条叫cxfbean的路线:

.to("cxfbean:reservationService")
在我的测试中试着用

@EndpointInject(uri = "mock:reservationService")
MockEndpoint reservationSystemMock;

@BeforeMethod
private void setUpContext() throws Exception
{
     context.getRouteDefinition( "send.to.res.svc.endpoint" ).adviceWith(
         context, new AdviceWithRouteBuilder() {
         @Override
         public void configure() throws Exception         
         {
              interceptSendToEndpoint("cxfbean:reservationService") 
                                      .skipSendToOriginalEndpoint()
                                      .to("mock:reservationService");
         }
     });
}
还尝试使用
weaveByToString(**reservationService”).replace().to(“mock:reservationService”)。在这两种情况下,我得到:

Caused by: org.apache.camel.NoSuchBeanException: No bean could be found in the registry for: reservationService

我想在没有cxf bean实例化的情况下测试我的路由。我正在使用CamelTestSupport类作为父类。

请记住在您的测试类上打开建议。如果使用这些注释,则将
@UseAdviceWith
添加到类中

然后在您建议的之后启动camel上下文


使用
weaveByToString(“to[cxfbean:reservationService]”模拟cxfbean端点

似乎我们还可以在debug watcher中使用
context.getRoutedDefinitions().get(0).toString()
查看
weaveByToString
的必要表达式

@EndpointInject(uri = "mock:reservationService")
protected MockEndpoint reservationSystemMock;

@BeforeMethod
private void setUpContext() throws Exception
{
    context.getRouteDefinition( "send.to.res.svc.endpoint" ).adviceWith(
        context, new AdviceWithRouteBuilder() {
            @Override
            public void configure() throws Exception {
                weaveByToString( "To[cxfbean:reservationService]" )
                .replace().to( "mock:reservationService" );
            }
        });
}