use of org.webpieces.util.futures.XFuture in project webpieces by deanhiller.
the class BeansController method pageParamAsync.
public XFuture<Action> pageParamAsync() {
XFuture<Action> future = new XFuture<>();
RequestContext ctx = Current.getContext();
executor.execute(new Runnable() {
@Override
public void run() {
ctx.getFlash().put("testkey", "testflashvalue");
future.complete(Actions.renderThis("user", "Dean Hiller"));
}
});
return future;
}
use of org.webpieces.util.futures.XFuture in project webpieces by deanhiller.
the class TestAsynchronousErrors method testNotFoundHandlerThrowsNotFound.
@Test
public void testNotFoundHandlerThrowsNotFound() {
XFuture<Integer> future = new XFuture<Integer>();
mockNotFoundLib.queueFuture(future);
HttpFullRequest req = Requests.createRequest(KnownHttpMethod.GET, "/route/that/does/not/exist");
XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
Assert.assertFalse(respFuture.isDone());
future.completeExceptionally(new NotFoundException("testing notfound from notfound route"));
ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
response.assertStatusCode(KnownStatusCode.HTTP_500_INTERNAL_SVR_ERROR);
response.assertContains("There was a bug in our software...sorry about that");
}
use of org.webpieces.util.futures.XFuture in project webpieces by deanhiller.
the class TestAsynchronousErrors method testWebappThrowsNotFound.
@Test
public void testWebappThrowsNotFound() {
XFuture<Integer> future = new XFuture<Integer>();
mockNotFoundLib.queueFuture(future);
XFuture<Integer> future2 = new XFuture<Integer>();
mockNotFoundLib.queueFuture(future2);
HttpFullRequest req = Requests.createRequest(KnownHttpMethod.GET, "/throwNotFound");
XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
Assert.assertFalse(respFuture.isDone());
future.completeExceptionally(new NotFoundException("some async NotFound"));
Assert.assertFalse(respFuture.isDone());
future2.complete(55);
ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
response.assertStatusCode(KnownStatusCode.HTTP_404_NOTFOUND);
response.assertContains("Your page was not found");
}
use of org.webpieces.util.futures.XFuture in project webpieces by deanhiller.
the class TestAsynchronousErrors method testNotFoundRoute.
@Test
public void testNotFoundRoute() {
// NOTE: This is adding future to the notFound route
XFuture<Integer> future = new XFuture<Integer>();
mockNotFoundLib.queueFuture(future);
HttpFullRequest req = Requests.createRequest(KnownHttpMethod.GET, "/route/that/does/not/exist");
XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
Assert.assertFalse(respFuture.isDone());
// now resolve the future (which would be done on another thread)
future.complete(22);
ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
response.assertStatusCode(KnownStatusCode.HTTP_404_NOTFOUND);
response.assertContains("Your page was not found");
}
use of org.webpieces.util.futures.XFuture in project webpieces by deanhiller.
the class TestAsynchronousErrors method testNotFoundThrowsException.
@Test
public void testNotFoundThrowsException() {
XFuture<Integer> future = new XFuture<Integer>();
mockNotFoundLib.queueFuture(future);
HttpFullRequest req = Requests.createRequest(KnownHttpMethod.GET, "/route/that/does/not/exist");
XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
Assert.assertFalse(respFuture.isDone());
future.completeExceptionally(new RuntimeException("testing notfound from notfound route"));
ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
response.assertStatusCode(KnownStatusCode.HTTP_500_INTERNAL_SVR_ERROR);
response.assertContains("There was a bug in our software...sorry about that");
}
Aggregations