ApplicationRouteRegistry extends AbstractRouteRegistry { @Override public void setRoute(String path, Class<? extends Component> navigationTarget, List<Class<? extends RouterLayout>> parentChain) { if (routeFilters.stream().allMatch( filter -> filter.testNavigationTarget(navigationTarget))) { super.setRoute(path, navigationTarget, parentChain); } else { LoggerFactory.getLogger(ApplicationRouteRegistry.class).info( "Not registering route {} because it's not valid for all registered routeFilters.", navigationTarget.getName()); } } protected  ApplicationRouteRegistry(); static ApplicationRouteRegistry getInstance(VaadinContext context); @Override void setRoute(String path,
            Class<? extends Component> navigationTarget,
            List<Class<? extends RouterLayout>> parentChain); void setErrorNavigationTargets(
            Set<Class<? extends Component>> errorNavigationTargets); Optional<ErrorTargetEntry> getErrorNavigationTarget(
            Exception exception); @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); boolean hasNavigationTargets(); Class<?> getPwaConfigurationClass(); void setPwaConfigurationClass(Class<?> pwaClass);  }
@Test public void lockingConfiguration_newConfigurationIsGottenOnlyAfterUnlock() { CountDownLatch waitReaderThread = new CountDownLatch(1); CountDownLatch waitUpdaterThread = new CountDownLatch(2); Thread readerThread = new Thread() { @Override public void run() { awaitCountDown(waitUpdaterThread); Assert.assertTrue("Registry should still remain empty", getTestedRegistry().getRegisteredRoutes().isEmpty()); awaitCountDown(waitUpdaterThread); Assert.assertTrue("Registry should still remain empty", getTestedRegistry().getRegisteredRoutes().isEmpty()); waitReaderThread.countDown(); } }; readerThread.start(); getTestedRegistry().update(() -> { getTestedRegistry().setRoute("", MyRoute.class, Collections.emptyList()); waitUpdaterThread.countDown(); getTestedRegistry().setRoute("path", Secondary.class, Collections.emptyList()); waitUpdaterThread.countDown(); awaitCountDown(waitReaderThread); }); Assert.assertEquals( "After unlock registry should be updated for others to configure with new data", 2, getTestedRegistry().getRegisteredRoutes().size()); }
@Test public void routeWithAliases_eventShowsCorrectlyAsRemoved() { List<RouteBaseData> added = new ArrayList<>(); List<RouteBaseData> removed = new ArrayList<>(); getTestedRegistry().addRoutesChangeListener(event -> { added.clear(); removed.clear(); added.addAll(event.getAddedRoutes()); removed.addAll(event.getRemovedRoutes()); }); getTestedRegistry().update(() -> { getTestedRegistry().setRoute("main", Secondary.class, Collections.emptyList()); getTestedRegistry().setRoute("Alias1", Secondary.class, Collections.emptyList()); getTestedRegistry().setRoute("Alias2", Secondary.class, Collections.emptyList()); }); Assert.assertEquals( "Main route and aliases should all be seen as added.", 3, added.size()); Assert.assertTrue("No routes should have been removed", removed.isEmpty()); getTestedRegistry().removeRoute("Alias2"); Assert.assertTrue("No routes should have been added", added.isEmpty()); Assert.assertEquals( "Removing the alias route should be seen in the event", 1, removed.size()); }