Search in sources :

Example 61 with HttpFullRequest

use of org.webpieces.httpclient11.api.HttpFullRequest in project webpieces by deanhiller.

the class TestDevSynchronousErrors 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() {
    mockNotFoundLib.throwRuntime();
    HttpFullRequest req = Requests.createRequest(KnownHttpMethod.GET, "/");
    XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
    ResponseWrapper response1 = ResponseExtract.waitResponseAndWrap(respFuture);
    response1.assertStatusCode(KnownStatusCode.HTTP_500_INTERNAL_SVR_ERROR);
    // There should be a callback url to render what shows in production
    response1.assertContains("/?webpiecesShowInternalErrorPage=true");
    // callback shows the original page...
    HttpFullRequest req2 = Requests.createRequest(KnownHttpMethod.GET, "/?webpiecesShowInternalErrorPage=true");
    XFuture<HttpFullResponse> respFuture2 = http11Socket.send(req2);
    ResponseWrapper response2 = ResponseExtract.waitResponseAndWrap(respFuture2);
    response2.assertStatusCode(KnownStatusCode.HTTP_500_INTERNAL_SVR_ERROR);
    response2.assertContains("There was a bug in our software...sorry about that");
}
Also used : HttpFullResponse(org.webpieces.httpclient11.api.HttpFullResponse) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest) ResponseWrapper(org.webpieces.webserver.test.ResponseWrapper) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) Test(org.junit.Test)

Example 62 with HttpFullRequest

use of org.webpieces.httpclient11.api.HttpFullRequest in project webpieces by deanhiller.

the class TestDevSynchronousErrors method testNotFoundFromMismatchArgType.

@Test
public void testNotFoundFromMismatchArgType() {
    // because 'notAnInt' is not convertable to integer, this result in NotFound rather than 500 as truly a route with
    // no int doesn't really exist so it's a NotFound
    HttpFullRequest req = Requests.createRequest(KnownHttpMethod.GET, "/redirectint/notAnInt");
    XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
    ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
    response.assertStatusCode(KnownStatusCode.HTTP_404_NOTFOUND);
    response.assertContains("Your app's webpage was not found");
}
Also used : HttpFullResponse(org.webpieces.httpclient11.api.HttpFullResponse) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest) ResponseWrapper(org.webpieces.webserver.test.ResponseWrapper) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) Test(org.junit.Test)

Example 63 with HttpFullRequest

use of org.webpieces.httpclient11.api.HttpFullRequest in project webpieces by deanhiller.

the class TestDevSynchronousErrors method testWebAppHasBugAndRender500HasBug.

@Test
public void testWebAppHasBugAndRender500HasBug() {
    mockNotFoundLib.throwRuntime();
    mockInternalSvrErrorLib.throwRuntime();
    HttpFullRequest req = Requests.createRequest(KnownHttpMethod.GET, "/");
    XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
    ResponseWrapper response1 = ResponseExtract.waitResponseAndWrap(respFuture);
    response1.assertStatusCode(KnownStatusCode.HTTP_500_INTERNAL_SVR_ERROR);
    // There should be a callback url to render what shows in production
    response1.assertContains("/?webpiecesShowInternalErrorPage=true");
    // callback shows the original page...
    HttpFullRequest req2 = Requests.createRequest(KnownHttpMethod.GET, "/?webpiecesShowInternalErrorPage=true");
    XFuture<HttpFullResponse> respFuture2 = http11Socket.send(req2);
    ResponseWrapper response2 = ResponseExtract.waitResponseAndWrap(respFuture2);
    response2.assertStatusCode(KnownStatusCode.HTTP_500_INTERNAL_SVR_ERROR);
    response2.assertContains("There was a bug in the developers application or webpieces server");
}
Also used : HttpFullResponse(org.webpieces.httpclient11.api.HttpFullResponse) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest) ResponseWrapper(org.webpieces.webserver.test.ResponseWrapper) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) Test(org.junit.Test)

Example 64 with HttpFullRequest

use of org.webpieces.httpclient11.api.HttpFullRequest in project webpieces by deanhiller.

the class TestSyncWebServer method testRedirectRawAbsoluteUrl.

@Test
public void testRedirectRawAbsoluteUrl() {
    HttpFullRequest req = Requests.createRequest(KnownHttpMethod.GET, "/rawabsoluteurlredirect");
    XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
    ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
    response.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
    Assert.assertEquals(0, response.getBody().getReadableSize());
    Assert.assertEquals("https://something.com/hi", response.getRedirectUrl());
}
Also used : HttpFullResponse(org.webpieces.httpclient11.api.HttpFullResponse) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest) ResponseWrapper(org.webpieces.webserver.test.ResponseWrapper) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) Test(org.junit.Test) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest)

Example 65 with HttpFullRequest

use of org.webpieces.httpclient11.api.HttpFullRequest in project webpieces by deanhiller.

the class TestSyncWebServer method testRedirect.

@Test
public void testRedirect() {
    HttpFullRequest req = Requests.createRequest(KnownHttpMethod.GET, "/");
    XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
    ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
    response.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
    Assert.assertEquals(0, response.getBody().getReadableSize());
    Assert.assertEquals("http://myhost.com/myroute", response.getRedirectUrl());
}
Also used : HttpFullResponse(org.webpieces.httpclient11.api.HttpFullResponse) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest) ResponseWrapper(org.webpieces.webserver.test.ResponseWrapper) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) Test(org.junit.Test) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest)

Aggregations

HttpFullRequest (org.webpieces.httpclient11.api.HttpFullRequest)222 HttpFullResponse (org.webpieces.httpclient11.api.HttpFullResponse)205 ResponseWrapper (org.webpieces.webserver.test.ResponseWrapper)204 Test (org.junit.Test)194 AbstractWebpiecesTest (org.webpieces.webserver.test.AbstractWebpiecesTest)193 PrivateWebserverForTest (org.webpieces.webserver.PrivateWebserverForTest)180 Header (org.webpieces.httpparser.api.common.Header)50 XFuture (org.webpieces.util.futures.XFuture)13 HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)12 Http2Header (com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)9 HttpRequestLine (org.webpieces.httpparser.api.dto.HttpRequestLine)9 HttpUri (org.webpieces.httpparser.api.dto.HttpUri)9 WebserverForTest (org.webpieces.plugins.fortesting.WebserverForTest)8 DataWrapper (org.webpieces.data.api.DataWrapper)6 UserDto (org.webpieces.webserver.basic.app.biz.UserDto)4 URL (java.net.URL)3 UserTestDbo (org.webpieces.plugins.hibernate.app.dbo.UserTestDbo)3 URI (java.net.URI)2 ByteBuffer (java.nio.ByteBuffer)2 NotFoundException (org.webpieces.http.exception.NotFoundException)2