use of org.webbitserver.HttpControl 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));
}
use of org.webbitserver.HttpControl 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());
}
}
Aggregations