use of org.webpieces.util.futures.XFuture in project webpieces by deanhiller.
the class TestAsyncWebServer method testCompletePromiseOnAnotherThread.
@Test
public void testCompletePromiseOnAnotherThread() {
XFuture<Integer> future = new XFuture<Integer>();
mockNotFoundLib.queueFuture(future);
HttpFullRequest req = Requests.createRequest(KnownHttpMethod.GET, "/asyncSuccessRoute");
XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
// no response yet...
Assert.assertFalse(respFuture.isDone());
// now have the server complete processing
future.complete(5);
ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
response.assertContains("Hi Dean Hiller, This is a page");
}
use of org.webpieces.util.futures.XFuture in project webpieces by deanhiller.
the class TestAsynchronousErrors method testWebAppHasBugRenders500Route.
/**
* This tests bug in your webapp "/another" route, you could also test you have a bug in that route AND a bug in your internal
* server route as well!!!
*/
@Test
public void testWebAppHasBugRenders500Route() {
XFuture<Integer> future = new XFuture<Integer>();
mockNotFoundLib.queueFuture(future);
HttpFullRequest req = Requests.createRequest(KnownHttpMethod.GET, "/");
XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
Assert.assertFalse(respFuture.isDone());
future.completeExceptionally(new RuntimeException("test async exception"));
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 testWebAppHasBugAndRender500HasBug.
@Test
public void testWebAppHasBugAndRender500HasBug() {
XFuture<Integer> future = new XFuture<Integer>();
mockNotFoundLib.queueFuture(future);
XFuture<Integer> future2 = new XFuture<Integer>();
mockInternalSvrErrorLib.queueFuture(future2);
HttpFullRequest req = Requests.createRequest(KnownHttpMethod.GET, "/");
XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
Assert.assertFalse(respFuture.isDone());
future.completeExceptionally(new RuntimeException("fail notfound route"));
Assert.assertFalse(respFuture.isDone());
future2.completeExceptionally(new RuntimeException("fail internal server error route"));
ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
response.assertStatusCode(KnownStatusCode.HTTP_500_INTERNAL_SVR_ERROR);
response.assertContains("There was a bug in the developers application or webpieces server");
}
use of org.webpieces.util.futures.XFuture in project webpieces by deanhiller.
the class TestAsynchronousErrors method testCompletePromiseAnotherThreadAndPageParamMissing.
@Test
public void testCompletePromiseAnotherThreadAndPageParamMissing() {
XFuture<Integer> future = new XFuture<Integer>();
mockNotFoundLib.queueFuture(future);
HttpFullRequest req = Requests.createRequest(KnownHttpMethod.GET, "/asyncFailRoute");
XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
// now have the server complete processing
future.complete(5);
ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
response.assertStatusCode(KnownStatusCode.HTTP_500_INTERNAL_SVR_ERROR);
response.assertContains("There was a bug in our software");
}
use of org.webpieces.util.futures.XFuture in project webpieces by deanhiller.
the class TestAsynchronousErrors method testNotFoundThrowsThenInternalSvrErrorHandlerThrows.
@Test
public void testNotFoundThrowsThenInternalSvrErrorHandlerThrows() {
XFuture<Integer> future = new XFuture<Integer>();
mockNotFoundLib.queueFuture(future);
XFuture<Integer> future2 = new XFuture<Integer>();
mockInternalSvrErrorLib.queueFuture(future2);
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("fail notfound route"));
Assert.assertFalse(respFuture.isDone());
future2.completeExceptionally(new RuntimeException("fail internal server error route"));
ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
response.assertStatusCode(KnownStatusCode.HTTP_500_INTERNAL_SVR_ERROR);
response.assertContains("There was a bug in the developers application or webpieces server");
}
Aggregations