Search in sources :

Example 11 with RequestPattern

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

the class GetRequestCountTask method execute.

@Override
public ResponseDefinition execute(Admin admin, Request request, PathParams pathParams) {
    RequestPattern requestPattern = Json.read(request.getBodyAsString(), RequestPattern.class);
    VerificationResult result = admin.countRequestsMatching(requestPattern);
    return responseDefinition().withStatus(HTTP_OK).withBody(write(result)).withHeader("Content-Type", "application/json").build();
}
Also used : VerificationResult(com.github.tomakehurst.wiremock.verification.VerificationResult) RequestPattern(com.github.tomakehurst.wiremock.matching.RequestPattern)

Example 12 with RequestPattern

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

the class SnapshotStubMappingGenerator method apply.

@Override
public StubMapping apply(ServeEvent event) {
    final RequestPattern requestPattern = requestTransformer.apply(event.getRequest()).build();
    final ResponseDefinition responseDefinition = responseTransformer.apply(event.getResponse());
    StubMapping stubMapping = new StubMapping(requestPattern, responseDefinition);
    URI uri = URI.create(event.getRequest().getUrl());
    stubMapping.setName(SafeNames.makeSafeNameFromUrl(uri.getPath()));
    return stubMapping;
}
Also used : ResponseDefinition(com.github.tomakehurst.wiremock.http.ResponseDefinition) StubMapping(com.github.tomakehurst.wiremock.stubbing.StubMapping) RequestPattern(com.github.tomakehurst.wiremock.matching.RequestPattern) URI(java.net.URI)

Example 13 with RequestPattern

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

the class SnapshotStubMappingPostProcessor method process.

public List<StubMapping> process(Iterable<StubMapping> stubMappings) {
    final Multiset<RequestPattern> requestCounts = HashMultiset.create();
    final List<StubMapping> processedStubMappings = new ArrayList<>();
    for (StubMapping stubMapping : stubMappings) {
        requestCounts.add(stubMapping.getRequest());
        // Skip duplicate requests if shouldRecordRepeatsAsScenarios is not enabled
        if (requestCounts.count(stubMapping.getRequest()) > 1 && !shouldRecordRepeatsAsScenarios) {
            continue;
        }
        if (bodyExtractMatcher != null && bodyExtractMatcher.match(stubMapping.getResponse()).isExactMatch()) {
            bodyExtractor.extractInPlace(stubMapping);
        }
        processedStubMappings.add(stubMapping);
    }
    if (shouldRecordRepeatsAsScenarios) {
        new ScenarioProcessor().putRepeatedRequestsInScenarios(processedStubMappings);
    }
    // Run any stub mapping transformer extensions
    return Lists.transform(processedStubMappings, transformerRunner);
}
Also used : ArrayList(java.util.ArrayList) StubMapping(com.github.tomakehurst.wiremock.stubbing.StubMapping) RequestPattern(com.github.tomakehurst.wiremock.matching.RequestPattern)

Example 14 with RequestPattern

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

the class RecordSpecBuilder method build.

public RecordSpec build() {
    RequestPattern filterRequestPattern = filterRequestPatternBuilder != null ? filterRequestPatternBuilder.build() : null;
    ProxiedServeEventFilters filters = filterRequestPatternBuilder != null || filterIds != null || allowNonProxied ? new ProxiedServeEventFilters(filterRequestPattern, filterIds, allowNonProxied) : null;
    ResponseDefinitionBodyMatcher responseDefinitionBodyMatcher = new ResponseDefinitionBodyMatcher(maxTextBodySize, maxBinaryBodySize);
    return new RecordSpec(targetBaseUrl, filters, headers.isEmpty() ? null : headers, requestBodyPatternFactory, responseDefinitionBodyMatcher, SnapshotOutputFormatter.FULL, persistentStubs, repeatsAsScenarios, transformerNames, transformerParameters);
}
Also used : RequestPattern(com.github.tomakehurst.wiremock.matching.RequestPattern)

Example 15 with RequestPattern

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

the class SortedConcurrentMappingSetTest method aMapping.

private StubMapping aMapping(Integer priority, String url) {
    RequestPattern requestPattern = newRequestPattern(ANY, urlEqualTo(url)).build();
    StubMapping mapping = new StubMapping(requestPattern, new ResponseDefinition());
    mapping.setPriority(priority);
    return mapping;
}
Also used : ResponseDefinition(com.github.tomakehurst.wiremock.http.ResponseDefinition) RequestPatternBuilder.newRequestPattern(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder.newRequestPattern) RequestPattern(com.github.tomakehurst.wiremock.matching.RequestPattern)

Aggregations

RequestPattern (com.github.tomakehurst.wiremock.matching.RequestPattern)20 StubMapping (com.github.tomakehurst.wiremock.stubbing.StubMapping)8 RequestPatternBuilder (com.github.tomakehurst.wiremock.matching.RequestPatternBuilder)6 UrlPattern (com.github.tomakehurst.wiremock.matching.UrlPattern)6 VerificationResult (com.github.tomakehurst.wiremock.verification.VerificationResult)6 ResponseDefinition (com.github.tomakehurst.wiremock.http.ResponseDefinition)5 Test (org.junit.jupiter.api.Test)5 EqualToPattern (com.github.tomakehurst.wiremock.matching.EqualToPattern)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 RequestPatternBuilder.newRequestPattern (com.github.tomakehurst.wiremock.matching.RequestPatternBuilder.newRequestPattern)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 RequestMethod (com.github.tomakehurst.wiremock.http.RequestMethod)2 ContentPattern (com.github.tomakehurst.wiremock.matching.ContentPattern)2 StringValuePattern (com.github.tomakehurst.wiremock.matching.StringValuePattern)2 GString (groovy.lang.GString)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2