use of com.github.tomakehurst.wiremock.matching.RequestPattern in project spring-cloud-contract by spring-cloud.
the class WireMockRequestStubStrategy method appendQueryParameters.
private void appendQueryParameters(RequestPatternBuilder requestPattern) {
QueryParameters queryParameters = Optional.ofNullable(request).map(Request::getUrlPath).map(Url::getQueryParameters).orElseGet(() -> Optional.ofNullable(request).map(Request::getUrl).map(Url::getQueryParameters).orElse(null));
Optional.ofNullable(queryParameters).map(QueryParameters::getParameters).ifPresent(parameters -> parameters.forEach(parameter -> requestPattern.withQueryParam(parameter.getName(), (StringValuePattern) convertToValuePattern(parameter.getClientValue()))));
}
use of com.github.tomakehurst.wiremock.matching.RequestPattern in project furms by unity-idm.
the class UnityClientTest method shouldSend_DELETE_toUnityServer.
@Test
void shouldSend_DELETE_toUnityServer() {
// given
RequestPattern request = new RequestPatternBuilder(DELETE, new UrlPattern(new EqualToPattern("/path/to/unity/test?recursive=true"), false)).build();
server.addStubMapping(new StubMapping(request, ResponseDefinitionBuilder.responseDefinition().withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE).withStatus(SC_OK).build()));
// when
unityClient.delete("/path/to/unity/test", Map.of("recursive", TRUE.toString()));
// then
VerificationResult verificationResult = server.countRequestsMatching(request);
assertThat(verificationResult.getCount()).isEqualTo(1);
}
use of com.github.tomakehurst.wiremock.matching.RequestPattern in project furms by unity-idm.
the class UnityClientTest method shouldSend_GET_toUnityServer.
@Test
void shouldSend_GET_toUnityServer() {
// given
RequestPattern request = new RequestPatternBuilder(GET, new UrlPattern(new EqualToPattern("/path/to/unity/test?param1=stringValue¶m2=1"), false)).build();
server.addStubMapping(new StubMapping(request, ResponseDefinitionBuilder.responseDefinition().withBody("{\"field\": \"string_value\"}").withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE).withStatus(SC_OK).build()));
// when
SampleDto response = unityClient.get("/path/to/unity/test", SampleDto.class, Map.of("param1", "stringValue", "param2", "1"));
// then
VerificationResult verificationResult = server.countRequestsMatching(request);
assertThat(verificationResult.getCount()).isEqualTo(1);
assertThat(response.getField()).isEqualTo("string_value");
}
use of com.github.tomakehurst.wiremock.matching.RequestPattern in project atlasdb by palantir.
the class AtlasDbHttpClientsTest method ifOneServerResponds503WithNoRetryHeaderTheRequestIsRerouted.
@Test
public void ifOneServerResponds503WithNoRetryHeaderTheRequestIsRerouted() {
RETRY_OTHER_FIRST_RESPONSE_TRANSFORMER.registerUrl(getUriForPort(availablePort1));
RETRY_OTHER_FIRST_RESPONSE_TRANSFORMER.registerUrl(getUriForPort(availablePort2));
TestResource client = AtlasDbHttpClients.createProxyWithFailover(MetricsManagers.createForTests(), ImmutableServerListConfig.builder().addServers(getUriForPort(availablePort1)).addServers(getUriForPort(availablePort2)).sslConfiguration(SSL_CONFIG).build(), TestResource.class, AUXILIARY_REMOTING_PARAMETERS);
int response = client.getTestNumber();
RequestPattern request = getRequestedFor(urlMatching(GET_ENDPOINT)).build();
assertThat(availableServer1.findRequestsMatching(request).getRequests()).hasSizeGreaterThanOrEqualTo(1);
assertThat(availableServer2.findRequestsMatching(request).getRequests()).hasSizeGreaterThanOrEqualTo(1);
assertThat(response).isIn(TEST_NUMBER_1, TEST_NUMBER_2);
RETRY_OTHER_FIRST_RESPONSE_TRANSFORMER.reset();
}
use of com.github.tomakehurst.wiremock.matching.RequestPattern in project wiremock by wiremock.
the class FindRequestsTask method execute.
@Override
public ResponseDefinition execute(Admin admin, Request request, PathParams pathParams) {
RequestPattern requestPattern = Json.read(request.getBodyAsString(), RequestPattern.class);
FindRequestsResult result = admin.findRequestsMatching(requestPattern);
return responseDefinition().withStatus(HTTP_OK).withBody(Json.write(result)).withHeader("Content-Type", "application/json").build();
}
Aggregations