use of org.webpieces.webserver.test.FullResponse in project webpieces by deanhiller.
the class TestSyncHibernate method testDbUseWhileRenderingPage.
/**
* Tests when we load user but not company, user.company.name will blow up since company was not
* loaded in the controller from the database.
*
* (ie. we only let you traverse the loaded graph so that we don't accidentally have 1+N queries running)
*/
@Test
public void testDbUseWhileRenderingPage() {
Integer id = loadDataInDb().getId();
verifyLazyLoad(id);
HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/dynamic/" + id);
http11Socket.send(req);
FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
response.assertStatusCode(KnownStatusCode.HTTP_500_INTERNAL_SVR_ERROR);
}
use of org.webpieces.webserver.test.FullResponse in project webpieces by deanhiller.
the class TestSyncHibernate method testRollback.
@Test
public void testRollback() {
HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/fail");
mock.addException(() -> {
throw new RuntimeException("for test");
});
http11Socket.send(req);
FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
response.assertStatusCode(KnownStatusCode.HTTP_500_INTERNAL_SVR_ERROR);
Assert.assertEquals(2, TransactionFilter.getState());
}
use of org.webpieces.webserver.test.FullResponse in project webpieces by deanhiller.
the class TestSyncHibernate method saveBean.
private String saveBean(String path) {
HttpRequest req = Requests.createRequest(KnownHttpMethod.POST, path);
http11Socket.send(req);
FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
response.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
return response.getRedirectUrl();
}
use of org.webpieces.webserver.test.FullResponse 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.webserver.test.FullResponse in project webpieces by deanhiller.
the class TestBeans method testDeveloperMistypesBeanNameVsFormNames.
/*
* Have the controller method be postUser(UserDbo user, String password) BUT then in the html have
* entity.name, entity.age, entity.password INSTEAD of user.name, etc. such that there
* is a mismatch and verify there is a clean error for that
*
* GET /adduser HTTP/1.1
* Host: localhost:59786
* User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:47.0) Gecko/20100101 Firefox/47.0
* Accept: text/html,application/xhtml+xml,application/xml;q=0.9,XX/XX;q=0.8
* Accept-Language: en-US,en;q=0.5
* Accept-Encoding: gzip, deflate
* Referer: http://localhost:59786/adduser
* Cookie: webSession=1-gzvc03bKRP2YYvWySwgENREwFSg=:__ST=3a2fda5dad7547d3b15b1f61bd3d12f5; webFlash=1:_message=Invalid+values+below&user.address.zipCode=Text+instead+of+number&__secureToken=3a2fda5dad7547d3b15b1f61bd3d12f5&user.firstName=Dean+Hiller; webErrors=1:user.address.zipCode=Could+not+convert+value
* Connection: keep-alive
*/
@Test
public void testDeveloperMistypesBeanNameVsFormNames() {
HttpDummyRequest req = Requests.createPostRequest("/postuser", "entity.firstName", "D&D", "entity.lastName", "Hiller", "entity.fullName", "Dean Hiller", "password", "hi");
http11Socket.send(req);
FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
response.assertStatusCode(KnownStatusCode.HTTP_500_INTERNAL_SVR_ERROR);
}
Aggregations