Search in sources :

Example 91 with FullResponse

use of org.webpieces.webserver.test.FullResponse in project webpieces by deanhiller.

the class ResponseExtract method assertSingleResponse.

public static FullResponse assertSingleResponse(Http11Socket http11Socket) {
    List<FullResponse> responses = http11Socket.getResponses();
    Assert.assertEquals(1, responses.size());
    FullResponse response = responses.get(0);
    http11Socket.clear();
    return response;
}
Also used : FullResponse(org.webpieces.webserver.test.FullResponse)

Example 92 with FullResponse

use of org.webpieces.webserver.test.FullResponse in project webpieces by deanhiller.

the class TestAsyncWebServer method testCompletePromiseOnAnotherThread.

@Test
public void testCompletePromiseOnAnotherThread() {
    CompletableFuture<Integer> future = new CompletableFuture<Integer>();
    mockNotFoundLib.queueFuture(future);
    HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/asyncSuccessRoute");
    http11Socket.send(req);
    //no response yet...
    List<FullResponse> responses1 = http11Socket.getResponses();
    Assert.assertEquals(0, responses1.size());
    //now have the server complete processing
    future.complete(5);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
    response.assertContains("Hi Dean Hiller, This is a page");
}
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 93 with FullResponse

use of org.webpieces.webserver.test.FullResponse in project webpieces by deanhiller.

the class TestAsyncWebServer method testRedirect.

@Test
public void testRedirect() {
    HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/");
    http11Socket.send(req);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
    Assert.assertEquals(0, response.getBody().getReadableSize());
}
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 94 with FullResponse

use of org.webpieces.webserver.test.FullResponse in project webpieces by deanhiller.

the class TestBeans method testQueryParamsToUserBean.

@Test
public void testQueryParamsToUserBean() {
    HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/getuser");
    http11Socket.send(req);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_404_NOTFOUND);
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) FullResponse(org.webpieces.webserver.test.FullResponse) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) Test(org.junit.Test) WebserverForTest(org.webpieces.webserver.WebserverForTest)

Example 95 with FullResponse

use of org.webpieces.webserver.test.FullResponse in project webpieces by deanhiller.

the class TestAsynchronousErrors method testNotFoundThrowsThenInternalSvrErrorHandlerThrows.

@Test
public void testNotFoundThrowsThenInternalSvrErrorHandlerThrows() {
    CompletableFuture<Integer> future = new CompletableFuture<Integer>();
    mockNotFoundLib.queueFuture(future);
    CompletableFuture<Integer> future2 = new CompletableFuture<Integer>();
    mockInternalSvrErrorLib.queueFuture(future2);
    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("fail notfound route"));
    List<FullResponse> responses3 = http11Socket.getResponses();
    Assert.assertEquals(0, responses3.size());
    future2.completeExceptionally(new RuntimeException("fail internal server error route"));
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_500_INTERNAL_SVR_ERROR);
    response.assertContains("The webpieces platform saved them");
}
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)

Aggregations

FullResponse (org.webpieces.webserver.test.FullResponse)154 Test (org.junit.Test)142 AbstractWebpiecesTest (org.webpieces.webserver.test.AbstractWebpiecesTest)142 WebserverForTest (org.webpieces.webserver.WebserverForTest)136 HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)120 HttpDummyRequest (org.webpieces.webserver.test.HttpDummyRequest)32 Header (org.webpieces.httpparser.api.common.Header)16 CompletableFuture (java.util.concurrent.CompletableFuture)11 PlatformOverridesForTest (org.webpieces.webserver.test.PlatformOverridesForTest)9 UserDto (org.webpieces.webserver.basic.app.biz.UserDto)4 UserTestDbo (org.webpieces.plugins.hibernate.app.dbo.UserTestDbo)3 NotFoundException (org.webpieces.router.api.exceptions.NotFoundException)2 ByteBuffer (java.nio.ByteBuffer)1 BufferCreationPool (org.webpieces.data.api.BufferCreationPool)1 DataWrapper (org.webpieces.data.api.DataWrapper)1 DataWrapperGenerator (org.webpieces.data.api.DataWrapperGenerator)1 HttpParser (org.webpieces.httpparser.api.HttpParser)1 MarshalState (org.webpieces.httpparser.api.MarshalState)1