Search in sources :

Example 1 with AbstractReactorHandler

use of io.gravitee.gateway.reactor.handler.AbstractReactorHandler in project gravitee-gateway by gravitee-io.

the class ReactorTest method processRequest_startedApi.

@Test
public void processRequest_startedApi() throws Exception {
    Request request = mock(Request.class);
    when(request.method()).thenReturn(HttpMethod.GET);
    when(request.headers()).thenReturn(new HttpHeaders());
    when(request.headers()).thenReturn(new HttpHeaders());
    when(request.path()).thenReturn("/team");
    when(request.metrics()).thenReturn(Metrics.on(System.currentTimeMillis()).build());
    when(handlerResolver.resolve(any(Request.class))).thenReturn(new AbstractReactorHandler() {

        @Override
        public Reactable reactable() {
            return new Reactable() {

                @Override
                public Object item() {
                    return null;
                }

                @Override
                public String contextPath() {
                    return "";
                }

                @Override
                public boolean enabled() {
                    return true;
                }

                @Override
                public Set dependencies(Class type) {
                    return null;
                }

                @Override
                public Map<String, Object> properties() {
                    return null;
                }
            };
        }

        @Override
        protected void doHandle(Request request, Response response, Handler<Response> handler) {
            Response proxyResponse = mock(Response.class);
            when(proxyResponse.headers()).thenReturn(new HttpHeaders());
            when(proxyResponse.status()).thenReturn(HttpStatusCode.OK_200);
            handler.handle(proxyResponse);
        }
    });
    final CountDownLatch lock = new CountDownLatch(1);
    Response proxyResponse = mock(Response.class);
    when(proxyResponse.headers()).thenReturn(new HttpHeaders());
    reactor.route(request, proxyResponse, response -> {
        Assert.assertEquals(HttpStatusCode.OK_200, response.status());
        lock.countDown();
    });
    Assert.assertEquals(true, lock.await(10000, TimeUnit.MILLISECONDS));
}
Also used : HttpHeaders(io.gravitee.common.http.HttpHeaders) Set(java.util.Set) AbstractReactorHandler(io.gravitee.gateway.reactor.handler.AbstractReactorHandler) Request(io.gravitee.gateway.api.Request) CountDownLatch(java.util.concurrent.CountDownLatch) Response(io.gravitee.gateway.api.Response) Map(java.util.Map) Test(org.junit.Test)

Aggregations

HttpHeaders (io.gravitee.common.http.HttpHeaders)1 Request (io.gravitee.gateway.api.Request)1 Response (io.gravitee.gateway.api.Response)1 AbstractReactorHandler (io.gravitee.gateway.reactor.handler.AbstractReactorHandler)1 Map (java.util.Map)1 Set (java.util.Set)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1