Search in sources :

Example 91 with HttpRequest

use of org.webpieces.httpparser.api.dto.HttpRequest in project webpieces by deanhiller.

the class TestRequestParsing method testPartialHttpMessage.

@Test
public void testPartialHttpMessage() {
    HttpRequest request = createPostRequest();
    byte[] payload = unwrap(parser.marshalToByteBuffer(state, request));
    byte[] firstPart = new byte[10];
    byte[] secondPart = new byte[payload.length - firstPart.length];
    //let's split the payload up into two pieces
    System.arraycopy(payload, 0, firstPart, 0, firstPart.length);
    System.arraycopy(payload, firstPart.length, secondPart, 0, secondPart.length);
    DataWrapper data1 = dataGen.wrapByteArray(firstPart);
    DataWrapper data2 = dataGen.wrapByteArray(secondPart);
    Memento memento = parser.prepareToParse();
    memento = parser.parse(memento, data1);
    Assert.assertEquals(0, memento.getParsedMessages().size());
    memento = parser.parse(memento, data2);
    Assert.assertEquals(1, memento.getParsedMessages().size());
    HttpPayload httpMessage = memento.getParsedMessages().get(0);
    HttpRequest req = (HttpRequest) httpMessage;
    Assert.assertEquals(request.getRequestLine(), req.getRequestLine());
    Assert.assertEquals(request.getHeaders(), req.getHeaders());
    Assert.assertEquals(request, httpMessage);
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) DataWrapper(org.webpieces.data.api.DataWrapper) HttpPayload(org.webpieces.httpparser.api.dto.HttpPayload) Test(org.junit.Test)

Example 92 with HttpRequest

use of org.webpieces.httpparser.api.dto.HttpRequest in project webpieces by deanhiller.

the class TestFlashAndSelect method testMultiSelectSingleSelection.

@Test
public void testMultiSelectSingleSelection() {
    HttpDummyRequest req1 = Requests.createPostRequest("/multiselect", "entity.id", user.getId() + "", //invalid first name
    "entity.firstName", //invalid first name
    "NextName", "entity.email", "dean@zz.com", "entity.lastName", "", "entity.password", "", "entity.levelOfEducation", "", "selectedRoles", "j");
    http11Socket.send(req1);
    FullResponse response1 = ResponseExtract.assertSingleResponse(http11Socket);
    response1.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
    String urlPath = "/multiselect/" + user.getId();
    Assert.assertEquals("http://myhost.com" + urlPath, response1.getRedirectUrl());
    HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, urlPath);
    Header cookieHeader = response1.createCookieRequestHeader();
    req.addHeader(cookieHeader);
    http11Socket.send(req);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
    response.assertContains("<option value=`b` >Badass</script>".replace('`', '\"'));
    response.assertContains("<option value=`j` selected=`selected`>Jerk</script>".replace('`', '\"'));
    response.assertContains("<option value=`d` >Delinquint</script>".replace('`', '\"'));
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) FullResponse(org.webpieces.webserver.test.FullResponse) Header(org.webpieces.httpparser.api.common.Header) HttpDummyRequest(org.webpieces.webserver.test.HttpDummyRequest) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) Test(org.junit.Test) WebserverForTest(org.webpieces.webserver.WebserverForTest)

Example 93 with HttpRequest

use of org.webpieces.httpparser.api.dto.HttpRequest in project webpieces by deanhiller.

the class TestFlashAndSelect method testAssertBeanNoNullsOnLastNameAndEnum.

@Test
public void testAssertBeanNoNullsOnLastNameAndEnum() {
    String urlPath = "/user/edit/" + user.getId();
    HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, urlPath);
    http11Socket.send(req);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
    //assert the nulls came through
    response.assertContains("<input type=`text` name=`entity.lastName` value=`Hill` class=`input-xlarge`>".replace('`', '\"'));
    response.assertContains("<option value=`` >Unselected</option>".replace('`', '\"'));
    response.assertContains("<option value=`k` selected=`selected`>Kindergarten</script>".replace('`', '\"'));
}
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 94 with HttpRequest

use of org.webpieces.httpparser.api.dto.HttpRequest in project webpieces by deanhiller.

the class TestAsyncHibernate method saveBean.

private String saveBean(String path) {
    HttpRequest req = Requests.createRequest(KnownHttpMethod.POST, path);
    http11Socket.send(req);
    List<FullResponse> responses1 = http11Socket.getResponses();
    Assert.assertEquals(0, responses1.size());
    List<Runnable> runnables = mockExecutor.getRunnablesScheduled();
    runnables.get(0).run();
    mockExecutor.clear();
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
    Header header = response.getResponse().getHeaderLookupStruct().getHeader(KnownHeaderName.LOCATION);
    String url = header.getValue();
    return url;
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) FullResponse(org.webpieces.webserver.test.FullResponse) Header(org.webpieces.httpparser.api.common.Header)

Example 95 with HttpRequest

use of org.webpieces.httpparser.api.dto.HttpRequest in project webpieces by deanhiller.

the class TestSyncHibernate method testRenderAddPage.

@Test
public void testRenderAddPage() {
    HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/user/new");
    http11Socket.send(req);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
    response.assertContains("name='' email=''");
}
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)

Aggregations

HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)157 Test (org.junit.Test)136 AbstractWebpiecesTest (org.webpieces.webserver.test.AbstractWebpiecesTest)120 FullResponse (org.webpieces.webserver.test.FullResponse)120 WebserverForTest (org.webpieces.webserver.WebserverForTest)114 Header (org.webpieces.httpparser.api.common.Header)33 DataWrapper (org.webpieces.data.api.DataWrapper)17 PlatformOverridesForTest (org.webpieces.webserver.test.PlatformOverridesForTest)15 HttpData (org.webpieces.httpparser.api.dto.HttpData)13 HttpRequestLine (org.webpieces.httpparser.api.dto.HttpRequestLine)13 HttpUri (org.webpieces.httpparser.api.dto.HttpUri)13 CompletableFuture (java.util.concurrent.CompletableFuture)11 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)8 HttpPayload (org.webpieces.httpparser.api.dto.HttpPayload)8 HttpResponse (org.webpieces.httpparser.api.dto.HttpResponse)8 Http2Response (com.webpieces.hpack.api.dto.Http2Response)6 HttpDummyRequest (org.webpieces.webserver.test.HttpDummyRequest)6 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)4 StreamWriter (com.webpieces.http2engine.api.StreamWriter)3 Http2Header (com.webpieces.http2parser.api.dto.lib.Http2Header)3