use of io.helidon.common.http.Http.ResponseStatus in project helidon by oracle.
the class ContextLifeCycleTest method testContextMediaSupport.
@Test
void testContextMediaSupport() {
Handler handler = (req, res) -> {
String cid = req.context().id();
req.content().as(String.class).thenAccept(payload -> {
if (cid.equals(contextId())) {
res.send();
} else {
res.status(400).send();
}
});
};
WebServer webServer = WebServer.builder(Routing.builder().post(handler)).build().start().await(10, TimeUnit.SECONDS);
ResponseStatus responseStatus = WebClient.builder().baseUri("http://localhost:" + webServer.port()).build().post().submit("some-payload").map(WebClientResponse::status).onTerminate(webServer::shutdown).await(10, TimeUnit.SECONDS);
assertThat(responseStatus.code(), is(200));
}
use of io.helidon.common.http.Http.ResponseStatus in project helidon by oracle.
the class ContextLifeCycleTest method testContextReactive.
@Test
void testContextReactive() {
Handler handler = (req, res) -> {
String cid = req.context().id();
req.content().subscribe(new Subscriber<>() {
@Override
public void onSubscribe(Subscription subscription) {
subscription.request(Long.MAX_VALUE);
}
@Override
public void onNext(DataChunk item) {
item.release();
if (!cid.equals(contextId())) {
throw new IllegalStateException("Context invalid");
}
}
@Override
public void onError(Throwable throwable) {
res.send(throwable);
}
@Override
public void onComplete() {
if (!cid.equals(contextId())) {
res.send(new IllegalStateException("Context invalid"));
} else {
res.send();
}
}
});
};
WebServer webServer = WebServer.builder(Routing.builder().post(handler)).build().start().await(10, TimeUnit.SECONDS);
ResponseStatus responseStatus = WebClient.builder().baseUri("http://localhost:" + webServer.port()).build().post().submit("some-payload").map(WebClientResponse::status).onTerminate(webServer::shutdown).await(10, TimeUnit.SECONDS);
assertThat(responseStatus.code(), is(200));
}
Aggregations