Search in sources :

Example 1 with HttpRequest

use of org.webbitserver.HttpRequest in project cucumber-jvm by cucumber.

the class URLOutputStreamTest method can_http_put.

@Test
public void can_http_put() throws IOException, ExecutionException, InterruptedException {
    final BlockingQueue<String> data = new LinkedBlockingDeque<String>();
    Rest r = new Rest(webbit);
    r.PUT("/.cucumber/stepdefs.json", new HttpHandler() {

        @Override
        public void handleHttpRequest(HttpRequest req, HttpResponse res, HttpControl ctl) throws Exception {
            data.offer(req.body());
            res.end();
        }
    });
    Writer w = new UTF8OutputStreamWriter(new URLOutputStream(new URL(Utils.toURL("http://localhost:9873/.cucumber"), "stepdefs.json")));
    w.write("Hellesøy");
    w.flush();
    w.close();
    assertEquals("Hellesøy", data.poll(1000, TimeUnit.MILLISECONDS));
}
Also used : HttpRequest(org.webbitserver.HttpRequest) HttpHandler(org.webbitserver.HttpHandler) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) HttpResponse(org.webbitserver.HttpResponse) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ExecutionException(java.util.concurrent.ExecutionException) URL(java.net.URL) Rest(org.webbitserver.rest.Rest) HttpControl(org.webbitserver.HttpControl) Writer(java.io.Writer) Test(org.junit.Test)

Example 2 with HttpRequest

use of org.webbitserver.HttpRequest in project cucumber-jvm by cucumber.

the class URLOutputStreamTest method throws_ioe_if_http_response_is_500.

@Test
public void throws_ioe_if_http_response_is_500() throws IOException, ExecutionException, InterruptedException {
    Rest r = new Rest(webbit);
    r.PUT("/.cucumber/stepdefs.json", new HttpHandler() {

        @Override
        public void handleHttpRequest(HttpRequest req, HttpResponse res, HttpControl ctl) throws Exception {
            res.status(500);
            res.content("something went wrong");
            res.end();
        }
    });
    Writer w = new UTF8OutputStreamWriter(new URLOutputStream(new URL(Utils.toURL("http://localhost:9873/.cucumber"), "stepdefs.json")));
    w.write("Hellesøy");
    w.flush();
    try {
        w.close();
        fail();
    } catch (IOException expected) {
        assertEquals("PUT http://localhost:9873/.cucumber/stepdefs.json\n" + "HTTP 500\nsomething went wrong", expected.getMessage());
    }
}
Also used : HttpRequest(org.webbitserver.HttpRequest) HttpHandler(org.webbitserver.HttpHandler) Rest(org.webbitserver.rest.Rest) HttpResponse(org.webbitserver.HttpResponse) HttpControl(org.webbitserver.HttpControl) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ExecutionException(java.util.concurrent.ExecutionException) Writer(java.io.Writer) URL(java.net.URL) Test(org.junit.Test)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 Writer (java.io.Writer)2 URISyntaxException (java.net.URISyntaxException)2 URL (java.net.URL)2 ExecutionException (java.util.concurrent.ExecutionException)2 Test (org.junit.Test)2 HttpControl (org.webbitserver.HttpControl)2 HttpHandler (org.webbitserver.HttpHandler)2 HttpRequest (org.webbitserver.HttpRequest)2 HttpResponse (org.webbitserver.HttpResponse)2 Rest (org.webbitserver.rest.Rest)2 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)1