use of com.github.tomakehurst.wiremock.stubbing.StubMapping in project georocket by georocket.
the class RemoteElasticsearchClientTest method createIndexWithSettings.
/**
* Test if the client can create an index with settings
* @param context the test context
*/
@Test
public void createIndexWithSettings(TestContext context) {
StubMapping settings = stubFor(put(urlEqualTo("/" + INDEX)).withRequestBody(equalToJson(SETTINGS_WRAPPER.encode())).willReturn(aResponse().withBody(ACKNOWLEDGED.encode()).withStatus(200)));
Async async = context.async();
client.createIndex(SETTINGS).subscribe(ok -> {
context.assertTrue(ok);
verify(putRequestedFor(settings.getRequest().getUrlMatcher()));
async.complete();
}, context::fail);
}
use of com.github.tomakehurst.wiremock.stubbing.StubMapping in project blueocean-plugin by jenkinsci.
the class GithubMockBase method addPerTestStub.
/**
* Add a StubMapping to Wiremock corresponding to the supplied builder.
* Any mappings added will automatically be removed when @After fires.
* @param builder
*/
protected void addPerTestStub(MappingBuilder builder) {
StubMapping mapping = githubApi.stubFor(builder);
perTestStubMappings.add(mapping);
}
use of com.github.tomakehurst.wiremock.stubbing.StubMapping in project irontest by zheng-wang.
the class HTTPStubsHitInOrderAssertionVerifier method verify.
@Override
public AssertionVerificationResult verify(Object... inputs) {
HTTPStubsHitInOrderAssertionVerificationResult result = new HTTPStubsHitInOrderAssertionVerificationResult();
HTTPStubsHitInOrderAssertionProperties otherProperties = (HTTPStubsHitInOrderAssertionProperties) getAssertion().getOtherProperties();
Map<Date, Short> hitMap = new TreeMap<>();
List<ServeEvent> allServeEvents = (List<ServeEvent>) inputs[0];
for (ServeEvent serveEvent : allServeEvents) {
if (serveEvent.getWasMatched()) {
StubMapping stubMapping = serveEvent.getStubMapping();
hitMap.put(serveEvent.getRequest().getLoggedDate(), (Short) stubMapping.getMetadata().get(WIREMOCK_STUB_METADATA_ATTR_NAME_IRON_TEST_NUMBER));
}
}
List<Short> actualHitOrder = new ArrayList(hitMap.values());
result.setResult(otherProperties.getExpectedHitOrder().equals(actualHitOrder) ? TestResult.PASSED : TestResult.FAILED);
result.setActualHitOrder(actualHitOrder);
return result;
}
use of com.github.tomakehurst.wiremock.stubbing.StubMapping in project irontest by zheng-wang.
the class IronTestUtils method createStubInstance.
/**
* Create (clone) a new instance out of the stub spec, with UUID generated for the instance.
* The instance also has the ironTestId as metadata.
* The spec is not changed.
* @param spec
* @return
*/
public static StubMapping createStubInstance(long ironTestId, short ironTestNumber, StubMapping spec) {
StubMapping stubInstance = StubMapping.buildFrom(StubMapping.buildJsonStringFor(spec));
stubInstance.setMetadata(metadata().attr(WIREMOCK_STUB_METADATA_ATTR_NAME_IRON_TEST_ID, ironTestId).attr(WIREMOCK_STUB_METADATA_ATTR_NAME_IRON_TEST_NUMBER, ironTestNumber).build());
stubInstance.setDirty(false);
return stubInstance;
}
use of com.github.tomakehurst.wiremock.stubbing.StubMapping in project irontest by zheng-wang.
the class HTTPStubResource method loadAll.
@POST
@Path("testcases/{testcaseId}/httpstubs/loadAll")
@PermitAll
public void loadAll(@PathParam("testcaseId") long testcaseId) throws IOException {
// gather referenceable string properties
List<UserDefinedProperty> testcaseUDPs = udpDAO.findByTestcaseId(testcaseId);
Map<String, String> referenceableStringProperties = IronTestUtils.udpListToMap(testcaseUDPs);
DataTable dataTable = dataTableDAO.getTestcaseDataTable(testcaseId, true);
if (dataTable.getRows().size() > 0) {
IronTestUtils.checkDuplicatePropertyNameBetweenDataTableAndUPDs(referenceableStringProperties.keySet(), dataTable);
referenceableStringProperties.putAll(dataTable.getStringPropertiesInRow(0));
}
List<HTTPStubMapping> stubs = httpStubMappingDAO.findByTestcaseId(testcaseId);
// resolve string property references in HTTPStubMapping objects
List<String> undefinedStringProperties = new ArrayList<>();
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
IronTestUtils.addMixInsForWireMock(objectMapper);
String httpStubMappingsJSON = objectMapper.writeValueAsString(stubs);
MapValueLookup propertyReferenceResolver = new MapValueLookup(referenceableStringProperties, true);
String resolvedHttpStubMappingsJSON = new StrSubstitutor(propertyReferenceResolver).replace(httpStubMappingsJSON);
stubs = objectMapper.readValue(resolvedHttpStubMappingsJSON, new TypeReference<List<HTTPStubMapping>>() {
});
undefinedStringProperties.addAll(propertyReferenceResolver.getUnfoundKeys());
if (!undefinedStringProperties.isEmpty()) {
throw new RuntimeException("String properties " + undefinedStringProperties + " not defined.");
}
IronTestUtils.substituteRequestBodyMainPatternValue(stubs);
// load stubs
final List<HTTPStubMapping> finalStubs = stubs;
wireMockServer.loadMappingsUsing(stubMappings -> {
for (HTTPStubMapping stub : finalStubs) {
// delete old instances if exist
List<StubMapping> existingInstances = wireMockServer.findStubMappingsByMetadata(matchingJsonPath("$." + WIREMOCK_STUB_METADATA_ATTR_NAME_IRON_TEST_ID, equalTo(Long.toString(stub.getId()))));
for (StubMapping existingInstance : existingInstances) {
wireMockServer.removeStubMapping(existingInstance);
}
StubMapping stubInstance = IronTestUtils.createStubInstance(stub.getId(), stub.getNumber(), stub.getSpec());
stubMappings.addMapping(stubInstance);
}
});
}
Aggregations