Search in sources :

Example 41 with Request

use of io.gravitee.gateway.api.Request 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)

Example 42 with Request

use of io.gravitee.gateway.api.Request in project gravitee-gateway by gravitee-io.

the class ReactorHandlerResolverTest method test_multipleContextPath_unknownRequestPath2.

@Test
public void test_multipleContextPath_unknownRequestPath2() {
    Collection<ReactorHandler> handlers = new ArrayList<>(new ArrayList<ReactorHandler>() {

        {
            add(createMockHandler("/teams"));
            add(createMockHandler("/teams2"));
        }
    });
    when(handlerRegistry.getReactorHandlers()).thenReturn(handlers);
    Request request = Mockito.mock(Request.class);
    when(request.path()).thenReturn("/teamss");
    ReactorHandler handler = handlerResolver.resolve(request);
    Assert.assertNull(handler);
}
Also used : ArrayList(java.util.ArrayList) Request(io.gravitee.gateway.api.Request) Test(org.junit.Test)

Example 43 with Request

use of io.gravitee.gateway.api.Request in project gravitee-gateway by gravitee-io.

the class ReactorHandlerResolverTest method test_multipleContextPath_unknownRequestPath.

@Test
public void test_multipleContextPath_unknownRequestPath() {
    Collection<ReactorHandler> handlers = new ArrayList<>(new ArrayList<ReactorHandler>() {

        {
            add(createMockHandler("/teams"));
            add(createMockHandler("/teams2"));
        }
    });
    when(handlerRegistry.getReactorHandlers()).thenReturn(handlers);
    Request request = Mockito.mock(Request.class);
    when(request.path()).thenReturn("/team");
    ReactorHandler handler = handlerResolver.resolve(request);
    Assert.assertNull(handler);
}
Also used : ArrayList(java.util.ArrayList) Request(io.gravitee.gateway.api.Request) Test(org.junit.Test)

Example 44 with Request

use of io.gravitee.gateway.api.Request in project gravitee-gateway by gravitee-io.

the class ReactorHandlerResolverTest method test_multipleContextPath_extraSeparatorRequestPath.

@Test
public void test_multipleContextPath_extraSeparatorRequestPath() {
    Collection<ReactorHandler> handlers = new ArrayList<>(new ArrayList<ReactorHandler>() {

        {
            add(createMockHandler("/teams2"));
            add(createMockHandler("/teams"));
        }
    });
    when(handlerRegistry.getReactorHandlers()).thenReturn(handlers);
    Request request = Mockito.mock(Request.class);
    when(request.path()).thenReturn("/teams/");
    ReactorHandler handler = handlerResolver.resolve(request);
    Assert.assertEquals("/teams/", handler.contextPath());
}
Also used : ArrayList(java.util.ArrayList) Request(io.gravitee.gateway.api.Request) Test(org.junit.Test)

Example 45 with Request

use of io.gravitee.gateway.api.Request in project gravitee-gateway by gravitee-io.

the class ReactorHandlerResolverTest method test_multipleContextPath_validRequestPath.

@Test
public void test_multipleContextPath_validRequestPath() {
    Collection<ReactorHandler> handlers = new ArrayList<>(new ArrayList<ReactorHandler>() {

        {
            add(createMockHandler("/teams"));
            add(createMockHandler("/teams2"));
        }
    });
    when(handlerRegistry.getReactorHandlers()).thenReturn(handlers);
    Request request = Mockito.mock(Request.class);
    when(request.path()).thenReturn("/teams");
    ReactorHandler handler = handlerResolver.resolve(request);
    Assert.assertEquals("/teams/", handler.contextPath());
}
Also used : ArrayList(java.util.ArrayList) Request(io.gravitee.gateway.api.Request) Test(org.junit.Test)

Aggregations

Request (io.gravitee.gateway.api.Request)51 Test (org.junit.Test)42 HttpHeaders (io.gravitee.common.http.HttpHeaders)24 Response (io.gravitee.gateway.api.Response)21 ExecutionContext (io.gravitee.gateway.api.ExecutionContext)16 PolicyChain (io.gravitee.policy.api.PolicyChain)11 ArrayList (java.util.ArrayList)8 SubscriptionRepository (io.gravitee.repository.management.api.SubscriptionRepository)7 SubscriptionCriteria (io.gravitee.repository.management.api.search.SubscriptionCriteria)7 Metrics (io.gravitee.reporter.api.http.Metrics)6 Before (org.junit.Before)6 Subscription (io.gravitee.repository.management.model.Subscription)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 UUID (io.gravitee.common.utils.UUID)4 Handler (io.gravitee.gateway.api.handler.Handler)4 TimeUnit (java.util.concurrent.TimeUnit)4 Assert.assertEquals (org.junit.Assert.assertEquals)4 Assert.assertNotNull (org.junit.Assert.assertNotNull)4 Mock (org.mockito.Mock)4 Mockito.when (org.mockito.Mockito.when)4