Search in sources :

Example 1 with RequestMethod

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);
}
Also used : RequestMethod(com.github.tomakehurst.wiremock.http.RequestMethod) RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder) UrlPattern(com.github.tomakehurst.wiremock.matching.UrlPattern)

Example 2 with RequestMethod

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();
}
Also used : RequestMethod(com.github.tomakehurst.wiremock.http.RequestMethod) RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder)

Example 3 with RequestMethod

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();
}
Also used : RequestMethod(com.github.tomakehurst.wiremock.http.RequestMethod) RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder)

Example 4 with RequestMethod

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);
}
Also used : RequestMethod(com.github.tomakehurst.wiremock.http.RequestMethod) RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder) UrlPattern(com.github.tomakehurst.wiremock.matching.UrlPattern)

Example 5 with RequestMethod

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);
}
Also used : RequestMethod(com.github.tomakehurst.wiremock.http.RequestMethod) RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder) UrlPattern(com.github.tomakehurst.wiremock.matching.UrlPattern) Pair(com.github.mjeanroy.junit.servers.utils.commons.Pair)

Aggregations

RequestMethod (com.github.tomakehurst.wiremock.http.RequestMethod)9 RequestPatternBuilder (com.github.tomakehurst.wiremock.matching.RequestPatternBuilder)7 UrlPattern (com.github.tomakehurst.wiremock.matching.UrlPattern)6 Pair (com.github.mjeanroy.junit.servers.utils.commons.Pair)1 ResponseDefinitionBuilder (com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder)1 Body (com.github.tomakehurst.wiremock.http.Body)1 ContentTypeHeader (com.github.tomakehurst.wiremock.http.ContentTypeHeader)1 Cookie (com.github.tomakehurst.wiremock.http.Cookie)1 HttpHeader (com.github.tomakehurst.wiremock.http.HttpHeader)1 HttpHeaders (com.github.tomakehurst.wiremock.http.HttpHeaders)1 QueryParameter (com.github.tomakehurst.wiremock.http.QueryParameter)1 Request (com.github.tomakehurst.wiremock.http.Request)1 BinaryEqualToPattern (com.github.tomakehurst.wiremock.matching.BinaryEqualToPattern)1 MultipartValuePatternBuilder (com.github.tomakehurst.wiremock.matching.MultipartValuePatternBuilder)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Enumeration (java.util.Enumeration)1