Search in sources :

Example 21 with Request

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

the class JDiscContainerRequestTest method requireThatRequestHandlerThatThrowsInWriteWorks.

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

Example 22 with Request

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

the class RestApiTest method testbasicUpdate.

@Test
public void testbasicUpdate() throws Exception {
    Request request = new Request("http://localhost:" + getFirstListenPort() + update_test_uri);
    HttpPut httpPut = new HttpPut(request.getUri());
    StringEntity entity = new StringEntity(update_test_doc, ContentType.create("application/json"));
    httpPut.setEntity(entity);
    assertThat(doRest(httpPut), is(update_test_response));
    assertThat(getLog(), not(containsString("CREATE IF NON EXISTING IS TRUE")));
}
Also used : StringEntity(org.apache.http.entity.StringEntity) Request(com.yahoo.application.container.handler.Request) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 23 with Request

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

the class RestApiTest method testConditionalPost.

@Test
public void testConditionalPost() throws Exception {
    Request request = new Request("http://localhost:" + getFirstListenPort() + post_test_uri_cond);
    HttpPost httpPost = new HttpPost(request.getUri());
    StringEntity entity = new StringEntity(post_test_doc_cond, ContentType.create("application/json"));
    httpPost.setEntity(entity);
    String x = doRest(httpPost);
    assertThat(x, is(post_test_response_cond));
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) Request(com.yahoo.application.container.handler.Request) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Test(org.junit.Test)

Example 24 with Request

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

the class RestApiTest method testbasicGet.

@Test
public void testbasicGet() throws Exception {
    Request request = new Request("http://localhost:" + getFirstListenPort() + get_test_uri);
    HttpGet get = new HttpGet(request.getUri());
    final String rest = doRest(get);
    assertThat(rest, containsString(get_response_part1));
    assertThat(rest, containsString(get_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 25 with Request

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

the class RestApiTest method testCreateIfNonExistingUpdateInDocTrue.

@Test
public void testCreateIfNonExistingUpdateInDocTrue() throws Exception {
    Request request = new Request("http://localhost:" + getFirstListenPort() + update_test_create_if_non_existient_uri);
    HttpPut httpPut = new HttpPut(request.getUri());
    StringEntity entity = new StringEntity(update_test_create_if_non_existient_doc, ContentType.create("application/json"));
    httpPut.setEntity(entity);
    assertThat(doRest(httpPut), is(update_test_create_if_non_existing_response));
    assertThat(getLog(), containsString("CREATE IF NON EXISTENT IS TRUE"));
}
Also used : StringEntity(org.apache.http.entity.StringEntity) Request(com.yahoo.application.container.handler.Request) HttpPut(org.apache.http.client.methods.HttpPut) 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