Search in sources :

Example 21 with HttpRequest

use of org.webpieces.httpparser.api.dto.HttpRequest in project webpieces by deanhiller.

the class TestAsyncWebServer method testCompletePromiseOnRequestThread.

@Test
public void testCompletePromiseOnRequestThread() {
    HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/myroute");
    http11Socket.send(req);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
    response.assertContains("This is the first raw html page");
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) FullResponse(org.webpieces.webserver.test.FullResponse) Test(org.junit.Test) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) WebserverForTest(org.webpieces.webserver.WebserverForTest)

Example 22 with HttpRequest

use of org.webpieces.httpparser.api.dto.HttpRequest in project webpieces by deanhiller.

the class TestAsynchronousErrors method testNotFoundThrowsException.

@Test
public void testNotFoundThrowsException() {
    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 RuntimeException("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");
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) CompletableFuture(java.util.concurrent.CompletableFuture) FullResponse(org.webpieces.webserver.test.FullResponse) Test(org.junit.Test) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) WebserverForTest(org.webpieces.webserver.WebserverForTest)

Example 23 with HttpRequest

use of org.webpieces.httpparser.api.dto.HttpRequest 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");
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) CompletableFuture(java.util.concurrent.CompletableFuture) FullResponse(org.webpieces.webserver.test.FullResponse) NotFoundException(org.webpieces.router.api.exceptions.NotFoundException) Test(org.junit.Test) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) WebserverForTest(org.webpieces.webserver.WebserverForTest)

Example 24 with HttpRequest

use of org.webpieces.httpparser.api.dto.HttpRequest 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");
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) CompletableFuture(java.util.concurrent.CompletableFuture) FullResponse(org.webpieces.webserver.test.FullResponse) Test(org.junit.Test) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) WebserverForTest(org.webpieces.webserver.WebserverForTest)

Example 25 with HttpRequest

use of org.webpieces.httpparser.api.dto.HttpRequest 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");
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) CompletableFuture(java.util.concurrent.CompletableFuture) FullResponse(org.webpieces.webserver.test.FullResponse) NotFoundException(org.webpieces.router.api.exceptions.NotFoundException) Test(org.junit.Test) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) WebserverForTest(org.webpieces.webserver.WebserverForTest)

Aggregations

HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)157 Test (org.junit.Test)136 AbstractWebpiecesTest (org.webpieces.webserver.test.AbstractWebpiecesTest)120 FullResponse (org.webpieces.webserver.test.FullResponse)120 WebserverForTest (org.webpieces.webserver.WebserverForTest)114 Header (org.webpieces.httpparser.api.common.Header)33 DataWrapper (org.webpieces.data.api.DataWrapper)17 PlatformOverridesForTest (org.webpieces.webserver.test.PlatformOverridesForTest)15 HttpData (org.webpieces.httpparser.api.dto.HttpData)13 HttpRequestLine (org.webpieces.httpparser.api.dto.HttpRequestLine)13 HttpUri (org.webpieces.httpparser.api.dto.HttpUri)13 CompletableFuture (java.util.concurrent.CompletableFuture)11 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)8 HttpPayload (org.webpieces.httpparser.api.dto.HttpPayload)8 HttpResponse (org.webpieces.httpparser.api.dto.HttpResponse)8 Http2Response (com.webpieces.hpack.api.dto.Http2Response)6 HttpDummyRequest (org.webpieces.webserver.test.HttpDummyRequest)6 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)4 StreamWriter (com.webpieces.http2engine.api.StreamWriter)3 Http2Header (com.webpieces.http2parser.api.dto.lib.Http2Header)3