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