RouteUtil { public static Class<? extends RouterLayout> getTopParentLayout( final Class<?> component, final String path) { if (path == null) { Optional<ParentLayout> parentLayout = AnnotationReader .getAnnotationFor(component, ParentLayout.class); if (parentLayout.isPresent()) { return recurseToTopLayout(parentLayout.get().value()); } return null; } Optional<Route> route = AnnotationReader.getAnnotationFor(component, Route.class); List<RouteAlias> routeAliases = AnnotationReader .getAnnotationsFor(component, RouteAlias.class); if (route.isPresent() && path.equals(getRoutePath(component, route.get())) && !route.get().layout().equals(UI.class)) { return recurseToTopLayout(route.get().layout()); } else { Optional<RouteAlias> matchingRoute = getMatchingRouteAlias( component, path, routeAliases); if (matchingRoute.isPresent()) { return recurseToTopLayout(matchingRoute.get().layout()); } } return null; } protected  RouteUtil(); static List<Class<? extends RouterLayout>> getParentLayouts(
            Class<?> component, String path); static String getRoutePath(Class<?> component, Route route); static String getRouteAliasPath(Class<?> component,
            RouteAlias alias); static List<Class<? extends RouterLayout>> getParentLayoutsForNonRouteTarget(
            Class<?> navigationTarget); static Class<? extends RouterLayout> getTopParentLayout(
            final Class<?> component, final String path); static String resolve(Class<?> component, Route route); static void updateRouteRegistry(RouteRegistry registry,
            Set<Class<?>> addedClasses, Set<Class<?>> modifiedClasses,
            Set<Class<?>> deletedClasses);  }
@Test public void top_parent_layout_should_be_found_for_base_route() { Class<? extends RouterLayout> parent = RouteUtil.getTopParentLayout( BaseRouteWithParentPrefixAndRouteAlias.class, "parent"); Assert.assertNotNull("Didn't find any parent for route", parent); Assert.assertEquals("Received wrong parent class.", RoutePrefixParent.class, parent); }
@Test public void top_parent_layout_should_be_found_for_non_base_route() { Class<? extends RouterLayout> parent = RouteUtil.getTopParentLayout( RouteWithParentPrefixAndRouteAlias.class, "parent/flow"); Assert.assertNotNull("Didn't find any parent for route", parent); Assert.assertEquals("Received wrong parent class.", RoutePrefixParent.class, parent); }
@Test public void no_top_parent_layout_for_route_alias() { Class<? extends RouterLayout> parent = RouteUtil.getTopParentLayout( BaseRouteWithParentPrefixAndRouteAlias.class, "alias"); Assert.assertNull("Found parent for RouteAlias without parent.", parent); }
@Test public void top_parent_layout_for_route_alias() { Class<? extends RouterLayout> parent = RouteUtil.getTopParentLayout( RouteAliasWithParentPrefix.class, "aliasparent/alias"); Assert.assertNotNull("Didn't find any parent for route", parent); Assert.assertEquals("Received wrong parent class.", RouteAliasPrefixParent.class, parent); }
@Test public void top_parent_layout_for_absolute_route() { Class<? extends RouterLayout> parent = RouteUtil .getTopParentLayout(AbsoluteRoute.class, "single"); Assert.assertNotNull("Didn't find any parent for route", parent); Assert.assertEquals("Received wrong parent class.", RoutePrefixParent.class, parent); }
@Test public void top_parent_layout_for_absolute_route_parent() { Class<? extends RouterLayout> parent = RouteUtil.getTopParentLayout( AbsoluteCenterRoute.class, "absolute/child"); Assert.assertNotNull("Didn't find any parent for route", parent); Assert.assertEquals("Received wrong parent class.", RoutePrefixParent.class, parent); }
@Test public void top_parent_layout_for_absolute_route_alias() { Class<? extends RouterLayout> parent = RouteUtil .getTopParentLayout(AbsoluteRoute.class, "alias"); Assert.assertNotNull("Didn't find any parent for route", parent); Assert.assertEquals("Received wrong parent class.", RoutePrefixParent.class, parent); }
@Test public void top_parent_layout_for_absolute_route_alias_parent() { Class<? extends RouterLayout> parent = RouteUtil.getTopParentLayout( AbsoluteCenterRoute.class, "absolute/alias"); Assert.assertNotNull("Didn't find any parent for route", parent); Assert.assertEquals("Received wrong parent class.", RoutePrefixParent.class, parent); }
@Test public void also_non_routes_can_be_used_to_get_top_parent_layout() { Class<? extends RouterLayout> topParentLayout = RouteUtil .getTopParentLayout(MiddleParent.class, null); Assert.assertEquals( "Middle parent should have gotten Parent as top parent layout", Parent.class, topParentLayout); }
@Test public void top_layout_resolves_correctly_for_route_parent() { Class<? extends RouterLayout> topParentLayout = RouteUtil .getTopParentLayout(MultiTarget.class, ""); Assert.assertEquals( "@Route path should have gotten Parent as top parent layout", Parent.class, topParentLayout); topParentLayout = RouteUtil.getTopParentLayout(MultiTarget.class, "alias"); Assert.assertEquals( "@RouteAlias path should have gotten Parent as top parent layout", Parent.class, topParentLayout); topParentLayout = RouteUtil.getTopParentLayout(SubLayout.class, "parent/sub"); Assert.assertEquals( "SubLayout using MultiTarget as parent should have gotten RoutePrefixParent as top parent layout", RoutePrefixParent.class, topParentLayout); }