Search in sources :

Example 21 with HttpDummyRequest

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

the class TestJson method testAsyncJsonGet.

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

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

the class TestSyncHibernate method testHibernateNoUserIdParamWillSaveNewUser.

@Test
public void testHibernateNoUserIdParamWillSaveNewUser() {
    String email = "test1";
    HttpDummyRequest req = Requests.createPostRequest("/testmerge", "user.email", email, "user.name", "blah1", "user.firstName", "blah2");
    http11Socket.send(req);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
    UserTestDbo user2 = loadByEmail(email);
    //name changed
    Assert.assertEquals("blah1", user2.getName());
    //firstname changed
    Assert.assertEquals("blah2", user2.getFirstName());
}
Also used : FullResponse(org.webpieces.webserver.test.FullResponse) UserTestDbo(org.webpieces.plugins.hibernate.app.dbo.UserTestDbo) HttpDummyRequest(org.webpieces.webserver.test.HttpDummyRequest) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) Test(org.junit.Test) WebserverForTest(org.webpieces.webserver.WebserverForTest)

Example 23 with HttpDummyRequest

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

the class TestFlashAndSelect method testMultiSelectSingleSelection.

@Test
public void testMultiSelectSingleSelection() {
    HttpDummyRequest req1 = Requests.createPostRequest("/multiselect", "entity.id", user.getId() + "", //invalid first name
    "entity.firstName", //invalid first name
    "NextName", "entity.email", "dean@zz.com", "entity.lastName", "", "entity.password", "", "entity.levelOfEducation", "", "selectedRoles", "j");
    http11Socket.send(req1);
    FullResponse response1 = ResponseExtract.assertSingleResponse(http11Socket);
    response1.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
    String urlPath = "/multiselect/" + user.getId();
    Assert.assertEquals("http://myhost.com" + urlPath, response1.getRedirectUrl());
    HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, urlPath);
    Header cookieHeader = response1.createCookieRequestHeader();
    req.addHeader(cookieHeader);
    http11Socket.send(req);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
    response.assertContains("<option value=`b` >Badass</script>".replace('`', '\"'));
    response.assertContains("<option value=`j` selected=`selected`>Jerk</script>".replace('`', '\"'));
    response.assertContains("<option value=`d` >Delinquint</script>".replace('`', '\"'));
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) FullResponse(org.webpieces.webserver.test.FullResponse) Header(org.webpieces.httpparser.api.common.Header) HttpDummyRequest(org.webpieces.webserver.test.HttpDummyRequest) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) Test(org.junit.Test) WebserverForTest(org.webpieces.webserver.WebserverForTest)

Example 24 with HttpDummyRequest

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

the class TestSyncHibernate method testHibernateNoUserIdWillSaveNewUser.

@Test
public void testHibernateNoUserIdWillSaveNewUser() {
    String email = "test2";
    HttpDummyRequest req = Requests.createPostRequest("/testmerge", "user.id", "", "user.email", email, "user.name", "blah1", "user.firstName", "blah2", "user.levelOfEducation", LevelEducation.COLLEGE.getDbCode() + "");
    http11Socket.send(req);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
    UserTestDbo user2 = loadByEmail(email);
    //name changed
    Assert.assertEquals("blah1", user2.getName());
    //firstname changed
    Assert.assertEquals("blah2", user2.getFirstName());
    Assert.assertEquals(LevelEducation.COLLEGE, user2.getLevelOfEducation());
}
Also used : FullResponse(org.webpieces.webserver.test.FullResponse) UserTestDbo(org.webpieces.plugins.hibernate.app.dbo.UserTestDbo) HttpDummyRequest(org.webpieces.webserver.test.HttpDummyRequest) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) Test(org.junit.Test) WebserverForTest(org.webpieces.webserver.WebserverForTest)

Example 25 with HttpDummyRequest

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

the class TestSyncHibernate method testHibernatePostPartialDataDoesntBlowDataAway.

@Test
public void testHibernatePostPartialDataDoesntBlowDataAway() {
    UserTestDbo user = loadDataInDb();
    HttpDummyRequest req = Requests.createPostRequest("/testmerge", "user.id", user.getId() + "", "user.name", "blah1", "user.firstName", "blah2");
    http11Socket.send(req);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
    UserTestDbo user2 = load(user.getId());
    //name changed
    Assert.assertEquals("blah1", user2.getName());
    //firstname changed
    Assert.assertEquals("blah2", user2.getFirstName());
    //lastname remained the same
    Assert.assertEquals(user.getLastName(), user2.getLastName());
}
Also used : FullResponse(org.webpieces.webserver.test.FullResponse) UserTestDbo(org.webpieces.plugins.hibernate.app.dbo.UserTestDbo) HttpDummyRequest(org.webpieces.webserver.test.HttpDummyRequest) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) Test(org.junit.Test) 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