Search in sources :

Example 6 with Request

use of com.yahoo.application.container.handler.Request in project vespa by vespa-engine.

the class ScrewdriverApiTest method testTriggerJobForApplication.

@Test
public void testTriggerJobForApplication() {
    ContainerControllerTester tester = new ContainerControllerTester(container, responseFiles);
    DeploymentQueue deploymentQueue = tester.controller().applications().deploymentTrigger().deploymentQueue();
    tester.containerTester().updateSystemVersion();
    Application app = tester.createApplication();
    tester.controller().applications().lockOrThrow(app.id(), application -> tester.controller().applications().store(application.withProjectId(1)));
    // Unknown application
    assertResponse(new Request("http://localhost:8080/screwdriver/v1/trigger/tenant/foo/application/bar", new byte[0], Request.Method.POST), 400, "{\"error-code\":\"BAD_REQUEST\",\"message\":\"foo.bar not found\"}");
    // Invalid job
    assertResponse(new Request("http://localhost:8080/screwdriver/v1/trigger/tenant/" + app.id().tenant().value() + "/application/" + app.id().application().value(), "invalid".getBytes(StandardCharsets.UTF_8), Request.Method.POST), 400, "{\"error-code\":\"BAD_REQUEST\",\"message\":\"Unknown job name 'invalid'\"}");
    // component is triggered if no job is specified in request body
    assertResponse(new Request("http://localhost:8080/screwdriver/v1/trigger/tenant/" + app.id().tenant().value() + "/application/" + app.id().application().value(), new byte[0], Request.Method.POST), 200, "{\"message\":\"Triggered component for tenant1.application1\"}");
    assertFalse(deploymentQueue.jobs().isEmpty());
    assertEquals(JobType.component.jobName(), deploymentQueue.jobs().get(0).jobName());
    assertEquals(1L, deploymentQueue.jobs().get(0).projectId());
    deploymentQueue.takeJobsToRun();
    // Triggers specific job when given
    assertResponse(new Request("http://localhost:8080/screwdriver/v1/trigger/tenant/" + app.id().tenant().value() + "/application/" + app.id().application().value(), "staging-test".getBytes(StandardCharsets.UTF_8), Request.Method.POST), 200, "{\"message\":\"Triggered staging-test for tenant1.application1\"}");
    assertFalse(deploymentQueue.jobs().isEmpty());
    assertEquals(JobType.stagingTest.jobName(), deploymentQueue.jobs().get(0).jobName());
    assertEquals(1L, deploymentQueue.jobs().get(0).projectId());
}
Also used : ContainerControllerTester(com.yahoo.vespa.hosted.controller.restapi.ContainerControllerTester) Request(com.yahoo.application.container.handler.Request) Application(com.yahoo.vespa.hosted.controller.Application) DeploymentQueue(com.yahoo.vespa.hosted.controller.deployment.DeploymentQueue) ControllerContainerTest(com.yahoo.vespa.hosted.controller.restapi.ControllerContainerTest) Test(org.junit.Test)

Example 7 with Request

use of com.yahoo.application.container.handler.Request in project vespa by vespa-engine.

the class RestApiTest method testbasicEncodingV2.

@Test
public void testbasicEncodingV2() throws Exception {
    Request request = new Request("http://localhost:" + getFirstListenPort() + get_enc_test_uri_v2);
    HttpGet get = new HttpGet(request.getUri());
    String rest = doRest(get);
    assertThat(rest, containsString(get_enc_response_part1_v2));
    assertThat(rest, containsString(get_enc_response_part2));
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) Request(com.yahoo.application.container.handler.Request) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Test(org.junit.Test)

Example 8 with Request

use of com.yahoo.application.container.handler.Request in project vespa by vespa-engine.

the class RestApiTest method testUseExpressionOnVisit.

@Test
public void testUseExpressionOnVisit() throws Exception {
    Request request = new Request("http://localhost:" + getFirstListenPort() + visit_test_uri_selection_rewrite);
    HttpGet get = new HttpGet(request.getUri());
    String rest = doRest(get);
    assertThat(rest, containsString(visit_test_response_selection_rewrite));
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) Request(com.yahoo.application.container.handler.Request) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Test(org.junit.Test)

Example 9 with Request

use of com.yahoo.application.container.handler.Request in project vespa by vespa-engine.

the class RestApiTest method wanted_document_count_returned_parameter_is_propagated.

@Test
public void wanted_document_count_returned_parameter_is_propagated() throws IOException {
    Request request = new Request(String.format("http://localhost:%s/document/v1/namespace/document-type/docid/?wantedDocumentCount=321", getFirstListenPort()));
    HttpGet get = new HttpGet(request.getUri());
    String rest = doRest(get);
    assertThat(rest, containsString("min docs returned: 321"));
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) Request(com.yahoo.application.container.handler.Request) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Test(org.junit.Test)

Example 10 with Request

use of com.yahoo.application.container.handler.Request in project vespa by vespa-engine.

the class RestApiTest method testSlashesInId.

@Test
public void testSlashesInId() throws Exception {
    Request request = new Request("http://localhost:" + getFirstListenPort() + id_test_uri);
    HttpGet get = new HttpGet(request.getUri());
    final String rest = doRest(get);
    assertThat(rest, containsString(id_response_part1));
    assertThat(rest, containsString(id_response_part2));
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) Request(com.yahoo.application.container.handler.Request) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Test(org.junit.Test)

Aggregations

Request (com.yahoo.application.container.handler.Request)46 Test (org.junit.Test)44 StringContains.containsString (org.hamcrest.core.StringContains.containsString)17 HttpGet (org.apache.http.client.methods.HttpGet)14 Response (com.yahoo.application.container.handler.Response)7 StringEntity (org.apache.http.entity.StringEntity)7 HttpPut (org.apache.http.client.methods.HttpPut)4 HttpPost (org.apache.http.client.methods.HttpPost)3 Application (com.yahoo.vespa.hosted.controller.Application)2 ContainerControllerTester (com.yahoo.vespa.hosted.controller.restapi.ContainerControllerTester)2 ControllerContainerTest (com.yahoo.vespa.hosted.controller.restapi.ControllerContainerTest)2 HttpResponse (org.apache.http.HttpResponse)2 HttpDelete (org.apache.http.client.methods.HttpDelete)2 MockHttpHandler (com.yahoo.application.container.handlers.MockHttpHandler)1 MockRenderer (com.yahoo.application.container.renderers.MockRenderer)1 Version (com.yahoo.component.Version)1 RequestHandler (com.yahoo.jdisc.handler.RequestHandler)1 HttpRequest (com.yahoo.jdisc.http.HttpRequest)1 DiscFilterRequest (com.yahoo.jdisc.http.filter.DiscFilterRequest)1 ServletOrJdiscHttpRequest (com.yahoo.jdisc.http.servlet.ServletOrJdiscHttpRequest)1