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));
}
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);
}
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);
}
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());
}
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());
}
Aggregations