use of com.vaadin.flow.router.Location in project flow by vaadin.
the class RouterConfigurationTest method defaultErrorHandlerStatusCode.
@Test
public void defaultErrorHandlerStatusCode() {
Router router = new Router();
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 assertRoutePriority.
private static void assertRoutePriority(String location, String strongerRoute, String weakerRoute) {
// First verify that the test makes sense
assertMatches(location, strongerRoute);
assertMatches(location, weakerRoute);
NavigationHandler weakerHandler = createNoopHandler();
NavigationHandler strongerHandler = createNoopHandler();
RouterConfiguration configuration = createConfiguration();
configuration.setRoute(strongerRoute, strongerHandler);
configuration.setRoute(weakerRoute, weakerHandler);
Optional<NavigationHandler> handler = configuration.resolveRoute(new Location(location));
Assert.assertSame(handler.get(), strongerHandler);
// Do the same again with setRoute run in the opposite order
configuration = createConfiguration();
configuration.setRoute(weakerRoute, weakerHandler);
configuration.setRoute(strongerRoute, strongerHandler);
handler = configuration.resolveRoute(new Location(location));
Assert.assertSame(handler.get(), strongerHandler);
}
use of com.vaadin.flow.router.Location in project flow by vaadin.
the class RouterTest method testNavigateWithToggledSlash.
@Test
public void testNavigateWithToggledSlash() {
UI ui = new RouterTestUI();
Router router = new Router();
router.reconfigure(c -> {
c.setRoute("foo/{name}", TestView.class);
c.setRoute("bar/*", TestView.class);
});
router.navigate(ui, new Location("foo/bar/"), NavigationTrigger.PROGRAMMATIC);
Assert.assertEquals("foo/bar", ui.getInternals().getActiveViewLocation().getPath());
router.navigate(ui, new Location("bar"), NavigationTrigger.PROGRAMMATIC);
Assert.assertEquals("bar/", ui.getInternals().getActiveViewLocation().getPath());
}
use of com.vaadin.flow.router.Location in project flow by vaadin.
the class RouterTest method testSetRouteIfNoResolverHandler.
@Test
public void testSetRouteIfNoResolverHandler() {
Router router = new Router();
AtomicReference<String> usedHandler = new AtomicReference<>();
router.reconfigure(configuration -> {
configuration.setResolver(resolveEvent -> Optional.empty());
configuration.setRoute("*", e -> {
usedHandler.set("route");
return HttpServletResponse.SC_OK;
});
});
router.navigate(new RouterTestUI(), new Location(""), NavigationTrigger.PROGRAMMATIC);
Assert.assertEquals("route", usedHandler.get());
}
use of com.vaadin.flow.router.Location in project flow by vaadin.
the class RouterTest method testResolve.
@Test
public void testResolve() {
UI ui = new RouterTestUI();
Router router = new Router();
TestResolver resolver = new TestResolver();
router.reconfigure(c -> c.setResolver(resolver));
Assert.assertNull(resolver.resolvedLocation.get());
Assert.assertNull(resolver.handledEvent.get());
Location testLocation = new Location("");
router.navigate(ui, testLocation, NavigationTrigger.PROGRAMMATIC);
Assert.assertSame(testLocation, resolver.resolvedLocation.get());
Assert.assertSame(testLocation, resolver.handledEvent.get().getLocation());
Assert.assertSame(ui, resolver.handledEvent.get().getUI());
}
Aggregations