RouteRegistryInitializer extends AbstractRouteRegistryInitializer implements ClassLoaderAwareServletContainerInitializer { @Override public void process(Set<Class<?>> classSet, ServletContext servletContext) throws ServletException { VaadinServletContext context = new VaadinServletContext(servletContext); try { if (classSet == null) { ApplicationRouteRegistry routeRegistry = ApplicationRouteRegistry .getInstance(context); routeRegistry.clean(); return; } Set<Class<? extends Component>> routes = validateRouteClasses( classSet.stream()); ApplicationRouteRegistry routeRegistry = ApplicationRouteRegistry .getInstance(context); RouteConfiguration routeConfiguration = RouteConfiguration .forRegistry(routeRegistry); routeConfiguration.update( () -> setAnnotatedRoutes(routeConfiguration, routes)); routeRegistry.setPwaConfigurationClass(validatePwaClass( routes.stream().map(clazz -> (Class<?>) clazz))); } catch (InvalidRouteConfigurationException irce) { throw new ServletException( "Exception while registering Routes on servlet startup", irce); } }  @Override void process(Set<Class<?>> classSet, ServletContext servletContext);  }
@Test(expected = ServletException.class) public void registerClassesWithSameRoute_unrelatedClass_class_throws() throws ServletException { LinkedHashSet<Class<?>> classes = new LinkedHashSet<>(); classes.add(OtherRouteTarget.class); classes.add(BaseRouteTarget.class); routeRegistryInitializer.process(classes, servletContext); }
@Test public void process() throws ServletException { routeRegistryInitializer.process( Stream.of(NavigationTarget.class, NavigationTargetFoo.class, NavigationTargetBar.class).collect(Collectors.toSet()), servletContext); Assert.assertEquals("Route '' registered to NavigationTarget.class", NavigationTarget.class, registry.getNavigationTarget("").get()); Assert.assertEquals( "Route 'foo' registered to NavigationTargetFoo.class", NavigationTargetFoo.class, registry.getNavigationTarget("foo").get()); Assert.assertEquals( "Route 'bar' registered to NavigationTargetBar.class", NavigationTargetBar.class, registry.getNavigationTarget("bar").get()); }
@Test public void process_no_exception_with_null_arguments() { try { routeRegistryInitializer.process(null, servletContext); } catch (Exception e) { Assert.fail( "RouteRegistryInitializer.process should not throw with null arguments"); } }
@Test(expected = ServletException.class) public void process_duplicate_routes_throws() throws ServletException { routeRegistryInitializer.process( Stream.of(NavigationTargetFoo.class, NavigationTargetFoo2.class) .collect(Collectors.toSet()), servletContext); }
@Test(expected = ServletException.class) public void process_duplicate_routesViaAlias_throws() throws ServletException { routeRegistryInitializer.process( Stream.of(NavigationTargetBar.class, NavigationTargetBar2.class) .collect(Collectors.toSet()), servletContext); }
@Test public void routeRegistry_registers_correctly_route_with_parentLayout() throws ServletException { routeRegistryInitializer.process(Stream .of(NavigationTarget.class, NavigationTargetFoo.class, MiddleParentWithRoute.class) .collect(Collectors.toSet()), servletContext); Optional<Class<? extends Component>> navigationTarget = registry .getNavigationTarget("middle_parent"); Assert.assertTrue("Couldn't find navigation target for `middle_parent`", navigationTarget.isPresent()); }
@Test(expected = InvalidRouteLayoutConfigurationException.class) public void routeRegistry_fails_on_aloneRouteAlias() throws ServletException { routeRegistryInitializer.process( Stream.of(NavigationTarget.class, NavigationTargetFoo.class, RouteAliasAlone.class).collect(Collectors.toSet()), servletContext); }
@Test public void routeRegistry_stores_whole_path_with_parent_route_prefix() throws ServletException { routeRegistryInitializer.process( Stream.of(ExtendingPrefix.class).collect(Collectors.toSet()), servletContext); Optional<Class<? extends Component>> navigationTarget = registry .getNavigationTarget("parent/prefix"); Assert.assertTrue("Couldn't find navigation target for `parent/prefix`", navigationTarget.isPresent()); Assert.assertEquals( "Route 'parent/prefix' was not registered to ExtendingPrefix.class", ExtendingPrefix.class, navigationTarget.get()); }
@Test public void routeRegistry_route_with_absolute_ignores_parent_route_prefix() throws ServletException { routeRegistryInitializer.process( Stream.of(AbsoluteRoute.class).collect(Collectors.toSet()), servletContext); Optional<Class<? extends Component>> navigationTarget = registry .getNavigationTarget("absolute"); Assert.assertTrue("Could not find navigation target for `absolute`", navigationTarget.isPresent()); Assert.assertEquals("Route 'absolute' was not registered correctly", AbsoluteRoute.class, navigationTarget.get()); }
@Test public void routeRegistry_route_with_absolute_parent_prefix_ignores_remaining_parent_route_prefixes() throws ServletException { routeRegistryInitializer.process( Stream.of(MultiLevelRoute.class).collect(Collectors.toSet()), servletContext); assertRouteTarget(MultiLevelRoute.class, "absolute/levels", "Route 'absolute' was not registered correctly"); }
@Test public void routeRegistry_routeWithAlias_parentRoutePrefix() throws ServletException { routeRegistryInitializer.process(Stream.of(MultiLevelRouteAlias.class) .collect(Collectors.toSet()), servletContext); assertRouteTarget(MultiLevelRouteAlias.class, "absolute/levels", "Route 'absolute' was not registered correctly"); Optional<String> url = registry .getTargetUrl(MultiLevelRouteAlias.class); Assert.assertTrue(url.isPresent()); Assert.assertEquals("absolute/levels", url.get()); assertRouteTarget(MultiLevelRouteAlias.class, "parent/alias1", "RouteAlias 'alias1' was not registered correctly"); }
@Test public void routeRegistry_routeWithAlias_parent_prefix_ignores_remaining_parent_route_prefixes() throws ServletException { routeRegistryInitializer.process(Stream.of(MultiLevelRouteAlias.class) .collect(Collectors.toSet()), servletContext); assertRouteTarget(MultiLevelRouteAlias.class, "absolute/alias2", "RouteAlias 'alias2' was not registered correctly"); }
@Test public void routeRegistry_routeWithAlias_absoluteRoute() throws ServletException { routeRegistryInitializer.process(Stream.of(MultiLevelRouteAlias.class) .collect(Collectors.toSet()), servletContext); assertRouteTarget(MultiLevelRouteAlias.class, "alias3", "RouteAlias 'alias3' was not registered correctly"); }
@Test public void routeRegistry_routeWithAlias_noParent() throws ServletException { routeRegistryInitializer.process(Stream.of(MultiLevelRouteAlias.class) .collect(Collectors.toSet()), servletContext); assertRouteTarget(MultiLevelRouteAlias.class, "alias4", "RouteAlias 'alias4' was not registered correctly"); }
@Test public void routeRegistry_routeWithAlias_twoParentLevels() throws ServletException { routeRegistryInitializer.process(Stream.of(MultiLevelRouteAlias.class) .collect(Collectors.toSet()), servletContext); assertRouteTarget(MultiLevelRouteAlias.class, "parent/middle/alias5", "RouteAlias 'alias5' was not registered correctly"); }
@Test public void routeRegistry_route_returns_registered_string_for_get_url() throws ServletException { routeRegistryInitializer.process(Stream .of(NavigationTarget.class, NavigationTargetFoo.class, AbsoluteRoute.class, ExtendingPrefix.class) .collect(Collectors.toSet()), servletContext); Assert.assertEquals("", registry.getTargetUrl(NavigationTarget.class).get()); Assert.assertEquals("foo", registry.getTargetUrl(NavigationTargetFoo.class).get()); Assert.assertEquals("absolute", registry.getTargetUrl(AbsoluteRoute.class).get()); Assert.assertEquals("parent/prefix", registry.getTargetUrl(ExtendingPrefix.class).get()); }
@Test public void routeRegistry_routes_with_parameters_return_parameter_type_for_target_url() throws ServletException { routeRegistryInitializer.process( Stream.of(ParameterRoute.class, StringParameterRoute.class) .collect(Collectors.toSet()), servletContext); Assert.assertEquals( String.format("parameter/:%s(%s)", HasUrlParameterFormat.PARAMETER_NAME, RouteParameterRegex.INTEGER), registry.getTemplate(ParameterRoute.class).get()); Assert.assertEquals( String.format("string/:%s", HasUrlParameterFormat.PARAMETER_NAME), registry.getTemplate(StringParameterRoute.class).get()); }
@Test public void routeRegistry_route_returns_string_not_ending_in_dash() throws ServletException { routeRegistryInitializer.process(Stream .of(NavigationRootWithParent.class).collect(Collectors.toSet()), servletContext); Assert.assertEquals( "The root target for a parent layout should not end with '/'", "parent", registry.getTargetUrl(NavigationRootWithParent.class).get()); }
@Test public void registration_fails_for_navigation_target_with_duplicate_title() throws ServletException { expectedEx.expect(DuplicateNavigationTitleException.class); expectedEx.expectMessage(String.format( "'%s' has a PageTitle annotation, but also implements HasDynamicTitle.", FaultyNavigationTargetWithTitle.class.getName())); routeRegistryInitializer.process( Collections.singleton(FaultyNavigationTargetWithTitle.class), servletContext); }
@Test public void registration_fails_for_navigation_target_with_inherited_dynamic_title() throws ServletException { expectedEx.expect(DuplicateNavigationTitleException.class); expectedEx.expectMessage(String.format( "'%s' has a PageTitle annotation, but also implements HasDynamicTitle.", FaultyChildWithDuplicateTitle.class.getName())); routeRegistryInitializer.process( Collections.singleton(FaultyChildWithDuplicateTitle.class), servletContext); }
@Test public void registration_succeeds_for_navigation_target_with_inherited_title_annotation() throws ServletException { routeRegistryInitializer.process( Collections.singleton(ChildWithDynamicTitle.class), servletContext); Assert.assertEquals("bar", registry.getTargetUrl(ChildWithDynamicTitle.class).get()); }
@Test public void process_wrong_position_view_layout_throws() throws ServletException { expectedEx.expect(InvalidRouteLayoutConfigurationException.class); expectedEx.expectMessage(String.format( "Viewport annotation should be on the top most route layout '%s'. Offending class: '%s'", Parent.class.getName(), MiddleParentLayout.class.getName())); routeRegistryInitializer.process( Stream.of(RootWithParents.class).collect(Collectors.toSet()), servletContext); }
@Test public void process_check_only_one_viewport_in_route_chain() throws ServletException { expectedEx.expect(InvalidRouteLayoutConfigurationException.class); expectedEx.expectMessage( "Only one Viewport annotation is supported for navigation chain and should be on the top most level. Offending classes in chain: " + MultiMiddleParentLayout.class.getName() + ", " + MiddleParentLayout.class.getName()); routeRegistryInitializer.process( Stream.of(MultiViewport.class).collect(Collectors.toSet()), servletContext); }
@Test public void process_route_can_not_contain_viewport_if_has_parent() throws ServletException { expectedEx.expect(InvalidRouteLayoutConfigurationException.class); expectedEx.expectMessage(String.format( "Viewport annotation needs to be on the top parent layout '%s' not on '%s'", Parent.class.getName(), RootViewportWithParent.class.getName())); routeRegistryInitializer.process(Stream.of(RootViewportWithParent.class) .collect(Collectors.toSet()), servletContext); }
@Test public void process_one_viewport_in_chain_and_one_for_route_passes() throws ServletException { routeRegistryInitializer.process( Stream.of(SingleNavigationTarget.class, RootWithParent.class) .collect(Collectors.toSet()), servletContext); }
@Test public void process_check_also_faulty_alias_route() throws ServletException { expectedEx.expect(InvalidRouteLayoutConfigurationException.class); expectedEx.expectMessage(String.format( "Viewport annotation needs to be on the top parent layout '%s' not on '%s'", Parent.class.getName(), FailingAliasView.class.getName())); routeRegistryInitializer.process( Stream.of(FailingAliasView.class).collect(Collectors.toSet()), servletContext); }
@Test public void process_valid_alias_does_not_throw() throws ServletException { routeRegistryInitializer.process( Stream.of(AliasView.class).collect(Collectors.toSet()), servletContext); }
@Test public void process_wrong_position_body_size_view_layout_throws() throws ServletException { expectedEx.expect(InvalidRouteLayoutConfigurationException.class); expectedEx.expectMessage(String.format( "BodySize annotation should be on the top most route layout '%s'. Offending class: '%s'", BodyParent.class.getName(), BodyMiddleParentLayout.class.getName())); routeRegistryInitializer.process(Stream.of(BodyRootWithParents.class) .collect(Collectors.toSet()), servletContext); }
@Test public void process_check_only_one_body_size_in_route_chain() throws ServletException { expectedEx.expect(InvalidRouteLayoutConfigurationException.class); expectedEx.expectMessage( "Only one BodySize annotation is supported for navigation chain and should be on the top most level. Offending classes in chain: " + BodyMultiMiddleParentLayout.class.getName() + ", " + BodyMiddleParentLayout.class.getName()); routeRegistryInitializer.process( Stream.of(BodyMultiViewport.class).collect(Collectors.toSet()), servletContext); }
@Test public void process_route_can_not_contain_body_size_if_has_parent() throws ServletException { expectedEx.expect(InvalidRouteLayoutConfigurationException.class); expectedEx.expectMessage(String.format( "BodySize annotation needs to be on the top parent layout '%s' not on '%s'", BodyParent.class.getName(), BodyRootViewportWithParent.class.getName())); routeRegistryInitializer .process(Stream.of(BodyRootViewportWithParent.class) .collect(Collectors.toSet()), servletContext); }
@Test public void process_one_body_size_in_chain_and_one_for_route_passes() throws ServletException { routeRegistryInitializer.process( Stream.of(BodySingleNavigationTarget.class, BodyRootWithParent.class).collect(Collectors.toSet()), servletContext); }
@Test public void process_check_also_faulty_body_size_alias_route() throws ServletException { expectedEx.expect(InvalidRouteLayoutConfigurationException.class); expectedEx.expectMessage(String.format( "BodySize annotation needs to be on the top parent layout '%s' not on '%s'", BodyParent.class.getName(), BodyFailingAliasView.class.getName())); routeRegistryInitializer.process(Stream.of(BodyFailingAliasView.class) .collect(Collectors.toSet()), servletContext); }
@Test public void process_valid_body_size_alias_does_not_throw() throws ServletException { routeRegistryInitializer.process( Stream.of(BodyAliasView.class).collect(Collectors.toSet()), servletContext); }
@Test public void process_valid_page_configurator_does_not_throw() throws ServletException { routeRegistryInitializer.process( Stream.of(SingleConfigurator.class).collect(Collectors.toSet()), servletContext); }
@Test public void process_wrong_position_page_configurator_throws() throws ServletException { expectedEx.expect(InvalidRouteLayoutConfigurationException.class); expectedEx.expectMessage(String.format( "PageConfigurator implementation should be the top most route layout '%s'. Offending class: '%s'", Parent.class.getName(), MiddleParentConfigurator.class.getName())); routeRegistryInitializer .process(Stream.of(RootWithMultipleParentConfigurator.class) .collect(Collectors.toSet()), servletContext); }
@Test public void process_check_only_one_page_configurator_in_route_chain() throws ServletException { expectedEx.expect(InvalidRouteLayoutConfigurationException.class); expectedEx.expectMessage( "Only one PageConfigurator implementation is supported for navigation chain and should be on the top most level. Offending classes in chain: " + MultiMiddleParentConfigurator.class.getName() + ", " + MiddleParentConfigurator.class.getName()); routeRegistryInitializer.process( Stream.of(MultiConfigurator.class).collect(Collectors.toSet()), servletContext); }
@Test public void process_route_can_not_contain_page_configurator_if_has_parent() throws ServletException { expectedEx.expect(InvalidRouteLayoutConfigurationException.class); expectedEx.expectMessage(String.format( "PageConfigurator needs to be the top parent layout '%s' not '%s'", Parent.class.getName(), RootConfiguratorWithParent.class.getName())); routeRegistryInitializer .process(Stream.of(RootConfiguratorWithParent.class) .collect(Collectors.toSet()), servletContext); }
@Test public void process_one_page_configurator_in_chain_and_one_for_route_passes() throws ServletException { routeRegistryInitializer.process(Stream .of(SingleConfigurator.class, RootWithParentConfigurator.class) .collect(Collectors.toSet()), servletContext); }
@Test public void process_check_page_configurator_for_faulty_alias_route() throws ServletException { expectedEx.expect(InvalidRouteLayoutConfigurationException.class); expectedEx.expectMessage(String.format( "PageConfigurator needs to be the top parent layout '%s' not '%s'", Parent.class.getName(), FailingAliasConfigurator.class.getName())); routeRegistryInitializer.process(Stream .of(FailingAliasConfigurator.class).collect(Collectors.toSet()), servletContext); }
@Test public void process_wrong_position_inline_view_layout_throws() throws ServletException { expectedEx.expect(InvalidRouteLayoutConfigurationException.class); expectedEx.expectMessage(String.format( "Inline annotation should be on the top most route layout '%s'. Offending class: '%s'", InlineParent.class.getName(), InlineMiddleParentLayout.class.getName())); routeRegistryInitializer.process(Stream.of(InlineRootWithParents.class) .collect(Collectors.toSet()), servletContext); }
@Test public void process_check_only_one_inline_in_route_chain() throws ServletException { expectedEx.expect(InvalidRouteLayoutConfigurationException.class); expectedEx.expectMessage( "Only one Inline annotation is supported for navigation chain and should be on the top most level. Offending classes in chain: " + InlineMultiMiddleParentLayout.class.getName() + ", " + InlineMiddleParentLayout.class.getName()); routeRegistryInitializer.process(Stream.of(InlineMultiViewport.class) .collect(Collectors.toSet()), servletContext); }
@Test public void process_route_can_not_contain_inline_if_has_parent() throws ServletException { expectedEx.expect(InvalidRouteLayoutConfigurationException.class); expectedEx.expectMessage(String.format( "Inline annotation needs to be on the top parent layout '%s' not on '%s'", InlineParent.class.getName(), InlineRootViewportWithParent.class.getName())); routeRegistryInitializer .process(Stream.of(InlineRootViewportWithParent.class) .collect(Collectors.toSet()), servletContext); }
@Test public void process_one_inline_in_chain_and_one_for_route_passes() throws ServletException { routeRegistryInitializer.process( Stream.of(InlineSingleNavigationTarget.class, InlineRootWithParent.class).collect(Collectors.toSet()), servletContext); }
@Test public void process_check_also_faulty_inline_alias_route() throws ServletException { expectedEx.expect(InvalidRouteLayoutConfigurationException.class); expectedEx.expectMessage(String.format( "Inline annotation needs to be on the top parent layout '%s' not on '%s'", InlineParent.class.getName(), InlineFailingAliasView.class.getName())); routeRegistryInitializer.process(Stream.of(InlineFailingAliasView.class) .collect(Collectors.toSet()), servletContext); }
@Test public void process_valid_inline_alias_does_not_throw() throws ServletException { routeRegistryInitializer.process( Stream.of(InlineAliasView.class).collect(Collectors.toSet()), servletContext); }
@Test public void routeData_returns_all_registered_routes() throws ServletException { Set<Class<?>> routes = Stream.of(NavigationTarget.class, NavigationTargetFoo.class, NavigationTargetBar.class) .collect(Collectors.toSet()); routeRegistryInitializer.process(routes, servletContext); List<RouteData> registeredRoutes = registry.getRegisteredRoutes(); Assert.assertEquals("Not all registered routes were returned", 3, registeredRoutes.size()); Set<Class<?>> collectedRoutes = registeredRoutes.stream() .map(RouteData::getNavigationTarget) .collect(Collectors.toSet()); Assert.assertTrue("Not all targets were correct", routes.containsAll(collectedRoutes)); }
@Test public void routeData_gets_correct_urls_for_targets() throws ServletException { routeRegistryInitializer.process(Stream.of(NavigationTarget.class, NavigationRootWithParent.class, AbsoluteRoute.class, ExtendingPrefix.class, StringParameterRoute.class, ParameterRoute.class, MultiLevelRouteAlias.class) .collect(Collectors.toSet()), servletContext); List<RouteData> registeredRoutes = registry.getRegisteredRoutes(); Assert.assertEquals("Not all registered routes were returned", 7, registeredRoutes.size()); Assert.assertEquals("Sort order was not the one expected", "", registeredRoutes.get(0).getTemplate()); Assert.assertEquals("Sort order was not the one expected", "absolute", registeredRoutes.get(1).getTemplate()); Assert.assertEquals("Sort order was not the one expected", "absolute/levels", registeredRoutes.get(2).getTemplate()); Assert.assertEquals("Sort order was not the one expected", HasUrlParameterFormat.getTemplate("parameter", ParameterRoute.class), registeredRoutes.get(3).getTemplate()); Assert.assertEquals("Sort order was not the one expected", "parent", registeredRoutes.get(4).getTemplate()); Assert.assertEquals("Sort order was not the one expected", "parent/prefix", registeredRoutes.get(5).getTemplate()); Assert.assertEquals("Sort order was not the one expected", HasUrlParameterFormat.getTemplate("string", StringParameterRoute.class), registeredRoutes.get(6).getTemplate()); }
@Test public void routeData_gets_correct_parents_for_targets() throws ServletException { routeRegistryInitializer.process(Stream.of(NavigationTarget.class, NavigationRootWithParent.class, AbsoluteRoute.class, ExtendingPrefix.class, StringParameterRoute.class, ParameterRoute.class, MultiLevelRouteAlias.class) .collect(Collectors.toSet()), servletContext); List<RouteData> registeredRoutes = registry.getRegisteredRoutes(); Assert.assertEquals("Not all registered routes were returned", 7, registeredRoutes.size()); Assert.assertEquals("Parent is wrongly set to data", Collections.emptyList(), registeredRoutes.get(0).getParentLayouts()); Assert.assertEquals("Parent is wrongly set to data", ParentWithRoutePrefix.class, registeredRoutes.get(1).getParentLayout()); Assert.assertEquals("Parent is wrongly set to data", AbsoluteMiddleParent.class, registeredRoutes.get(2).getParentLayout()); Assert.assertEquals("Parent is wrongly set to data", Collections.emptyList(), registeredRoutes.get(3).getParentLayouts()); Assert.assertEquals("Parent is wrongly set to data", ParentWithRoutePrefix.class, registeredRoutes.get(4).getParentLayout()); Assert.assertEquals("Parent is wrongly set to data", ParentWithRoutePrefix.class, registeredRoutes.get(5).getParentLayout()); Assert.assertEquals("Parent is wrongly set to data", Collections.emptyList(), registeredRoutes.get(6).getParentLayouts()); }
@Test public void routeData_gets_correct_parameters_for_targets() throws ServletException { routeRegistryInitializer.process(Stream.of(NavigationTarget.class, NavigationRootWithParent.class, AbsoluteRoute.class, ExtendingPrefix.class, StringParameterRoute.class, ParameterRoute.class, MultiLevelRouteAlias.class) .collect(Collectors.toSet()), servletContext); List<RouteData> registeredRoutes = registry.getRegisteredRoutes(); Assert.assertEquals("Not all registered routes were returned", 7, registeredRoutes.size()); Assert.assertEquals("Unexpected parameters encountered", 0, registeredRoutes.get(0).getRouteParameters().size()); Assert.assertEquals("Unexpected parameters encountered", 0, registeredRoutes.get(1).getRouteParameters().size()); Assert.assertEquals("Unexpected parameters encountered", 0, registeredRoutes.get(2).getRouteParameters().size()); Assert.assertEquals("Missing parameters", 1, registeredRoutes.get(3).getRouteParameters().size()); Assert.assertEquals("Unexpected parameters encountered", 0, registeredRoutes.get(4).getRouteParameters().size()); Assert.assertEquals("Unexpected parameters encountered", 0, registeredRoutes.get(5).getRouteParameters().size()); Assert.assertEquals("Missing parameters", 1, registeredRoutes.get(6).getRouteParameters().size()); Assert.assertEquals("Unexpected parameter type encountered", ":" + HasUrlParameterFormat.PARAMETER_NAME + "(" + RouteParameterRegex.INTEGER + ")", registeredRoutes.get(3).getRouteParameters() .get(HasUrlParameterFormat.PARAMETER_NAME) .getTemplate()); Assert.assertEquals("Unexpected parameter type encountered", ":" + HasUrlParameterFormat.PARAMETER_NAME, registeredRoutes.get(6).getRouteParameters() .get(HasUrlParameterFormat.PARAMETER_NAME) .getTemplate()); }
@Test public void routeData_for_alias_data_is_correct() throws ServletException { routeRegistryInitializer.process(Stream.of(MultiLevelRouteAlias.class) .collect(Collectors.toSet()), servletContext); List<RouteData> registeredRoutes = registry.getRegisteredRoutes(); Assert.assertEquals("Not all registered routes were returned", 1, registeredRoutes.size()); RouteData routeData = registeredRoutes.get(0); Assert.assertEquals("Not all registered routes were returned", 5, routeData.getRouteAliases().size()); List<RouteAliasData> routeAliases = routeData.getRouteAliases(); Assert.assertEquals("Sort order was not the one expected", "absolute/alias2", routeAliases.get(0).getTemplate()); Assert.assertEquals("Sort order was not the one expected", "alias3", routeAliases.get(1).getTemplate()); Assert.assertEquals("Sort order was not the one expected", "alias4", routeAliases.get(2).getTemplate()); Assert.assertEquals("Sort order was not the one expected", "parent/alias1", routeAliases.get(3).getTemplate()); Assert.assertEquals("Sort order was not the one expected", "parent/middle/alias5", routeAliases.get(4).getTemplate()); Assert.assertEquals("Sort order was not the one expected", AbsoluteMiddleParent.class, routeAliases.get(0).getParentLayout()); Assert.assertEquals("Sort order was not the one expected", ParentWithRoutePrefix.class, routeAliases.get(1).getParentLayout()); Assert.assertEquals("Sort order was not the one expected", Collections.emptyList(), routeAliases.get(2).getParentLayouts()); Assert.assertEquals("Sort order was not the one expected", ParentWithRoutePrefix.class, routeAliases.get(3).getParentLayout()); Assert.assertEquals("Sort order was not the one expected", MiddleParent.class, routeAliases.get(4).getParentLayout()); }
@Test public void routeFilter_ignoresRoutes() throws InvalidRouteConfigurationException, ServletException { routeRegistryInitializer .process(Stream.of(IgnoredView.class, NavigationTarget.class) .collect(Collectors.toSet()), servletContext); List<?> registeredTargets = registry.getRegisteredRoutes().stream() .map(RouteData::getNavigationTarget) .collect(Collectors.toList()); Assert.assertEquals(Arrays.asList(NavigationTarget.class), registeredTargets); }
@Test public void registerClassesWithSameRoute_abstractClass_subclass_subclassIsRegistered() throws ServletException { LinkedHashSet<Class<?>> classes = new LinkedHashSet<>(); classes.add(AbstractRouteTarget.class); classes.add(BaseRouteTarget.class); routeRegistryInitializer.process(classes, servletContext); Assert.assertEquals(BaseRouteTarget.class, registry.getNavigationTarget("foo").get()); }
@Test public void registerClassesWithSameRoute_class_abstractSuperClass_subclassIsRegistered() throws ServletException { LinkedHashSet<Class<?>> classes = new LinkedHashSet<>(); classes.add(BaseRouteTarget.class); classes.add(AbstractRouteTarget.class); routeRegistryInitializer.process(classes, servletContext); Assert.assertEquals(BaseRouteTarget.class, registry.getNavigationTarget("foo").get()); }
@Test public void registerClassesWithSameRoute_class_subclass_subclassIsRegistered() throws ServletException { LinkedHashSet<Class<?>> classes = new LinkedHashSet<>(); classes.add(BaseRouteTarget.class); classes.add(SuperRouteTarget.class); routeRegistryInitializer.process(classes, servletContext); Assert.assertEquals(SuperRouteTarget.class, registry.getNavigationTarget("foo").get()); }
@Test public void registerClassesWithSameRoute_class_superClass_subclassIsRegistered() throws ServletException { LinkedHashSet<Class<?>> classes = new LinkedHashSet<>(); classes.add(SuperRouteTarget.class); classes.add(BaseRouteTarget.class); routeRegistryInitializer.process(classes, servletContext); Assert.assertEquals(SuperRouteTarget.class, registry.getNavigationTarget("foo").get()); }
@Test(expected = ServletException.class) public void registerClassesWithSameRoute_absatrctClass_unrelatedClass_throws() throws ServletException { LinkedHashSet<Class<?>> classes = new LinkedHashSet<>(); classes.add(AbstractRouteTarget.class); classes.add(OtherRouteTarget.class); routeRegistryInitializer.process(classes, servletContext); }
@Test(expected = ServletException.class) public void registerClassesWithSameRoute_unrelatedClass_abstractClass_throws() throws ServletException { LinkedHashSet<Class<?>> classes = new LinkedHashSet<>(); classes.add(OtherRouteTarget.class); classes.add(AbstractRouteTarget.class); routeRegistryInitializer.process(classes, servletContext); }
@Test(expected = ServletException.class) public void registerClassesWithSameRoute_class_unrelatedClass_throws() throws ServletException { LinkedHashSet<Class<?>> classes = new LinkedHashSet<>(); classes.add(BaseRouteTarget.class); classes.add(OtherRouteTarget.class); routeRegistryInitializer.process(classes, servletContext); }