Class Routes

java.lang.Object
com.vaadin.browserless.internal.Routes
All Implemented Interfaces:
Serializable

public final class Routes extends Object implements Serializable
A configuration object of all routes and error routes in the application. Simply use autoDiscoverViews(String...) to discover everything.

To speed up the tests, you can create one instance of this class only, then reuse that instance in every call to MockVaadin.setup(com.vaadin.browserless.internal.Routes, com.vaadin.browserless.internal.UIFactory, java.util.Set<? extends java.lang.Class<?>>, com.vaadin.browserless.BrowserlessConfiguration).

For internal use only. May be renamed or removed in a future release.

See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an empty configuration, with only MockRouteNotFoundError registered as an error route, and with the PWA initialization skipped.
    Routes(Set<Class<? extends com.vaadin.flow.component.Component>> routes, Set<Class<? extends com.vaadin.flow.router.HasErrorParameter<?>>> errorRoutes, Set<Class<? extends com.vaadin.flow.router.RouterLayout>> layouts, boolean skipPwaInit)
    Creates the configuration.
  • Method Summary

    Modifier and Type
    Method
    Description
    Auto-discovers everything in the whole classpath, registers it into this and returns this.
    autoDiscoverViews(String... packageNames)
    Auto-discovers everything, registers it into this and returns this.
    static void
    clearPwaClass(com.vaadin.flow.server.startup.ApplicationRouteRegistry registry)
    Clears the PWA class config from the given registry.
    copy(Set<Class<? extends com.vaadin.flow.component.Component>> routes, Set<Class<? extends com.vaadin.flow.router.HasErrorParameter<?>>> errorRoutes, Set<Class<? extends com.vaadin.flow.router.RouterLayout>> layouts, boolean skipPwaInit)
    Creates a new configuration with the given values; the sets are not copied.
    boolean
    equals(Object other)
     
    Set<Class<? extends com.vaadin.flow.router.HasErrorParameter<?>>>
    Returns all error views in the application.
    Set<Class<? extends com.vaadin.flow.router.RouterLayout>>
    Returns all Layout-annotated RouterLayout classes.
    Set<Class<? extends com.vaadin.flow.component.Component>>
    Returns all route views in the application.
    boolean
    Whether the PWA initialization code is skipped in Vaadin.
    int
     
    merge(Routes other)
    Creates a new configuration containing the routes, error routes and layouts of both this and the other configuration.
    void
    register(com.vaadin.flow.server.VaadinContext sc)
    Registers all routes to the Vaadin registry.
    void
    setSkipPwaInit(boolean skipPwaInit)
    Sets whether the PWA initialization code is skipped in Vaadin.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Routes

      public Routes(Set<Class<? extends com.vaadin.flow.component.Component>> routes, Set<Class<? extends com.vaadin.flow.router.HasErrorParameter<?>>> errorRoutes, Set<Class<? extends com.vaadin.flow.router.RouterLayout>> layouts, boolean skipPwaInit)
      Creates the configuration.
      Parameters:
      routes - the route views, mutable.
      errorRoutes - the error views, mutable.
      layouts - the Layout-annotated router layouts, mutable.
      skipPwaInit - whether to skip the PWA initialization.
    • Routes

      public Routes()
      Creates an empty configuration, with only MockRouteNotFoundError registered as an error route, and with the PWA initialization skipped.
  • Method Details

    • getRoutes

      public Set<Class<? extends com.vaadin.flow.component.Component>> getRoutes()
      Returns all route views in the application.
      Returns:
      the mutable set of route views.
    • getErrorRoutes

      public Set<Class<? extends com.vaadin.flow.router.HasErrorParameter<?>>> getErrorRoutes()
      Returns all error views in the application.
      Returns:
      the mutable set of error views.
    • getLayouts

      public Set<Class<? extends com.vaadin.flow.router.RouterLayout>> getLayouts()
      Returns all Layout-annotated RouterLayout classes.
      Returns:
      the mutable set of layouts.
    • getSkipPwaInit

      public boolean getSkipPwaInit()
      Whether the PWA initialization code is skipped in Vaadin.
      Returns:
      true if the PWA initialization is skipped.
    • setSkipPwaInit

      public void setSkipPwaInit(boolean skipPwaInit)
      Sets whether the PWA initialization code is skipped in Vaadin.
      Parameters:
      skipPwaInit - true to skip the PWA initialization.
    • register

      public void register(com.vaadin.flow.server.VaadinContext sc)
      Parameters:
      sc - the Vaadin context.
    • autoDiscoverViews

      public Routes autoDiscoverViews()
      Auto-discovers everything in the whole classpath, registers it into this and returns this. This is quite slow; consider autoDiscoverViews(String...) with package names instead.
      Returns:
      this
    • autoDiscoverViews

      public Routes autoDiscoverViews(String... packageNames)
      Auto-discovers everything, registers it into this and returns this.
      • Route-annotated views go into routes
      • HasErrorParameter error views go into errorRoutes
      After this function finishes, you can still modify the routes and errorRoutes sets, for example you can clear the errorRoutes if there is some kind of misdetection.
      Parameters:
      packageNames - set the package name for the detector to be faster; or provide null to scan the whole classpath, but this is quite slow.
      Returns:
      this
    • merge

      public Routes merge(Routes other)
      Creates a new configuration containing the routes, error routes and layouts of both this and the other configuration.
      Parameters:
      other - the other configuration.
      Returns:
      a new merged configuration; uses this configuration's skipPwaInit.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • copy

      public Routes copy(Set<Class<? extends com.vaadin.flow.component.Component>> routes, Set<Class<? extends com.vaadin.flow.router.HasErrorParameter<?>>> errorRoutes, Set<Class<? extends com.vaadin.flow.router.RouterLayout>> layouts, boolean skipPwaInit)
      Creates a new configuration with the given values; the sets are not copied.
      Parameters:
      routes - the route views.
      errorRoutes - the error views.
      layouts - the router layouts.
      skipPwaInit - whether to skip the PWA initialization.
      Returns:
      the new configuration.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • clearPwaClass

      public static void clearPwaClass(com.vaadin.flow.server.startup.ApplicationRouteRegistry registry)
      Clears the PWA class config from the given registry.
      Parameters:
      registry - the registry.