Search in sources :

Example 96 with HttpResponse

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

the class SessionActiveHandlerTest method require_that_session_created_from_active_that_is_no_longer_active_cannot_be_activated.

@Test
public void require_that_session_created_from_active_that_is_no_longer_active_cannot_be_activated() throws Exception {
    Clock clock = Clock.systemUTC();
    long sessionId = 1;
    activateAndAssertOK(1, 0, clock);
    sessionId++;
    activateAndAssertOK(sessionId, 1, clock);
    sessionId++;
    ActivateRequest activateRequest = new ActivateRequest(sessionId, 1, "", Clock.systemUTC()).invoke();
    HttpResponse actResponse = activateRequest.getActResponse();
    String message = getRenderedString(actResponse);
    assertThat(message, actResponse.getStatus(), Is.is(CONFLICT));
    assertThat(message, containsString("Cannot activate session 3 because the currently active session (2) has changed since session 3 was created (was 1 at creation time)"));
}
Also used : HttpResponse(com.yahoo.container.jdisc.HttpResponse) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Clock(java.time.Clock) HandlerTest(com.yahoo.vespa.config.server.http.HandlerTest) SessionHandlerTest(com.yahoo.vespa.config.server.http.SessionHandlerTest) SessionTest(com.yahoo.vespa.config.server.session.SessionTest) Test(org.junit.Test)

Example 97 with HttpResponse

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

the class HttpProxyTest method testFetchException.

@Test(expected = RequestTimeoutException.class)
public void testFetchException() {
    when(fetcher.get(any(), any())).thenThrow(new RequestTimeoutException("timed out"));
    HttpResponse actualResponse = proxy.get(applicationMock, hostname, "container-clustercontroller", "clustercontroller-status/v1/clusterName");
}
Also used : RequestTimeoutException(com.yahoo.vespa.config.server.http.RequestTimeoutException) HttpResponse(com.yahoo.container.jdisc.HttpResponse) Test(org.junit.Test)

Example 98 with HttpResponse

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

the class ContentHandlerTestBase method require_that_nonexistant_file_returns_not_found.

@Test
public void require_that_nonexistant_file_returns_not_found() throws IOException {
    HttpResponse response = doRequest(HttpRequest.Method.GET, "/test2.txt");
    assertNotNull(response);
    assertThat(response.getStatus(), is(NOT_FOUND));
}
Also used : HttpResponse(com.yahoo.container.jdisc.HttpResponse) Test(org.junit.Test)

Example 99 with HttpResponse

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

the class ContentHandlerTestBase method assertStatus.

protected void assertStatus(String path, String expectedContent) throws IOException {
    HttpResponse response = doRequest(HttpRequest.Method.GET, path);
    assertNotNull(response);
    final String renderedString = SessionHandlerTest.getRenderedString(response);
    assertThat(renderedString, response.getStatus(), is(OK));
    assertThat(renderedString, is(expectedContent));
}
Also used : HttpResponse(com.yahoo.container.jdisc.HttpResponse)

Example 100 with HttpResponse

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

the class HttpHandlerTest method testResponse.

@Test
public void testResponse() throws IOException {
    final String message = "failed";
    HttpHandler httpHandler = new HttpTestHandler(new InvalidApplicationException(message));
    HttpResponse response = httpHandler.handle(HttpRequest.createTestRequest("foo", com.yahoo.jdisc.http.HttpRequest.Method.GET));
    assertThat(response.getStatus(), is(Response.Status.BAD_REQUEST));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    response.render(baos);
    Slime data = new Slime();
    new JsonDecoder().decode(data, baos.toByteArray());
    assertThat(data.get().field("error-code").asString(), is(HttpErrorResponse.errorCodes.INVALID_APPLICATION_PACKAGE.name()));
    assertThat(data.get().field("message").asString(), is(message));
}
Also used : JsonDecoder(com.yahoo.slime.JsonDecoder) HttpResponse(com.yahoo.container.jdisc.HttpResponse) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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