use of org.webpieces.data.api.DataWrapperGenerator 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());
}
use of org.webpieces.data.api.DataWrapperGenerator in project webpieces by deanhiller.
the class TestBeansAndSplit method testIncomingDataAndDataSeperate.
@Test
public void testIncomingDataAndDataSeperate() {
HttpFullRequest 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("a", new SimpleMeterRegistry(), new TwoPools("pl", new SimpleMeterRegistry()));
MarshalState state = parser.prepareToMarshal();
ByteBuffer buffer = parser.marshalToByteBuffer(state, req.getRequest());
DataWrapper d1 = dataGen.wrapByteBuffer(buffer);
DataWrapper data = dataGen.chainDataWrappers(d1, req.getData());
// Split the body in half
List<? extends DataWrapper> split = dataGen.split(data, data.getReadableSize() - 20);
ByteBuffer buffer1 = ByteBuffer.wrap(split.get(0).createByteArray());
ByteBuffer buffer2 = ByteBuffer.wrap(split.get(1).createByteArray());
dataListener.incomingData(channel, buffer1);
dataListener.incomingData(channel, buffer2);
ResponseWrapper response = create();
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());
}
Aggregations