Search in sources :

Example 1 with HttpResponse

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

the class MockHttpHandler method handle.

@Override
public HttpResponse handle(HttpRequest request) {
    return new HttpResponse(200) {

        @Override
        public void render(OutputStream outputStream) throws IOException {
            PrintStream out = new PrintStream(outputStream);
            out.print("OK");
            out.flush();
        }
    };
}
Also used : PrintStream(java.io.PrintStream) OutputStream(java.io.OutputStream) HttpResponse(com.yahoo.container.jdisc.HttpResponse)

Example 2 with HttpResponse

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

the class SessionExampleHandlerTest method invalidMethod.

@Test
public void invalidMethod() {
    final SessionExampleHandler handler = new SessionExampleHandler(Executors.newCachedThreadPool());
    final HttpRequest request = HttpRequest.createTestRequest(URI, GET);
    HttpResponse response = handler.handle(request);
    assertThat(response.getStatus(), is(METHOD_NOT_ALLOWED));
}
Also used : HttpRequest(com.yahoo.container.jdisc.HttpRequest) HttpResponse(com.yahoo.container.jdisc.HttpResponse) Test(org.junit.Test)

Example 3 with HttpResponse

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

the class SessionExampleHandlerTest method basicPut.

@Test
public void basicPut() throws IOException {
    final SessionExampleHandler handler = new SessionExampleHandler(Executors.newCachedThreadPool());
    final HttpRequest request = HttpRequest.createTestRequest(URI, PUT);
    HttpResponse response = handler.handle(request);
    assertThat(response.getStatus(), is(OK));
    assertThat(SessionHandlerTest.getRenderedString(response), is("{\"test\":\"PUT received\"}"));
}
Also used : HttpRequest(com.yahoo.container.jdisc.HttpRequest) HttpResponse(com.yahoo.container.jdisc.HttpResponse) Test(org.junit.Test)

Example 4 with HttpResponse

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

the class StatusHandlerTest method require_that_handler_works.

@Test
public void require_that_handler_works() throws IOException {
    TestComponentRegistry componentRegistry = new TestComponentRegistry.Builder().build();
    StatusHandler handler = new StatusHandler(StatusHandler.testOnlyContext(), componentRegistry);
    HttpResponse response = handler.handle(HttpRequest.createTestRequest("/status", GET));
    JsonNode jsonNode = mapper.readTree(SessionHandlerTest.getRenderedString(response));
    ConfigserverConfig expectedConfig = componentRegistry.getConfigserverConfig();
    assertEquals(expectedConfig.rpcport(), jsonNode.get("configserverConfig").get("rpcport").asInt());
    assertEquals(expectedConfig.applicationDirectory(), jsonNode.get("configserverConfig").get("applicationDirectory").asText());
    assertEquals(1, jsonNode.get("modelVersions").size());
}
Also used : ConfigserverConfig(com.yahoo.cloud.config.ConfigserverConfig) TestComponentRegistry(com.yahoo.vespa.config.server.TestComponentRegistry) HttpResponse(com.yahoo.container.jdisc.HttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test) SessionHandlerTest(com.yahoo.vespa.config.server.http.SessionHandlerTest)

Example 5 with HttpResponse

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

the class ApplicationHandlerTest method testClusterControllerStatus.

@Test
public void testClusterControllerStatus() throws Exception {
    long sessionId = 1;
    ApplicationId application = new ApplicationId.Builder().applicationName(ApplicationName.defaultName()).tenant(mytenantName).build();
    addMockApplication(tenants.getTenant(mytenantName), application, sessionId, Clock.systemUTC());
    String host = "foo.yahoo.com";
    String url = toUrlPath(application, Zone.defaultZone(), true) + "/clustercontroller/" + host + "/status/v1/clusterName1";
    when(mockHttpProxy.get(any(), eq(host), eq("container-clustercontroller"), eq("clustercontroller-status/v1/clusterName1"))).thenReturn(new StaticResponse(200, "text/html", "<html>...</html>"));
    HttpResponse response = mockHandler.handle(HttpRequest.createTestRequest(url, com.yahoo.jdisc.http.HttpRequest.Method.GET));
    HandlerTest.assertHttpStatusCodeAndMessage(response, 200, "text/html", "<html>...</html>");
}
Also used : StaticResponse(com.yahoo.vespa.config.server.http.StaticResponse) 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)

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