Search in sources :

Example 1 with StaticResponse

use of com.yahoo.vespa.config.server.http.StaticResponse 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)

Example 2 with StaticResponse

use of com.yahoo.vespa.config.server.http.StaticResponse 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)2 StaticResponse (com.yahoo.vespa.config.server.http.StaticResponse)2 Test (org.junit.Test)2 ApplicationId (com.yahoo.config.provision.ApplicationId)1 HandlerTest (com.yahoo.vespa.config.server.http.HandlerTest)1 HttpFetcher (com.yahoo.vespa.config.server.http.HttpFetcher)1 SessionHandlerTest (com.yahoo.vespa.config.server.http.SessionHandlerTest)1 URL (java.net.URL)1