com.github.tomakehurst.wiremock.client.WireMock.givenThat()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(2.8k)|赞(0)|评价(0)|浏览(113)

本文整理了Java中com.github.tomakehurst.wiremock.client.WireMock.givenThat()方法的一些代码示例,展示了WireMock.givenThat()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WireMock.givenThat()方法的具体详情如下:
包路径:com.github.tomakehurst.wiremock.client.WireMock
类名称:WireMock
方法名:givenThat

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);
  }
}

相关文章