本文整理了Java中com.github.tomakehurst.wiremock.client.WireMock.givenThat()
方法的一些代码示例,展示了WireMock.givenThat()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WireMock.givenThat()
方法的具体详情如下:
包路径:com.github.tomakehurst.wiremock.client.WireMock
类名称:WireMock
方法名:givenThat
暂无
代码示例来源:origin: com.github.tomakehurst/wiremock-jre8
public static StubMapping stubFor(MappingBuilder mappingBuilder) {
return givenThat(mappingBuilder);
}
代码示例来源:origin: authorjapps/zerocode
public static void createWithWireMock(MockSteps mockSteps, int mockPort) {
restartWireMock(mockPort);
mockSteps.getMocks().forEach(mockStep -> {
String jsonBodyRequest = mockStep.getResponse().get("body").toString();
if("GET".equals(mockStep.getOperation())){
LOGGER.info("*****WireMock- Mocking the GET endpoint");
givenThat(createGetRequestBuilder(mockStep)
.willReturn(responseBuilder(mockStep, jsonBodyRequest)));
LOGGER.info("WireMock- Mocking the GET endpoint -done- *****");
}
else if("POST".equals(mockStep.getOperation())){
LOGGER.info("*****WireMock- Mocking the POST endpoint");
givenThat(createPostRequestBuilder(mockStep)
.willReturn(responseBuilder(mockStep, jsonBodyRequest)));
LOGGER.info("WireMock- Mocking the POST endpoint -done-*****");
}
else if("PUT".equals(mockStep.getOperation())){
LOGGER.info("*****WireMock- Mocking the PUT endpoint");
givenThat(createPutRequestBuilder(mockStep)
.willReturn(responseBuilder(mockStep, jsonBodyRequest)));
LOGGER.info("WireMock- Mocking the PUT endpoint -done-*****");
}
});
}
代码示例来源:origin: authorjapps/zerocode
@Test
public void bioViaJson() throws Exception{
String jsonBodyRequest = "{\n" +
" \"id\": \"303021\",\n" +
" \"names\": [\n" +
" {\n" +
" \"firstName\": \"You First\",\n" +
" \"lastName\": \"Me Last\"\n" +
" }\n" +
" ]\n" +
"}";
givenThat(WireMock.get(urlEqualTo("/identitymanagement-services/identitymanagement-services/person/internalHandle/person_id_009/biographics/default"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", APPLICATION_JSON)
.withBody(jsonBodyRequest)));
ApacheHttpClientExecutor httpClientExecutor = new ApacheHttpClientExecutor();
ClientRequest clientExecutor = httpClientExecutor.createRequest("http://localhost:9073/identitymanagement-services/identitymanagement-services/person/internalHandle/person_id_009/biographics/default");
clientExecutor.setHttpMethod("GET");
ClientResponse serverResponse = clientExecutor.execute();
final String respBodyAsString = (String)serverResponse.getEntity(String.class);
JSONAssert.assertEquals(jsonBodyRequest, respBodyAsString, true);
System.out.println("### bio response from mapping: \n" + respBodyAsString);
}
}
内容来源于网络,如有侵权,请联系作者删除!