Search in sources :

Example 11 with FullResponse

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);
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) FullResponse(org.webpieces.webserver.test.FullResponse) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) Test(org.junit.Test) WebserverForTest(org.webpieces.webserver.WebserverForTest)

Example 12 with FullResponse

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());
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) FullResponse(org.webpieces.webserver.test.FullResponse) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) Test(org.junit.Test) WebserverForTest(org.webpieces.webserver.WebserverForTest)

Example 13 with FullResponse

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();
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) FullResponse(org.webpieces.webserver.test.FullResponse)

Example 14 with FullResponse

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());
}
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 15 with FullResponse

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);
}
Also used : FullResponse(org.webpieces.webserver.test.FullResponse) HttpDummyRequest(org.webpieces.webserver.test.HttpDummyRequest) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) Test(org.junit.Test) WebserverForTest(org.webpieces.webserver.WebserverForTest)

Aggregations

FullResponse (org.webpieces.webserver.test.FullResponse)154 Test (org.junit.Test)142 AbstractWebpiecesTest (org.webpieces.webserver.test.AbstractWebpiecesTest)142 WebserverForTest (org.webpieces.webserver.WebserverForTest)136 HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)120 HttpDummyRequest (org.webpieces.webserver.test.HttpDummyRequest)32 Header (org.webpieces.httpparser.api.common.Header)16 CompletableFuture (java.util.concurrent.CompletableFuture)11 PlatformOverridesForTest (org.webpieces.webserver.test.PlatformOverridesForTest)9 UserDto (org.webpieces.webserver.basic.app.biz.UserDto)4 UserTestDbo (org.webpieces.plugins.hibernate.app.dbo.UserTestDbo)3 NotFoundException (org.webpieces.router.api.exceptions.NotFoundException)2 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