Search in sources :

Example 26 with HttpResponse

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

the class HttpListConfigsHandlerTest method require_error_on_bad_request.

@Test
public void require_error_on_bad_request() throws IOException {
    HttpRequest req = HttpRequest.createTestRequest("http://foo.com:8080/config/v2/tenant/mytenant/application/myapplication/foobar/conf/id/", GET);
    HttpResponse resp = namedHandler.handle(req);
    HandlerTest.assertHttpStatusCodeErrorCodeAndMessage(resp, BAD_REQUEST, HttpErrorResponse.errorCodes.BAD_REQUEST, "Illegal config, must be of form namespace.name.");
    req = HttpRequest.createTestRequest("http://foo.com:8080/config/v2/tenant/mytenant/application/myapplication/foo.barNOPE/conf/id/", GET);
    resp = namedHandler.handle(req);
    HandlerTest.assertHttpStatusCodeErrorCodeAndMessage(resp, NOT_FOUND, HttpErrorResponse.errorCodes.NOT_FOUND, "No such config: foo.barNOPE");
    req = HttpRequest.createTestRequest("http://foo.com:8080/config/v2/tenant/mytenant/application/myapplication/foo.bar/conf/id/NOPE/", GET);
    resp = namedHandler.handle(req);
    HandlerTest.assertHttpStatusCodeErrorCodeAndMessage(resp, NOT_FOUND, HttpErrorResponse.errorCodes.NOT_FOUND, "No such config id: conf/id/NOPE");
}
Also used : HttpRequest(com.yahoo.container.jdisc.HttpRequest) 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 27 with HttpResponse

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

the class HttpListConfigsHandlerTest method require_that_request_can_be_created_from_full_appid.

@Test
public void require_that_request_can_be_created_from_full_appid() throws IOException {
    HttpResponse response = handler.handle(HttpRequest.createTestRequest("http://yahoo.com:8080/config/v2/tenant/mytenant/application/myapplication/environment/test/region/myregion/instance/myinstance/", GET));
    assertThat(SessionHandlerTest.getRenderedString(response), is("{\"children\":[],\"configs\":[]}"));
}
Also used : 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 28 with HttpResponse

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

the class HttpListConfigsHandlerTest method require_that_named_handler_can_be_created_from_full_appid.

@Test
public void require_that_named_handler_can_be_created_from_full_appid() throws IOException {
    HttpRequest req = HttpRequest.createTestRequest("http://foo.com:8080/config/v2/tenant/mytenant/application/myapplication/environment/prod/region/myregion/instance/myinstance/foo.bar/conf/id/", GET);
    req.getJDiscRequest().parameters().put("http.path", Arrays.asList("foo.bar"));
    HttpResponse response = namedHandler.handle(req);
    assertThat(SessionHandlerTest.getRenderedString(response), is("{\"children\":[],\"configs\":[]}"));
}
Also used : HttpRequest(com.yahoo.container.jdisc.HttpRequest) 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 29 with HttpResponse

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

the class SessionActiveHandlerTest method testActivationOfUnpreparedSession.

@Test
public void testActivationOfUnpreparedSession() throws Exception {
    Clock clock = Clock.systemUTC();
    // Needed so we can test that previous active session is still active after a failed activation
    RemoteSession firstSession = activateAndAssertOK(90l, 0l, clock);
    long sessionId = 91L;
    ActivateRequest activateRequest = new ActivateRequest(sessionId, 0l, Session.Status.NEW, "", clock).invoke();
    HttpResponse actResponse = activateRequest.getActResponse();
    RemoteSession session = activateRequest.getSession();
    assertThat(actResponse.getStatus(), is(Response.Status.BAD_REQUEST));
    assertThat(getRenderedString(actResponse), is("{\"error-code\":\"BAD_REQUEST\",\"message\":\"tenant:" + tenant + " app:default:default Session " + sessionId + " is not prepared\"}"));
    assertThat(session.getStatus(), is(not(Session.Status.ACTIVATE)));
    assertThat(firstSession.getStatus(), is(Session.Status.ACTIVATE));
}
Also used : RemoteSession(com.yahoo.vespa.config.server.session.RemoteSession) HttpResponse(com.yahoo.container.jdisc.HttpResponse) 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 30 with HttpResponse

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

the class SessionActiveHandlerTest method testAlreadyActivatedSession.

@Test
public void testAlreadyActivatedSession() throws Exception {
    activateAndAssertOK(1, 0, Clock.systemUTC());
    HttpResponse response = createHandler().handle(SessionHandlerTest.createTestRequest(pathPrefix, HttpRequest.Method.PUT, Cmd.ACTIVE, 1l));
    String message = getRenderedString(response);
    assertThat(message, response.getStatus(), Is.is(BAD_REQUEST));
    assertThat(message, containsString("Session 1 is already active"));
}
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)

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