2017-04-26 63 views
1

我正在使用wireMock,即使存根響應爲200 OK,我也得到500內部服務器錯誤的一致響應。Wiremock模擬返回HTTP 500

如果我調試,我看到連接總是關閉。任何想法可能會出錯?或者我做錯了什麼。

這裏的測試

public class MyControllerTest { 

@Autowired 
MyController myController; 

String id1 = "id1"; 
String id2 = "id2"; 
Integer offset = 0; 
Integer limit = 1; 
int port = 8080; 
protected WireMockServer wireMockServer; 

@Rule 
public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(port); 

@Test 
public void hosDriversHoursOfServiceGet() throws Exception { 
    stubFor(WireMock.get(urlEqualTo("/path/endPoint")) 
        .withQueryParam("id1", equalTo(id1)) 
        .withQueryParam("id2", equalTo(id2)) 
        .withQueryParam("limit", equalTo(limit.toString())) 
        .withQueryParam("offset", equalTo(offset.toString())) 
        .willReturn(aResponse().withStatus(200).withBody((getJsonString())))); 
Response response = myController.hosDriversHoursOfServiceGet(driverId, 1, 1); 
    assertEquals(Integer.valueOf(1), response.getCount()); 
} 

private String getJsonString() { 
    return "{\"count\":1}"; 
} 


} 

試圖模擬: http://localhost:8080/path/endPoint?id1= {ID1} & ID2 = {ID2} &極限= {極限} &偏移= {偏移量}

上述呼叫是由在MyController中自動裝配的客戶端類中。這甚至有可能嘲笑,因爲它不是一個直接的電話?

回答

1

這個問題已經解決,它全都與wiremock和我的應用程序中的Javax-servlet-api依賴有關。 Wiremock從2.6.0改爲Wiremock-standalone,它使用了應用程序的servlet-api依賴關係,本質上它工作正常。

不知道這是否是正確的答案,但它的工作。