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

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

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

WireMock.post介绍

暂无

代码示例

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testAppend() throws Exception {
  wireMockRule.stubFor(post(urlEqualTo("/test/log4j/"))
    .willReturn(SUCCESS_RESPONSE));
  final Appender appender = HttpAppender.newBuilder()
    .withName("Http")
    .withLayout(JsonLayout.createDefaultLayout())
    .setConfiguration(ctx.getConfiguration())
    .setUrl(new URL("http://localhost:" + wireMockRule.port() + "/test/log4j/"))
    .build();
  appender.append(createLogEvent());
  wireMockRule.verify(postRequestedFor(urlEqualTo("/test/log4j/"))
    .withHeader("Host", containing("localhost"))
    .withHeader("Content-Type", containing("application/json"))
    .withRequestBody(containing("\"message\" : \"" + LOG_MESSAGE + "\"")));
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test(expected = AppenderLoggingException.class)
public void testAppendError() throws Exception {
  wireMockRule.stubFor(post(urlEqualTo("/test/log4j/"))
    .willReturn(FAILURE_RESPONSE));
  final Appender appender = HttpAppender.newBuilder()
    .withName("Http")
    .withLayout(JsonLayout.createDefaultLayout())
    .setConfiguration(ctx.getConfiguration())
    .withIgnoreExceptions(false)
    .setUrl(new URL("http://localhost:" + wireMockRule.port() + "/test/log4j/"))
    .build();
  appender.append(createLogEvent());
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testAppendHttps() throws Exception {
  wireMockRule.stubFor(post(urlEqualTo("/test/log4j/"))
    .willReturn(SUCCESS_RESPONSE));
  final Appender appender = HttpAppender.newBuilder()
    .withName("Http")
    .withLayout(JsonLayout.createDefaultLayout())
    .setConfiguration(ctx.getConfiguration())
    .setUrl(new URL("https://localhost:" + wireMockRule.httpsPort() + "/test/log4j/"))
    .setSslConfiguration(SslConfiguration.createSSLConfiguration(null,
      KeyStoreConfiguration.createKeyStoreConfiguration(TestConstants.KEYSTORE_FILE, TestConstants.KEYSTORE_PWD(), TestConstants.KEYSTORE_TYPE, null),
      TrustStoreConfiguration.createKeyStoreConfiguration(TestConstants.TRUSTSTORE_FILE, TestConstants.TRUSTSTORE_PWD(), TestConstants.TRUSTSTORE_TYPE, null)))
    .setVerifyHostname(false)
    .build();
  appender.append(createLogEvent());
  wireMockRule.verify(postRequestedFor(urlEqualTo("/test/log4j/"))
    .withHeader("Host", containing("localhost"))
    .withHeader("Content-Type", containing("application/json"))
    .withRequestBody(containing("\"message\" : \"" + LOG_MESSAGE + "\"")));
}

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

private void setupPostStubs() {
 wireMockRule.stubFor(post(urlEqualTo("/api/query"))
   .withRequestBody(equalToJson(POST_REQUEST_WITHOUT_TAGS))
   .willReturn(aResponse()
 wireMockRule.stubFor(post(urlEqualTo("/api/query"))
   .withRequestBody(equalToJson(POST_REQUEST_WITH_TAGS))
   .willReturn(aResponse()
 wireMockRule.stubFor(post(urlEqualTo("/api/query"))
   .withRequestBody(equalToJson(DOWNSAMPLE_REQUEST_WTIHOUT_TAGS))
   .willReturn(aResponse()
 wireMockRule.stubFor(post(urlEqualTo("/api/query"))
     .withRequestBody(equalToJson(END_PARAM_REQUEST_WTIHOUT_TAGS))
     .willReturn(aResponse()
 wireMockRule.stubFor(post(urlEqualTo("/api/query"))
   .withRequestBody(equalToJson(DOWNSAMPLE_REQUEST_WITH_TAGS))
   .willReturn(aResponse()
 wireMockRule.stubFor(post(urlEqualTo("/api/query"))
     .withRequestBody(equalToJson(END_PARAM_REQUEST_WITH_TAGS))
     .willReturn(aResponse()
 wireMockRule.stubFor(post(urlEqualTo("/api/query"))
   .withRequestBody(equalToJson(REQUEST_TO_NONEXISTENT_METRIC))
   .willReturn(aResponse()

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testAppendErrorIgnore() throws Exception {
  wireMockRule.stubFor(post(urlEqualTo("/test/log4j/"))
    .willReturn(FAILURE_RESPONSE));

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

@Test
public void userAgentsPresentOnRequestsToTimelockServer() {
  setUpTimeLockBlockInInstallConfig();
  availableServer.stubFor(post(urlMatching("/")).willReturn(aResponse().withStatus(200).withBody("3")));
  availableServer.stubFor(TIMELOCK_LOCK_MAPPING.willReturn(aResponse().withStatus(200).withBody("4")));
  verifyUserAgentOnTimelockTimestampAndLockRequests();
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testAppendCustomHeader() throws Exception {
  wireMockRule.stubFor(post(urlEqualTo("/test/log4j/"))
    .willReturn(SUCCESS_RESPONSE));
  final Appender appender = HttpAppender.newBuilder()
    .withName("Http")
    .withLayout(JsonLayout.createDefaultLayout())
    .setConfiguration(ctx.getConfiguration())
    .setUrl(new URL("http://localhost:" + wireMockRule.port() + "/test/log4j/"))
    .setHeaders(new Property[] {
      Property.createProperty("X-Test", "header value"),
      Property.createProperty("X-Runtime", "${java:runtime}")
    })
    .build();
  appender.append(createLogEvent());
  wireMockRule.verify(postRequestedFor(urlEqualTo("/test/log4j/"))
    .withHeader("Host", containing("localhost"))
    .withHeader("X-Test", equalTo("header value"))
    .withHeader("X-Runtime", equalTo(JAVA_LOOKUP.getRuntime()))
    .withHeader("Content-Type", containing("application/json"))
    .withRequestBody(containing("\"message\" : \"" + LOG_MESSAGE + "\"")));
}

代码示例来源:origin: authorjapps/zerocode

private static MappingBuilder createPostRequestBuilder(MockStep mockStep) {
  final MappingBuilder requestBuilder = post(urlEqualTo(mockStep.getUrl()));
  return createRequestBuilderWithHeaders(mockStep, requestBuilder);
}

代码示例来源:origin: hibernate/hibernate-search

@Test
public void tinyPayload() throws Exception {
  SearchConfigurationForTest configuration = createConfiguration();
  wireMockRule.stubFor( post( urlPathLike( "/myIndex/myType" ) )
      .willReturn( elasticsearchResponse().withStatus( 200 ) ) );
  try ( ElasticsearchClient client = createClient( configuration ) ) {
    doPost( client, "/myIndex/myType", produceBody( 1 ) );
    wireMockRule.verify(
        postRequestedFor( urlPathLike( "/myIndex/myType" ) )
            .withoutHeader( "Transfer-Encoding" )
            .withHeader( "Content-length", equalTo( String.valueOf( BODY_PART_BYTE_SIZE ) ) )
        );
  }
}

代码示例来源:origin: allegro/hermes

public void expectMessages(List<String> messages) {
  receivedRequests.clear();
  expectedMessages = messages;
  messages.forEach(m -> listener
    .register(
      post(urlEqualTo(path))
      .willReturn(aResponse().withStatus(returnedStatusCode).withFixedDelay(delay))));
}

代码示例来源:origin: kamax-matrix/mxisd

@Test
public void forNameNotFound() {
  stubFor(post(urlEqualTo(displayNameEndpoint))
      .willReturn(aResponse()
          .withStatus(404)
      )
  );
  Optional<String> v = p.getDisplayName(userId);
  verify(postRequestedFor(urlMatching(displayNameEndpoint))
      .withHeader("Content-Type", containing(ContentType.APPLICATION_JSON.getMimeType()))
      .withRequestBody(equalTo(GsonUtil.get().toJson(new JsonProfileRequest(userId))))
  );
  assertFalse(v.isPresent());
}

代码示例来源:origin: pl.allegro.tech.hermes/hermes-test-helper

public void expectMessages(List<String> messages) {
  receivedRequests.clear();
  expectedMessages = messages;
  messages.forEach(m -> listener
    .register(
      post(urlEqualTo(path))
      .willReturn(aResponse().withStatus(returnedStatusCode).withFixedDelay(delay))));
}

代码示例来源:origin: allegro/hermes

public void addStub(String topicName, int statusCode, String contentType) {
    wireMockServer.stubFor(post(urlEqualTo("/topics/" + topicName))
        .willReturn(aResponse()
            .withStatus(statusCode)
            .withHeader("Content-Type", contentType)
            .withHeader("Hermes-Message-Id", UUID.randomUUID().toString())
        )
    );
  }
}

代码示例来源:origin: uber/rides-java-sdk

@Test
  public void testRefresh_whenSuccessful() throws Exception {
    stubFor(post(urlEqualTo("/token"))
        .withRequestBody(equalTo(REQUEST_BODY))
        .willReturn(aResponse()
            .withBodyFile("token_token.json")));

    AccessToken accessToken = oAuth2Service.refresh(REFRESH_TOKEN, CLIENT_ID).execute().body();

    assertThat(accessToken.getExpiresIn()).isEqualTo(2592000);
    assertThat(accessToken.getToken()).isEqualTo("Access999Token");
    assertThat(accessToken.getRefreshToken()).isEqualTo("888RefreshToken");
  }
}

代码示例来源:origin: kamax-matrix/mxisd

@Test
public void lookupBulkFound() {
  stubFor(post(urlEqualTo(lookupBulkPath))
      .willReturn(aResponse()
          .withHeader("Content-Type", ContentType.APPLICATION_JSON.getMimeType())
          .withBody(lookupBulkFoundBody)
      )
  );
  List<ThreePidMapping> mappings = p.populate(lookupBulkList);
  assertNotNull(mappings);
  assertEquals(2, mappings.size());
  assertTrue(StringUtils.equals(mappings.get(0).getMxid(), "@john:example.org"));
  assertTrue(StringUtils.equals(mappings.get(1).getMxid(), "@jane:example.org"));
}

代码示例来源:origin: sargue/mailgun

private MappingBuilder expectedBasicPost() {
  return post(urlEqualTo("/api/" + DOMAIN + "/messages"))
    .withHeader("Authorization", equalTo("Basic " + expectedAuthHeader))
    .withHeader("Content-Type",
          equalTo("application/x-www-form-urlencoded"));
}

代码示例来源:origin: alfa-laboratory/akita

@Test
void sendHttpRequestPost() throws Exception {
  stubFor(post(urlEqualTo("/post/resource"))
    .willReturn(aResponse()
      .withStatus(200)
      .withHeader("Content-Type", "text/xml")
      .withBody("TEST_BODY")));
  api.sendHttpRequestWithoutParams("POST", "/post/resource", "RESPONSE_POST_BODY");
  assertThat(akitaScenario.getVar("RESPONSE_POST_BODY"), equalTo("TEST_BODY"));
}

代码示例来源:origin: kamax-matrix/mxisd

@Test
public void lookupBulkNotFound() {
  stubFor(post(urlEqualTo(lookupBulkPath))
      .willReturn(aResponse()
          .withHeader("Content-Type", ContentType.APPLICATION_JSON.getMimeType())
          .withBody(lookupBulkNotFoundBody)
      )
  );
  List<ThreePidMapping> mappings = p.populate(lookupBulkList);
  assertNotNull(mappings);
  assertEquals(0, mappings.size());
}

代码示例来源:origin: mozilla/zest

@Before
public void before() {
  server.stubFor(
      post(urlEqualTo(PATH_SERVER_FILE))
          .willReturn(
              aResponse()
                  .withStatus(404)
                  .withHeader("Content-Type", "text/plain")
                  .withHeader("Name", "value")
                  .withHeader("Server", "abc")
                  .withBody("This is the response")));
}

代码示例来源:origin: kptfh/feign-reactive

@Test
 public void testPayBill_success() throws JsonProcessingException {

  Bill bill = Bill.makeBill(new OrderGenerator().generate(30));

  wireMockRule.stubFor(post(urlEqualTo("/icecream/bills/pay"))
      .withRequestBody(equalTo(TestUtils.MAPPER.writeValueAsString(bill)))
      .willReturn(aResponse().withStatus(200)
          .withHeader("Content-Type", "application/json")));

  Mono<Void> result = client.payBill(bill);
  StepVerifier.create(result)
    .expectNextCount(0)
    .verifyComplete();
 }
}

相关文章