Search in sources :

Example 36 with Http2Request

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());
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) Test(org.junit.Test)

Example 37 with Http2Request

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());
}
Also used : RouterService(org.webpieces.router.api.RouterService) Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) StreamRef(com.webpieces.http2.api.streaming.StreamRef) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) Test(org.junit.Test)

Example 38 with Http2Request

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"));
}
Also used : RouterService(org.webpieces.router.api.RouterService) Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) StreamRef(com.webpieces.http2.api.streaming.StreamRef) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) MockStreamHandle(org.webpieces.router.api.error.MockStreamHandle) Test(org.junit.Test) ErrorCommonTest(org.webpieces.router.api.error.ErrorCommonTest)

Example 39 with Http2Request

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));
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) StreamRef(com.webpieces.http2.api.streaming.StreamRef) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) MockStreamHandle(org.webpieces.router.api.error.MockStreamHandle) Test(org.junit.Test)

Example 40 with Http2Request

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));
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) StreamRef(com.webpieces.http2.api.streaming.StreamRef) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) MockStreamHandle(org.webpieces.router.api.error.MockStreamHandle) Test(org.junit.Test)

Aggregations

Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)71 Test (org.junit.Test)39 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)36 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)36 Http2Header (com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)33 StreamRef (com.webpieces.http2.api.streaming.StreamRef)32 DataWrapper (org.webpieces.data.api.DataWrapper)18 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)14 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)14 XFuture (org.webpieces.util.futures.XFuture)13 RequestStreamHandle (com.webpieces.http2.api.streaming.RequestStreamHandle)11 GoAwayFrame (com.webpieces.http2.api.dto.lowlevel.GoAwayFrame)10 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)10 CancelReason (com.webpieces.http2.api.dto.lowlevel.CancelReason)9 Http2Msg (com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)9 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)9 InetSocketAddress (java.net.InetSocketAddress)8 Http2Push (com.webpieces.http2.api.dto.highlevel.Http2Push)7 MockStreamWriter (org.webpieces.httpfrontend2.api.mock2.MockStreamWriter)7 Http2HeaderName (com.webpieces.http2.api.dto.lowlevel.lib.Http2HeaderName)6