com.vaadin.flow.server.RouteRegistry Java Examples

The following examples show how to use com.vaadin.flow.server.RouteRegistry. 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: RouteConfigurationTest.java    From flow with Apache License 2.0 6 votes vote down vote up
@Test
public void routeWithParent_parentsAreCollectedCorrectly() {
    RouteRegistry registry = Mockito.mock(RouteRegistry.class);
    RouteConfiguration routeConfiguration = RouteConfiguration
            .forRegistry(registry);

    routeConfiguration.setAnnotatedRoute(SingleLayout.class);

    Mockito.verify(registry).setRoute("single", SingleLayout.class,
            Collections.singletonList(MainLayout.class));

    routeConfiguration.setAnnotatedRoute(DoubleLayout.class);

    Mockito.verify(registry).setRoute("double", DoubleLayout.class,
            Arrays.asList(MiddleLayout.class, MainLayout.class));
}
 
Example #2
Source File: RouteConfigurationTest.java    From flow with Apache License 2.0 6 votes vote down vote up
@Test
public void registeredRouteWithAlias_allPathsAreRegistered() {
    RouteRegistry registry = Mockito.mock(RouteRegistry.class);
    RouteConfiguration routeConfiguration = RouteConfiguration
            .forRegistry(registry);

    routeConfiguration.setAnnotatedRoute(MyRouteWithAliases.class);

    Mockito.verify(registry).setRoute("withAliases",
            MyRouteWithAliases.class, Collections.emptyList());
    Mockito.verify(registry).setRoute("version", MyRouteWithAliases.class,
            Collections.emptyList());
    Mockito.verify(registry).setRoute("person", MyRouteWithAliases.class,
            Collections.emptyList());

}
 
Example #3
Source File: MockServiceSessionSetup.java    From vertx-vaadin with MIT License 5 votes vote down vote up
@Override
protected RouteRegistry getRouteRegistry() {
    if (routeRegistry != null) {
        return routeRegistry;
    }
    return super.getRouteRegistry();
}
 
Example #4
Source File: Router.java    From flow with Apache License 2.0 5 votes vote down vote up
public RouteRegistry getRegistry() {
    // If we have a session then return the session registry
    // else return router registry
    if (VaadinSession.getCurrent() != null) {
        return SessionRouteRegistry
                .getSessionRegistry(VaadinSession.getCurrent());
    }
    return registry;
}
 
Example #5
Source File: DefaultRouteResolverTest.java    From flow with Apache License 2.0 5 votes vote down vote up
private void setRoutes(RouteRegistry registry,
        Set<Class<? extends Component>> routes) {
    RouteConfiguration routeConfiguration = RouteConfiguration
            .forRegistry(registry);
    routeConfiguration.update(() -> {
        routeConfiguration.getHandledRegistry().clean();
        routes.forEach(routeConfiguration::setAnnotatedRoute);
    });
}
 
Example #6
Source File: RouteConfigurationTest.java    From flow with Apache License 2.0 5 votes vote down vote up
@Test
public void parentLayoutAnnotatedClass_parentsCorrecltCollected() {
    RouteRegistry registry = Mockito.mock(RouteRegistry.class);
    RouteConfiguration routeConfiguration = RouteConfiguration
            .forRegistry(registry);

    routeConfiguration.setParentAnnotatedRoute("middle",
            MiddleLayout.class);

    Mockito.verify(registry).setRoute("middle", MiddleLayout.class,
            Collections.singletonList(MainLayout.class));
}
 
Example #7
Source File: DefaultRouteResolver.java    From flow with Apache License 2.0 5 votes vote down vote up
@Override
public NavigationState resolve(ResolveRequest request) {
    RouteRegistry registry = request.getRouter().getRegistry();

    final String path = request.getLocation().getPath();
    NavigationRouteTarget navigationResult = registry
            .getNavigationRouteTarget(path);

    if (!navigationResult.hasTarget()) {
        return null;
    }
    
    NavigationStateBuilder builder = new NavigationStateBuilder(
            request.getRouter());
    try {
        builder.withTarget(navigationResult.getRouteTarget(),
                navigationResult.getRouteParameters());
        builder.withPath(navigationResult.getPath());
    } catch (NotFoundException nfe) {
        String message = "Exception while navigation to path " + path;
        LoggerFactory.getLogger(this.getClass().getName()).warn(message,
                nfe);
        throw nfe;
    }

    return builder.build();
}
 
Example #8
Source File: RouteConfigurationTest.java    From flow with Apache License 2.0 5 votes vote down vote up
@Test
public void setRoutes_allExpectedRoutesAreSet() {

    RouteRegistry registry = Mockito.mock(RouteRegistry.class);
    RouteConfiguration routeConfiguration = RouteConfiguration
            .forRegistry(registry);

    Mockito.doAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        ((Command) args[0]).execute();
        return null;
    }).when(registry).update(Mockito.any(Command.class));

    routeConfiguration.update(() -> {
        routeConfiguration.getHandledRegistry().clean();
        Arrays.asList(MyRoute.class, MyInfo.class, MyPalace.class,
                MyModular.class)
                .forEach(routeConfiguration::setAnnotatedRoute);
    });

    Mockito.verify(registry).update(Mockito.any());

    Mockito.verify(registry).setRoute("home", MyRoute.class,
            Collections.emptyList());

    Mockito.verify(registry).setRoute("info", MyInfo.class,
            Collections.emptyList());

    Mockito.verify(registry).setRoute("palace", MyPalace.class,
            Collections.emptyList());

    Mockito.verify(registry).setRoute("modular", MyModular.class,
            Collections.emptyList());
}
 
Example #9
Source File: NavigationStateRendererTest.java    From flow with Apache License 2.0 4 votes vote down vote up
@Before
public void init() {
    RouteRegistry registry = ApplicationRouteRegistry.getInstance(
            new VaadinServletContext(Mockito.mock(ServletContext.class)));
    router = new Router(registry);
}
 
Example #10
Source File: VertxVaadinService.java    From vertx-vaadin with MIT License 4 votes vote down vote up
@Override
protected RouteRegistry getRouteRegistry() {
    return ApplicationRouteRegistry.getInstance(vertxVaadin.servletContext());
}
 
Example #11
Source File: RouteConfigurationTest.java    From flow with Apache License 2.0 4 votes vote down vote up
@Override
public RouteRegistry getRouteRegistry() {
    return super.getRouteRegistry();
}
 
Example #12
Source File: ApplicationRouteRegistryTest.java    From flow with Apache License 2.0 4 votes vote down vote up
@Override
protected RouteRegistry getTestedRegistry() {
    return registry;
}
 
Example #13
Source File: ApplicationRouteRegistryTest.java    From flow with Apache License 2.0 4 votes vote down vote up
@Override
protected RouteRegistry getInitializationRegistry() {
    return registry;
}
 
Example #14
Source File: RoutesChangedEvent.java    From flow with Apache License 2.0 4 votes vote down vote up
@Override
public RouteRegistry getSource() {
    return (RouteRegistry) super.getSource();
}
 
Example #15
Source File: RouteConfiguration.java    From flow with Apache License 2.0 4 votes vote down vote up
private static RouteRegistry getSessionRegistry() {
    return SessionRouteRegistry
            .getSessionRegistry(VaadinSession.getCurrent());
}
 
Example #16
Source File: RouteConfiguration.java    From flow with Apache License 2.0 4 votes vote down vote up
private static RouteRegistry getApplicationRegistry() {
    return ApplicationRouteRegistry
            .getInstance(VaadinService.getCurrent().getContext());
}
 
Example #17
Source File: RouteConfiguration.java    From flow with Apache License 2.0 4 votes vote down vote up
private RouteConfiguration(RouteRegistry registry) {
    handledRegistry = registry;
}
 
Example #18
Source File: RoutesChangedEvent.java    From flow with Apache License 2.0 3 votes vote down vote up
/**
 * Constructs a prototypical Event.
 *
 * @param source
 *         The object on which the Event initially occurred.
 * @param added
 *         list of all the added routes
 * @param removed
 *         list of all the removed routes
 * @throws IllegalArgumentException
 *         if source is null.
 */
public RoutesChangedEvent(RouteRegistry source,
        List<RouteBaseData<?>> added, List<RouteBaseData<?>> removed) {
    super(source);
    this.added = Collections.unmodifiableList(added);
    this.removed = Collections.unmodifiableList(removed);
}
 
Example #19
Source File: RouteRegistryTestBase.java    From flow with Apache License 2.0 2 votes vote down vote up
/**
 * Returns registry which is tested.
 * <p>
 * This may be the same registry which is returned by
 * {@link #getInitializationRegistry()} but doesn't have to be.
 *
 * @return the tested registry
 */
protected abstract RouteRegistry getTestedRegistry();
 
Example #20
Source File: RouteRegistryTestBase.java    From flow with Apache License 2.0 2 votes vote down vote up
/**
 * Returns registry which is used to initialize the registry with data.
 *
 * @return initialization registry
 */
protected abstract RouteRegistry getInitializationRegistry();
 
Example #21
Source File: RouteConfiguration.java    From flow with Apache License 2.0 2 votes vote down vote up
/**
 * Get the registry that this configuration is working with.
 *
 * @return handled RouteRegistry
 */
public RouteRegistry getHandledRegistry() {
    return handledRegistry;
}
 
Example #22
Source File: RouteConfiguration.java    From flow with Apache License 2.0 2 votes vote down vote up
/**
 * Get a {@link RouteConfiguration} for editing the given RouteRegistry
 * implementation. This enables editing of registry when the required
 * {@link CurrentInstance} is not yet populated.
 *
 * @param registry
 *         registry to edit through the controller
 * @return configurator for editing given registry
 */
public static RouteConfiguration forRegistry(RouteRegistry registry) {
    return new RouteConfiguration(registry);
}
 
Example #23
Source File: Router.java    From flow with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs a new router with the given route registry and a
 * {@link DefaultRouteResolver}.
 *
 * @param registry
 *            the route registry to use, not <code>null</code>
 */
public Router(RouteRegistry registry) {
    assert registry != null;
    this.registry = registry;
    routeResolver = new DefaultRouteResolver();
}