use of com.github.tomakehurst.wiremock.stubbing.StubMapping in project spring-cloud-netflix by spring-cloud.
the class WireMockRestAssuredRequestAdapter method filter.
@Override
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext context) {
Map<String, Object> configuration = getConfiguration(requestSpec, context);
configuration.put("contract.jsonPaths", this.jsonPaths.keySet());
Response response = context.next(requestSpec, responseSpec);
if (requestSpec.getBody() != null && !this.jsonPaths.isEmpty()) {
String actual = new String((byte[]) requestSpec.getBody());
for (JsonPath jsonPath : this.jsonPaths.values()) {
new JsonPathValue(jsonPath, actual).assertHasValue(Object.class, "an object");
}
}
if (this.builder != null) {
this.builder.willReturn(getResponseDefinition(response));
StubMapping stubMapping = this.builder.build();
MatchResult match = stubMapping.getRequest().match(new WireMockRestAssuredRequestAdapter(requestSpec));
assertThat(match.isExactMatch()).as("wiremock did not match request").isTrue();
configuration.put("contract.stubMapping", stubMapping);
}
return response;
}
use of com.github.tomakehurst.wiremock.stubbing.StubMapping in project irontest by zheng-wang.
the class IronTestUtils method substituteRequestBodyMainPatternValue.
public static void substituteRequestBodyMainPatternValue(List<HTTPStubMapping> httpStubMappings) {
for (HTTPStubMapping httpStubMapping : httpStubMappings) {
StubMapping spec = httpStubMapping.getSpec();
List<ContentPattern<?>> requestBodyPatterns = spec.getRequest().getBodyPatterns();
if (requestBodyPatterns != null) {
for (int i = 0; i < requestBodyPatterns.size(); i++) {
ContentPattern requestBodyPattern = requestBodyPatterns.get(i);
if (requestBodyPattern instanceof EqualToXmlPattern) {
EqualToXmlPattern equalToXmlPattern = (EqualToXmlPattern) requestBodyPattern;
requestBodyPatterns.set(i, new EqualToXmlPattern(httpStubMapping.getRequestBodyMainPatternValue(), equalToXmlPattern.isEnablePlaceholders(), equalToXmlPattern.getPlaceholderOpeningDelimiterRegex(), equalToXmlPattern.getPlaceholderClosingDelimiterRegex()));
break;
} else if (requestBodyPattern instanceof EqualToJsonPattern) {
EqualToJsonPattern equalToJsonPattern = (EqualToJsonPattern) requestBodyPattern;
requestBodyPatterns.set(i, new EqualToJsonPattern(httpStubMapping.getRequestBodyMainPatternValue(), equalToJsonPattern.isIgnoreArrayOrder(), equalToJsonPattern.isIgnoreExtraElements()));
break;
}
}
}
}
}
use of com.github.tomakehurst.wiremock.stubbing.StubMapping in project irontest by zheng-wang.
the class HTTPStubsSetupTeststepRunner method run.
@Override
public BasicTeststepRun run() {
WireMockServer wireMockServer = getTestcaseRunContext().getWireMockServer();
// reset mock server
wireMockServer.resetAll();
// load stub mappings into mock server
Map<Short, UUID> httpStubMappingInstanceIds = getTestcaseRunContext().getHttpStubMappingInstanceIds();
HTTPStubsSetupTeststepProperties otherProperties = (HTTPStubsSetupTeststepProperties) getTeststep().getOtherProperties();
wireMockServer.loadMappingsUsing(stubMappings -> {
for (HTTPStubMapping stubMapping : otherProperties.getHttpStubMappings()) {
StubMapping stubInstance = IronTestUtils.createStubInstance(stubMapping.getId(), stubMapping.getNumber(), stubMapping.getSpec());
stubMappings.addMapping(stubInstance);
httpStubMappingInstanceIds.put(stubMapping.getNumber(), stubInstance.getId());
}
});
return new BasicTeststepRun();
}
use of com.github.tomakehurst.wiremock.stubbing.StubMapping in project irontest by zheng-wang.
the class HTTPStubMappingMapper method map.
@Override
public HTTPStubMapping map(ResultSet rs, StatementContext ctx) throws SQLException {
String specJSON = rs.getString("spec_json");
StubMapping spec = StubMapping.buildFrom(specJSON);
HTTPStubMapping httpStubMapping = new HTTPStubMapping(rs.getLong("id"), rs.getLong("testcase_id"), rs.getShort("number"), spec, rs.getString("request_body_main_pattern_value"), rs.getShort("expected_hit_count"));
return httpStubMapping;
}
use of com.github.tomakehurst.wiremock.stubbing.StubMapping in project georocket by georocket.
the class RemoteElasticsearchClientTest method createIndex.
/**
* Test if the client can create an index
* @param context the test context
*/
@Test
public void createIndex(TestContext context) {
StubMapping settings = stubFor(put(urlEqualTo("/" + INDEX)).withRequestBody(equalTo("")).willReturn(aResponse().withBody(ACKNOWLEDGED.encode()).withStatus(200)));
Async async = context.async();
client.createIndex().subscribe(ok -> {
context.assertTrue(ok);
verify(putRequestedFor(settings.getRequest().getUrlMatcher()));
async.complete();
}, context::fail);
}
Aggregations