Search in sources :

Example 6 with HttpResponse

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

the class ApplicationHandlerTest method testFileDistributionStatus.

@Test
public void testFileDistributionStatus() throws Exception {
    long sessionId = 1;
    ApplicationId application = new ApplicationId.Builder().applicationName(ApplicationName.defaultName()).tenant(mytenantName).build();
    addMockApplication(tenants.getTenant(mytenantName), application, sessionId, Clock.systemUTC());
    Zone zone = Zone.defaultZone();
    HttpResponse response = fileDistributionStatus(application, zone);
    assertEquals(200, response.getStatus());
    SessionHandlerTest.getRenderedString(response);
    assertEquals("{\"hosts\":[{\"hostname\":\"mytesthost\",\"status\":\"UNKNOWN\",\"message\":\"error: Connection error(104)\",\"fileReferences\":[]}],\"status\":\"UNKNOWN\"}", SessionHandlerTest.getRenderedString(response));
    // 404 for unknown application
    ApplicationId unknown = new ApplicationId.Builder().applicationName("unknown").tenant(mytenantName).build();
    HttpResponse responseForUnknown = fileDistributionStatus(unknown, zone);
    assertEquals(404, responseForUnknown.getStatus());
    assertEquals("{\"error-code\":\"NOT_FOUND\",\"message\":\"No such application id: mytenant.unknown\"}", SessionHandlerTest.getRenderedString(responseForUnknown));
}
Also used : Zone(com.yahoo.config.provision.Zone) HttpResponse(com.yahoo.container.jdisc.HttpResponse) ApplicationId(com.yahoo.config.provision.ApplicationId) HandlerTest(com.yahoo.vespa.config.server.http.HandlerTest) SessionHandlerTest(com.yahoo.vespa.config.server.http.SessionHandlerTest) Test(org.junit.Test)

Example 7 with HttpResponse

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

the class HttpGetConfigHandlerTest method require_that_handler_can_be_created.

@Test
public void require_that_handler_can_be_created() throws IOException {
    // Define config response for mock handler
    final long generation = 1L;
    ConfigPayload payload = ConfigPayload.fromInstance(new SimpletypesConfig(new SimpletypesConfig.Builder()));
    InnerCNode targetDef = getInnerCNode();
    mockRequestHandler.responses.put(new ApplicationId.Builder().tenant(tenant).applicationName("myapplication").build(), SlimeConfigResponse.fromConfigPayload(payload, targetDef, generation, "mymd5"));
    HttpResponse response = handler.handle(HttpRequest.createTestRequest(configUri, GET));
    assertThat(SessionHandlerTest.getRenderedString(response), is(EXPECTED_RENDERED_STRING));
}
Also used : SimpletypesConfig(com.yahoo.config.SimpletypesConfig) InnerCNode(com.yahoo.config.codegen.InnerCNode) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) HttpResponse(com.yahoo.container.jdisc.HttpResponse) HandlerTest(com.yahoo.vespa.config.server.http.HandlerTest) Test(org.junit.Test) SessionHandlerTest(com.yahoo.vespa.config.server.http.SessionHandlerTest)

Example 8 with HttpResponse

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

the class ListApplicationsHandlerTest method assertResponse.

static void assertResponse(ListApplicationsHandler handler, String url, int expectedStatus, String expectedResponse, Method method) throws IOException {
    HttpResponse response = handler.handle(HttpRequest.createTestRequest(url, method));
    assertNotNull(response);
    assertThat(response.getStatus(), is(expectedStatus));
    assertThat(SessionHandlerTest.getRenderedString(response), is(expectedResponse));
}
Also used : HttpResponse(com.yahoo.container.jdisc.HttpResponse)

Example 9 with HttpResponse

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

the class SessionContentHandlerTest method assertWriteFile.

private void assertWriteFile(String path, String content) throws IOException {
    HttpResponse response = put(path, content);
    assertNotNull(response);
    assertThat(response.getStatus(), is(Response.Status.OK));
    assertContent(path, content);
    assertThat(SessionHandlerTest.getRenderedString(response), is("{\"prepared\":\"http://foo:1337" + pathPrefix + "1/prepared\"}"));
}
Also used : HttpResponse(com.yahoo.container.jdisc.HttpResponse)

Example 10 with HttpResponse

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

the class SessionContentHandlerTest method require_that_nonexistant_session_returns_not_found.

@Test
public void require_that_nonexistant_session_returns_not_found() throws IOException {
    HttpResponse response = doRequest(HttpRequest.Method.GET, "/test.txt", 2l);
    assertNotNull(response);
    assertThat(response.getStatus(), is(Response.Status.NOT_FOUND));
}
Also used : HttpResponse(com.yahoo.container.jdisc.HttpResponse) Test(org.junit.Test) SessionHandlerTest(com.yahoo.vespa.config.server.http.SessionHandlerTest)

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