2017-04-26 3 views
0

http 요청/응답을 테스트하고 싶습니다. 그래서 WireMock을 사용합니다.WireMock : 스터 빙 - 오브젝트 "testClient"를 얻는 방법은 무엇입니까?

나는 특정 요청에 대한 응답을 스텁하려면 : 다음 코드 :

public class WireMockPersons { 

    @Rule 
    public WireMockRule wireMockRule = new WireMockRule(8089); 

    @Test 
public void exactUrlOnly() { 
    stubFor(get(urlEqualTo("/some/thing")) 
      .willReturn(aResponse() 
       .withHeader("Content-Type", "text/plain") 
       .withBody("Hello world!"))); 

    assertThat(testClient.get("/some/thing").statusCode(), is(200)); 
    assertThat(testClient.get("/some/thing/else").statusCode(), is(404)); 
} 

코드는 컴파일되지 아니 객체 TestClient을 때문이다. 어떻게 testClient 개체를 얻을 수 있습니까?

답변

0

testClient은 조롱하는 API에 대한 클라이언트 라이브러리입니다.

표시가있는 예에서 직접 복사 한 것처럼 보입니다.

testClient을 선택한 HTTP 라이브러리로 바꾸십시오 (예 : HttpClient).

String url = "http://localhost:8089/some/thing"; 
try (CloseableHttpClient client = HttpClientBuilder.create().build()) { 
    HttpGet get = new HttpGet(url); 
    HttpEntity entity = client.execute(get).getEntity(); 
    return EntityUtils.toString(entity, "UTF-8"); 
} catch (IOException e) { 
    throw new RuntimeException("Unable to call " + url, e); 
}