use of org.webpieces.webserver.test.FullResponse in project webpieces by deanhiller.
the class TestBeans method testPostFailDueToSecureTokenCheck.
@Test
public void testPostFailDueToSecureTokenCheck() {
HttpDummyRequest req = Requests.createPostRequest("/postuser", "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);
//We should change this to a 400 bad request
response.assertStatusCode(KnownStatusCode.HTTP_500_INTERNAL_SVR_ERROR);
}
use of org.webpieces.webserver.test.FullResponse 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());
}
use of org.webpieces.webserver.test.FullResponse in project webpieces by deanhiller.
the class TestBeans method testNullIdFromForm.
/**
* Found this bug where it blew up translating 'null' to 'null' and tried to convert it
* to int instead, so added test then fixed
*/
@Test
public void testNullIdFromForm() {
HttpDummyRequest req = Requests.createPostRequest("/postuser2", //multipart is "" and nearly all webservers convert that to null(including ours)
"user.id", //multipart is "" and nearly all webservers convert that to null(including ours)
"");
http11Socket.send(req);
FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
response.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
//should not have any errors and should redirect back to list of users page..
Assert.assertEquals("http://myhost.com/listusers", response.getRedirectUrl());
}
use of org.webpieces.webserver.test.FullResponse in project webpieces by deanhiller.
the class TestAsyncWebServer method testCompletePromiseOnRequestThread.
@Test
public void testCompletePromiseOnRequestThread() {
HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/myroute");
http11Socket.send(req);
FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
response.assertContains("This is the first raw html page");
}
use of org.webpieces.webserver.test.FullResponse in project webpieces by deanhiller.
the class TestAsynchronousErrors method testNotFoundThrowsException.
@Test
public void testNotFoundThrowsException() {
CompletableFuture<Integer> future = new CompletableFuture<Integer>();
mockNotFoundLib.queueFuture(future);
HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/route/that/does/not/exist");
http11Socket.send(req);
List<FullResponse> responses2 = http11Socket.getResponses();
Assert.assertEquals(0, responses2.size());
future.completeExceptionally(new RuntimeException("testing notfound from notfound route"));
FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
response.assertStatusCode(KnownStatusCode.HTTP_500_INTERNAL_SVR_ERROR);
response.assertContains("There was a bug in our software...sorry about that");
}
Aggregations