use of org.webpieces.webserver.test.FullResponse in project webpieces by deanhiller.
the class TestAsynchronousErrors method testWebappThrowsNotFound.
@Test
public void testWebappThrowsNotFound() {
CompletableFuture<Integer> future = new CompletableFuture<Integer>();
mockNotFoundLib.queueFuture(future);
CompletableFuture<Integer> future2 = new CompletableFuture<Integer>();
mockNotFoundLib.queueFuture(future2);
HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/throwNotFound");
http11Socket.send(req);
List<FullResponse> responses2 = http11Socket.getResponses();
Assert.assertEquals(0, responses2.size());
future.completeExceptionally(new NotFoundException("some async NotFound"));
List<FullResponse> responses3 = http11Socket.getResponses();
Assert.assertEquals(0, responses3.size());
future2.complete(55);
FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
response.assertStatusCode(KnownStatusCode.HTTP_404_NOTFOUND);
response.assertContains("Your page was not found");
}
use of org.webpieces.webserver.test.FullResponse in project webpieces by deanhiller.
the class TestAsynchronousErrors method testNotFoundRoute.
@Test
public void testNotFoundRoute() {
//NOTE: This is adding future to the notFound route
CompletableFuture<Integer> future = new CompletableFuture<Integer>();
mockNotFoundLib.queueFuture(future);
HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/route/that/does/not/exist");
http11Socket.send(req);
List<FullResponse> responses2 = http11Socket.getResponses();
Assert.assertEquals(0, responses2.size());
//now resolve the future (which would be done on another thread)
future.complete(22);
FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
response.assertStatusCode(KnownStatusCode.HTTP_404_NOTFOUND);
response.assertContains("Your page was not found");
}
use of org.webpieces.webserver.test.FullResponse in project webpieces by deanhiller.
the class TestAsynchronousErrors method testNotFoundHandlerThrowsNotFound.
@Test
public void testNotFoundHandlerThrowsNotFound() {
CompletableFuture<Integer> future = new CompletableFuture<Integer>();
mockNotFoundLib.queueFuture(future);
HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/route/that/does/not/exist");
http11Socket.send(req);
List<FullResponse> responses2 = http11Socket.getResponses();
Assert.assertEquals(0, responses2.size());
future.completeExceptionally(new NotFoundException("testing notfound from notfound route"));
FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
response.assertStatusCode(KnownStatusCode.HTTP_500_INTERNAL_SVR_ERROR);
response.assertContains("There was a bug in our software...sorry about that");
}
use of org.webpieces.webserver.test.FullResponse in project webpieces by deanhiller.
the class TestSyncWebServer method testRedirectRawRelativeUrl.
@Test
public void testRedirectRawRelativeUrl() {
HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/rawurlredirect");
http11Socket.send(req);
FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
response.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
Assert.assertEquals(0, response.getBody().getReadableSize());
Assert.assertEquals("http://myhost.com/myroute", response.getRedirectUrl());
}
use of org.webpieces.webserver.test.FullResponse in project webpieces by deanhiller.
the class TestSyncWebServer method testRedirectRawAbsoluteUrl.
@Test
public void testRedirectRawAbsoluteUrl() {
HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/rawabsoluteurlredirect");
http11Socket.send(req);
FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
response.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
Assert.assertEquals(0, response.getBody().getReadableSize());
Assert.assertEquals("https://something.com/hi", response.getRedirectUrl());
}
Aggregations