2015-04-02 98 views
0

我有我試圖測試在騾子使用Munit一個基本的HTTP流量的流量,流量看起來是這樣的:獲取HTTP響應代碼在MUnit

<flow name="health-checkFlow"> 
    <http:listener config-ref="HTTP_Listener_Configuration" 
     path="/" allowedMethods="GET" doc:name="HTTP"> 
     <http:response-builder /> 
    </http:listener> 
.... 
</flow> 

隨着Munit我使用調用流:

MuleEvent resultEvent = runFlow("health-checkFlow", testEvent("")); 

的對象的ResultEvent具有正確的有效載荷,但是當我試圖讓HTTP響應代碼使用:

assertEquals("HTTP status code should be 200","200",resultEvent.getMessage().getOutboundProperty("http.status")); 

狀態始終爲空。如何從Munit的消息中獲取http響應代碼?

回答

1

通過調用runFlow,你實際上繞過了http:listener並直接調用流。默認情況下,入站端點和連接器將被禁用。爲了測試HTTP部分覆蓋測試用例執行以下操作:

@Override 
protected boolean haveToMockMuleConnectors() 
{ 
return false; 
} 

@Override 
protected boolean haveToDisableInboundEndpoints() 
{ 
return false; 
} 

然後我會用一個標準的Java HTTP客戶端或者可能騾客戶端來測試HTTP入站端點,並檢查狀態代碼。