Search in sources :

Example 1 with StringValuePattern

use of com.github.tomakehurst.wiremock.matching.StringValuePattern 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()))));
}
Also used : Arrays(java.util.Arrays) JsonPaths(org.springframework.cloud.contract.verifier.util.JsonPaths) XmlToXPathsConverter.retrieveValue(org.springframework.cloud.contract.verifier.util.xml.XmlToXPathsConverter.retrieveValue) JsonToJsonPathsConverter(org.springframework.cloud.contract.verifier.util.JsonToJsonPathsConverter) YamlContract(org.springframework.cloud.contract.verifier.converter.YamlContract) SingleContractMetadata(org.springframework.cloud.contract.verifier.file.SingleContractMetadata) MatchingType(org.springframework.cloud.contract.spec.internal.MatchingType) RequestPattern(com.github.tomakehurst.wiremock.matching.RequestPattern) FromFileProperty(org.springframework.cloud.contract.spec.internal.FromFileProperty) BodyMatcher(org.springframework.cloud.contract.spec.internal.BodyMatcher) RegexpBuilders.buildGStringRegexpForStubSide(org.springframework.cloud.contract.verifier.util.RegexpBuilders.buildGStringRegexpForStubSide) QueryParameters(org.springframework.cloud.contract.spec.internal.QueryParameters) YamlContractConverter(org.springframework.cloud.contract.verifier.converter.YamlContractConverter) Contract(org.springframework.cloud.contract.spec.Contract) Map(java.util.Map) BodyMatchers(org.springframework.cloud.contract.spec.internal.BodyMatchers) FORM(org.springframework.cloud.contract.verifier.util.ContentType.FORM) MapConverter(org.springframework.cloud.contract.verifier.util.MapConverter) DslProperty(org.springframework.cloud.contract.spec.internal.DslProperty) ContentUtils(org.springframework.cloud.contract.verifier.util.ContentUtils) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) RegexpBuilders.buildJSONRegexpMatch(org.springframework.cloud.contract.verifier.util.RegexpBuilders.buildJSONRegexpMatch) RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder) GString(groovy.lang.GString) ClientDslProperty(org.springframework.cloud.contract.spec.internal.ClientDslProperty) ContentType(org.springframework.cloud.contract.verifier.util.ContentType) List(java.util.List) StringValuePattern(com.github.tomakehurst.wiremock.matching.StringValuePattern) PathBodyMatcher(org.springframework.cloud.contract.spec.internal.PathBodyMatcher) OptionalProperty(org.springframework.cloud.contract.spec.internal.OptionalProperty) MatchingStrategy(org.springframework.cloud.contract.spec.internal.MatchingStrategy) CollectionUtils(org.springframework.util.CollectionUtils) Optional(java.util.Optional) ContentPattern(com.github.tomakehurst.wiremock.matching.ContentPattern) Pattern(java.util.regex.Pattern) EQUALITY(org.springframework.cloud.contract.spec.internal.MatchingType.EQUALITY) ContentUtils.getEqualsTypeFromContentType(org.springframework.cloud.contract.verifier.util.ContentUtils.getEqualsTypeFromContentType) Request(org.springframework.cloud.contract.spec.internal.Request) Function(java.util.function.Function) WireMock(com.github.tomakehurst.wiremock.client.WireMock) HashSet(java.util.HashSet) NamedProperty(org.springframework.cloud.contract.spec.internal.NamedProperty) UrlPattern(com.github.tomakehurst.wiremock.matching.UrlPattern) Body(org.springframework.cloud.contract.spec.internal.Body) Url(org.springframework.cloud.contract.spec.internal.Url) XmlToXPathsConverter(org.springframework.cloud.contract.verifier.util.xml.XmlToXPathsConverter) Parameters(com.github.tomakehurst.wiremock.extension.Parameters) Iterator(java.util.Iterator) JSON(org.springframework.cloud.contract.verifier.util.ContentType.JSON) MethodBufferingJsonVerifiable(org.springframework.cloud.contract.verifier.util.MethodBufferingJsonVerifiable) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) StringEscapeUtils(org.apache.commons.text.StringEscapeUtils) ContractVerifierMetadata(org.springframework.cloud.contract.verifier.dsl.ContractVerifierMetadata) RegexProperty(org.springframework.cloud.contract.spec.internal.RegexProperty) RequestMethod(com.github.tomakehurst.wiremock.http.RequestMethod) RegexPatterns(org.springframework.cloud.contract.spec.internal.RegexPatterns) Collections(java.util.Collections) BINARY_EQUAL_TO(org.springframework.cloud.contract.spec.internal.MatchingStrategy.Type.BINARY_EQUAL_TO) StringUtils(org.springframework.util.StringUtils) Request(org.springframework.cloud.contract.spec.internal.Request) QueryParameters(org.springframework.cloud.contract.spec.internal.QueryParameters) Url(org.springframework.cloud.contract.spec.internal.Url)

Example 2 with StringValuePattern

use of com.github.tomakehurst.wiremock.matching.StringValuePattern in project mod-kb-ebsco-java by folio-org.

the class TransactionLoadHoldingsImplTest method mockPostDeltaReport.

private void mockPostDeltaReport() {
    StringValuePattern urlPattern = new EqualToPattern(RMAPI_DELTAS_URL);
    stubFor(post(new UrlPathPattern(urlPattern, false)).willReturn(new ResponseDefinitionBuilder().withBody(DELTA_ID).withStatus(202)));
}
Also used : ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) StringValuePattern(com.github.tomakehurst.wiremock.matching.StringValuePattern)

Example 3 with StringValuePattern

use of com.github.tomakehurst.wiremock.matching.StringValuePattern in project mod-kb-ebsco-java by folio-org.

the class TransactionLoadHoldingsImplTest method mockPostHoldings.

private void mockPostHoldings() {
    StringValuePattern urlPattern = new EqualToPattern(RMAPI_POST_TRANSACTIONS_HOLDINGS_URL);
    stubFor(post(new UrlPathPattern(urlPattern, false)).willReturn(new ResponseDefinitionBuilder().withBody(Json.encode(createTransactionId())).withStatus(202)));
}
Also used : ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) EqualToPattern(com.github.tomakehurst.wiremock.matching.EqualToPattern) StringValuePattern(com.github.tomakehurst.wiremock.matching.StringValuePattern)

Example 4 with StringValuePattern

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

the class RemoveServeEventsByStubMetadataTask method execute.

@Override
public ResponseDefinition execute(Admin admin, Request request, PathParams pathParams) {
    StringValuePattern metadataPattern = Json.read(request.getBodyAsString(), StringValuePattern.class);
    FindServeEventsResult findServeEventsResult = admin.removeServeEventsForStubsMatchingMetadata(metadataPattern);
    return ResponseDefinition.okForJson(findServeEventsResult);
}
Also used : FindServeEventsResult(com.github.tomakehurst.wiremock.verification.FindServeEventsResult) StringValuePattern(com.github.tomakehurst.wiremock.matching.StringValuePattern)

Example 5 with StringValuePattern

use of com.github.tomakehurst.wiremock.matching.StringValuePattern in project sechub by mercedes-benz.

the class JSONAdapterSupportTest method buildFromMap_json_with_one_entry_returns_map_with_this_entry.

@Test
public void buildFromMap_json_with_one_entry_returns_map_with_this_entry() throws Exception {
    /* prepare */
    Map<String, Object> json = new TreeMap<>();
    json.put("key1", "value1");
    /* execute */
    String jsonAsString = supportToTest.toJSON(json);
    /* test */
    assertNotNull(jsonAsString);
    StringValuePattern p = WireMock.equalToJson("{\"key1\":\"value1\"}");
    assertTrue(p.match(jsonAsString).isExactMatch());
}
Also used : TreeMap(java.util.TreeMap) StringValuePattern(com.github.tomakehurst.wiremock.matching.StringValuePattern) Test(org.junit.Test)

Aggregations

StringValuePattern (com.github.tomakehurst.wiremock.matching.StringValuePattern)9 ResponseDefinitionBuilder (com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder)3 EqualToPattern (com.github.tomakehurst.wiremock.matching.EqualToPattern)3 UrlPathPattern (com.github.tomakehurst.wiremock.matching.UrlPathPattern)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Zulip (com.github.jamesnetherton.zulip.client.Zulip)1 ListStubMappingsResult (com.github.tomakehurst.wiremock.admin.model.ListStubMappingsResult)1 WireMock (com.github.tomakehurst.wiremock.client.WireMock)1 Parameters (com.github.tomakehurst.wiremock.extension.Parameters)1 RequestMethod (com.github.tomakehurst.wiremock.http.RequestMethod)1 ContentPattern (com.github.tomakehurst.wiremock.matching.ContentPattern)1 RequestPattern (com.github.tomakehurst.wiremock.matching.RequestPattern)1 RequestPatternBuilder (com.github.tomakehurst.wiremock.matching.RequestPatternBuilder)1 UrlPattern (com.github.tomakehurst.wiremock.matching.UrlPattern)1 FindServeEventsResult (com.github.tomakehurst.wiremock.verification.FindServeEventsResult)1 GString (groovy.lang.GString)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1