Class SpringUIUnitTest

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

public abstract class SpringUIUnitTest extends AbstractUIUnitTest
Base class for unit testing Vaadin Spring applications.
  • Constructor Details

    • SpringUIUnitTest

      public SpringUIUnitTest()
  • Method Details

    • mockVaadin

      public com.vaadin.ui.UI mockVaadin() throws com.vaadin.server.ServiceException
      Description copied from class: AbstractUIUnitTest
      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.
      Specified by:
      mockVaadin in class AbstractUIUnitTest
      Returns:
      Plank mock UI instance
      Throws:
      com.vaadin.server.ServiceException
      See Also:
    • mockVaadin

      public void mockVaadin(com.vaadin.ui.UI ui) throws com.vaadin.server.ServiceException
      Description copied from class: AbstractUIUnitTest
      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.
      Specified by:
      mockVaadin in class AbstractUIUnitTest
      Parameters:
      ui - UI instance
      Throws:
      com.vaadin.server.ServiceException
      See Also:
    • tearDown

      public void tearDown()
      Description copied from class: AbstractUIUnitTest
      Do clean-up of the mocked Vaadin created with mockVaadin methods. This may be necessary especially if custom UI have side effects.
      Specified by:
      tearDown in class AbstractUIUnitTest
      See Also:
    • getConfigurationClasses

      protected abstract Class<?>[] getConfigurationClasses()
      Spring configuration classes to register in the test context.
      Returns:
      configuration classes
    • getUiClass

      protected Class<? extends com.vaadin.ui.UI> getUiClass()
      The UI class to create. By default, the class is resolved from SpringUIProvider.
      Returns:
      UI class or null
    • configureContext

      protected void configureContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext context)
      Customize the Spring web application context before it is refreshed.
      Parameters:
      context - Spring context
    • beforeMockVaadin

      protected void beforeMockVaadin()
      Hook invoked before the Spring/Vaadin mock environment is created.
    • afterContextRefresh

      protected void afterContextRefresh(org.springframework.web.context.support.AnnotationConfigWebApplicationContext context)
      Hook invoked after the Spring context is refreshed.
      Parameters:
      context - Spring context
    • runSpringBootStartupRunners

      protected boolean runSpringBootStartupRunners()
      Whether Spring Boot startup runners should be executed after refreshing the context.
      Returns:
      true by default
    • getDeploymentMode

      protected AbstractUIUnitTest.DeploymentMode getDeploymentMode()
      Resolve deployment mode for the mocked Spring Vaadin service.

      Default is AbstractUIUnitTest.DeploymentMode.AUTO: it detects production mode from Spring properties and falls back to debug mode when no property is configured.

      Overrides:
      getDeploymentMode in class AbstractUIUnitTest
      Returns:
      deployment mode
    • getApplicationContext

      protected org.springframework.web.context.support.AnnotationConfigWebApplicationContext getApplicationContext()
      Get the active Spring application context.
      Returns:
      Spring context or null
    • getServletContext

      protected MockServletContext getServletContext()
      Get the mock servlet context used by the Spring context and Vaadin service.
      Returns:
      mock servlet context
    • getSession

      protected MockHttpSession getSession()
      Get the mock HTTP session or create a new one if it doesn't exist.
      Returns:
      mock HTTP session
    • getService

      protected com.vaadin.spring.server.SpringVaadinServletService getService() throws com.vaadin.server.ServiceException
      Get the mock Vaadin service or create a new one if it doesn't exist.
      Returns:
      Spring Vaadin service
      Throws:
      com.vaadin.server.ServiceException - if service initialization fails
    • getVaadinSession

      protected MockVaadinSession getVaadinSession() throws com.vaadin.server.ServiceException
      Get the mock Vaadin session or create a new one if it doesn't exist.
      Returns:
      mock Vaadin session
      Throws:
      com.vaadin.server.ServiceException - if service initialization fails
    • getVaadinRequest

      protected com.vaadin.server.VaadinServletRequest getVaadinRequest() throws com.vaadin.server.ServiceException
      Create a Vaadin servlet request for the mocked HTTP session and Spring Vaadin service.
      Returns:
      Vaadin servlet request
      Throws:
      com.vaadin.server.ServiceException - if service initialization fails