use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class AdminApiTest method returnsBadEntityStatusWhenInvalidMatchOperatorManyBodyPatterns.
@Test
public void returnsBadEntityStatusWhenInvalidMatchOperatorManyBodyPatterns() {
WireMockResponse response = testClient.postJson("/__admin/mappings", "{\n" + " \"request\": {\n" + " \"bodyPatterns\": [\n" + " {\n" + " \"equalTo\": \"fine\"\n" + " },\n" + " {\n" + " \"matching\": \"somebad]]][[stuff\"\n" + " }\n" + " ]\n" + " }\n" + "}");
assertThat(response.statusCode(), is(422));
Errors errors = Json.read(response.content(), Errors.class);
assertThat(errors.first().getSource().getPointer(), is("/request/bodyPatterns/1"));
assertThat(errors.first().getDetail(), is("{\"matching\":\"somebad]]][[stuff\"} is not a valid match operation"));
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class AdminApiTest method importMultipleStubsWithDefaultParameters.
@Test
public void importMultipleStubsWithDefaultParameters() {
WireMockResponse response = testClient.postJson("/__admin/mappings/import", STUB_IMPORT_JSON);
assertThat(response.statusCode(), is(200));
List<StubMapping> allStubs = wm.getStubMappings();
assertThat(allStubs.size(), is(2));
assertThat(allStubs.get(0).getRequest().getUrl(), is("/one"));
assertThat(allStubs.get(1).getRequest().getUrl(), is("/two"));
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class AdminApiTest method returnsBadEntityStatusWhenEqualToOperandIsWrongType.
@Test
public void returnsBadEntityStatusWhenEqualToOperandIsWrongType() {
WireMockResponse response = testClient.postJson("/__admin/mappings", "{\n" + " \"request\": {\n" + " \"bodyPatterns\": [\n" + " {\n" + " \"equalTo\": 12\n" + " }\n" + " ]\n" + " }\n" + "}");
assertThat(response.statusCode(), is(422));
Errors errors = Json.read(response.content(), Errors.class);
assertThat(errors.first().getSource().getPointer(), is("/request/bodyPatterns/0"));
assertThat(errors.first().getTitle(), is("Error parsing JSON"));
assertThat(errors.first().getDetail(), is("equalTo operand must be a non-null string"));
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class AdminApiTest method servesSwaggerSpec.
@Test
public void servesSwaggerSpec() {
WireMockResponse response = testClient.get("/__admin/docs/swagger");
assertThat(response.statusCode(), is(200));
assertThat(response.content(), containsString("\"openapi\": \"3.0.0\""));
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class AdminApiTest method getLoggedRequestById.
@Test
public void getLoggedRequestById() throws Exception {
for (int i = 1; i <= 3; i++) {
testClient.get("/received-request/" + i);
}
List<ServeEvent> serveEvents = dsl.getAllServeEvents();
UUID servedStubId = serveEvents.get(1).getId();
WireMockResponse response = testClient.get("/__admin/requests/" + servedStubId);
String body = response.content();
System.out.println("BODY:" + body);
assertThat(response.statusCode(), is(200));
JsonVerifiable check = JsonAssertion.assertThat(body);
check.field("id").isEqualTo(servedStubId);
check.field("request").field("url").isEqualTo("/received-request/2");
}
Aggregations