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 Details

    • Routes

      public Routes(Set<Class<? extends Component>> routes, Set<Class<? extends HasErrorParameter<?>>> errorRoutes, Set<Class<? extends 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 Component>> getRoutes()
      Returns all route views in the application.
      Returns:
      the mutable set of route views.
    • getErrorRoutes

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

      public Set<Class<? extends 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(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. 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 Component>> routes, Set<Class<? extends HasErrorParameter<?>>> errorRoutes, Set<Class<? extends 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(ApplicationRouteRegistry registry)
      Clears the PWA class config from the given registry.
      Parameters:
      registry - the registry.