use of com.vaadin.flow.router.Location in project flow by vaadin.
the class RouterConfigurationTest method routeMatches.
private static boolean routeMatches(String location, String route) {
RouterConfiguration configuration = createConfiguration();
configuration.setRoute(route, createNoopHandler());
Optional<NavigationHandler> resolveRoute = configuration.resolveRoute(new Location(location));
return resolveRoute.isPresent();
}
use of com.vaadin.flow.router.Location in project flow by vaadin.
the class RouterConfigurationTest method normalViewStatusCode.
@Test
public void normalViewStatusCode() {
Router router = new Router();
router.reconfigure(c -> c.setRoute("*", ParentView.class));
int statusCode = router.getConfiguration().resolveRoute(new Location("")).get().handle(new NavigationEvent(router, new Location(""), new UI(), NavigationTrigger.PROGRAMMATIC));
Assert.assertEquals(HttpServletResponse.SC_OK, statusCode);
}
use of com.vaadin.flow.router.Location in project flow by vaadin.
the class RouterConfigurationTest method customErrorViewStatusCode.
@Test
public void customErrorViewStatusCode() {
Router router = new Router();
router.reconfigure(c -> {
c.setErrorView(ParentView.class);
});
int statusCode = router.getConfiguration().getErrorHandler().handle(new NavigationEvent(router, new Location(""), new UI(), NavigationTrigger.PROGRAMMATIC));
Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, statusCode);
}
use of com.vaadin.flow.router.Location in project flow by vaadin.
the class RouterConfigurationTest method testRemoveRoutes.
@Test
public void testRemoveRoutes() {
RouterConfiguration configuration = createConfiguration();
NavigationHandler navigationHandler = createNoopHandler();
configuration.setRoute("foo", navigationHandler);
configuration.setRoute("{name}", navigationHandler);
configuration.setRoute("*", navigationHandler);
configuration.removeRoute("foo");
Assert.assertNotNull(configuration.resolveRoute(new Location("foo")));
configuration.removeRoute("{otherName}");
Assert.assertNotNull(configuration.resolveRoute(new Location("foo")));
configuration.removeRoute("*");
// Should resolve to empty optional only after removing all the routes
Assert.assertFalse(configuration.resolveRoute(new Location("foo")).isPresent());
}
use of com.vaadin.flow.router.Location in project flow by vaadin.
the class RouterConfigurationTest method testParentViewsWithoutParent.
@Test
public void testParentViewsWithoutParent() {
UI ui = new UI();
Router router = new Router();
router.reconfigure(conf -> {
conf.setRoute("route", TestView.class);
conf.setParentView(TestView.class, ParentView.class);
conf.setParentView(ParentView.class, AnotherParentView.class);
});
router.navigate(ui, new Location("route"), NavigationTrigger.PROGRAMMATIC);
Assert.assertEquals(ParentView.class, router.getConfiguration().getParentView(TestView.class).get());
Assert.assertEquals(AnotherParentView.class, router.getConfiguration().getParentView(ParentView.class).get());
Assert.assertEquals(Arrays.asList(TestView.class, ParentView.class, AnotherParentView.class), getViewChainTypes(ui));
}
Aggregations