Search in sources :

Example 1 with Response

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

the class ApplicationTest method handler.

@Test
public void handler() throws Exception {
    try (ApplicationFacade app = new ApplicationFacade(Application.fromBuilder(new Application.Builder().container("default", new Application.Builder.Container().handler("http://*/*", MockHttpHandler.class))))) {
        RequestHandler handler = app.getRequestHandlerById(MockHttpHandler.class.getName());
        assertNotNull(handler);
        Request request = new Request("http://localhost:" + getDefaults().vespaWebServicePort() + "/");
        Response response = app.handleRequest(request);
        assertNotNull(response);
        assertEquals(response.getStatus(), 200);
        assertEquals(response.getBodyAsString(), "OK");
        request = new Request("http://localhost");
        response = app.handleRequest(request);
        assertNotNull(response);
        assertEquals(response.getStatus(), 200);
        assertEquals(response.getBodyAsString(), "OK");
        request = new Request("http://localhost/query=foo");
        response = app.handleRequest(request);
        assertNotNull(response);
        assertEquals(response.getStatus(), 200);
        assertEquals(response.getBodyAsString(), "OK");
    }
}
Also used : MockHttpHandler(com.yahoo.application.container.handlers.MockHttpHandler) Response(com.yahoo.application.container.handler.Response) HttpResponse(org.apache.http.HttpResponse) RequestHandler(com.yahoo.jdisc.handler.RequestHandler) Request(com.yahoo.application.container.handler.Request) Test(org.junit.Test)

Example 2 with Response

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

the class ApplicationTest method renderer.

@Test
public void renderer() throws Exception {
    try (ApplicationFacade app = new ApplicationFacade(Application.fromBuilder(new Application.Builder().container("default", new Application.Builder.Container().renderer("mock", MockRenderer.class))))) {
        Request request = new Request("http://localhost:" + getDefaults().vespaWebServicePort() + "/search/?format=mock");
        Response response = app.handleRequest(request);
        assertNotNull(response);
        assertEquals(response.getStatus(), 200);
        assertEquals(response.getBodyAsString(), "<mock hits=\"0\" />");
    }
}
Also used : Response(com.yahoo.application.container.handler.Response) HttpResponse(org.apache.http.HttpResponse) MockRenderer(com.yahoo.application.container.renderers.MockRenderer) Request(com.yahoo.application.container.handler.Request) Test(org.junit.Test)

Example 3 with Response

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

the class JDiscContainerRequestTest method requireThatCustomRequestHeadersWork.

@Test
public void requireThatCustomRequestHeadersWork() throws InterruptedException {
    Request req = new Request("http://banana/echo");
    req.getHeaders().add("X-Foo", "Bar");
    try (JDisc container = JDisc.fromServicesXml(getXML(HeaderEchoRequestHandler.class.getCanonicalName(), "http://*/echo"), Networking.disable)) {
        Response response = container.handleRequest(req);
        assertThat(response.getHeaders().contains("X-Foo", "Bar"), is(true));
        req.toString();
        response.toString();
    }
}
Also used : Response(com.yahoo.application.container.handler.Response) Request(com.yahoo.application.container.handler.Request) Test(org.junit.Test)

Example 4 with Response

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

the class JDiscContainerRequestTest method requireThatRequestBodyWorks.

@Test
public void requireThatRequestBodyWorks() throws InterruptedException, CharacterCodingException {
    String DATA = "we have no bananas today";
    Request req = new Request("http://banana/echo", DATA.getBytes(Utf8.getCharset()));
    try (JDisc container = JDisc.fromServicesXml(getXML(EchoRequestHandler.class.getCanonicalName(), "http://*/echo"), Networking.disable)) {
        Response response = container.handleRequest(req);
        assertThat(response.getBodyAsString(), equalTo(DATA));
        req.toString();
        response.toString();
    }
}
Also used : Response(com.yahoo.application.container.handler.Response) Request(com.yahoo.application.container.handler.Request) Test(org.junit.Test)

Example 5 with Response

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

the class ApplicationApiTest method testJobStatusReporting.

@Test
public void testJobStatusReporting() throws Exception {
    ContainerControllerTester tester = new ContainerControllerTester(container, responseFiles);
    addUserToHostedOperatorRole(HostedAthenzIdentities.from(HOSTED_VESPA_OPERATOR));
    tester.containerTester().updateSystemVersion();
    long projectId = 1;
    Application app = tester.createApplication();
    ApplicationPackage applicationPackage = new ApplicationPackageBuilder().environment(Environment.prod).region("corp-us-east-1").build();
    // system version from mock config server client
    Version vespaVersion = new Version("6.1");
    BuildJob job = new BuildJob(report -> notifyCompletion(report, tester), tester.artifactRepository()).application(app).projectId(projectId);
    job.type(DeploymentJobs.JobType.component).uploadArtifact(applicationPackage).submit();
    tester.deploy(app, applicationPackage, TEST_ZONE, projectId);
    job.type(DeploymentJobs.JobType.systemTest).submit();
    // Notifying about unknown job fails
    Request request = request("/application/v4/tenant/tenant1/application/application1/jobreport", POST).data(asJson(job.type(DeploymentJobs.JobType.productionUsEast3).report())).userIdentity(HOSTED_VESPA_OPERATOR).get();
    tester.containerTester().assertResponse(request, new File("jobreport-unexpected-completion.json"), 400);
    // ... and assert it was recorded
    JobStatus recordedStatus = tester.controller().applications().get(app.id()).get().deploymentJobs().jobStatus().get(DeploymentJobs.JobType.component);
    assertNotNull("Status was recorded", recordedStatus);
    assertTrue(recordedStatus.isSuccess());
    assertEquals(vespaVersion, recordedStatus.lastCompleted().get().version());
    recordedStatus = tester.controller().applications().get(app.id()).get().deploymentJobs().jobStatus().get(DeploymentJobs.JobType.productionApNortheast2);
    assertNull("Status of never-triggered jobs is empty", recordedStatus);
    Response response;
    response = container.handleRequest(request("/screwdriver/v1/jobsToRun", GET).get());
    assertTrue("Response contains system-test", response.getBodyAsString().contains(DeploymentJobs.JobType.systemTest.jobName()));
    assertTrue("Response contains staging-test", response.getBodyAsString().contains(DeploymentJobs.JobType.stagingTest.jobName()));
    assertEquals("Response contains only two items", 2, SlimeUtils.jsonToSlime(response.getBody()).get().entries());
    // Check that GET didn't affect the enqueued jobs.
    response = container.handleRequest(request("/screwdriver/v1/jobsToRun", GET).get());
    assertTrue("Response contains system-test", response.getBodyAsString().contains(DeploymentJobs.JobType.systemTest.jobName()));
    assertTrue("Response contains staging-test", response.getBodyAsString().contains(DeploymentJobs.JobType.stagingTest.jobName()));
    assertEquals("Response contains only two items", 2, SlimeUtils.jsonToSlime(response.getBody()).get().entries());
}
Also used : JobStatus(com.yahoo.vespa.hosted.controller.application.JobStatus) Response(com.yahoo.application.container.handler.Response) ContainerControllerTester(com.yahoo.vespa.hosted.controller.restapi.ContainerControllerTester) Version(com.yahoo.component.Version) Request(com.yahoo.application.container.handler.Request) ApplicationPackageBuilder(com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder) BuildJob(com.yahoo.vespa.hosted.controller.deployment.BuildJob) Application(com.yahoo.vespa.hosted.controller.Application) ApplicationPackage(com.yahoo.vespa.hosted.controller.application.ApplicationPackage) File(java.io.File) ControllerContainerTest(com.yahoo.vespa.hosted.controller.restapi.ControllerContainerTest) Test(org.junit.Test)

Aggregations

Response (com.yahoo.application.container.handler.Response)12 Request (com.yahoo.application.container.handler.Request)7 Test (org.junit.Test)7 File (java.io.File)2 HttpResponse (org.apache.http.HttpResponse)2 MockHttpHandler (com.yahoo.application.container.handlers.MockHttpHandler)1 MockRenderer (com.yahoo.application.container.renderers.MockRenderer)1 Version (com.yahoo.component.Version)1 FilterChainRepository (com.yahoo.container.http.filter.FilterChainRepository)1 RequestHandler (com.yahoo.jdisc.handler.RequestHandler)1 SecurityRequestFilter (com.yahoo.jdisc.http.filter.SecurityRequestFilter)1 SecurityRequestFilterChain (com.yahoo.jdisc.http.filter.SecurityRequestFilterChain)1 Application (com.yahoo.vespa.hosted.controller.Application)1 ApplicationPackage (com.yahoo.vespa.hosted.controller.application.ApplicationPackage)1 JobStatus (com.yahoo.vespa.hosted.controller.application.JobStatus)1 ApplicationPackageBuilder (com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder)1 BuildJob (com.yahoo.vespa.hosted.controller.deployment.BuildJob)1 ContainerControllerTester (com.yahoo.vespa.hosted.controller.restapi.ContainerControllerTester)1 ControllerContainerTest (com.yahoo.vespa.hosted.controller.restapi.ControllerContainerTest)1 ComparisonFailure (org.junit.ComparisonFailure)1