use of org.webpieces.webserver.test.HttpDummyRequest in project webpieces by deanhiller.
the class TestJson method testSyncJsonGet.
@Test
public void testSyncJsonGet() {
HttpDummyRequest req = Requests.createJsonRequest(KnownHttpMethod.GET, "/json/45");
http11Socket.send(req);
FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
response.assertContains("{`searchTime`:5,`matches`:[`match1`,`match2`]}".replace("`", "\""));
response.assertContentType("application/json");
}
use of org.webpieces.webserver.test.HttpDummyRequest in project webpieces by deanhiller.
the class TestJson method testNotFoundInJsonUrls.
@Test
public void testNotFoundInJsonUrls() {
HttpDummyRequest req = Requests.createBadJsonRequest(KnownHttpMethod.POST, "/json/some/notexist/route");
http11Socket.send(req);
FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
response.assertStatusCode(KnownStatusCode.HTTP_404_NOTFOUND);
response.assertContains("{`error`:`This url has no api. try another url`,`code`:0}".replace("`", "\""));
response.assertContentType("application/json");
}
use of org.webpieces.webserver.test.HttpDummyRequest in project webpieces by deanhiller.
the class TestJson method testSyncBadJsonPost.
@Test
public void testSyncBadJsonPost() {
HttpDummyRequest req = Requests.createBadJsonRequest(KnownHttpMethod.POST, "/json/45");
http11Socket.send(req);
FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
response.assertStatusCode(KnownStatusCode.HTTP_400_BADREQUEST);
response.assertContains("{`error`:`invalid json in client request. Unexpected character ('c' (code 99)): was expecting a colon to separate field name and value".replace("`", "\""));
response.assertContentType("application/json");
}
use of org.webpieces.webserver.test.HttpDummyRequest in project webpieces by deanhiller.
the class TestJson method testSimulateCurl.
//had a bug on this one so add a test
@Test
public void testSimulateCurl() {
HttpDummyRequest req = Requests.createJsonRequest(KnownHttpMethod.GET, "/json/45");
req.addHeader(new Header(KnownHeaderName.CONTENT_TYPE, "application/x-www-form-urlencoded"));
http11Socket.send(req);
FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
response.assertContains("{`searchTime`:5,`matches`:[`match1`,`match2`]}".replace("`", "\""));
response.assertContentType("application/json");
}
use of org.webpieces.webserver.test.HttpDummyRequest in project webpieces by deanhiller.
the class TestScopes method testValidationErrorDoesNotPersist.
//A basic POST form with invalid field, redirect to error page and load AND THEN
//POST form with valid data and expect success redirect
//This tests out the Validation scoped cookie
@Test
public void testValidationErrorDoesNotPersist() {
//POST first resulting in redirect with errors
//RENDER page WITH errors, verify errors are there
//POST again with valid data and verify POST succeeds
FullResponse response1 = runInvalidPost();
FullResponse response2 = runGetUserFormWithErrors(response1);
Header header = response2.createCookieRequestHeader();
HttpDummyRequest req = Requests.createPostRequest("/user/post", "user.id", "", //valid firstname
"user.firstName", //valid firstname
"Dean", "user.lastName", "Hiller", "user.fullName", "Dean Hiller", "user.address.zipCode", "555", "user.address.street", "Coolness Dr.");
req.addHeader(header);
http11Socket.send(req);
FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
response.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
Assert.assertEquals("http://myhost.com/user/list", response.getRedirectUrl());
}
Aggregations