Search in sources :

Example 6 with HttpRequest

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

the class HttpListConfigsHandlerTest method require_that_named_handler_can_be_created.

@Test
public void require_that_named_handler_can_be_created() throws IOException {
    HttpRequest req = HttpRequest.createTestRequest("http://foo.com:8080/config/v2/tenant/mytenant/application/myapplication/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 7 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/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 8 with HttpRequest

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

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

the class SessionCreateHandlerTest method assertIllegalFromParameter.

private void assertIllegalFromParameter(String fromValue) throws IOException {
    File outFile = CompressedApplicationInputStreamTest.createTarFile();
    HttpRequest request = post(outFile, postHeaders, Collections.singletonMap("from", fromValue));
    HandlerTest.assertHttpStatusCodeErrorCodeAndMessage(createHandler().handle(request), BAD_REQUEST, HttpErrorResponse.errorCodes.BAD_REQUEST, "Parameter 'from' has illegal value '" + fromValue + "'");
}
Also used : HttpRequest(com.yahoo.container.jdisc.HttpRequest) File(java.io.File)

Example 10 with HttpRequest

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

the class QueryProfileIntegrationTestCase method testTyped.

public void testTyped() {
    String configId = "dir:src/test/java/com/yahoo/search/query/profile/config/test/typed";
    System.setProperty("config.id", configId);
    Container container = new Container();
    HandlersConfigurerTestWrapper configurer = new HandlersConfigurerTestWrapper(container, configId);
    SearchHandler searchHandler = (SearchHandler) configurer.getRequestHandlerRegistry().getComponent(SearchHandler.class.getName());
    // Should get "default" query profile containing the "test" search chain containing the "test" searcher
    HttpRequest request = HttpRequest.createTestRequest("search", Method.GET);
    // Cast to access content directly
    HttpSearchResponse response = (HttpSearchResponse) searchHandler.handle(request);
    assertNotNull(response.getResult().hits().get("from:test"));
    // Should get the "test' query profile containing the "default" search chain containing the "default" searcher
    request = HttpRequest.createTestRequest("search?queryProfile=test", Method.GET);
    // Cast to access content directly
    response = (HttpSearchResponse) searchHandler.handle(request);
    assertNotNull(response.getResult().hits().get("from:default"));
    // Should get "default" query profile, but override the search chain to default
    request = HttpRequest.createTestRequest("search?searchChain=default", Method.GET);
    // Cast to access content directly
    response = (HttpSearchResponse) searchHandler.handle(request);
    assertNotNull(response.getResult().hits().get("from:default"));
    // Tests a profile setting hits and offset
    request = HttpRequest.createTestRequest("search?queryProfile=hitsoffset", Method.GET);
    // Cast to access content directly
    response = (HttpSearchResponse) searchHandler.handle(request);
    assertEquals(22, response.getQuery().getHits());
    assertEquals(80, response.getQuery().getOffset());
    // Tests a non-resolved profile request
    request = HttpRequest.createTestRequest("search?queryProfile=none", Method.GET);
    // Cast to access content directly
    response = (HttpSearchResponse) searchHandler.handle(request);
    assertNotNull("Got an error", response.getResult().hits().getError());
    assertEquals("Could not resolve query profile 'none'", response.getResult().hits().getError().getDetailedMessage());
    // Test overriding a sub-profile in the request
    request = HttpRequest.createTestRequest("search?queryProfile=root&sub=newsub", Method.GET);
    // Cast to access content directly
    response = (HttpSearchResponse) searchHandler.handle(request);
    assertEquals("newsubvalue1", response.getQuery().properties().get("sub.value1"));
    assertEquals("newsubvalue2", response.getQuery().properties().get("sub.value2"));
    configurer.shutdown();
}
Also used : SearchHandler(com.yahoo.search.handler.SearchHandler) HttpRequest(com.yahoo.container.jdisc.HttpRequest) Container(com.yahoo.container.Container) HandlersConfigurerTestWrapper(com.yahoo.container.core.config.testutil.HandlersConfigurerTestWrapper) HttpSearchResponse(com.yahoo.search.handler.HttpSearchResponse)

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