Search in sources :

Example 16 with HttpDummyRequest

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

the class TestJson method testAsyncJsonPost.

@Test
public void testAsyncJsonPost() {
    HttpDummyRequest req = Requests.createJsonRequest(KnownHttpMethod.POST, "/json/async/45");
    http11Socket.send(req);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
    response.assertContains("{`searchTime`:98,`matches`:[`match1`,`match2`]}".replace("`", "\""));
    response.assertContentType("application/json");
}
Also used : FullResponse(org.webpieces.webserver.test.FullResponse) HttpDummyRequest(org.webpieces.webserver.test.HttpDummyRequest) Test(org.junit.Test) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) WebserverForTest(org.webpieces.webserver.WebserverForTest)

Example 17 with HttpDummyRequest

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

the class TestJson method testSyncBadJsonGet.

@Test
public void testSyncBadJsonGet() {
    HttpDummyRequest req = Requests.createBadJsonRequest(KnownHttpMethod.GET, "/json/45");
    http11Socket.send(req);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_400_BADREQUEST);
    response.assertContains("{`error`:`invalid json in client request.  Unexpected character ('c' (code 99)): was expecting a colon to separate field name and value".replace("`", "\""));
    response.assertContentType("application/json");
}
Also used : FullResponse(org.webpieces.webserver.test.FullResponse) HttpDummyRequest(org.webpieces.webserver.test.HttpDummyRequest) Test(org.junit.Test) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) WebserverForTest(org.webpieces.webserver.WebserverForTest)

Example 18 with HttpDummyRequest

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

the class TestJson method testNotFoundInHtmlUrls.

@Test
public void testNotFoundInHtmlUrls() {
    HttpDummyRequest req = Requests.createBadJsonRequest(KnownHttpMethod.POST, "/html");
    http11Socket.send(req);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_404_NOTFOUND);
    response.assertContains("Your page was not found");
    response.assertContentType("text/html; charset=utf-8");
}
Also used : FullResponse(org.webpieces.webserver.test.FullResponse) HttpDummyRequest(org.webpieces.webserver.test.HttpDummyRequest) Test(org.junit.Test) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) WebserverForTest(org.webpieces.webserver.WebserverForTest)

Example 19 with HttpDummyRequest

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

the class TestJson method testAsyncBadJsonGet.

@Test
public void testAsyncBadJsonGet() {
    HttpDummyRequest req = Requests.createBadJsonRequest(KnownHttpMethod.GET, "/json/async/45");
    http11Socket.send(req);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_400_BADREQUEST);
    response.assertContains("{`error`:`invalid json in client request.  Unexpected character ('c' (code 99)): was expecting a colon to separate field name and value".replace("`", "\""));
    response.assertContentType("application/json");
}
Also used : FullResponse(org.webpieces.webserver.test.FullResponse) HttpDummyRequest(org.webpieces.webserver.test.HttpDummyRequest) Test(org.junit.Test) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) WebserverForTest(org.webpieces.webserver.WebserverForTest)

Example 20 with HttpDummyRequest

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

the class TestJson method testControllerThrowsNotFound.

@Test
public void testControllerThrowsNotFound() {
    HttpDummyRequest req = Requests.createJsonRequest(KnownHttpMethod.GET, "/json/throw/333");
    http11Socket.send(req);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    //clearly this url has nothing there
    response.assertStatusCode(KnownStatusCode.HTTP_404_NOTFOUND);
    response.assertContains("{`error`:`This url has no api.  try another url`,`code`:0}".replace("`", "\""));
    response.assertContentType("application/json");
}
Also used : FullResponse(org.webpieces.webserver.test.FullResponse) HttpDummyRequest(org.webpieces.webserver.test.HttpDummyRequest) Test(org.junit.Test) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) WebserverForTest(org.webpieces.webserver.WebserverForTest)

Aggregations

HttpDummyRequest (org.webpieces.webserver.test.HttpDummyRequest)35 FullResponse (org.webpieces.webserver.test.FullResponse)32 Test (org.junit.Test)31 WebserverForTest (org.webpieces.webserver.WebserverForTest)31 AbstractWebpiecesTest (org.webpieces.webserver.test.AbstractWebpiecesTest)31 Header (org.webpieces.httpparser.api.common.Header)9 HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)6 DataWrapper (org.webpieces.data.api.DataWrapper)4 UserDto (org.webpieces.webserver.basic.app.biz.UserDto)4 HttpData (org.webpieces.httpparser.api.dto.HttpData)3 UserTestDbo (org.webpieces.plugins.hibernate.app.dbo.UserTestDbo)3 ByteBuffer (java.nio.ByteBuffer)1 BufferCreationPool (org.webpieces.data.api.BufferCreationPool)1 DataWrapperGenerator (org.webpieces.data.api.DataWrapperGenerator)1 HttpParser (org.webpieces.httpparser.api.HttpParser)1 MarshalState (org.webpieces.httpparser.api.MarshalState)1 HttpRequestLine (org.webpieces.httpparser.api.dto.HttpRequestLine)1 HttpUri (org.webpieces.httpparser.api.dto.HttpUri)1