Search in sources :

Example 11 with HttpResponse

use of com.yahoo.container.jdisc.HttpResponse in project vespa by vespa-engine.

the class SessionContentHandlerTest method assertDeleteFile.

private void assertDeleteFile(int statusCode, String filePath, String expectedResponse) throws IOException {
    HttpResponse response = doRequest(HttpRequest.Method.DELETE, filePath);
    assertNotNull(response);
    assertThat(response.getStatus(), is(statusCode));
    assertThat(SessionHandlerTest.getRenderedString(response), is(expectedResponse));
}
Also used : HttpResponse(com.yahoo.container.jdisc.HttpResponse)

Example 12 with HttpResponse

use of com.yahoo.container.jdisc.HttpResponse in project vespa by vespa-engine.

the class SessionPrepareHandlerTest method require_get_response_error_on_not_prepared.

@Test
public void require_get_response_error_on_not_prepared() throws Exception {
    MockSession session = new MockSession(1, null);
    localRepo.addSession(session);
    SessionHandler sessHandler = createHandler(fromLocalSessionRepo(localRepo, Clock.systemUTC()));
    session.setStatus(Session.Status.NEW);
    zooKeeperClient.writeStatus(Session.Status.NEW);
    HttpResponse getResponse = sessHandler.handle(SessionHandlerTest.createTestRequest(pathPrefix, HttpRequest.Method.GET, Cmd.PREPARED, 1L));
    assertHttpStatusCodeErrorCodeAndMessage(getResponse, BAD_REQUEST, HttpErrorResponse.errorCodes.BAD_REQUEST, "Session not prepared: 1");
    session.setStatus(Session.Status.ACTIVATE);
    zooKeeperClient.writeStatus(Session.Status.ACTIVATE);
    getResponse = sessHandler.handle(SessionHandlerTest.createTestRequest(pathPrefix, HttpRequest.Method.GET, Cmd.PREPARED, 1L));
    assertHttpStatusCodeErrorCodeAndMessage(getResponse, BAD_REQUEST, HttpErrorResponse.errorCodes.BAD_REQUEST, "Session is active: 1");
}
Also used : HttpResponse(com.yahoo.container.jdisc.HttpResponse) Test(org.junit.Test)

Example 13 with HttpResponse

use of com.yahoo.container.jdisc.HttpResponse in project vespa by vespa-engine.

the class SessionPrepareHandlerTest method require_error_when_session_id_does_not_exist.

@Test
public void require_error_when_session_id_does_not_exist() throws Exception {
    // No session with this id exists
    HttpResponse response = createHandler().handle(SessionHandlerTest.createTestRequest(pathPrefix, HttpRequest.Method.PUT, Cmd.PREPARED, 9999L));
    assertHttpStatusCodeErrorCodeAndMessage(response, NOT_FOUND, HttpErrorResponse.errorCodes.NOT_FOUND, "Session 9999 was not found");
}
Also used : HttpResponse(com.yahoo.container.jdisc.HttpResponse) Test(org.junit.Test)

Example 14 with HttpResponse

use of com.yahoo.container.jdisc.HttpResponse in project vespa by vespa-engine.

the class SessionPrepareHandlerTest method testUnsupportedMethod.

private void testUnsupportedMethod(com.yahoo.container.jdisc.HttpRequest request) throws Exception {
    HttpResponse response = createHandler().handle(request);
    assertHttpStatusCodeErrorCodeAndMessage(response, METHOD_NOT_ALLOWED, HttpErrorResponse.errorCodes.METHOD_NOT_ALLOWED, "Method '" + request.getMethod().name() + "' is not supported");
}
Also used : HttpResponse(com.yahoo.container.jdisc.HttpResponse)

Example 15 with HttpResponse

use of com.yahoo.container.jdisc.HttpResponse in project vespa by vespa-engine.

the class SessionPrepareHandlerTest method test_that_nullpointerexception_gives_internal_server_error.

@Test
public void test_that_nullpointerexception_gives_internal_server_error() throws InterruptedException, IOException {
    String message = "No nodes available";
    SessionThrowingException session = new SessionThrowingException(new NullPointerException(message));
    localRepo.addSession(session);
    HttpResponse response = createHandler().handle(SessionHandlerTest.createTestRequest(pathPrefix, HttpRequest.Method.PUT, Cmd.PREPARED, 1L));
    assertEquals(500, response.getStatus());
    Slime data = getData(response);
    assertThat(data.get().field("error-code").asString(), is(HttpErrorResponse.errorCodes.INTERNAL_SERVER_ERROR.name()));
    assertThat(data.get().field("message").asString(), is(message));
}
Also used : HttpResponse(com.yahoo.container.jdisc.HttpResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Slime(com.yahoo.slime.Slime) Test(org.junit.Test)

Aggregations

HttpResponse (com.yahoo.container.jdisc.HttpResponse)103 Test (org.junit.Test)75 SessionHandlerTest (com.yahoo.vespa.config.server.http.SessionHandlerTest)33 HandlerTest (com.yahoo.vespa.config.server.http.HandlerTest)24 HttpRequest (com.yahoo.container.jdisc.HttpRequest)16 CompressedApplicationInputStreamTest (com.yahoo.vespa.config.server.http.CompressedApplicationInputStreamTest)6 SessionTest (com.yahoo.vespa.config.server.session.SessionTest)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 SimpletypesConfig (com.yahoo.config.SimpletypesConfig)5 InnerCNode (com.yahoo.config.codegen.InnerCNode)5 Slime (com.yahoo.slime.Slime)5 ConfigPayload (com.yahoo.vespa.config.ConfigPayload)5 OutputStream (java.io.OutputStream)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 ApplicationId (com.yahoo.config.provision.ApplicationId)4 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3