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;
}
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());
}
Aggregations