Search in sources :

Example 31 with HttpDummyRequest

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

the class TestJson method testSyncJsonGet.

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

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

the class TestJson method testNotFoundInJsonUrls.

@Test
public void testNotFoundInJsonUrls() {
    HttpDummyRequest req = Requests.createBadJsonRequest(KnownHttpMethod.POST, "/json/some/notexist/route");
    http11Socket.send(req);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    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 33 with HttpDummyRequest

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

the class TestJson method testSyncBadJsonPost.

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

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

the class TestJson method testSimulateCurl.

//had a bug on this one so add a test
@Test
public void testSimulateCurl() {
    HttpDummyRequest req = Requests.createJsonRequest(KnownHttpMethod.GET, "/json/45");
    req.addHeader(new Header(KnownHeaderName.CONTENT_TYPE, "application/x-www-form-urlencoded"));
    http11Socket.send(req);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
    response.assertContains("{`searchTime`:5,`matches`:[`match1`,`match2`]}".replace("`", "\""));
    response.assertContentType("application/json");
}
Also used : Header(org.webpieces.httpparser.api.common.Header) 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 35 with HttpDummyRequest

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

the class TestScopes method testValidationErrorDoesNotPersist.

//A basic POST form with invalid field, redirect to error page and load AND THEN
//POST form with valid data and expect success redirect
//This tests out the Validation scoped cookie
@Test
public void testValidationErrorDoesNotPersist() {
    //POST first resulting in redirect with errors
    //RENDER page WITH errors, verify errors are there
    //POST again with valid data and verify POST succeeds
    FullResponse response1 = runInvalidPost();
    FullResponse response2 = runGetUserFormWithErrors(response1);
    Header header = response2.createCookieRequestHeader();
    HttpDummyRequest req = Requests.createPostRequest("/user/post", "user.id", "", //valid firstname
    "user.firstName", //valid firstname
    "Dean", "user.lastName", "Hiller", "user.fullName", "Dean Hiller", "user.address.zipCode", "555", "user.address.street", "Coolness Dr.");
    req.addHeader(header);
    http11Socket.send(req);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
    Assert.assertEquals("http://myhost.com/user/list", response.getRedirectUrl());
}
Also used : FullResponse(org.webpieces.webserver.test.FullResponse) Header(org.webpieces.httpparser.api.common.Header) 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