Class AbstractUIUnitTest

java.lang.Object
com.vaadin.testbench.uiunittest.AbstractUIUnitTest
Direct Known Subclasses:
UIUnitTest

public abstract class AbstractUIUnitTest extends Object
Base class for unit testing complex Vaadin Components and UIs. Mock and tear down methods are un-implemented at this level. Extend this class to create base class for different environments such as CDI and Spring by implementing the methods.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    AbstractUIUnitTest.QueryResult<T extends com.vaadin.server.ClientConnector>
    Result type for component searches.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    <T extends com.vaadin.server.ClientConnector>
    AbstractUIUnitTest.QueryResult<T>
    $(com.vaadin.ui.HasComponents container, Class<T> clazz)
    Find all components of given type recursively within the given component container.
    <T extends com.vaadin.server.ClientConnector>
    AbstractUIUnitTest.QueryResult<T>
    $(Class<T> clazz)
    Find all components of given type recursively within the UI.
    abstract com.vaadin.ui.UI
    Create mocked Vaadin environment with blank UI without Atmosphere support.
    abstract void
    mockVaadin(com.vaadin.ui.UI ui)
    Create mocked Vaadin environment with given UI without Atmosphere support.
    <T> T
    navigate(String name, Class<T> clazz)
    Navigate to a view
    void
    Print the component tree for debugging.
    abstract void
    Do clean-up of the mocked Vaadin created with mockVaadin methods.
    test(com.vaadin.ui.AbstractComponent component)
    Perform operations with the component as a user.
    <T extends Temporal & TemporalAdjuster & Serializable & Comparable<? super T>, R extends Enum<R>>
    AbstractDateFieldTester<T,R>
    test(com.vaadin.ui.AbstractDateField<T,R> component)
    Perform operations with the component as a user.
    test(com.vaadin.ui.AbstractField<T> component)
    Perform operations with the component as a user.
    test(com.vaadin.ui.AbstractMultiSelect<T> component)
    Perform operations with the component as a user.
    test(com.vaadin.ui.AbstractSingleSelect<T> component)
    Perform operations with the component as a user.
    test(com.vaadin.ui.Button component)
    Perform operations with the component as a user.
    test(com.vaadin.ui.ComboBox<T> component)
    Perform operations with the component as a user.
    <T> GridTester<T>
    test(com.vaadin.ui.Grid<T> component)
    Perform operations with the component as a user.
    test(com.vaadin.ui.MenuBar component)
    Perform operations with the component as a user.
    test(com.vaadin.ui.TabSheet component)
    Perform operations with the component as a user.
    test(com.vaadin.ui.TreeGrid<T> component)
    Perform operations with the component as a user.
    <T> void
    waitWhile(T param, Predicate<T> condition, int timeout)
    Utility method that waits while condition is true.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AbstractUIUnitTest

      public AbstractUIUnitTest()
  • Method Details

    • mockVaadin

      public abstract com.vaadin.ui.UI mockVaadin() throws com.vaadin.server.ServiceException
      Create mocked Vaadin environment with blank UI without Atmosphere support. This is enough for common use cases testing standalone server side components. Session is locked. UI and VaadinSession thread locals are set.
      Returns:
      Plank mock UI instance
      Throws:
      com.vaadin.server.ServiceException
      See Also:
    • mockVaadin

      public abstract void mockVaadin(com.vaadin.ui.UI ui) throws com.vaadin.server.ServiceException
      Create mocked Vaadin environment with given UI without Atmosphere support. This is makes possible to test more complex UI logic. Session is locked. UI and VaadinSession thread locals are set.
      Parameters:
      ui - UI instance
      Throws:
      com.vaadin.server.ServiceException
      See Also:
    • tearDown

      public abstract void tearDown()
      Do clean-up of the mocked Vaadin created with mockVaadin methods. This may be necessary especially if custom UI have side effects.
      See Also:
    • $

      public <T extends com.vaadin.server.ClientConnector> AbstractUIUnitTest.QueryResult<T> $(Class<T> clazz)
      Find all components of given type recursively within the UI.
      Type Parameters:
      T - Component type
      Parameters:
      clazz - Component class
      Returns:
      QueryResult of components
      See Also:
    • $

      public <T extends com.vaadin.server.ClientConnector> AbstractUIUnitTest.QueryResult<T> $(com.vaadin.ui.HasComponents container, Class<T> clazz)
      Find all components of given type recursively within the given component container.
      Type Parameters:
      T - Component type
      Parameters:
      container - Component container to search
      clazz - Component class
      Returns:
      QueryResult of components
      See Also:
    • test

      public ButtonTester test(com.vaadin.ui.Button component)
      Perform operations with the component as a user. E.g. if the operation fires an event as an side effect, it has isUserOriginated = true.
      Parameters:
      component - The component
      Returns:
      Tester for operations
    • test

      public <T> ComboBoxTester<T> test(com.vaadin.ui.ComboBox<T> component)
      Perform operations with the component as a user. E.g. if the operation fires an event as an side effect, it has isUserOriginated = true.
      Parameters:
      component - The component
      Returns:
      Tester for operations
    • test

      public <T extends Temporal & TemporalAdjuster & Serializable & Comparable<? super T>, R extends Enum<R>> AbstractDateFieldTester<T,R> test(com.vaadin.ui.AbstractDateField<T,R> component)
      Perform operations with the component as a user. E.g. if the operation fires an event as an side effect, it has isUserOriginated = true.
      Parameters:
      component - The component
      Returns:
      Tester for operations
    • test

      public TabSheetTester test(com.vaadin.ui.TabSheet component)
      Perform operations with the component as a user. E.g. if the operation fires an event as an side effect, it has isUserOriginated = true.
      Parameters:
      component - The component
      Returns:
      Tester for operations
    • test

      public <T> GridTester<T> test(com.vaadin.ui.Grid<T> component)
      Perform operations with the component as a user. E.g. if the operation fires an event as an side effect, it has isUserOriginated = true.
      Parameters:
      component - The component
      Returns:
      Tester for operations
    • test

      public <T> TreeGridTester<T> test(com.vaadin.ui.TreeGrid<T> component)
      Perform operations with the component as a user. E.g. if the operation fires an event as an side effect, it has isUserOriginated = true.
      Parameters:
      component - The component
      Returns:
      Tester for operations
    • test

      public <T> AbstractFieldTester<T> test(com.vaadin.ui.AbstractField<T> component)
      Perform operations with the component as a user. E.g. if the operation fires an event as an side effect, it has isUserOriginated = true.
      Parameters:
      component - The component
      Returns:
      Tester for operations
    • test

      public <T> AbstractSingleSelectTester<T> test(com.vaadin.ui.AbstractSingleSelect<T> component)
      Perform operations with the component as a user. E.g. if the operation fires an event as an side effect, it has isUserOriginated = true.
      Parameters:
      component - The component
      Returns:
      Tester for operations
    • test

      public <T> AbstractMultiSelectTester<T> test(com.vaadin.ui.AbstractMultiSelect<T> component)
      Perform operations with the component as a user. E.g. if the operation fires an event as an side effect, it has isUserOriginated = true.
      Parameters:
      component - The component
      Returns:
      Tester for operations
    • test

      public MenuBarTester test(com.vaadin.ui.MenuBar component)
      Perform operations with the component as a user. E.g. if the operation fires an event as an side effect, it has isUserOriginated = true.
      Parameters:
      component - The component
      Returns:
      Tester for operations
    • test

      public ComponentTester test(com.vaadin.ui.AbstractComponent component)
      Perform operations with the component as a user. E.g. if the operation fires an event as an side effect, it has isUserOriginated = true.
      Parameters:
      component - The component
      Returns:
      Tester for operations
    • printComponentTree

      public void printComponentTree()
      Print the component tree for debugging. This includes all components within the UI and all windows. Also notifications are printed. Indentation is used to indicate component hierarchy.
    • waitWhile

      public <T> void waitWhile(T param, Predicate<T> condition, int timeout)
      Utility method that waits while condition is true. Unlocks the mocked session and returns lock after wait ends. This is useful when waiting background thread activity to complete and letting ui.access to happen.
      Type Parameters:
      T - Parameter type
      Parameters:
      param - Parameter for the predicate
      condition - Boolean predicate, can be lambda expression
      timeout - Wait maximum seconds
      See Also:
      • UI.access(Runnable)