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");
}
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");
}
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;
}
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);
}
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");
}
Aggregations