@Test public void testDefaultIndex() { TemplateEngine templateEngine = mock(TemplateEngine.class); RoutingContext routingContext = mock(RoutingContext.class); when(routingContext.normalisedPath()).thenReturn("/"); Route currentRoute = mock(Route.class); when(currentRoute.getPath()).thenReturn("/"); when(routingContext.currentRoute()).thenReturn(currentRoute); TemplateHandler templateHandler = new TemplateHandlerImpl(templateEngine, "templates", "ext"); templateHandler.handle(routingContext); verify(templateEngine).render(any(JsonObject.class), eq("templates/index"), any()); }
@Test public void testSimpleTemplate() { TemplateEngine templateEngine = mock(TemplateEngine.class); RoutingContext routingContext = mock(RoutingContext.class); when(routingContext.normalisedPath()).thenReturn("/about"); Route currentRoute = mock(Route.class); when(currentRoute.getPath()).thenReturn("/"); when(routingContext.currentRoute()).thenReturn(currentRoute); TemplateHandler templateHandler = new TemplateHandlerImpl(templateEngine, "templates", "ext"); templateHandler.handle(routingContext); verify(templateEngine).render(any(JsonObject.class), eq("templates/about"), any()); }
@Test public void testSetIndex() { TemplateEngine templateEngine = mock(TemplateEngine.class); RoutingContext routingContext = mock(RoutingContext.class); when(routingContext.normalisedPath()).thenReturn("/"); Route currentRoute = mock(Route.class); when(currentRoute.getPath()).thenReturn("/"); when(routingContext.currentRoute()).thenReturn(currentRoute); TemplateHandler templateHandler = new TemplateHandlerImpl(templateEngine, "templates", "ext"); templateHandler.setIndexTemplate("home"); templateHandler.handle(routingContext); verify(templateEngine).render(any(JsonObject.class), eq("templates/home"), any()); }
@Test public void testTurnOffIndex() { TemplateEngine templateEngine = mock(TemplateEngine.class); RoutingContext routingContext = mock(RoutingContext.class); when(routingContext.normalisedPath()).thenReturn("/"); Route currentRoute = mock(Route.class); when(currentRoute.getPath()).thenReturn("/"); when(routingContext.currentRoute()).thenReturn(currentRoute); TemplateHandler templateHandler = new TemplateHandlerImpl(templateEngine, "templates", "ext"); templateHandler.setIndexTemplate(null); templateHandler.handle(routingContext); verify(templateEngine).render(any(JsonObject.class), eq("templates/"), any()); }
/** * Something has happened, so handle it. * @param event the event to handle */ public void handle(io.vertx.rxjava.ext.web.RoutingContext event) { delegate.handle(event.getDelegate()); }
/** * Something has happened, so handle it. * @param event the event to handle */ public void handle(io.vertx.rxjava.ext.web.RoutingContext event) { delegate.handle(event.getDelegate()); }
@Test public void testDefaultIndex() { TemplateEngine templateEngine = mock(TemplateEngine.class); RoutingContext routingContext = mock(RoutingContext.class); when(routingContext.normalisedPath()).thenReturn("/"); Route currentRoute = mock(Route.class); when(currentRoute.getPath()).thenReturn("/"); when(routingContext.currentRoute()).thenReturn(currentRoute); TemplateHandler templateHandler = new TemplateHandlerImpl(templateEngine, "templates", "ext"); templateHandler.handle(routingContext); verify(templateEngine).render(any(JsonObject.class), eq("templates/index"), any()); }
@Override public void handle(RoutingContext event) { String path = event.request().path(); LOGGER.info("handling template for url " + event.normalisedPath() + " | " + path); if (path.endsWith("/")) { LOGGER.info("REROUTING TO: " + path); path += "index.html"; event.reroute(path); } else { templateHandler.handle(event); } }
@Test public void testSimpleTemplate() { TemplateEngine templateEngine = mock(TemplateEngine.class); RoutingContext routingContext = mock(RoutingContext.class); when(routingContext.normalisedPath()).thenReturn("/about"); Route currentRoute = mock(Route.class); when(currentRoute.getPath()).thenReturn("/"); when(routingContext.currentRoute()).thenReturn(currentRoute); TemplateHandler templateHandler = new TemplateHandlerImpl(templateEngine, "templates", "ext"); templateHandler.handle(routingContext); verify(templateEngine).render(any(JsonObject.class), eq("templates/about"), any()); }
@Test public void testSetIndex() { TemplateEngine templateEngine = mock(TemplateEngine.class); RoutingContext routingContext = mock(RoutingContext.class); when(routingContext.normalisedPath()).thenReturn("/"); Route currentRoute = mock(Route.class); when(currentRoute.getPath()).thenReturn("/"); when(routingContext.currentRoute()).thenReturn(currentRoute); TemplateHandler templateHandler = new TemplateHandlerImpl(templateEngine, "templates", "ext"); templateHandler.setIndexTemplate("home"); templateHandler.handle(routingContext); verify(templateEngine).render(any(JsonObject.class), eq("templates/home"), any()); }
@Test public void testTurnOffIndex() { TemplateEngine templateEngine = mock(TemplateEngine.class); RoutingContext routingContext = mock(RoutingContext.class); when(routingContext.normalisedPath()).thenReturn("/"); Route currentRoute = mock(Route.class); when(currentRoute.getPath()).thenReturn("/"); when(routingContext.currentRoute()).thenReturn(currentRoute); TemplateHandler templateHandler = new TemplateHandlerImpl(templateEngine, "templates", "ext"); templateHandler.setIndexTemplate(null); templateHandler.handle(routingContext); verify(templateEngine).render(any(JsonObject.class), eq("templates/"), any()); }