SessionRouteRegistry extends AbstractRouteRegistry { @Override @Deprecated public List<Class<? extends RouterLayout>> getRouteLayouts(String path, Class<? extends Component> navigationTarget) { final NavigationRouteTarget navigationRouteTarget = getConfiguration() .getNavigationRouteTarget(path); if (navigationRouteTarget.hasTarget()) { return navigationRouteTarget.getRouteTarget().getParentLayouts(); } return getParentRegistry().getRouteLayouts(path, navigationTarget); } SessionRouteRegistry(VaadinSession session); static RouteRegistry getSessionRegistry(VaadinSession session); @Override List<RouteData> getRegisteredRoutes(); @Override Registration addRoutesChangeListener(
            RoutesChangedListener listener); @Override NavigationRouteTarget getNavigationRouteTarget(String url); @Override RouteTarget getRouteTarget(Class<? extends Component> target,
            RouteParameters parameters); @Override Optional<Class<? extends Component>> getNavigationTarget(
            String url); @Override Optional<Class<? extends Component>> getNavigationTarget(
            String url, List<String> segments); @Override Optional<String> getTargetUrl(
            Class<? extends Component> navigationTarget); @Override Optional<String> getTargetUrl(
            Class<? extends Component> navigationTarget,
            RouteParameters parameters); @Override Optional<String> getTemplate(
            Class<? extends Component> navigationTarget); @Override @Deprecated List<Class<? extends RouterLayout>> getRouteLayouts(String path,
            Class<? extends Component> navigationTarget);  }
@Test public void routesWithParentLayouts_parentLayoutReturnsAsExpected() { SessionRouteRegistry sessionRegistry = getRegistry(session); sessionRegistry.setRoute("MyRoute", MyRouteWithAliases.class, Collections.singletonList(MainLayout.class)); sessionRegistry.setRoute("info", MyRouteWithAliases.class, Collections.emptyList()); sessionRegistry.setRoute("version", MyRouteWithAliases.class, Arrays.asList(MiddleLayout.class, MainLayout.class)); Assert.assertFalse("'MyRoute' should have a single parent", sessionRegistry .getRouteLayouts("MyRoute", MyRouteWithAliases.class) .isEmpty()); Assert.assertTrue("'info' should have no parents.", sessionRegistry .getRouteLayouts("info", MyRouteWithAliases.class).isEmpty()); Assert.assertEquals("'version' should return two parents", 2, sessionRegistry .getRouteLayouts("version", MyRouteWithAliases.class) .size()); }
@Test public void registeredParentLayouts_changingListDoesntChangeRegistration() { SessionRouteRegistry registry = getRegistry(session); List<Class<? extends RouterLayout>> parentChain = new ArrayList<>( Arrays.asList(MiddleLayout.class, MainLayout.class)); registry.setRoute("version", MyRoute.class, parentChain); parentChain.remove(MainLayout.class); Assert.assertEquals( "'version' should return two parents even when original list is changed", 2, registry.getRouteLayouts("version", MyRoute.class).size()); }
@Test public void registeredParentLayouts_returnedListInSameOrder() { SessionRouteRegistry registry = getRegistry(session); List<Class<? extends RouterLayout>> parentChain = new ArrayList<>( Arrays.asList(MiddleLayout.class, MainLayout.class)); registry.setRoute("version", MyRoute.class, parentChain); Assert.assertArrayEquals( "Registry should return parent layouts in the same order as set.", parentChain.toArray(), registry.getRouteLayouts("version", MyRoute.class).toArray()); }