Search in sources :

Example 31 with HttpResponse

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

the class SessionActiveHandlerTest method testActivationOfSessionThatDoesNotExistAsLocalSession.

@Test
public void testActivationOfSessionThatDoesNotExistAsLocalSession() throws Exception {
    ActivateRequest activateRequest = new ActivateRequest(90l, 0l, "", Clock.systemUTC()).invoke(false);
    HttpResponse actResponse = activateRequest.getActResponse();
    assertThat(actResponse.getStatus(), Is.is(NOT_FOUND));
    String message = getRenderedString(actResponse);
    assertThat(message, Is.is("{\"error-code\":\"NOT_FOUND\",\"message\":\"Session 90 was not found\"}"));
}
Also used : HttpResponse(com.yahoo.container.jdisc.HttpResponse) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) 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 32 with HttpResponse

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

the class SessionActiveHandlerTest method activateAndAssertOKPut.

private ActivateRequest activateAndAssertOKPut(long sessionId, long previousSessionId, String subPath, Clock clock) throws Exception {
    ActivateRequest activateRequest = new ActivateRequest(sessionId, previousSessionId, subPath, clock);
    activateRequest.invoke();
    HttpResponse actResponse = activateRequest.getActResponse();
    String message = getRenderedString(actResponse);
    assertThat(message, actResponse.getStatus(), Is.is(OK));
    assertActivationMessageOK(activateRequest, message);
    RemoteSession session = activateRequest.getSession();
    assertThat(session.getStatus(), Is.is(Session.Status.ACTIVATE));
    return activateRequest;
}
Also used : RemoteSession(com.yahoo.vespa.config.server.session.RemoteSession) HttpResponse(com.yahoo.container.jdisc.HttpResponse) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Example 33 with HttpResponse

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

the class ContentHandlerTestBase method require_that_illegal_return_property_fails.

@Test
public void require_that_illegal_return_property_fails() {
    HttpResponse response = doRequest(HttpRequest.Method.GET, "/test.txt?return=foo");
    assertThat(response.getStatus(), is(BAD_REQUEST));
}
Also used : HttpResponse(com.yahoo.container.jdisc.HttpResponse) Test(org.junit.Test)

Example 34 with HttpResponse

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

the class ContentHandlerTestBase method assertContent.

protected void assertContent(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 35 with HttpResponse

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

the class HttpProxyTest method testNormalGet.

@Test
public void testNormalGet() throws Exception {
    ArgumentCaptor<HttpFetcher.Params> actualParams = ArgumentCaptor.forClass(HttpFetcher.Params.class);
    ArgumentCaptor<URL> actualUrl = ArgumentCaptor.forClass(URL.class);
    HttpResponse response = new StaticResponse(200, "application/json", "body");
    when(fetcher.get(actualParams.capture(), actualUrl.capture())).thenReturn(response);
    HttpResponse actualResponse = proxy.get(applicationMock, hostname, "container-clustercontroller", "clustercontroller-status/v1/clusterName");
    assertEquals(1, actualParams.getAllValues().size());
    assertEquals(2000, actualParams.getValue().readTimeoutMs);
    assertEquals(1, actualUrl.getAllValues().size());
    assertEquals(new URL("http://" + hostname + ":" + port + "/clustercontroller-status/v1/clusterName"), actualUrl.getValue());
    // The HttpResponse returned by the fetcher IS the same object as the one returned by the proxy,
    // when everything goes well.
    assertTrue(actualResponse == response);
}
Also used : StaticResponse(com.yahoo.vespa.config.server.http.StaticResponse) HttpFetcher(com.yahoo.vespa.config.server.http.HttpFetcher) HttpResponse(com.yahoo.container.jdisc.HttpResponse) URL(java.net.URL) 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