Search in sources :

Example 1 with RouteAliasData

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

the class AbstractRouteRegistry method populateRegisteredRoutes.

private void populateRegisteredRoutes(ConfiguredRoutes configuration, List<RouteData> registeredRoutes, Class<? extends Component> target, String template) {
    List<RouteAliasData> routeAliases = new ArrayList<>();
    configuration.getRoutePaths(target).stream().filter(routePathTemplate -> !routePathTemplate.equals(template)).forEach(aliasRoutePathTemplate -> routeAliases.add(new RouteAliasData(getParentLayouts(configuration, aliasRoutePathTemplate), aliasRoutePathTemplate, configuration.getParameters(aliasRoutePathTemplate), target)));
    List<Class<? extends RouterLayout>> parentLayouts = getParentLayouts(configuration, template);
    RouteData route = new RouteData(parentLayouts, template, configuration.getParameters(template), target, routeAliases);
    registeredRoutes.add(route);
}
Also used : RouteAliasData(com.vaadin.flow.router.RouteAliasData) Component(com.vaadin.flow.component.Component) SerializableBiConsumer(com.vaadin.flow.function.SerializableBiConsumer) Registration(com.vaadin.flow.shared.Registration) ArrayList(java.util.ArrayList) Map(java.util.Map) Command(com.vaadin.flow.server.Command) HasErrorParameter(com.vaadin.flow.router.HasErrorParameter) NotFoundException(com.vaadin.flow.router.NotFoundException) RouterLayout(com.vaadin.flow.router.RouterLayout) ReentrantLock(java.util.concurrent.locks.ReentrantLock) RouteData(com.vaadin.flow.router.RouteData) RouteRegistry(com.vaadin.flow.server.RouteRegistry) ReflectTools(com.vaadin.flow.internal.ReflectTools) RoutesChangedListener(com.vaadin.flow.router.RoutesChangedListener) Serializable(java.io.Serializable) InvalidRouteConfigurationException(com.vaadin.flow.server.InvalidRouteConfigurationException) Objects(java.util.Objects) List(java.util.List) Optional(java.util.Optional) RoutesChangedEvent(com.vaadin.flow.router.RoutesChangedEvent) RouteBaseData(com.vaadin.flow.router.RouteBaseData) Collections(java.util.Collections) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) RouteParameters(com.vaadin.flow.router.RouteParameters) RouterLayout(com.vaadin.flow.router.RouterLayout) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) RouteData(com.vaadin.flow.router.RouteData) RouteAliasData(com.vaadin.flow.router.RouteAliasData)

Example 2 with RouteAliasData

use of com.vaadin.flow.router.RouteAliasData 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 3 with RouteAliasData

use of com.vaadin.flow.router.RouteAliasData 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

RouteAliasData (com.vaadin.flow.router.RouteAliasData)3 RouteData (com.vaadin.flow.router.RouteData)3 Component (com.vaadin.flow.component.Component)1 Lookup (com.vaadin.flow.di.Lookup)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 RouteBaseData (com.vaadin.flow.router.RouteBaseData)1 RouteParameters (com.vaadin.flow.router.RouteParameters)1 RouterLayout (com.vaadin.flow.router.RouterLayout)1 RoutesChangedEvent (com.vaadin.flow.router.RoutesChangedEvent)1 RoutesChangedListener (com.vaadin.flow.router.RoutesChangedListener)1 Command (com.vaadin.flow.server.Command)1 InvalidRouteConfigurationException (com.vaadin.flow.server.InvalidRouteConfigurationException)1 RouteRegistry (com.vaadin.flow.server.RouteRegistry)1 VaadinServletContext (com.vaadin.flow.server.VaadinServletContext)1 Registration (com.vaadin.flow.shared.Registration)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1