Search in sources :

Example 16 with ResponseWrapper

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);
}
Also used : HttpFullResponse(org.webpieces.httpclient11.api.HttpFullResponse) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest) Header(org.webpieces.httpparser.api.common.Header) ResponseWrapper(org.webpieces.webserver.test.ResponseWrapper) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) Test(org.junit.Test) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest)

Example 17 with ResponseWrapper

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;
}
Also used : HttpFullResponse(org.webpieces.httpclient11.api.HttpFullResponse) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest) ResponseWrapper(org.webpieces.webserver.test.ResponseWrapper)

Example 18 with ResponseWrapper

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;
}
Also used : HttpFullResponse(org.webpieces.httpclient11.api.HttpFullResponse) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest) Header(org.webpieces.httpparser.api.common.Header) ResponseWrapper(org.webpieces.webserver.test.ResponseWrapper)

Example 19 with ResponseWrapper

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");
}
Also used : HttpFullResponse(org.webpieces.httpclient11.api.HttpFullResponse) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest) ResponseWrapper(org.webpieces.webserver.test.ResponseWrapper) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) Test(org.junit.Test)

Example 20 with ResponseWrapper

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());
}
Also used : HttpFullResponse(org.webpieces.httpclient11.api.HttpFullResponse) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest) ResponseWrapper(org.webpieces.webserver.test.ResponseWrapper) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) Test(org.junit.Test)

Aggregations

ResponseWrapper (org.webpieces.webserver.test.ResponseWrapper)209 HttpFullRequest (org.webpieces.httpclient11.api.HttpFullRequest)204 HttpFullResponse (org.webpieces.httpclient11.api.HttpFullResponse)200 Test (org.junit.Test)189 AbstractWebpiecesTest (org.webpieces.webserver.test.AbstractWebpiecesTest)189 PrivateWebserverForTest (org.webpieces.webserver.PrivateWebserverForTest)174 Header (org.webpieces.httpparser.api.common.Header)39 XFuture (org.webpieces.util.futures.XFuture)11 WebserverForTest (org.webpieces.plugins.fortesting.WebserverForTest)8 UserDto (org.webpieces.webserver.basic.app.biz.UserDto)4 URL (java.net.URL)3 UserTestDbo (org.webpieces.plugins.hibernate.app.dbo.UserTestDbo)3 URI (java.net.URI)2 DataWrapper (org.webpieces.data.api.DataWrapper)2 NotFoundException (org.webpieces.http.exception.NotFoundException)2 AcmeInfo (org.webpieces.plugin.secure.sslcert.acme.AcmeInfo)2 SearchRequest (org.webpieces.webserver.json.app.SearchRequest)2 FetchValueResponse (webpiecesxxxxxpackage.service.FetchValueResponse)2 Counter (io.micrometer.core.instrument.Counter)1 RequiredSearch (io.micrometer.core.instrument.search.RequiredSearch)1