use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class ProxyAcceptanceTest method stripsCorsHeadersFromTheTarget.
@Test
public void stripsCorsHeadersFromTheTarget() {
initWithDefaultConfig();
proxy.register(any(anyUrl()).willReturn(aResponse().proxiedFrom(targetServiceBaseUrl)));
target.register(any(urlPathEqualTo("/cors")).withName("Target with CORS").willReturn(ok()));
WireMockResponse response = testClient.get("/cors", withHeader("Origin", "http://somewhere.com"));
Collection<String> allowOriginHeaderValues = response.headers().get("Access-Control-Allow-Origin");
assertThat(allowOriginHeaderValues.size(), is(0));
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class AdminApiTest method returnsBadEntityStatusWhenContainsOperandIsNull.
@Test
public void returnsBadEntityStatusWhenContainsOperandIsNull() {
WireMockResponse response = testClient.postJson("/__admin/mappings", "{\n" + " \"request\": {\n" + " \"bodyPatterns\": [\n" + " {\n" + " \"contains\": null\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("contains operand must be a non-null string"));
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class AdminApiTest method getLoggedRequestsWithInvalidSinceDateReturnsBadRequest.
@Test
public void getLoggedRequestsWithInvalidSinceDateReturnsBadRequest() throws Exception {
WireMockResponse response = testClient.get("/__admin/requests?since=foo");
assertThat(response.statusCode(), is(400));
assertThat(response.firstHeader("Content-Type"), is("application/json"));
JsonVerifiable check = JsonAssertion.assertThat(response.content());
JsonVerifiable error = check.field("errors").elementWithIndex(0);
error.field("code").isEqualTo(10);
error.field("source").field("pointer").isEqualTo("since");
error.field("title").isEqualTo("foo is not a valid ISO8601 date");
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class AdminApiTest method treatsEmptyOrNullUuidFieldsAsNotPresent.
@Test
public void treatsEmptyOrNullUuidFieldsAsNotPresent() {
WireMockResponse response = testClient.postJson("/__admin/mappings/import", EMPTY_UUID_IMPORT_JSON);
assertThat(response.statusCode(), is(200));
List<StubMapping> stubs = wireMockServer.listAllStubMappings().getMappings();
assertThat(stubs, everyItem(hasIdAndUuid()));
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class AdminApiTest method listStubFiles.
@Test
public void listStubFiles() throws Exception {
FileSource fileSource = wireMockServer.getOptions().filesRoot().child(FILES_ROOT);
fileSource.createIfNecessary();
fileSource.writeTextFile("bar.txt", "contents");
fileSource.writeTextFile("zoo.txt", "contents");
WireMockResponse response = testClient.get("/__admin/files");
assertEquals(200, response.statusCode());
String pathSeparatorRegex = File.separator;
if (File.separator.equals("\\")) {
pathSeparatorRegex = "\\\\";
}
assertThat(new String(response.binaryContent()), matches("\\[ \".*" + pathSeparatorRegex + "bar.txt\", \".*zoo.*txt\" ]"));
}
Aggregations