use of com.yahoo.application.container.handler.Response in project vespa by vespa-engine.
the class ContainerTester method assertResponse.
public void assertResponse(Request request, File responseFile, int expectedStatusCode) throws IOException {
String expectedResponse = IOUtils.readFile(new File(responseFilePath + responseFile.toString()));
expectedResponse = include(expectedResponse);
// Remove whitespace
expectedResponse = expectedResponse.replaceAll("(\"[^\"]*\")|\\s*", "$1");
FilterResult filterResult = invokeSecurityFilters(request);
request = filterResult.request;
Response response = filterResult.response != null ? filterResult.response : container.handleRequest(request);
String responseString = response.getBodyAsString();
if (expectedResponse.contains("(ignore)")) {
// Convert expected response to a literal pattern and replace any ignored field with a pattern that matches
// until the first stop character
String stopCharacters = "[^,:\\\\[\\\\]{}]";
String expectedResponsePattern = Pattern.quote(expectedResponse).replaceAll("\"?\\(ignore\\)\"?", "\\\\E" + stopCharacters + "*\\\\Q");
if (!Pattern.matches(expectedResponsePattern, responseString)) {
throw new ComparisonFailure(responseFile.toString() + " (with ignored fields)", expectedResponsePattern, responseString);
}
} else {
assertEquals(responseFile.toString(), expectedResponse, responseString);
}
assertEquals("Status code", expectedStatusCode, response.getStatus());
}
use of com.yahoo.application.container.handler.Response in project vespa by vespa-engine.
the class RestApiTest method assertHardwareFailure.
private void assertHardwareFailure(Request request, Optional<Boolean> expectedHardwareFailure) throws CharacterCodingException {
Response response = container.handleRequest(request);
String json = response.getBodyAsString();
Optional<Boolean> actualHardwareFailure = getHardwareFailure(json);
assertEquals(expectedHardwareFailure, actualHardwareFailure);
assertEquals(200, response.getStatus());
}
use of com.yahoo.application.container.handler.Response in project vespa by vespa-engine.
the class JDiscContainerRequestTest method requireThatRequestHandlerThatThrowsDelayedInWriteWorks.
@Test(expected = DelayedWriteException.class)
public void requireThatRequestHandlerThatThrowsDelayedInWriteWorks() throws InterruptedException {
String DATA = "we have no bananas today";
Request req = new Request("http://banana/delayedthrowwrite", DATA.getBytes(Utf8.getCharset()));
try (JDisc container = JDisc.fromServicesXml(getXML(DelayedThrowingInWriteRequestHandler.class.getCanonicalName(), "http://*/delayedthrowwrite"), Networking.disable)) {
Response response = container.handleRequest(req);
req.toString();
}
}
use of com.yahoo.application.container.handler.Response in project vespa by vespa-engine.
the class JDiscContainerRequestTest method requireThatRequestHandlerThatThrowsInWriteWorks.
@Test(expected = WriteException.class)
public void requireThatRequestHandlerThatThrowsInWriteWorks() throws InterruptedException {
String DATA = "we have no bananas today";
Request req = new Request("http://banana/throwwrite", DATA.getBytes(Utf8.getCharset()));
try (JDisc container = JDisc.fromServicesXml(getXML(ThrowingInWriteRequestHandler.class.getCanonicalName(), "http://*/throwwrite"), Networking.disable)) {
Response response = container.handleRequest(req);
req.toString();
}
}
use of com.yahoo.application.container.handler.Response in project vespa by vespa-engine.
the class RestApiTest method assertResponse.
private void assertResponse(Request request, int responseStatus, String responseMessage) throws IOException {
Response response = container.handleRequest(request);
// Compare both status and message at once for easier diagnosis
assertEquals("status: " + responseStatus + "\nmessage: " + responseMessage, "status: " + response.getStatus() + "\nmessage: " + response.getBodyAsString());
}
Aggregations