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));
}
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());
}
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());
}
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();
}
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();
}
Aggregations