Class SpringUIUnitTest
java.lang.Object
com.vaadin.testbench.uiunittest.AbstractUIUnitTest
com.vaadin.testbench.uiunittest.SpringUIUnitTest
- Direct Known Subclasses:
SpringSecurityUIUnitTest
Base class for unit testing Vaadin Spring applications.
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractUIUnitTest
AbstractUIUnitTest.DeploymentMode, AbstractUIUnitTest.QueryResult<T> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidafterContextRefresh(org.springframework.web.context.support.AnnotationConfigWebApplicationContext context) Hook invoked after the Spring context is refreshed.protected voidHook invoked before the Spring/Vaadin mock environment is created.protected voidconfigureContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext context) Customize the Spring web application context before it is refreshed.protected org.springframework.web.context.support.AnnotationConfigWebApplicationContextGet the active Spring application context.protected abstract Class<?>[]Spring configuration classes to register in the test context.protected AbstractUIUnitTest.DeploymentModeResolve deployment mode for the mocked Spring Vaadin service.protected com.vaadin.spring.server.SpringVaadinServletServiceGet the mock Vaadin service or create a new one if it doesn't exist.protected MockServletContextGet the mock servlet context used by the Spring context and Vaadin service.protected MockHttpSessionGet the mock HTTP session or create a new one if it doesn't exist.protected Class<? extends com.vaadin.ui.UI> The UI class to create.protected com.vaadin.server.VaadinServletRequestCreate a Vaadin servlet request for the mocked HTTP session and Spring Vaadin service.protected MockVaadinSessionGet the mock Vaadin session or create a new one if it doesn't exist.com.vaadin.ui.UICreate mocked Vaadin environment with blank UI without Atmosphere support.voidmockVaadin(com.vaadin.ui.UI ui) Create mocked Vaadin environment with given UI without Atmosphere support.protected <T extends com.vaadin.navigator.View>
TNavigate to a Vaadin Spring view using the view name fromSpringView.protected booleanWhether Spring Boot startup runners should be executed after refreshing the context.voidtearDown()Do clean-up of the mocked Vaadin created with mockVaadin methods.
-
Constructor Details
-
SpringUIUnitTest
public SpringUIUnitTest()
-
-
Method Details
-
mockVaadin
public com.vaadin.ui.UI mockVaadin() throws com.vaadin.server.ServiceExceptionDescription copied from class:AbstractUIUnitTestCreate 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:
mockVaadinin classAbstractUIUnitTest- 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:AbstractUIUnitTestCreate 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:
mockVaadinin classAbstractUIUnitTest- Parameters:
ui- UI instance- Throws:
com.vaadin.server.ServiceException- See Also:
-
tearDown
public void tearDown()Description copied from class:AbstractUIUnitTestDo clean-up of the mocked Vaadin created with mockVaadin methods. This may be necessary especially if custom UI have side effects.- Specified by:
tearDownin classAbstractUIUnitTest- See Also:
-
getConfigurationClasses
Spring configuration classes to register in the test context.- Returns:
- configuration classes
-
getUiClass
The UI class to create. By default, the class is resolved fromSpringUIProvider.- 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:
trueby default
-
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:
getDeploymentModein classAbstractUIUnitTest- Returns:
- deployment mode
-
getApplicationContext
protected org.springframework.web.context.support.AnnotationConfigWebApplicationContext getApplicationContext()Get the active Spring application context.- Returns:
- Spring context or
null
-
getServletContext
Get the mock servlet context used by the Spring context and Vaadin service.- Returns:
- mock servlet context
-
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.ServiceExceptionGet 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
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.ServiceExceptionCreate 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
-