2016-10-31 44 views
0

我正在研究Citrus Framework以便在我的項目的測試自動化中使用它。我想運行兩個Web服務,請將其命名爲:如何在同一個端口上使用不同的URL在citrus上運行兩個模擬Web服務?

http://localhost:port/service1 
http://localhosr:port/sercice2 

然後調用我的SUT(待測系統)。 SUT將同時呼叫以上兩種模擬服務(service1 & service2)並返回答案。

我已經成功地做到這一點,但在不同的端口:

<citrus-ws:server id="helloMockService1" 
      port="${server.port1}" 
      servlet-mapping-path="/service1" 
      auto-start="true" 
      timeout="10000" 
      endpoint-adapter="genericResponseAdapter1" /> 

    <citrus-ws:server id="helloMockService2" 
      port="${server.port2}" 
      servlet-mapping-path="/service2" 
      auto-start="true" 
      timeout="10000" /> 

我需要在同一端口上。我也試着寫我的自定義DispatchingEndpointAdapter並以某種方式提取請求消息中的上下文路徑,但沒有成功..

<citrus:dispatching-endpoint-adapter id="dispatchingEndpointAdapter" 
     mapping-key-extractor="mappingKeyExtractor" 
     mapping-strategy="mappingStrategy"/> 

<bean id="mappingStrategy" 
    class="com.consol.citrus.endpoint.adapter.mapping.SimpleMappingStrategy"> 
    <property name="adapterMappings"> 
     <map> 
      <entry key="service1" value-ref="genericResponseAdapter1"/> 
      <entry key="service2" value-ref="genericResponseAdapter2"/> 
     </map> 
    </property> 
</bean> 

<bean id="mappingKeyExtractor" 
    class="com.mycompany.citrus.CustomExtractor"> 

</bean> 

我不能在類型com.citrus.message的請求參數找到URL。消息..

package com.mycompany.citrus; 

import com.consol.citrus.endpoint.adapter.mapping.MappingKeyExtractor; 
import com.consol.citrus.message.Message; 

public class CustomExtractor implements MappingKeyExtractor{ 

    @Override 
    public String extractMappingKey(Message request) { 

     // ther is no URL information in Message object!!!!!!!!!!!! 
     return "service1"; 
    } 

} 

如何在同一端口上運行Citrus Framework中的兩個模擬服務?我想通過URL區分它們,而不是有效載荷本身...(通過peyload,使用上面的自定義MappingKeyExtractor會很容易,因爲Message對象包含有效載荷)

請幫忙!我不相信Citrus Framework可能設計得太差,以至於錯過了這樣一個基本的測試要求。

回答

1

你幾乎在那裏。卸下Servlet映射路徑設置,並使用該映射鍵提取:

<bean id="mappingKeyExtractor" class="com.consol.citrus.endpoint.adapter.mapping.HeaderMappingKeyExtractor"> 
    <property name="headerName" value="#{T(com.consol.citrus.http.message.HttpMessageHeaders).HTTP_REQUEST_URI}"/> 
</bean> 

這將基於地圖的請求路徑傳入的請求。因此,您可以在簡單映射策略中添加映射關鍵字/service1/service2

+0

非常感謝。有用! – supertramp

相關問題