Search in sources :

Example 21 with RequestPatternBuilder

use of com.github.tomakehurst.wiremock.matching.RequestPatternBuilder in project wiremock by wiremock.

the class SnapshotStubMappingGeneratorTest method apply.

@Test
public void apply() {
    final RequestPatternBuilder requestPatternBuilder = newRequestPattern().withUrl("/foo");
    final ResponseDefinition responseDefinition = ResponseDefinition.ok();
    SnapshotStubMappingGenerator stubMappingTransformer = new SnapshotStubMappingGenerator(requestPatternTransformer(requestPatternBuilder), responseDefinitionTransformer(responseDefinition));
    StubMapping actual = stubMappingTransformer.apply(serveEvent());
    StubMapping expected = new StubMapping(requestPatternBuilder.build(), responseDefinition);
    expected.setId(actual.getId());
    assertThat(actual, is(expected));
}
Also used : ResponseDefinition(com.github.tomakehurst.wiremock.http.ResponseDefinition) StubMapping(com.github.tomakehurst.wiremock.stubbing.StubMapping) RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder) Test(org.junit.jupiter.api.Test)

Example 22 with RequestPatternBuilder

use of com.github.tomakehurst.wiremock.matching.RequestPatternBuilder in project wiremock by wiremock.

the class RequestPatternTransformerTest method applyIncludesMethodAndUrlMatchers.

@Test
public void applyIncludesMethodAndUrlMatchers() {
    Request request = mockRequest().url("/foo").method(RequestMethod.GET).header("User-Agent", "foo").header("X-Foo", "bar");
    RequestPatternBuilder expected = new RequestPatternBuilder(RequestMethod.GET, urlEqualTo("/foo"));
    assertEquals(expected.build(), new RequestPatternTransformer(null, null).apply(request).build());
}
Also used : MockRequest.mockRequest(com.github.tomakehurst.wiremock.matching.MockRequest.mockRequest) Request(com.github.tomakehurst.wiremock.http.Request) RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder) Test(org.junit.jupiter.api.Test)

Example 23 with RequestPatternBuilder

use of com.github.tomakehurst.wiremock.matching.RequestPatternBuilder in project wiremock by wiremock.

the class RequestPatternTransformerTest method applyWithHeaders.

@Test
public void applyWithHeaders() {
    Request request = mockRequest().url("/").method(RequestMethod.POST).header("X-CaseSensitive", "foo").header("X-Ignored", "ignored").header("X-CaseInsensitive", "Baz");
    RequestPatternBuilder expected = new RequestPatternBuilder(RequestMethod.POST, urlEqualTo("/")).withHeader("X-CaseSensitive", equalTo("foo")).withHeader("X-CaseInsensitive", equalToIgnoreCase("Baz"));
    Map<String, CaptureHeadersSpec> headers = ImmutableMap.of("X-CaseSensitive", new CaptureHeadersSpec(false), "X-CaseInsensitive", new CaptureHeadersSpec(true));
    assertEquals(expected.build(), new RequestPatternTransformer(headers, null).apply(request).build());
}
Also used : MockRequest.mockRequest(com.github.tomakehurst.wiremock.matching.MockRequest.mockRequest) Request(com.github.tomakehurst.wiremock.http.Request) RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder) Test(org.junit.jupiter.api.Test)

Example 24 with RequestPatternBuilder

use of com.github.tomakehurst.wiremock.matching.RequestPatternBuilder 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 25 with RequestPatternBuilder

use of com.github.tomakehurst.wiremock.matching.RequestPatternBuilder 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)

Aggregations

RequestPatternBuilder (com.github.tomakehurst.wiremock.matching.RequestPatternBuilder)37 Test (org.junit.jupiter.api.Test)13 UrlPattern (com.github.tomakehurst.wiremock.matching.UrlPattern)11 RequestMethod (com.github.tomakehurst.wiremock.http.RequestMethod)9 RequestPattern (com.github.tomakehurst.wiremock.matching.RequestPattern)6 StubMapping (com.github.tomakehurst.wiremock.stubbing.StubMapping)5 Map (java.util.Map)5 Test (org.junit.Test)5 EqualToPattern (com.github.tomakehurst.wiremock.matching.EqualToPattern)4 VerificationResult (com.github.tomakehurst.wiremock.verification.VerificationResult)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 AbstractWireMockTest (com.redhat.service.smartevents.test.wiremock.AbstractWireMockTest)3 QuarkusTest (io.quarkus.test.junit.QuarkusTest)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 WireMock (com.github.tomakehurst.wiremock.client.WireMock)2 Parameters (com.github.tomakehurst.wiremock.extension.Parameters)2 Request (com.github.tomakehurst.wiremock.http.Request)2 ContentPattern (com.github.tomakehurst.wiremock.matching.ContentPattern)2