Search in sources :

Example 6 with RouteData

use of com.vaadin.flow.router.RouteData in project flow by vaadin.

the class RouteRegistryInitializerTest method firstInitRouteRegistry.

private ApplicationRouteRegistry firstInitRouteRegistry() throws VaadinInitializerException {
    vaadinContext = new VaadinServletContext(servletContext) {

        private Map<Class<?>, Object> map = new HashMap<>();

        @Override
        public <T> T getAttribute(Class<T> type) {
            if (Lookup.class.equals(type)) {
                return type.cast(lookup);
            } else {
                return type.cast(map.get(type));
            }
        }

        @Override
        public <T> void setAttribute(Class<T> clazz, T value) {
            map.put(clazz, value);
        }
    };
    // first time initialization
    routeRegistryInitializer.initialize(Collections.singleton(OldRouteTarget.class), vaadinContext);
    ApplicationRouteRegistry registry = ApplicationRouteRegistry.getInstance(vaadinContext);
    List<RouteData> routes = registry.getRegisteredRoutes();
    // self check
    Assert.assertEquals(1, routes.size());
    RouteData data = routes.get(0);
    Assert.assertEquals("foo-bar", data.getTemplate());
    List<RouteAliasData> aliases = data.getRouteAliases();
    Assert.assertEquals(1, aliases.size());
    RouteAliasData alias = aliases.get(0);
    Assert.assertEquals("baz", alias.getTemplate());
    return registry;
}
Also used : VaadinServletContext(com.vaadin.flow.server.VaadinServletContext) HashMap(java.util.HashMap) Lookup(com.vaadin.flow.di.Lookup) RouteData(com.vaadin.flow.router.RouteData) RouteAliasData(com.vaadin.flow.router.RouteAliasData)

Example 7 with RouteData

use of com.vaadin.flow.router.RouteData in project flow by vaadin.

the class RouteRegistryInitializerTest method routeData_for_alias_data_is_correct.

@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());
}
Also used : RouteData(com.vaadin.flow.router.RouteData) RouteAliasData(com.vaadin.flow.router.RouteAliasData) Test(org.junit.Test)

Aggregations

RouteData (com.vaadin.flow.router.RouteData)7 ArrayList (java.util.ArrayList)4 RouteAliasData (com.vaadin.flow.router.RouteAliasData)3 RouteBaseData (com.vaadin.flow.router.RouteBaseData)3 Component (com.vaadin.flow.component.Component)2 RouteParameters (com.vaadin.flow.router.RouteParameters)2 RouterLayout (com.vaadin.flow.router.RouterLayout)2 RoutesChangedEvent (com.vaadin.flow.router.RoutesChangedEvent)2 RoutesChangedListener (com.vaadin.flow.router.RoutesChangedListener)2 Registration (com.vaadin.flow.shared.Registration)2 List (java.util.List)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 Lookup (com.vaadin.flow.di.Lookup)1 DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)1 SerializableBiConsumer (com.vaadin.flow.function.SerializableBiConsumer)1 ReflectTools (com.vaadin.flow.internal.ReflectTools)1 HasErrorParameter (com.vaadin.flow.router.HasErrorParameter)1 NotFoundException (com.vaadin.flow.router.NotFoundException)1