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

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

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

WireMock.aResponse介绍

暂无

代码示例

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

@Test
public void decorateUnsuccessfulCall() throws Exception {
  stubFor(get(urlPathEqualTo("/greeting"))
      .willReturn(aResponse()
          .withStatus(500)
          .withHeader("Content-Type", "text/plain")));
  final Response<String> response = service.greeting().execute();
  assertThat(response.code())
      .describedAs("Response code")
      .isEqualTo(500);
  final CircuitBreaker.Metrics metrics = circuitBreaker.getMetrics();
  assertThat(metrics.getNumberOfFailedCalls()).isEqualTo(1);
}

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

@Test
public void decorateUnsuccessfulEnqueuedCall() throws Throwable {
  stubFor(get(urlPathEqualTo("/greeting"))
          .willReturn(aResponse()
                    .withStatus(500)
                    .withHeader("Content-Type", "text/plain")));
  final Response<String> response = EnqueueDecorator.enqueue(service.greeting());
  assertThat(response.code())
      .describedAs("Response code")
      .isEqualTo(500);
  final CircuitBreaker.Metrics metrics = circuitBreaker.getMetrics();
  assertThat(metrics.getNumberOfFailedCalls()).isEqualTo(1);
}

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

private void setupStub(int responseCode) {
    stubFor(get(urlPathEqualTo("/greeting"))
        .willReturn(aResponse()
            .withStatus(responseCode)
            .withHeader("Content-Type", "text/plain")
            .withBody("hello world")));
  }
}

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

private void setupStub(int responseCode) {
    stubFor(get(urlPathEqualTo("/greeting"))
        .willReturn(aResponse()
            .withStatus(responseCode)
            .withHeader("Content-Type", "text/plain")
            .withBody("hello world")));
  }
}

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

private void setupStub(int responseCode) {
    stubFor(get(urlPathEqualTo("/greeting"))
        .willReturn(aResponse()
            .withStatus(responseCode)
            .withHeader("Content-Type", "text/plain")
            .withBody("Hello, world!")));
  }
}

代码示例来源:origin: apache/drill

private void setupGetStubs() {
 wireMockRule.stubFor(get(urlEqualTo("/api/suggest?type=metrics&max=" + Integer.MAX_VALUE))
   .willReturn(aResponse()
     .withStatus(200)
     .withHeader("Content-Type", "application/json")
     .withBody(SAMPLE_DATA_FOR_GET_TABLE_NAME_REQUEST)));
 wireMockRule.stubFor(get(urlEqualTo("/api/query?start=47y-ago&m=sum:warp.speed.test"))
   .willReturn(aResponse()
     .withStatus(200)
     .withBody(SAMPLE_DATA_FOR_GET_TABLE_REQUEST)
   ));
}

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

@Test
public void decorateTimingOutEnqueuedCall() throws Exception {
  stubFor(get(urlPathEqualTo("/greeting"))
          .willReturn(aResponse()
                    .withFixedDelay(500)
                    .withStatus(200)

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

@Test
public void decorateTimingOutCall() throws Exception {
  stubFor(get(urlPathEqualTo("/greeting"))
      .willReturn(aResponse()
          .withFixedDelay(500)
          .withStatus(200)

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

@Test(expected = IOException.class)
public void shouldNotCatchEnqueuedCallExceptionsInRateLimiter() throws Throwable {
  stubFor(get(urlPathEqualTo("/greeting"))
          .willReturn(aResponse()
                    .withStatus(200)
                    .withFixedDelay(400)));
  EnqueueDecorator.enqueue(service.greeting());
}

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

@Test(expected = IOException.class)
public void shouldNotCatchCallExceptionsInRateLimiter() throws Exception {
  stubFor(get(urlPathEqualTo("/greeting"))
      .willReturn(aResponse()
          .withStatus(200)
          .withFixedDelay(400)));
  service.greeting().execute();
}

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

@Test
public void decorateRateLimitedCall() throws Exception {
  stubFor(get(urlPathEqualTo("/greeting"))
      .willReturn(aResponse()
          .withStatus(200)
          .withHeader("Content-Type", "text/plain")
          .withBody("hello world")));
  final Response<String> execute = service.greeting().execute();
  assertThat(execute.isSuccessful())
      .describedAs("Response successful")
      .isTrue();
  final Response<String> rateLimitedResponse = service.greeting().execute();
  assertThat(rateLimitedResponse.isSuccessful())
      .describedAs("Response successful")
      .isFalse();
  assertThat(rateLimitedResponse.code())
      .describedAs("HTTP Error Code")
      .isEqualTo(429);
}

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

@Test
public void decorateRateLimitedEnqueuedCall() throws Throwable {
  stubFor(get(urlPathEqualTo("/greeting"))
          .willReturn(aResponse()
                    .withStatus(200)
                    .withHeader("Content-Type", "text/plain")
                    .withBody("hello world")));
  final Response<String> execute = EnqueueDecorator.enqueue(service.greeting());
  assertThat(execute.isSuccessful())
      .describedAs("Response successful")
      .isTrue();
  final Response<String> rateLimitedResponse = EnqueueDecorator.enqueue(service.greeting());
  assertThat(rateLimitedResponse.isSuccessful())
      .describedAs("Response successful")
      .isFalse();
  assertThat(rateLimitedResponse.code())
      .describedAs("HTTP Error Code")
      .isEqualTo(429);
}

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

@Test
public void decorateSuccessfulEnqueuedCall() throws Throwable {
  stubFor(get(urlPathEqualTo("/greeting"))
          .willReturn(aResponse()
                    .withStatus(200)
                    .withHeader("Content-Type", "text/plain")
                    .withBody("hello world")));
  EnqueueDecorator.enqueue(service.greeting());
  verify(1, getRequestedFor(urlPathEqualTo("/greeting")));
}

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

@Test
public void decorateSuccessfulCall() throws Exception {
  stubFor(get(urlPathEqualTo("/greeting"))
      .willReturn(aResponse()
          .withStatus(200)
          .withHeader("Content-Type", "text/plain")
          .withBody("hello world")));
  service.greeting().execute();
  verify(1, getRequestedFor(urlPathEqualTo("/greeting")));
}

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

@Test
public void decorateSuccessfulEnqueuedCall() throws Throwable {
  stubFor(get(urlPathEqualTo("/greeting"))
          .willReturn(aResponse()
                    .withStatus(200)
                    .withHeader("Content-Type", "text/plain")
                    .withBody("hello world")));
  EnqueueDecorator.enqueue(service.greeting());
  verify(1, getRequestedFor(urlPathEqualTo("/greeting")));
}

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

@Test
public void shouldNotCallServiceOnEnqueueWhenOpen() throws Throwable {
  stubFor(get(urlPathEqualTo("/greeting"))
      .willReturn(aResponse()
          .withStatus(200)
          .withHeader("Content-Type", "text/plain")
          .withBody("hello world")));
  circuitBreaker.transitionToOpenState();
  try {
    EnqueueDecorator.enqueue(service.greeting());
    fail("CircuitBreakerOpenException was expected");
  } catch (CircuitBreakerOpenException ignore) {
  }
  ensureAllRequestsAreExecuted(Duration.ofSeconds(1));
  verify(0, getRequestedFor(urlPathEqualTo("/greeting")));
}

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

@Test
public void decorateSuccessfulCall() throws Exception {
  stubFor(get(urlPathEqualTo("/greeting"))
      .willReturn(aResponse()
          .withStatus(200)
          .withHeader("Content-Type", "text/plain")
          .withBody("hello world")));
  service.greeting().execute();
  verify(1, getRequestedFor(urlPathEqualTo("/greeting")));
}

代码示例来源:origin: knightliao/disconf

.willReturn(aResponse().withHeader("Content-Type", RemoteMockServer.CONTENT_TYPE).withStatus(200)
    .withBody(GsonUtils.toJson(valueVo))));
.willReturn(aResponse().withHeader("Content-Type", "text/html;charset=UTF-8")
    .withHeader("Content-Disposition",
        "attachment; filename=" + RemoteMockServer.FILE_NAME).withStatus(200)
.willReturn(aResponse().withHeader("Content-Type", "text/html;charset=UTF-8")
    .withHeader("Content-Disposition",
        "attachment; filename=" + RemoteMockServer.EMPTY_FILE_URL)
.willReturn(aResponse().withHeader("Content-Type", "text/html;charset=UTF-8")
    .withHeader("Content-Disposition",
        "attachment; filename=" + RemoteMockServer.STATIC_FILE_NAME)
.willReturn(aResponse().withHeader("Content-Type", "text/html;charset=UTF-8")
    .withHeader("Content-Disposition",
        "attachment; filename=" + RemoteMockServer.NON_ANOTATION_FILE_NAME)
.willReturn(aResponse().withHeader("Content-Type", "text/html;charset=UTF-8")
    .withHeader("Content-Disposition",
        "attachment; filename=" + RemoteMockServer.NON_ANOTATION_FILE_NAME2)
.willReturn(aResponse().withHeader("Content-Type", RemoteMockServer.CONTENT_TYPE).withStatus(200)
    .withBody(GsonUtils.toJson(valueVo))));
.willReturn(aResponse().withHeader("Content-Type", RemoteMockServer.CONTENT_TYPE).withStatus(200)
    .withBody(GsonUtils.toJson(valueVo))));

代码示例来源:origin: apache/drill

private void setupPostStubs() {
 wireMockRule.stubFor(post(urlEqualTo("/api/query"))
   .withRequestBody(equalToJson(POST_REQUEST_WITHOUT_TAGS))
   .willReturn(aResponse()
     .withStatus(200)
     .withHeader("Content-Type", "application/json")
   .willReturn(aResponse()
     .withStatus(200)
     .withHeader("Content-Type", "application/json")
   .willReturn(aResponse()
     .withStatus(200)
     .withHeader("Content-Type", "application/json")
     .willReturn(aResponse()
         .withStatus(200)
         .withHeader("Content-Type", "application/json")
   .willReturn(aResponse()
     .withStatus(200)
     .withHeader("Content-Type", "application/json")
     .willReturn(aResponse()
         .withStatus(200)
         .withHeader("Content-Type", "application/json")
   .willReturn(aResponse()
     .withStatus(400)
     .withHeader("Content-Type", "application/json")

代码示例来源:origin: palantir/atlasdb

@Before
public void setup() {
  String testNumberAsString = Integer.toString(TEST_NUMBER);
  availableServer.stubFor(ENDPOINT_MAPPING.willReturn(aResponse().withStatus(200).withBody(testNumberAsString)));
  proxyServer.stubFor(ENDPOINT_MAPPING.willReturn(aResponse().withStatus(200).withBody(testNumberAsString)));
  availablePort = availableServer.port();
  unavailablePort = unavailableServer.port();
  proxyPort = proxyServer.port();
  bothUris = ImmutableSet.of(
      getUriForPort(unavailablePort),
      getUriForPort(availablePort));
}

相关文章