Search in sources :

Example 11 with HttpDummyRequest

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

the class TestScopes method runInvalidPost.

private FullResponse runInvalidPost() {
    HttpDummyRequest req = Requests.createPostRequest("/user/post", //invalid first name
    "user.firstName", //invalid first name
    "D", "user.lastName", "Hiller", "user.fullName", "Dean Hiller", "user.address.zipCode", "555", "user.address.street", "Coolness Dr.");
    http11Socket.send(req);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
    return response;
}
Also used : FullResponse(org.webpieces.webserver.test.FullResponse) HttpDummyRequest(org.webpieces.webserver.test.HttpDummyRequest)

Example 12 with HttpDummyRequest

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

the class TestJson method testSyncWriteOnlyPost.

@Test
public void testSyncWriteOnlyPost() {
    HttpDummyRequest req = Requests.createJsonRequest(KnownHttpMethod.POST, "/json/write");
    http11Socket.send(req);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
    Assert.assertEquals("", response.getBodyAsString());
}
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 13 with HttpDummyRequest

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

the class TestJson method testRouteParamConversionFail.

@Test
public void testRouteParamConversionFail() {
    HttpDummyRequest req = Requests.createBadJsonRequest(KnownHttpMethod.POST, "/json/somenotexistroute");
    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)

Example 14 with HttpDummyRequest

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

the class TestJson method testAsyncBadJsonPost.

@Test
public void testAsyncBadJsonPost() {
    HttpDummyRequest req = Requests.createBadJsonRequest(KnownHttpMethod.POST, "/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 15 with HttpDummyRequest

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

the class TestJson method testSyncJsonPost.

@Test
public void testSyncJsonPost() {
    HttpDummyRequest req = Requests.createJsonRequest(KnownHttpMethod.POST, "/json/45");
    http11Socket.send(req);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
    response.assertContains("{`searchTime`:99,`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)

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