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));
}
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");
}
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");
}
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");
}
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));
}
Aggregations