Search in sources :

Example 1 with RoutePathProvider

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

the class LookupServletContainerInitializerTest method processLookupServletContainerInitializer_routePathProviderIsProvidedAsScannedClass_lookupReturnsTheProviderInstance.

@Test
public void processLookupServletContainerInitializer_routePathProviderIsProvidedAsScannedClass_lookupReturnsTheProviderInstance() throws ServletException {
    Lookup lookup = mockLookup(TestRoutePathProvider.class);
    RoutePathProvider handler = lookup.lookup(RoutePathProvider.class);
    Assert.assertNotNull(handler);
    Assert.assertEquals(TestRoutePathProvider.class, handler.getClass());
    Collection<RoutePathProvider> allHandlers = lookup.lookupAll(RoutePathProvider.class);
    Assert.assertEquals(1, allHandlers.size());
    Assert.assertEquals(TestRoutePathProvider.class, allHandlers.iterator().next().getClass());
}
Also used : RoutePathProvider(com.vaadin.flow.router.RoutePathProvider) Lookup(com.vaadin.flow.di.Lookup) Test(org.junit.Test)

Example 2 with RoutePathProvider

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

the class RouteUtil method resolve.

/**
 * Gets the effective route path value of the annotated class.
 *
 * @param context
 *            a Vaadin contexxt
 * @param component
 *            the component where the route points to
 * @return The value of the annotation or naming convention based value if
 *         no explicit value is given.
 */
public static String resolve(VaadinContext context, Class<?> component) {
    Lookup lookup = context.getAttribute(Lookup.class);
    RoutePathProvider provider = lookup.lookup(RoutePathProvider.class);
    assert provider != null;
    return provider.getRoutePath(component);
}
Also used : RoutePathProvider(com.vaadin.flow.router.RoutePathProvider) Lookup(com.vaadin.flow.di.Lookup)

Aggregations

Lookup (com.vaadin.flow.di.Lookup)2 RoutePathProvider (com.vaadin.flow.router.RoutePathProvider)2 Test (org.junit.Test)1