use of com.github.tomakehurst.wiremock.http.RequestMethod in project junit-servers by mjeanroy.
the class WireMockTestUtils method assertRequestWithHeader.
/**
* Verify that a given request has been triggered.
*
* @param endpoint Request endpoint.
* @param method Request method.
* @param headerName Header name.
* @param headerValue Header value.
*/
static void assertRequestWithHeader(String endpoint, HttpMethod method, String headerName, String headerValue) {
UrlPattern urlPattern = urlEqualTo(endpoint);
RequestMethod rqMethod = new RequestMethod(method.name());
RequestPatternBuilder rq = new RequestPatternBuilder(rqMethod, urlPattern);
rq.withHeader(headerName, equalTo(headerValue));
WireMock.verify(1, rq);
}
use of com.github.tomakehurst.wiremock.http.RequestMethod in project aws-sdk-java-v2 by aws.
the class SdkHttpClientTestSuite method validateResponse.
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(absent());
} else {
patternBuilder.withRequestBody(equalTo("Body"));
}
mockServer.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();
}
use of com.github.tomakehurst.wiremock.http.RequestMethod in project aws-sdk-java-v2 by aws.
the class SdkHttpClientDefaultTestSuite method validateResponse.
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(absent());
} else {
patternBuilder.withRequestBody(equalTo("Body"));
}
mockServer.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();
}
use of com.github.tomakehurst.wiremock.http.RequestMethod in project junit-servers by mjeanroy.
the class WireMockTestUtils method assertRequestWithBody.
/**
* Verify that a given request has been triggered.
*
* @param endpoint Request endpoint.
* @param method Request method.
* @param body Request body.
*/
static void assertRequestWithBody(String endpoint, HttpMethod method, String body) {
UrlPattern urlPattern = urlEqualTo(endpoint);
RequestMethod rqMethod = new RequestMethod(method.name());
RequestPatternBuilder rq = new RequestPatternBuilder(rqMethod, urlPattern);
rq.withRequestBody(equalTo(body));
WireMock.verify(1, rq);
}
use of com.github.tomakehurst.wiremock.http.RequestMethod in project junit-servers by mjeanroy.
the class WireMockTestUtils method assertRequestWithCookies.
/**
* Verify that a given request has been triggered.
*
* @param endpoint Request endpoint.
* @param method Request method.
* @param cookies Cookies sent in HTTP request.
*/
static void assertRequestWithCookies(String endpoint, HttpMethod method, Iterable<Pair> cookies) {
UrlPattern urlPattern = urlEqualTo(endpoint);
RequestMethod rqMethod = new RequestMethod(method.name());
RequestPatternBuilder rq = new RequestPatternBuilder(rqMethod, urlPattern);
for (Pair cookie : cookies) {
String cookieName = cookie.getO1();
String cookieValue = cookie.getO2().get(0);
rq.withCookie(cookieName, equalTo(cookieValue));
}
WireMock.verify(1, rq);
}
Aggregations