SessionRouteRegistry extends AbstractRouteRegistry { @Override public List<RouteData> getRegisteredRoutes() { List<RouteData> routes = new ArrayList<>(super.getRegisteredRoutes()); List<RouteData> registeredRoutes = getParentRegistry() .getRegisteredRoutes(); if (!registeredRoutes.isEmpty()) { Set<String> collect = routes.stream().map(RouteData::getTemplate) .collect(Collectors.toSet()); registeredRoutes.stream() .filter(data -> !collect.contains(data.getTemplate())) .forEach(routes::add); } return routes; } 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 addSameClassForMultipleRoutes_removalOfRouteClassClearsRegisttry() { SessionRouteRegistry registry = getRegistry(session); registry.setRoute("home", MyRoute.class, Collections.emptyList()); registry.setRoute("info", MyRoute.class, Collections.emptyList()); registry.setRoute("path", MyRoute.class, Collections.emptyList()); registry.setRoute("palace", MyRoute.class, Collections.emptyList()); Assert.assertTrue( "Registry didn't contain navigation targets even though some were registered", !registry.getRegisteredRoutes().isEmpty()); registry.removeRoute(MyRoute.class); Assert.assertFalse( "Registry should be empty as only one class was registered", !registry.getRegisteredRoutes().isEmpty()); }
@Test public void lockingConfiguration_configurationIsUpdatedOnlyAfterUnlockk() { CountDownLatch waitReaderThread = new CountDownLatch(1); CountDownLatch waitUpdaterThread = new CountDownLatch(2); SessionRouteRegistry registry = getRegistry(session); Thread readerThread = new Thread() { @Override public void run() { awaitCountDown(waitUpdaterThread); Assert.assertTrue("Registry should still remain empty", getRegistry(session).getRegisteredRoutes().isEmpty()); awaitCountDown(waitUpdaterThread); Assert.assertTrue("Registry should still remain empty", getRegistry(session).getRegisteredRoutes().isEmpty()); waitReaderThread.countDown(); } }; readerThread.start(); registry.update(() -> { registry.setRoute("", MyRoute.class, Collections.emptyList()); waitUpdaterThread.countDown(); registry.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, getRegistry(session).getRegisteredRoutes().size()); }