Search in sources :

Example 76 with HttpRequest

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

the class TestIfGenerator method testElseIFTag.

@Test
public void testElseIFTag() {
    HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/elseif");
    http11Socket.send(req);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
    response.assertNotContains("This should not exist");
    response.assertContains("This should exist");
    response.assertContains("ElseIf1");
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) FullResponse(org.webpieces.webserver.test.FullResponse) Test(org.junit.Test) WebserverForTest(org.webpieces.webserver.WebserverForTest) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest)

Example 77 with HttpRequest

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

the class TestIfGenerator method testIfTag.

@Test
public void testIfTag() {
    HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/if");
    http11Socket.send(req);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
    response.assertContains("This should exist");
    response.assertNotContains("Negative1");
    response.assertNotContains("Negative2");
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) FullResponse(org.webpieces.webserver.test.FullResponse) Test(org.junit.Test) WebserverForTest(org.webpieces.webserver.WebserverForTest) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest)

Example 78 with HttpRequest

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

the class TestLesson1BasicRequestResponse method createRequest.

static HttpRequest createRequest(String uri) {
    HttpRequestLine requestLine = new HttpRequestLine();
    requestLine.setMethod(KnownHttpMethod.GET);
    requestLine.setUri(new HttpUri(uri));
    HttpRequest req = new HttpRequest();
    req.setRequestLine(requestLine);
    req.addHeader(new Header(KnownHeaderName.HOST, "yourdomain.com"));
    return req;
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) HttpRequestLine(org.webpieces.httpparser.api.dto.HttpRequestLine) Header(org.webpieces.httpparser.api.common.Header) HttpUri(org.webpieces.httpparser.api.dto.HttpUri)

Example 79 with HttpRequest

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

the class TestLesson1BasicRequestResponse method testAsyncControllerAndRemoteSystem.

/**
	 * It is highly suggested you step through this test in debug mode to understand the description below...
	 * 
	 * This is a single threaded test that actually allows the webserver thread to return back to the test before 
	 * the response comes.  (in production the thread would process other requests while waiting for remote system response).  
	 * Then the test simulates the response coming in from remote system and makes sure we send a response back
	 * to the ResponseSender.  In implementations like this with a remote system, one can avoid holding threads up
	 * and allow them to keep working while waiting for a response from the remote system.
	 */
@Test
public void testAsyncControllerAndRemoteSystem() {
    CompletableFuture<Integer> future = new CompletableFuture<Integer>();
    mockRemote.addValueToReturn(future);
    HttpRequest req = createRequest("/async");
    http11Socket.send(req);
    List<FullResponse> responses = http11Socket.getResponses();
    Assert.assertEquals(0, responses.size());
    //notice that the thread returned but there is no response back to browser yet such that thread can do more work.
    //next, simulate remote system returning a value..
    int value = 85;
    future.complete(value);
    List<FullResponse> responses2 = http11Socket.getResponses();
    Assert.assertEquals(1, responses2.size());
    FullResponse httpPayload = responses2.get(0);
    httpPayload.assertStatusCode(KnownStatusCode.HTTP_200_OK);
    httpPayload.assertContains("This is a page with value=" + value);
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) CompletableFuture(java.util.concurrent.CompletableFuture) FullResponse(org.webpieces.webserver.test.FullResponse) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) Test(org.junit.Test)

Example 80 with HttpRequest

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

the class TestLesson2Errors method testNotFound.

/**
	 * You could also test notFound route fails with exception too...
	 */
@Test
public void testNotFound() {
    HttpRequest req = TestLesson1BasicRequestResponse.createRequest("/route/that/does/not/exist");
    http11Socket.send(req);
    List<FullResponse> responses = http11Socket.getResponses();
    Assert.assertEquals(1, responses.size());
    FullResponse httpPayload = responses.get(0);
    httpPayload.assertStatusCode(KnownStatusCode.HTTP_404_NOTFOUND);
    httpPayload.assertContains("Your page was not found");
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) FullResponse(org.webpieces.webserver.test.FullResponse) Test(org.junit.Test) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest)

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