Search in sources :

Example 1 with HttpRequest

use of com.yahoo.container.jdisc.HttpRequest 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 2 with HttpRequest

use of com.yahoo.container.jdisc.HttpRequest 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 3 with HttpRequest

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

the class HttpGetConfigHandlerTest method require_that_request_gets_correct_fields_with_full_appid.

@Test
public void require_that_request_gets_correct_fields_with_full_appid() {
    String uriLongAppId = "http://yahoo.com:8080/config/v2/tenant/bill/application/sookie/environment/dev/region/bellefleur/instance/sam/foo.bar/myid";
    HttpRequest r = HttpRequest.createTestRequest(uriLongAppId, GET);
    HttpConfigRequest req = HttpConfigRequest.createFromRequestV2(r);
    assertThat(req.getApplicationId().tenant().value(), is("bill"));
    assertThat(req.getApplicationId().application().value(), is("sookie"));
    assertThat(req.getApplicationId().instance().value(), is("sam"));
}
Also used : HttpRequest(com.yahoo.container.jdisc.HttpRequest) HttpConfigRequest(com.yahoo.vespa.config.server.http.HttpConfigRequest) HandlerTest(com.yahoo.vespa.config.server.http.HandlerTest) Test(org.junit.Test) SessionHandlerTest(com.yahoo.vespa.config.server.http.SessionHandlerTest)

Example 4 with HttpRequest

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

the class HttpGetConfigHandlerTest method require_that_nocache_property_works.

@Test
public void require_that_nocache_property_works() throws IOException {
    long generation = 1L;
    ConfigPayload payload = ConfigPayload.fromInstance(new SimpletypesConfig(new SimpletypesConfig.Builder()));
    InnerCNode targetDef = getInnerCNode();
    mockRequestHandler.responses.put(ApplicationId.defaultId(), SlimeConfigResponse.fromConfigPayload(payload, targetDef, generation, "mymd5"));
    final HttpRequest request = HttpRequest.createTestRequest(configUri, GET, null, Collections.singletonMap("nocache", "true"));
    HttpResponse response = handler.handle(request);
    assertThat(SessionHandlerTest.getRenderedString(response), is("{\"boolval\":false,\"doubleval\":0.0,\"enumval\":\"VAL1\",\"intval\":0,\"longval\":0,\"stringval\":\"s\"}"));
}
Also used : HttpRequest(com.yahoo.container.jdisc.HttpRequest) SimpletypesConfig(com.yahoo.config.SimpletypesConfig) InnerCNode(com.yahoo.config.codegen.InnerCNode) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) HttpResponse(com.yahoo.container.jdisc.HttpResponse) Test(org.junit.Test)

Example 5 with HttpRequest

use of com.yahoo.container.jdisc.HttpRequest 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/v1/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/v1/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/v1/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) Test(org.junit.Test)

Aggregations

HttpRequest (com.yahoo.container.jdisc.HttpRequest)37 Test (org.junit.Test)23 HttpResponse (com.yahoo.container.jdisc.HttpResponse)18 InputStream (java.io.InputStream)9 HandlerTest (com.yahoo.vespa.config.server.http.HandlerTest)7 SessionHandlerTest (com.yahoo.vespa.config.server.http.SessionHandlerTest)7 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Query (com.yahoo.search.Query)4 Joiner (com.google.common.base.Joiner)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 Inject (com.google.inject.Inject)3 Version (com.yahoo.component.Version)3 DeploymentSpec (com.yahoo.config.application.api.DeploymentSpec)3 ApplicationId (com.yahoo.config.provision.ApplicationId)3 ApplicationName (com.yahoo.config.provision.ApplicationName)3 Environment (com.yahoo.config.provision.Environment)3 RegionName (com.yahoo.config.provision.RegionName)3 TenantName (com.yahoo.config.provision.TenantName)3 LoggingRequestHandler (com.yahoo.container.jdisc.LoggingRequestHandler)3 IOUtils (com.yahoo.io.IOUtils)3