use of com.webpieces.http2.api.dto.highlevel.Http2Response in project webpieces by deanhiller.
the class TestSBasicRequestResponse method testPushPromise.
@Test
public void testPushPromise() throws InterruptedException, ExecutionException, TimeoutException {
Http2Request request1 = Http2Requests.createRequest(1, true);
mockChannel.send(request1);
PassedIn incoming = mockListener.getSingleRequest();
Assert.assertEquals(request1, incoming.request);
Http2Push push = Http2Requests.createPush(request1.getStreamId());
XFuture<PushPromiseListener> future = incoming.stream.openPushStream().process(push);
PushPromiseListener pushWriter = future.get(2, TimeUnit.SECONDS);
Http2Push pushRecv = (Http2Push) mockChannel.getFrameAndClear();
Assert.assertEquals(push, pushRecv);
Http2Response preEmptive = Http2Requests.createResponse(push.getPromisedStreamId());
pushWriter.processPushResponse(preEmptive);
Http2Headers preEmptRecv = (Http2Headers) mockChannel.getFrameAndClear();
Assert.assertEquals(preEmptive, preEmptRecv);
Http2Response response = Http2Requests.createResponse(request1.getStreamId());
incoming.stream.process(response);
Http2Headers responseRecv = (Http2Headers) mockChannel.getFrameAndClear();
Assert.assertEquals(response, responseRecv);
}
use of com.webpieces.http2.api.dto.highlevel.Http2Response in project webpieces by deanhiller.
the class ErrorCommonTest method testArgsTypeMismatch.
@Test
public void testArgsTypeMismatch() {
log.info("starting");
String moduleFileContents = CommonRoutesModules.class.getName();
RouterService server = createServer(isProdTest, moduleFileContents);
server.start();
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 response = mockStream.getLastResponse();
String contents = mockStream.getResponseBody();
verifyNotFoundRendered(response, contents);
// We did not send a keep alive so it should close
Assert.assertTrue(mockStream.isWasClosed());
}
use of com.webpieces.http2.api.dto.highlevel.Http2Response in project webpieces by deanhiller.
the class ErrorCommonTest method testRedirectRouteNotEnoughArguments.
@Test
public void testRedirectRouteNotEnoughArguments() {
// 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");
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) {
// prod template to use
Assert.assertTrue(contents.contains("There was a bug in the developers application or webpieces server"));
} else {
// The internalError template for DevServer should run...
Assert.assertTrue(contents.contains("NullTemplateApi.java is running for templatePath=org.webpieces.devrouter.impl.internalError_html"));
}
// We did not send a keep alive so it should close
Assert.assertTrue(mockStream.isWasClosed());
}
use of com.webpieces.http2.api.dto.highlevel.Http2Response in project webpieces by deanhiller.
the class ErrorCommonTest method testGetNotMatchPostRoute.
@Test
public void testGetNotMatchPostRoute() {
log.info("starting");
String moduleFileContents = CommonRoutesModules.class.getName();
RouterService server = createServer(isProdTest, moduleFileContents);
server.start();
Http2Request req = RequestCreation.createHttpRequest(HttpMethod.GET, "/postroute");
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();
verifyNotFoundRendered(response, contents);
// We did not send a keep alive so it should close
Assert.assertTrue(mockStream.isWasClosed());
}
use of com.webpieces.http2.api.dto.highlevel.Http2Response in project webpieces by deanhiller.
the class TestProdRouter method testAsyncRouteAndMocking.
/**
* This test won't work in DevRoute right now as we need to do the following
* 1. create CompileOnDemand very early on
* 2. do a Thread.current().setContextClassLoader(compileOnDemand.getLatestClassloader())
*
* and this all needs to be done BEFORE TestModule is created and more importantly before
* the bind(SomeService.class) as SomeService will be loaded from one classloader and then
* when DEVrouter creates the controller, the compileOnDemand classloader is used resulting
* in a mismatch.
*/
@Test
public void testAsyncRouteAndMocking() {
Http2Request req = RequestCreation.createHttpRequest(HttpMethod.GET, "/async");
// setup returning a response
XFuture<Integer> future1 = new XFuture<Integer>();
overrides.mockService.addToReturn(future1);
MockStreamHandle mockStream = new MockStreamHandle();
StreamRef ref = server.incomingRequest(req, mockStream);
XFuture<StreamWriter> future = ref.getWriter();
Assert.assertFalse(future.isDone());
// no response yet...
Assert.assertNull(mockStream.getLastResponse());
// release controlleer
int id = 78888;
future1.complete(id);
Assert.assertTrue(future.isDone() && !future.isCompletedExceptionally());
Http2Response resp = mockStream.getLastResponse();
Assert.assertNull(resp.getSingleHeaderValue(Http2HeaderName.AUTHORITY));
Assert.assertEquals("http://" + req.getAuthority() + "/meeting/" + id, resp.getSingleHeaderValue(Http2HeaderName.LOCATION));
// We did not send a keep alive so it should close
Assert.assertTrue(mockStream.isWasClosed());
}
Aggregations