com.vaadin.flow.server.startup.ApplicationRouteRegistry Java Examples
The following examples show how to use
com.vaadin.flow.server.startup.ApplicationRouteRegistry.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SessionRouteRegistryTest.java From flow with Apache License 2.0 | 6 votes |
@Before public void init() { registry = ApplicationRouteRegistry.getInstance( new VaadinServletContext(Mockito.mock(ServletContext.class))); vaadinService = Mockito.mock(MockService.class); Mockito.when(vaadinService.getRouteRegistry()).thenReturn(registry); VaadinService.setCurrent(vaadinService); session = new MockVaadinSession(vaadinService) { @Override public VaadinService getService() { return vaadinService; } }; }
Example #2
Source File: BootstrapContextTest.java From flow with Apache License 2.0 | 6 votes |
@Test public void getPushAnnotation_routeTargetIsAbsent_pushFromTheErrorNavigationTargetIsUsed() { Mockito.when(request.getPathInfo()).thenReturn("/bar"); ApplicationRouteRegistry registry = ApplicationRouteRegistry .getInstance(ui.getSession().getService().getContext()); registry.setErrorNavigationTargets( Collections.singleton(CustomRouteNotFound.class)); BootstrapContext context = new BootstrapContext(request, Mockito.mock(VaadinResponse.class), session, ui, request -> ""); Optional<Push> push = context .getPageConfigurationAnnotation(Push.class); Assert.assertTrue(push.isPresent()); Push pushAnnotation = push.get(); Assert.assertEquals(PushMode.AUTOMATIC, pushAnnotation.value()); Assert.assertEquals(Transport.WEBSOCKET, pushAnnotation.transport()); }
Example #3
Source File: BootstrapContextTest.java From flow with Apache License 2.0 | 6 votes |
@Test public void getPushAnnotation_routeTargetIsAbsent_pushIsDefinedOnParentLayout_pushFromTheErrorNavigationTargetParentLayoutIsUsed() { Mockito.when(request.getPathInfo()).thenReturn("/bar"); ApplicationRouteRegistry registry = ApplicationRouteRegistry .getInstance(ui.getSession().getService().getContext()); registry.setErrorNavigationTargets( Collections.singleton(AnotherCustomRouteNotFound.class)); BootstrapContext context = new BootstrapContext(request, Mockito.mock(VaadinResponse.class), session, ui, request -> ""); Optional<Push> push = context .getPageConfigurationAnnotation(Push.class); Assert.assertTrue(push.isPresent()); Push pushAnnotation = push.get(); Assert.assertEquals(PushMode.MANUAL, pushAnnotation.value()); Assert.assertEquals(Transport.LONG_POLLING, pushAnnotation.transport()); }
Example #4
Source File: RouteConfigurationTest.java From flow with Apache License 2.0 | 6 votes |
@Before public void init() { servletContext = new MockServletContext(); vaadinContext = new VaadinServletContext(servletContext); registry = ApplicationRouteRegistry .getInstance(vaadinContext); vaadinService = Mockito.mock(MockService.class); Mockito.when(vaadinService.getRouteRegistry()).thenReturn(registry); Mockito.when(vaadinService.getContext()).thenReturn(vaadinContext); VaadinService.setCurrent(vaadinService); session = new MockVaadinSession(vaadinService) { @Override public VaadinService getService() { return vaadinService; } }; }
Example #5
Source File: RouteUtilTest.java From flow with Apache License 2.0 | 6 votes |
@Test public void newRouteAnnotatedClass_updateRouteRegistry_routeIsAddedToRegistry() { // given @Route("a") class A extends Component { } ApplicationRouteRegistry registry = ApplicationRouteRegistry .getInstance(new MockVaadinServletService().getContext()); // when RouteUtil.updateRouteRegistry(registry, Collections.singleton(A.class), Collections.emptySet(), Collections.emptySet()); // then Assert.assertTrue(registry.getConfiguration().hasRoute("a")); }
Example #6
Source File: RouteUtilTest.java From flow with Apache License 2.0 | 6 votes |
@Test public void deletedRouteAnnotatedClass_updateRouteRegistry_routeIsRemovedFromRegistry() { // given @Route("a") class A extends Component { } ApplicationRouteRegistry registry = ApplicationRouteRegistry .getInstance(new MockVaadinServletService().getContext()); registry.setRoute("a", A.class, Collections.emptyList()); Assert.assertTrue(registry.getConfiguration().hasRoute("a")); // when RouteUtil.updateRouteRegistry(registry, Collections.emptySet(), Collections.emptySet(), Collections.singleton(A.class)); // then Assert.assertFalse(registry.getConfiguration().hasRoute("a")); }
Example #7
Source File: RouteUtilTest.java From flow with Apache License 2.0 | 6 votes |
@Test public void renamedRouteAnnotatedClass_updateRouteRegistry_routeIsUpdatedInRegistry() { // given @Route("aa") class A extends Component { } ApplicationRouteRegistry registry = ApplicationRouteRegistry .getInstance(new MockVaadinServletService().getContext()); registry.setRoute("a", A.class, Collections.emptyList()); Assert.assertTrue(registry.getConfiguration().hasRoute("a")); // when RouteUtil.updateRouteRegistry(registry, Collections.emptySet(), Collections.singleton(A.class), Collections.emptySet()); // then Assert.assertFalse(registry.getConfiguration().hasRoute("a")); Assert.assertTrue(registry.getConfiguration().hasRoute("aa")); }
Example #8
Source File: RouteUtilTest.java From flow with Apache License 2.0 | 6 votes |
@Test public void deannotatedRouteClass_updateRouteRegistry_routeIsRemovedFromRegistry() { // given class A extends Component { } ApplicationRouteRegistry registry = ApplicationRouteRegistry .getInstance(new MockVaadinServletService().getContext()); registry.setRoute("a", A.class, Collections.emptyList()); Assert.assertTrue(registry.getConfiguration().hasRoute("a")); // when RouteUtil.updateRouteRegistry(registry, Collections.emptySet(), Collections.singleton(A.class), Collections.emptySet()); // then Assert.assertFalse(registry.getConfiguration().hasRoute("a")); }
Example #9
Source File: Router.java From flow with Apache License 2.0 | 5 votes |
/** * Get a registered navigation target for given exception. * * @param exception * exception to search error view for * @return optional error target entry corresponding to the given exception */ public Optional<ErrorTargetEntry> getErrorNavigationTarget( Exception exception) { if (registry instanceof ApplicationRouteRegistry) { return ((ApplicationRouteRegistry) registry) .getErrorNavigationTarget(exception); } return Optional.empty(); }
Example #10
Source File: ErrorStateRendererTest.java From flow with Apache License 2.0 | 5 votes |
@Test(expected = ExceptionsTrace.class) public void handle_openNPEView_infiniteReroute_noStackOverflow_throws() { UI ui = configureMocks(); NavigationState state = new NavigationStateBuilder(ui.getRouter()) .withTarget(InfiniteLoopNPEView.class).build(); NavigationStateRenderer renderer = new NavigationStateRenderer(state); RouteConfiguration.forRegistry(ui.getRouter().getRegistry()) .setAnnotatedRoute(InfiniteLoopNPEView.class); ((ApplicationRouteRegistry) ui.getRouter().getRegistry()) .setErrorNavigationTargets( Collections.singleton(InfiniteLoopErrorTarget.class)); NavigationEvent event = new NavigationEvent(ui.getRouter(), new Location("npe"), ui, NavigationTrigger.CLIENT_SIDE); // event should route to ErrorTarget whose layout forwards to NPEView // which reroute to ErrorTarget and this is an infinite loop renderer.handle(event); JsonObject routerLinkState = Json.createObject(); routerLinkState.put("href", "router_link"); routerLinkState.put("scrollPositionX", 0d); routerLinkState.put("scrollPositionY", 0d); event = new NavigationEvent(ui.getRouter(), new Location("npe"), ui, NavigationTrigger.ROUTER_LINK, routerLinkState, false); // event should route to ErrorTarget whose layout forwards to NPEView // which reroute to ErrorTarget and this is an infinite loop renderer.handle(event); }
Example #11
Source File: VaadinIntegration.java From HotswapAgent with GNU General Public License v2.0 | 5 votes |
/** * Update Flow route registry and push refresh to UIs (concrete parameter * types as {@link org.hotswap.agent.command.ReflectionCommand} determines * the method from actual argument types). * * @param addedClasses * returns classes that have been added or modified * @param modifiedClasses * returns classes that have been deleted */ public void updateRoutes(HashSet<Class<?>> addedClasses, HashSet<Class<?>> modifiedClasses) { assert (vaadinServlet != null); LOGGER.debug("The following classes were added:"); addedClasses.forEach(clazz -> LOGGER.debug("+ {}", clazz)); LOGGER.debug("The following classes were modified:"); modifiedClasses.forEach(clazz -> LOGGER.debug("# {}", clazz)); Method getInstanceMethod = null; Object getInstanceMethodParam = null; try { // Vaadin 14.2+ getInstanceMethod = ApplicationRouteRegistry.class.getMethod("getInstance", VaadinContext.class); getInstanceMethodParam = vaadinServlet.getService().getContext(); } catch (NoSuchMethodException ex1) { // In Vaadin 14.1, this method instead takes a ServletContext parameter LOGGER.debug("ApplicationRouteRegistry::getInstance(VaadinContext) not found"); try { getInstanceMethod = ApplicationRouteRegistry.class.getMethod("getInstance", ServletContext.class); getInstanceMethodParam = vaadinServlet.getServletContext(); } catch (NoSuchMethodException ex2) { // In Vaadin 14.1, this method takes a ServletContext parameter LOGGER.warning("Unable to obtain ApplicationRouteRegistry instance; routes are not updated "); return; } } try { ApplicationRouteRegistry registry = (ApplicationRouteRegistry) getInstanceMethod.invoke(null, getInstanceMethodParam); updateRouteRegistry(registry, addedClasses, modifiedClasses, Collections.emptySet()); } catch (IllegalAccessException | InvocationTargetException ex) { LOGGER.warning("Unable to obtain ApplicationRouteRegistry instance; routes are not updated:", ex); } }
Example #12
Source File: VertxVaadinService.java From vertx-vaadin with MIT License | 4 votes |
@Override protected RouteRegistry getRouteRegistry() { return ApplicationRouteRegistry.getInstance(vertxVaadin.servletContext()); }
Example #13
Source File: VaadinServletService.java From flow with Apache License 2.0 | 4 votes |
@Override protected RouteRegistry getRouteRegistry() { return ApplicationRouteRegistry.getInstance(getContext()); }
Example #14
Source File: RouteConfiguration.java From flow with Apache License 2.0 | 4 votes |
private static RouteRegistry getApplicationRegistry() { return ApplicationRouteRegistry .getInstance(VaadinService.getCurrent().getContext()); }
Example #15
Source File: RouterTest.java From flow with Apache License 2.0 | 4 votes |
private void setErrorNavigationTargets( Class<? extends Component>... errorNavigationTargets) { ((ApplicationRouteRegistry) router.getRegistry()) .setErrorNavigationTargets( new HashSet<>(Arrays.asList(errorNavigationTargets))); }
Example #16
Source File: NavigationStateRendererTest.java From flow with Apache License 2.0 | 4 votes |
@Before public void init() { RouteRegistry registry = ApplicationRouteRegistry.getInstance( new VaadinServletContext(Mockito.mock(ServletContext.class))); router = new Router(registry); }