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

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

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

WireMock.binaryEqualTo介绍

暂无

代码示例

代码示例来源:origin: com.github.tomakehurst/wiremock-jre8

private MultipartValuePattern valuePatternForPart(Request.Part part) {
  MultipartValuePatternBuilder builder = new MultipartValuePatternBuilder().withName(part.getName()).matchingType(MultipartValuePattern.MatchingType.ALL);
  if (!headersToMatch.isEmpty()) {
    Collection<HttpHeader> all = part.getHeaders().all();
    for (HttpHeader httpHeader : all) {
      if (headersToMatch.contains(httpHeader.caseInsensitiveKey())) {
        builder.withHeader(httpHeader.key(), equalTo(httpHeader.firstValue()));
      }
    }
  }
  HttpHeader contentType = part.getHeader("Content-Type");
  if (!contentType.isPresent() || contentType.firstValue().contains("text")) {
    builder.withBody(equalTo(part.getBody().asString()));
  } else if (contentType.firstValue().contains("json")) {
    builder.withBody(equalToJson(part.getBody().asString(), true, true));
  } else if (contentType.firstValue().contains("xml")) {
    builder.withBody(equalToXml(part.getBody().asString()));
  } else {
    builder.withBody(binaryEqualTo(part.getBody().asBytes()));
  }
  return builder.build();
}

代码示例来源:origin: georocket/georocket

/**
  * Make sure request bodies that are too small are not compressed
  */
 @Test
 public void compressRequestBodiesMessageTooSmall(TestContext ctx) {
  client.close();
  client = new LoadBalancingHttpClient(rule.vertx(), true);

  Buffer body = Buffer.buffer("Hello World");

  wireMockRule1.stubFor(post(urlEqualTo("/"))
   .withHeader("Content-Encoding", absent())
   .withRequestBody(binaryEqualTo(body.getBytes()))
   .willReturn(aResponse()
    .withBody(expected1.encode())));

  client.setHosts(Collections.singletonList(
   URI.create("http://localhost:" + wireMockRule1.port())));

  Async async = ctx.async();
  client.performRequest(HttpMethod.POST, "/", body)
   .doOnSuccess(o -> ctx.assertEquals(expected1, o))
   .subscribe(o -> async.complete());
 }
}

代码示例来源:origin: georocket/georocket

/**
 * Test if request bodies can be compressed
 */
@Test
public void compressRequestBodies(TestContext ctx) {
 client.close();
 client = new LoadBalancingHttpClient(rule.vertx(), true);
 Buffer body = Buffer.buffer();
 for (int i = 0; i < 150; ++i) {
  body.appendString("Hello world");
 }
 wireMockRule1.stubFor(post(urlEqualTo("/"))
  .withHeader("Content-Encoding", equalTo("gzip"))
  .withRequestBody(binaryEqualTo(body.getBytes()))
  .willReturn(aResponse()
   .withBody(expected1.encode())));
 client.setHosts(Collections.singletonList(
  URI.create("http://localhost:" + wireMockRule1.port())));
 Async async = ctx.async();
 client.performRequest(HttpMethod.POST, "/", body)
  .doOnSuccess(o -> ctx.assertEquals(expected1, o))
  .subscribe(o -> async.complete());
}

相关文章