Search in sources :

Example 1 with UserDto

use of org.webpieces.webserver.basic.app.biz.UserDto in project webpieces by deanhiller.

the class TestBeans method testIncomingDataAndDataSeperate.

@Test
public void testIncomingDataAndDataSeperate() {
    HttpDummyRequest req = Requests.createPostRequest("/postArray2", "user.accounts[1].name", "Account2Name", "user.accounts[1].color", "green", "user.accounts[2].addresses[0].number", "56", "user.firstName", "D&D", "user.lastName", "Hiller", "user.fullName", "Dean Hiller");
    DataWrapperGenerator dataGen = DataWrapperGeneratorFactory.createDataWrapperGenerator();
    HttpParser parser = HttpParserFactory.createParser(new BufferCreationPool());
    MarshalState state = parser.prepareToMarshal();
    ByteBuffer buffer = parser.marshalToByteBuffer(state, req.getRequest());
    DataWrapper d1 = dataGen.wrapByteBuffer(buffer);
    ByteBuffer buf2 = parser.marshalToByteBuffer(state, req.getData());
    DataWrapper data = dataGen.chainDataWrappers(d1, dataGen.wrapByteBuffer(buf2));
    // Split the body in half
    List<? extends DataWrapper> split = dataGen.split(data, data.getReadableSize() - 20);
    http11Socket.sendBytes(split.get(0));
    http11Socket.sendBytes(split.get(1));
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
    UserDto user = mockSomeLib.getUser();
    Assert.assertEquals("D&D", user.getFirstName());
    Assert.assertEquals(3, user.getAccounts().size());
    Assert.assertEquals("Account2Name", user.getAccounts().get(1).getName());
    Assert.assertEquals(56, user.getAccounts().get(2).getAddresses().get(0).getNumber());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) DataWrapperGenerator(org.webpieces.data.api.DataWrapperGenerator) MarshalState(org.webpieces.httpparser.api.MarshalState) FullResponse(org.webpieces.webserver.test.FullResponse) HttpDummyRequest(org.webpieces.webserver.test.HttpDummyRequest) UserDto(org.webpieces.webserver.basic.app.biz.UserDto) HttpParser(org.webpieces.httpparser.api.HttpParser) ByteBuffer(java.nio.ByteBuffer) BufferCreationPool(org.webpieces.data.api.BufferCreationPool) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) Test(org.junit.Test) WebserverForTest(org.webpieces.webserver.WebserverForTest)

Example 2 with UserDto

use of org.webpieces.webserver.basic.app.biz.UserDto in project webpieces by deanhiller.

the class TestBeans method testInvalidComplexBean.

@Test
public void testInvalidComplexBean() {
    HttpDummyRequest req = Requests.createPostRequest("/postuser2", "user.firstName", "D&D", "user.lastName", "Hiller", "user.fullName", "Dean Hiller", "user.address.zipCode", "This test value invalid since not an int", "user.address.street", "Coolness Dr.", "password", "should be hidden from flash");
    http11Socket.send(req);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
    UserDto savedUser = mockSomeOtherLib.getUser();
    //user was not 
    Assert.assertEquals(null, savedUser);
    UserDto user = mockSomeLib.getUser();
    //this is not set since it was invalid
    Assert.assertEquals(0, user.getAddress().getZipCode());
    Assert.assertEquals("D&D", user.getFirstName());
    Assert.assertEquals("Coolness Dr.", user.getAddress().getStreet());
}
Also used : FullResponse(org.webpieces.webserver.test.FullResponse) HttpDummyRequest(org.webpieces.webserver.test.HttpDummyRequest) UserDto(org.webpieces.webserver.basic.app.biz.UserDto) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) Test(org.junit.Test) WebserverForTest(org.webpieces.webserver.WebserverForTest)

Example 3 with UserDto

use of org.webpieces.webserver.basic.app.biz.UserDto in project webpieces by deanhiller.

the class TestBeans method testArraySaved.

@Test
public void testArraySaved() {
    HttpDummyRequest req = Requests.createPostRequest("/postArray2", "user.accounts[1].name", "Account2Name", "user.accounts[1].color", "green", "user.accounts[2].addresses[0].number", "56", "user.firstName", "D&D", "user.lastName", "Hiller", "user.fullName", "Dean Hiller");
    http11Socket.send(req);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
    UserDto user = mockSomeLib.getUser();
    Assert.assertEquals("D&D", user.getFirstName());
    Assert.assertEquals(3, user.getAccounts().size());
    Assert.assertEquals("Account2Name", user.getAccounts().get(1).getName());
    Assert.assertEquals(56, user.getAccounts().get(2).getAddresses().get(0).getNumber());
}
Also used : FullResponse(org.webpieces.webserver.test.FullResponse) HttpDummyRequest(org.webpieces.webserver.test.HttpDummyRequest) UserDto(org.webpieces.webserver.basic.app.biz.UserDto) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) Test(org.junit.Test) WebserverForTest(org.webpieces.webserver.WebserverForTest)

Example 4 with UserDto

use of org.webpieces.webserver.basic.app.biz.UserDto in project webpieces by deanhiller.

the class TestBeans method testComplexBeanSaved.

@Test
public void testComplexBeanSaved() {
    HttpDummyRequest req = Requests.createPostRequest("/postuser2", "user.firstName", "D&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);
    UserDto user = mockSomeOtherLib.getUser();
    Assert.assertEquals(555, user.getAddress().getZipCode());
    Assert.assertEquals("D&D", user.getFirstName());
    Assert.assertEquals("Coolness Dr.", user.getAddress().getStreet());
}
Also used : FullResponse(org.webpieces.webserver.test.FullResponse) HttpDummyRequest(org.webpieces.webserver.test.HttpDummyRequest) UserDto(org.webpieces.webserver.basic.app.biz.UserDto) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) Test(org.junit.Test) WebserverForTest(org.webpieces.webserver.WebserverForTest)

Example 5 with UserDto

use of org.webpieces.webserver.basic.app.biz.UserDto in project webpieces by deanhiller.

the class ScopesController method userAddEdit.

public Action userAddEdit(Integer id) {
    if (id == null) {
        return Actions.renderThis("entity", new UserDto());
    }
    //lookup from database typically not create user
    UserDto user = new UserDto();
    user.setId(555);
    user.setFirstName("Dean");
    user.setLastName("Hiller");
    return Actions.renderThis("entity", user);
}
Also used : UserDto(org.webpieces.webserver.basic.app.biz.UserDto)

Aggregations

UserDto (org.webpieces.webserver.basic.app.biz.UserDto)6 Test (org.junit.Test)4 WebserverForTest (org.webpieces.webserver.WebserverForTest)4 AbstractWebpiecesTest (org.webpieces.webserver.test.AbstractWebpiecesTest)4 FullResponse (org.webpieces.webserver.test.FullResponse)4 HttpDummyRequest (org.webpieces.webserver.test.HttpDummyRequest)4 ByteBuffer (java.nio.ByteBuffer)1 BufferCreationPool (org.webpieces.data.api.BufferCreationPool)1 DataWrapper (org.webpieces.data.api.DataWrapper)1 DataWrapperGenerator (org.webpieces.data.api.DataWrapperGenerator)1 HttpParser (org.webpieces.httpparser.api.HttpParser)1 MarshalState (org.webpieces.httpparser.api.MarshalState)1 Address (org.webpieces.webserver.basic.app.biz.Address)1 Account (org.webpieces.webserver.tags.app.Account)1