2016-05-23 11 views
1

CXFコンポーネントを使用してSOAP Webサービスを呼び出すCamelルート用の単体テストを書く必要があります。
SOAP要求をスキップしてスタブ応答を返す最もクリーンな方法は何でしょうか?
私はモックエンドポイントを試していますが、リクエストは実際のエンドポイントに渡されるか、whenAnyExchangeReceivedプロセッサコールバックで無視されます。Camel BlueprintでCXFエンドポイントをスタブする方法

私はCamelにBlueprintを設定し、camel-test-blueprint 2.17.1で実行しています。これは私のblueprint.xml設定の様子です。

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0" 
    xmlns:camel="http://camel.apache.org/schema/blueprint" 
     xmlns:camelcxf="http://camel.apache.org/schema/blueprint/cxf" 
    xsi:schemaLocation=" 
      http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.0.0.xsd 
      http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd 
      http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd"> 

    <cm:property-placeholder id="routeConfiguration" 
     persistent-id="my.app" /> 

    <camelcxf:cxfEndpoint id="myWebService" 
        address="${myWebService.url}" 
        wsdlURL="classpath:wsdl/MyWebService.wsdl" 
        serviceClass="my.web.service.Ws" 
        serviceName="s:MyWebServiceImpl" 
        xmlns:s="http://mywebservice.it/"/> 


    <camelContext trace="false" id="myCamelContext" 
        xmlns="http://camel.apache.org/schema/blueprint"> 

     <propertyPlaceholder location="blueprint:routeConfiguration" /> 

     <route id="IwantToStubInsideHere"> 
      <from uri="activemq:someQueue"/> 
      <to uri="cxf:bean:myWebService"/> 
      <to uri="direct:processWebServiceResponse"/> 
     </route> 

    </camelContext> 

</blueprint>  

Testクラス

public class RouteTest extends CamelBlueprintTestSupport { 
    @Override 
    public String isMockEndpointsAndSkip() { 
     return "cxf*"; 
    } 

    @Test 
    public void testMethod() { 
     MockEndpoint mockEndpoint = getMockEndpoint("mock:cxf:bean:myWebService"); 
     mockEndpoint.expectedMessageCount(1); 
     mockEndpoint.whenAnyExchangeReceived(new StubWsProcessor()); 
     // run route here 
    } 
} 
+0

これはまさに私たちが直面している問題です。現時点では、(SOAP-UIのような)偽のサーバーを作成するための他の方法は見当たりませんでしたが、この方法はありませんでした。現時点では、実際のWSでこのケースについてのみ統合テストを行います。 –

+0

@ruffp私は実際のセットアップを投稿しました。私の場合はかなりうまくいきます。あなたの状況に適応できることを願っています。 –

答えて

0

私は私の解決策を投稿しています。私は自分のルートからCXF Beanを完全に削除し、エンドポイントをプロパティに置き換えました。テストの間、プロパティ値は適切なエンドポイントに変更される。 direct:something
私のセットアップは、それが動的なルーターを必要とするが、ここでの要点だともう少し複雑です:

<cm:property-placeholder id="routeConfiguration" 
         persistent-id="my.app"> 
    <cm:default-properties> 
     <cm:property name="cxfEndpoint" value="cxf:bean:myWebService"/> 
    </cm:default-properties> 
</cm:property-placeholder> 
..... 
<route id="IwantToStubInsideHere"> 
    <from uri="activemq:someQueue"/> 
    <to uri="${cxfEndpoint}"/> 
    <to uri="direct:processWebServiceResponse"/> 
</route> 

デフォルト値は、本番環境での使用のためokです、そして、それは適切なcxfEndpointを定義することで、テスト中にのみ上書きされますmy.app.cfgファイル。

関連する問題