use of org.webpieces.webserver.test.ResponseWrapper in project webpieces by deanhiller.
the class TestScopes method testSessionScopeModificationByClient.
@Test
public void testSessionScopeModificationByClient() {
HttpFullRequest req = Requests.createRequest(KnownHttpMethod.GET, "/home");
// not exactly part of this test but noticed an issue of context leak from server to client in embedded mode that should not exist
Assert.assertEquals(0, Context.getContext().size());
XFuture<HttpFullResponse> respFuture1 = http11Socket.send(req);
// not exactly part of this test but noticed an issue of context leak from server to client in embedded mode that should not exist
Assert.assertEquals(0, Context.getContext().size());
ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture1);
response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
response.assertContains("age=30");
Header cookie = response.getResponse().getHeaderLookupStruct().getHeader(KnownHeaderName.SET_COOKIE);
String value = cookie.getValue();
value = value.replace("age=30", "age=60");
value = value.replace("; path=/; HttpOnly", "");
// modify cookie and rerequest...
HttpFullRequest req2 = Requests.createRequest(KnownHttpMethod.GET, "/displaySession");
req2.addHeader(new Header(KnownHeaderName.COOKIE, value));
XFuture<HttpFullResponse> respFuture = http11Socket.send(req2);
response = ResponseExtract.waitResponseAndWrap(respFuture);
response.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
Header cookie2 = response.getResponse().getHeaderLookupStruct().getHeader(KnownHeaderName.SET_COOKIE);
String deleteCookie = cookie2.getValue();
Assert.assertEquals("webSession=; Max-Age=0; path=/; HttpOnly", deleteCookie);
Header header = response.getResponse().getHeaderLookupStruct().getHeader(KnownHeaderName.LOCATION);
String url = header.getValue();
Assert.assertEquals("http://myhost.com/displaySession", url);
}
use of org.webpieces.webserver.test.ResponseWrapper in project webpieces by deanhiller.
the class TestScopes method runInvalidPost.
private ResponseWrapper runInvalidPost() {
HttpFullRequest req = Requests.createPostRequest("/user/post", // invalid first name
"user.firstName", // invalid first name
"D", "user.lastName", "Hiller", "user.fullName", "Dean Hiller", "user.address.zipCode", "555", "user.address.street", "Coolness Dr.");
XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
response.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
return response;
}
use of org.webpieces.webserver.test.ResponseWrapper in project webpieces by deanhiller.
the class TestScopes method runGetUserFormWithErrors.
private ResponseWrapper runGetUserFormWithErrors(ResponseWrapper response1) {
Assert.assertEquals("http://myhost.com/user/new", response1.getRedirectUrl());
HttpFullRequest req = Requests.createRequest(KnownHttpMethod.GET, "/user/new");
Header cookieHeader = response1.createCookieRequestHeader();
req.addHeader(cookieHeader);
XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
response.assertContains("First name must be more than 2 characters");
return response;
}
use of org.webpieces.webserver.test.ResponseWrapper in project webpieces by deanhiller.
the class TestStaticPaths method testStaticDirWithHashLoad.
@Test
public void testStaticDirWithHashLoad() throws FileNotFoundException, IOException {
String hash = loadUrlEncodedHash();
HttpFullRequest req = Requests.createRequest(KnownHttpMethod.GET, "/public/fonts.css?hash=" + hash);
XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
response.assertContains("themes.googleusercontent.com");
response.assertContentType("text/css; charset=utf-8");
}
use of org.webpieces.webserver.test.ResponseWrapper in project webpieces by deanhiller.
the class TestStaticPaths method testStaticDir.
@Test
public void testStaticDir() throws InterruptedException {
HttpFullRequest req = Requests.createRequest(KnownHttpMethod.GET, "/public/staticMeta.txt");
XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
response.assertContains("org.webpieces.webserver.staticpath.app.StaticMeta");
response.assertContentType("text/plain; charset=utf-8");
if (!http11Socket.isClosed())
// we are across a second in one of the test cases so take a second to wait for close
Thread.sleep(2000);
// there is no keep alive. socket should be closed.
Assert.assertTrue(http11Socket.isClosed());
}
Aggregations