use of com.webpieces.http2.api.dto.highlevel.Http2Request in project webpieces by deanhiller.
the class TestSBasicRequestResponse method testWithData.
@Test
public void testWithData() throws InterruptedException, ExecutionException, TimeoutException {
MockStreamWriter mockSw = new MockStreamWriter();
mockSw.setDefaultRetValToThis();
mockListener.addMockStreamToReturn(mockSw);
Http2Request request1 = Http2Requests.createRequest(1, false);
DataFrame data = Http2Requests.createData1(request1.getStreamId(), true);
mockChannel.send(request1);
PassedIn incoming1 = mockListener.getSingleRequest();
Assert.assertEquals(request1, incoming1.request);
mockChannel.send(data);
DataFrame incoming = (DataFrame) mockSw.getSingleFrame();
Assert.assertEquals(3, incoming.getData().getReadableSize());
// clear window update frames
Assert.assertEquals(2, mockChannel.getFramesAndClear().size());
Http2Response resp = Http2Requests.createResponse(request1.getStreamId(), false);
XFuture<StreamWriter> future = incoming1.stream.process(resp);
Http2Msg response = mockChannel.getFrameAndClear();
Assert.assertEquals(resp, response);
StreamWriter writer = future.get(2, TimeUnit.SECONDS);
DataFrame data2 = Http2Requests.createData2(request1.getStreamId(), true);
writer.processPiece(data2);
DataFrame dataResp = (DataFrame) mockChannel.getFrameAndClear();
Assert.assertEquals(1, dataResp.getData().getReadableSize());
}
use of com.webpieces.http2.api.dto.highlevel.Http2Request in project webpieces by deanhiller.
the class ErrorCommonTest method testRedirectRouteNotEnoughArgumentsBUTwithKeepAlive.
@Test
public void testRedirectRouteNotEnoughArgumentsBUTwithKeepAlive() {
// say method is something(int arg, String this)
// we verify redirects MUST match type and number of method arguments every time
// then when we form url, we put the stuff in the path OR put it as query params so it works on the way back in again too
String moduleFileContents = CommonRoutesModules.class.getName();
RouterService server = createServer(isProdTest, moduleFileContents);
server.start();
Http2Request req = RequestCreation.createHttpRequest(HttpMethod.GET, "/user/5553");
// ADD a keep alive to test keeping alive
req.addHeader(new Http2Header(Http2HeaderName.CONNECTION, "keep-alive"));
MockStreamHandle mockStream = new MockStreamHandle();
StreamRef ref = server.incomingRequest(req, mockStream);
XFuture<StreamWriter> future = ref.getWriter();
Assert.assertTrue(future.isDone() && !future.isCompletedExceptionally());
Http2Response response = mockStream.getLastResponse();
String contents = mockStream.getResponseBody();
Assert.assertEquals(response.getSingleHeaderValue(Http2HeaderName.STATUS), "500");
if (isProdTest) {
Assert.assertTrue(contents.contains("There was a bug in the developers application or webpieces server."));
} else {
// use DevServer template
Assert.assertTrue(contents.contains("NullTemplateApi.java is running for templatePath=org.webpieces.devrouter.impl.internalError_html"));
}
// We did send a keep alive so it should close
Assert.assertFalse(mockStream.isWasClosed());
}
use of com.webpieces.http2.api.dto.highlevel.Http2Request in project webpieces by deanhiller.
the class ErrorTest method testNoMethod.
@Test
public void testNoMethod() {
log.info("starting");
String moduleFileContents = NoMethodRouterModules.class.getName();
RouterService server = ErrorCommonTest.createServer(true, moduleFileContents);
try {
server.start();
Assert.fail("Should have thrown exception on start since this is prod");
} catch (RuntimeException e) {
Assert.assertTrue(e.getMessage().contains("Cannot find 'public' method='thisMethodNotExist' on class="));
}
Http2Request req = RequestCreation.createHttpRequest(HttpMethod.GET, "/something");
MockStreamHandle mockStream = new MockStreamHandle();
StreamRef ref = server.incomingRequest(req, mockStream);
XFuture<StreamWriter> future = ref.getWriter();
// done and no exception SINCE we responded to client successfully
Assert.assertTrue(future.isDone() && !future.isCompletedExceptionally());
Http2Response response = mockStream.getLastResponse();
String body = mockStream.getResponseBody();
Assert.assertEquals(StatusCode.HTTP_500_INTERNAL_SERVER_ERROR, response.getKnownStatusCode());
Assert.assertTrue(body.contains("There was a bug in the developers application or webpieces server"));
}
use of com.webpieces.http2.api.dto.highlevel.Http2Request in project webpieces by deanhiller.
the class TestSimpleRoutes method testOneParamRoute.
@Test
public void testOneParamRoute() {
Http2Request req = RequestCreation.createHttpRequest(HttpMethod.POST, "/meeting");
MockStreamHandle mockStream = new MockStreamHandle();
StreamRef ref = server.incomingRequest(req, mockStream);
XFuture<StreamWriter> future = ref.getWriter();
Assert.assertTrue(future.isDone() && !future.isCompletedExceptionally());
Http2Response resp = mockStream.getLastResponse();
Assert.assertEquals("http://" + req.getAuthority() + "/meeting/888", resp.getSingleHeaderValue(Http2HeaderName.LOCATION));
}
use of com.webpieces.http2.api.dto.highlevel.Http2Request in project webpieces by deanhiller.
the class TestSimpleRoutes method testBasicRoute.
@Test
public void testBasicRoute() {
Http2Request req = RequestCreation.createHttpRequest(HttpMethod.GET, "/something");
MockStreamHandle mockStream = new MockStreamHandle();
StreamRef ref = server.incomingRequest(req, mockStream);
XFuture<StreamWriter> future = ref.getWriter();
Assert.assertTrue(future.isDone() && !future.isCompletedExceptionally());
Http2Response resp = mockStream.getLastResponse();
Assert.assertEquals("http://" + req.getAuthority() + "/something", resp.getSingleHeaderValue(Http2HeaderName.LOCATION));
}
Aggregations