Search in sources :

Example 6 with Response

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());
}
Also used : Response(com.yahoo.application.container.handler.Response) ComparisonFailure(org.junit.ComparisonFailure) File(java.io.File)

Example 7 with Response

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());
}
Also used : Response(com.yahoo.application.container.handler.Response)

Example 8 with Response

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();
    }
}
Also used : Response(com.yahoo.application.container.handler.Response) Request(com.yahoo.application.container.handler.Request) Test(org.junit.Test)

Example 9 with Response

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();
    }
}
Also used : Response(com.yahoo.application.container.handler.Response) Request(com.yahoo.application.container.handler.Request) Test(org.junit.Test)

Example 10 with Response

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());
}
Also used : Response(com.yahoo.application.container.handler.Response)

Aggregations

Response (com.yahoo.application.container.handler.Response)12 Request (com.yahoo.application.container.handler.Request)7 Test (org.junit.Test)7 File (java.io.File)2 HttpResponse (org.apache.http.HttpResponse)2 MockHttpHandler (com.yahoo.application.container.handlers.MockHttpHandler)1 MockRenderer (com.yahoo.application.container.renderers.MockRenderer)1 Version (com.yahoo.component.Version)1 FilterChainRepository (com.yahoo.container.http.filter.FilterChainRepository)1 RequestHandler (com.yahoo.jdisc.handler.RequestHandler)1 SecurityRequestFilter (com.yahoo.jdisc.http.filter.SecurityRequestFilter)1 SecurityRequestFilterChain (com.yahoo.jdisc.http.filter.SecurityRequestFilterChain)1 Application (com.yahoo.vespa.hosted.controller.Application)1 ApplicationPackage (com.yahoo.vespa.hosted.controller.application.ApplicationPackage)1 JobStatus (com.yahoo.vespa.hosted.controller.application.JobStatus)1 ApplicationPackageBuilder (com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder)1 BuildJob (com.yahoo.vespa.hosted.controller.deployment.BuildJob)1 ContainerControllerTester (com.yahoo.vespa.hosted.controller.restapi.ContainerControllerTester)1 ControllerContainerTest (com.yahoo.vespa.hosted.controller.restapi.ControllerContainerTest)1 ComparisonFailure (org.junit.ComparisonFailure)1