本文整理了Java中com.github.tomakehurst.wiremock.client.WireMock.containing()
方法的一些代码示例,展示了WireMock.containing()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WireMock.containing()
方法的具体详情如下:
包路径:com.github.tomakehurst.wiremock.client.WireMock
类名称:WireMock
方法名:containing
暂无
代码示例来源: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
public void testAppendMethodPut() throws Exception {
wireMockRule.stubFor(put(urlEqualTo("/test/log4j/1234"))
.willReturn(SUCCESS_RESPONSE));
final Appender appender = HttpAppender.newBuilder()
.withName("Http")
.withLayout(JsonLayout.createDefaultLayout())
.setConfiguration(ctx.getConfiguration())
.setMethod("PUT")
.setUrl(new URL("http://localhost:" + wireMockRule.port() + "/test/log4j/1234"))
.build();
appender.append(createLogEvent());
wireMockRule.verify(putRequestedFor(urlEqualTo("/test/log4j/1234"))
.withHeader("Host", containing("localhost"))
.withHeader("Content-Type", containing("application/json"))
.withRequestBody(containing("\"message\" : \"" + LOG_MESSAGE + "\"")));
}
代码示例来源: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: 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: org.apache.logging.log4j/log4j-core
.withHeader("Host", containing("localhost"))
.withHeader("Content-Type", containing("application/json"))
.withRequestBody(containing("\"message\" : \"" + LOG_MESSAGE + "\"")));
代码示例来源:origin: com.github.tomakehurst/wiremock-jre8
public MultipartValuePatternBuilder withName(String name) {
this.name = name;
return withHeader("Content-Disposition", containing("name=\"" + name + "\""));
}
代码示例来源:origin: aws/aws-sdk-java-v2
private void validateResponse(HttpExecuteResponse response, int returnCode, SdkHttpMethod method) throws IOException {
RequestMethod requestMethod = RequestMethod.fromString(method.name());
RequestPatternBuilder patternBuilder = RequestPatternBuilder.newRequestPattern(requestMethod, urlMatching("/"))
.withHeader("Host", containing("localhost"))
.withHeader("User-Agent", equalTo("hello-world!"));
if (method == SdkHttpMethod.HEAD) {
patternBuilder.withRequestBody(equalTo(""));
} else {
patternBuilder.withRequestBody(equalTo("Body"));
}
verify(1, patternBuilder);
if (method == SdkHttpMethod.HEAD) {
assertThat(response.responseBody()).isEmpty();
} else {
assertThat(IoUtils.toUtf8String(response.responseBody().orElse(null))).isEqualTo("hello");
}
assertThat(response.httpResponse().firstMatchingHeader("Some-Header")).contains("With Value");
assertThat(response.httpResponse().statusCode()).isEqualTo(returnCode);
mockServer.resetMappings();
}
代码示例来源:origin: kamax-matrix/mxisd
@Test
public void byThreepidFound() {
stubFor(post(urlEqualTo(endpoint))
.willReturn(aResponse()
.withHeader("Content-Type", ContentType.APPLICATION_JSON.getMimeType())
.withBody(new String(byThreepidResponse.getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8))
)
);
UserDirectorySearchResult result = p.searchBy3pid(byThreepidSearch);
assertTrue(!result.isLimited());
assertEquals(1, result.getResults().size());
UserDirectorySearchResult.Result entry = result.getResults().iterator().next();
assertNotNull(entry);
assertTrue(StringUtils.equals(byThreepidAvatar, entry.getAvatarUrl()));
assertTrue(StringUtils.equals(byThreepidDisplay, entry.getDisplayName()));
assertTrue(StringUtils.equals(MatrixID.asAcceptable(byThreepidId, domain).getId(), entry.getUserId()));
verify(postRequestedFor(urlMatching(endpoint))
.withHeader("Content-Type", containing(ContentType.APPLICATION_JSON.getMimeType()))
.withRequestBody(equalTo(byThreepidRequest))
);
}
代码示例来源: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: kamax-matrix/mxisd
@Test
public void byNameFound() {
stubFor(post(urlEqualTo(endpoint))
.willReturn(aResponse()
.withHeader("Content-Type", ContentType.APPLICATION_JSON.getMimeType())
.withBody(byNameResponse)
)
);
UserDirectorySearchResult result = p.searchByDisplayName(byNameSearch);
assertTrue(!result.isLimited());
assertEquals(1, result.getResults().size());
UserDirectorySearchResult.Result entry = result.getResults().iterator().next();
assertNotNull(entry);
assertTrue(StringUtils.equals(byNameAvatar, entry.getAvatarUrl()));
assertTrue(StringUtils.equals(byNameDisplay, entry.getDisplayName()));
assertTrue(StringUtils.equals(MatrixID.asAcceptable(byNameId, domain).getId(), entry.getUserId()));
verify(postRequestedFor(urlMatching(endpoint))
.withHeader("Content-Type", containing(ContentType.APPLICATION_JSON.getMimeType()))
.withRequestBody(equalTo(byNameRequest))
);
}
代码示例来源:origin: kamax-matrix/mxisd
@Test
public void forNameEmptyBody() {
stubFor(post(urlEqualTo(displayNameEndpoint))
.willReturn(aResponse()
.withHeader("Content-Type", ContentType.APPLICATION_JSON.getMimeType())
)
);
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: kamax-matrix/mxisd
@Test
public void forNameFound() {
String value = "This is my display name";
JsonProfileResult r = new JsonProfileResult();
r.setDisplayName(value);
stubFor(post(urlEqualTo(displayNameEndpoint))
.willReturn(aResponse()
.withHeader("Content-Type", ContentType.APPLICATION_JSON.getMimeType())
.withBody(GsonUtil.get().toJson(GsonUtil.makeObj("profile", r)))
)
);
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))))
);
assertTrue(v.isPresent());
assertEquals(value, v.get());
}
代码示例来源:origin: sargue/mailgun
@Test
public void sendWithInlineAttachment() {
stubFor(post(urlEqualTo("/api/" + DOMAIN + "/messages"))
.withHeader("Authorization",
equalTo("Basic " + expectedAuthHeader))
.withHeader("Content-Type",
containing("multipart/form-data"))
.willReturn(aResponse().withStatus(200)));
Response response = MailBuilder.using(configuration)
.to("doc@delorean.com")
.subject("This message has an text attachment")
.html("<html>Inline image here: <img src=\"cid:cartman.jpg\"></html>")
.multipart()
.inline(new ByteArrayInputStream("MockBytes".getBytes()), "cartman.jpg")
.build()
.send();
assertTrue(response.isOk());
//TODO proper content checking
}
代码示例来源:origin: kamax-matrix/mxisd
@Test
public void lookupSingleNotFound() {
stubFor(post(urlEqualTo(lookupSinglePath))
.willReturn(aResponse()
.withHeader("Content-Type", ContentType.APPLICATION_JSON.getMimeType())
.withBody(lookupSingleNotFoundBody)
)
);
Optional<SingleLookupReply> rep = p.find(lookupSingleRequest);
assertTrue(!rep.isPresent());
verify(postRequestedFor(urlMatching("/lookup/single"))
.withHeader("Content-Type", containing(ContentType.APPLICATION_JSON.getMimeType()))
.withRequestBody(equalTo(lookupSingleRequestBody))
);
}
代码示例来源:origin: kamax-matrix/mxisd
@Test
public void lookupSingleFound() {
stubFor(post(urlEqualTo(lookupSinglePath))
.willReturn(aResponse()
.withHeader("Content-Type", ContentType.APPLICATION_JSON.getMimeType())
.withBody(lookupSingleFoundBody)
)
);
Optional<SingleLookupReply> rep = p.find(lookupSingleRequest);
assertTrue(rep.isPresent());
rep.ifPresent(data -> {
assertNotNull(data.getMxid());
assertTrue(data.getMxid().getId(), StringUtils.equals(data.getMxid().getId(), "@john:example.org"));
});
verify(postRequestedFor(urlMatching("/lookup/single"))
.withHeader("Content-Type", containing(ContentType.APPLICATION_JSON.getMimeType()))
.withRequestBody(equalTo(lookupSingleRequestBody))
);
}
代码示例来源:origin: kamax-matrix/mxisd
@Test
public void byThreepidNotFound() {
stubFor(post(urlEqualTo(endpoint))
.willReturn(aResponse()
.withHeader("Content-Type", ContentType.APPLICATION_JSON.getMimeType())
.withBody(byThreepidEmptyResponse)
)
);
UserDirectorySearchResult result = p.searchBy3pid(byThreepidSearch);
assertTrue(!result.isLimited());
assertTrue(result.getResults().isEmpty());
verify(postRequestedFor(urlMatching(endpoint))
.withHeader("Content-Type", containing(ContentType.APPLICATION_JSON.getMimeType()))
.withRequestBody(equalTo(byThreepidRequest))
);
}
代码示例来源:origin: kamax-matrix/mxisd
@Test(expected = InternalServerError.class)
public void forNameInvalidBody() {
stubFor(post(urlEqualTo(displayNameEndpoint))
.willReturn(aResponse()
.withHeader("Content-Type", ContentType.APPLICATION_JSON.getMimeType())
.withBody("This is not a valid JSON object")
)
);
try {
p.getDisplayName(userId);
} finally {
verify(postRequestedFor(urlMatching(displayNameEndpoint))
.withHeader("Content-Type", containing(ContentType.APPLICATION_JSON.getMimeType()))
.withRequestBody(equalTo(GsonUtil.get().toJson(new JsonProfileRequest(userId))))
);
}
}
代码示例来源:origin: kamax-matrix/mxisd
@Test
public void byNameNotFound() {
stubFor(post(urlEqualTo(endpoint))
.willReturn(aResponse()
.withHeader("Content-Type", ContentType.APPLICATION_JSON.getMimeType())
.withBody(byNameEmptyResponse)
)
);
UserDirectorySearchResult result = p.searchByDisplayName(byNameSearch);
assertTrue(!result.isLimited());
assertTrue(result.getResults().isEmpty());
verify(postRequestedFor(urlMatching(endpoint))
.withHeader("Content-Type", containing(ContentType.APPLICATION_JSON.getMimeType()))
.withRequestBody(equalTo(byNameRequest))
);
}
代码示例来源:origin: kptfh/feign-reactive
@Test
public void testCompression() throws JsonProcessingException {
IceCreamOrder order = new OrderGenerator().generate(20);
Bill billExpected = Bill.makeBill(order);
wireMockRule.stubFor(post(urlEqualTo("/icecream/orders"))
.withHeader("Accept-Encoding", containing("gzip"))
.withRequestBody(equalTo(TestUtils.MAPPER.writeValueAsString(order)))
.willReturn(aResponse().withStatus(200)
.withHeader("Content-Type", "application/json")
.withHeader("Content-Encoding", "gzip")
.withBody(Gzip.gzip(TestUtils.MAPPER.writeValueAsString(billExpected)))));
IcecreamServiceApi client = builder(
new ReactiveOptions.Builder()
.setTryUseCompression(true)
.build())
.target(IcecreamServiceApi.class, "http://localhost:" + wireMockRule.port());
Mono<Bill> bill = client.makeOrder(order);
StepVerifier.create(bill)
.expectNextMatches(equalsComparingFieldByFieldRecursively(billExpected))
.verifyComplete();
}
}
代码示例来源:origin: sargue/mailgun
@Test
public void sendWithAttachment() {
stubFor(post(urlEqualTo("/api/" + DOMAIN + "/messages"))
.withHeader("Authorization",
equalTo("Basic " + expectedAuthHeader))
.withHeader("Content-Type",
containing("multipart/form-data"))
.willReturn(aResponse().withStatus(200)));
Response response = MailBuilder.using(configuration)
.to("doc@delorean.com")
.subject("This message has an text attachment")
.text("Please find attached some text.")
.multipart()
.attachment("This is the content of the attachment",
"readme.txt")
.build()
.send();
assertTrue(response.isOk());
//TODO proper content checking
}
内容来源于网络,如有侵权,请联系作者删除!