Package io.jmix.flowui.testassist
Class JmixUiTestExtension
java.lang.Object
io.jmix.flowui.testassist.JmixUiTestExtension
- All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterEachCallback
,org.junit.jupiter.api.extension.BeforeEachCallback
,org.junit.jupiter.api.extension.Extension
,org.junit.jupiter.api.extension.TestInstancePostProcessor
public class JmixUiTestExtension
extends Object
implements org.junit.jupiter.api.extension.TestInstancePostProcessor, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.AfterEachCallback
Extension starts Vaadin Flow before each test and configures view packages and authentication.
For instance:
@SpringBootTest(classes = {TestAssistApplication.class, FlowuiTestAssistConfiguration.class}) public class UserViewsTest { @RegisterExtension private JmixUiTestExtension extension = new JmixUiTestExtension(); @Autowired private ViewNavigators viewNavigators; @Test public void navigateToUserListView() { viewNavigators.view(UserListView.class) .navigate(); UserListView view = UiTestUtils.getCurrentView(); CollectionContainer<User> usersDc = ViewControllerUtils.getViewData(view) .getContainer("usersDc"); Assertions.assertTrue(usersDc.getItems().size() > 0); } }For annotation based approach use
UiTest
annotation to configure the extension.-
Field Summary
Modifier and TypeFieldDescriptionprotected com.vaadin.flow.component.UI
protected UiTestAuthenticator
protected com.vaadin.flow.server.VaadinSession
protected String[]
static final String
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
afterEach
(org.junit.jupiter.api.extension.ExtensionContext context) void
beforeEach
(org.junit.jupiter.api.extension.ExtensionContext context) protected void
clearViewBasePackages
(org.junit.jupiter.api.extension.ExtensionContext context) protected void
closeOpenedDialogs
(org.junit.jupiter.api.extension.ExtensionContext context) protected void
closeOpenedNotifications
(org.junit.jupiter.api.extension.ExtensionContext context) protected ViewControllersConfiguration
createViewControllersConfiguration
(org.springframework.context.ApplicationContext applicationContext, List<String> viewBasePackages) protected org.springframework.context.ApplicationContext
getApplicationContext
(org.junit.jupiter.api.extension.ExtensionContext context) getDefaultInitialViewClass
(org.junit.jupiter.api.extension.ExtensionContext context) getDefaultParentChain
(org.junit.jupiter.api.extension.ExtensionContext context) getInitialViewFromAnnotation
(org.junit.jupiter.api.extension.ExtensionContext context) getParentChain
(com.vaadin.flow.router.Route route, List<Class<? extends com.vaadin.flow.router.RouterLayout>> defaultChain) protected UiTestAuthenticator
getTestAuthenticatorFromAnnotation
(org.junit.jupiter.api.extension.ExtensionContext context) String[]
protected String[]
getViewBasePackagesToRegister
(org.junit.jupiter.api.extension.ExtensionContext context) protected boolean
isClassInPackages
(String classPackage, List<String> viewBasePackages) void
postProcessTestInstance
(Object testInstance, org.junit.jupiter.api.extension.ExtensionContext context) protected void
registerViewBasePackages
(org.junit.jupiter.api.extension.ExtensionContext context) protected void
registerViewRoutes
(List<String> viewBasePackages, org.junit.jupiter.api.extension.ExtensionContext context) protected void
removeAuthentication
(org.junit.jupiter.api.extension.ExtensionContext context) protected void
setupAuthentication
(org.junit.jupiter.api.extension.ExtensionContext context) protected void
setupVaadin
(org.junit.jupiter.api.extension.ExtensionContext context) protected void
setViewControllersConfigurations
(org.junit.jupiter.api.extension.ExtensionContext context, List<ViewControllersConfiguration> configurations) withInitialView
(Class<? extends View> initialView) Sets an initial view that will be opened before each test.withTestAuthenticator
(UiTestAuthenticator uiTestAuthenticator) Sets authentication management provider that will be used in tests before/after each test.withViewBasePackages
(String... viewBasePackages) Sets view base packages.
-
Field Details
-
WINDOW_NAME
- See Also:
-
viewBasePackages
-
vaadinSession
protected com.vaadin.flow.server.VaadinSession vaadinSession -
ui
protected com.vaadin.flow.component.UI ui -
uiTestAuthenticator
-
initialView
-
-
Constructor Details
-
JmixUiTestExtension
public JmixUiTestExtension()
-
-
Method Details
-
getViewBasePackages
- Returns:
- view base packages or
null
if not set
-
withViewBasePackages
Sets view base packages. Views under these packages will be available in test.Note that depending on the test's configuration all application views may be available.
- Parameters:
viewBasePackages
- view base packages- Returns:
- current instance of extension
-
getTestAuthenticator
- Returns:
- authenticator or
null
if not set
-
withTestAuthenticator
Sets authentication management provider that will be used in tests before/after each test.Provided authenticator will override a bean implementing
UiTestAuthenticator
for the test class.- Parameters:
uiTestAuthenticator
- authenticator to set- Returns:
- current instance of extension
- See Also:
-
getInitialView
- Returns:
- initial view or
null
if not set
-
withInitialView
Sets an initial view that will be opened before each test.Note that for application tests, by default, the Main View class specified in the application properties will be used. If it does not exist, the
InitialView
will be used instead.- Parameters:
initialView
- the view to set- Returns:
- current instance of extension
-
postProcessTestInstance
public void postProcessTestInstance(Object testInstance, org.junit.jupiter.api.extension.ExtensionContext context) throws Exception - Specified by:
postProcessTestInstance
in interfaceorg.junit.jupiter.api.extension.TestInstancePostProcessor
- Throws:
Exception
-
beforeEach
- Specified by:
beforeEach
in interfaceorg.junit.jupiter.api.extension.BeforeEachCallback
- Throws:
Exception
-
afterEach
- Specified by:
afterEach
in interfaceorg.junit.jupiter.api.extension.AfterEachCallback
- Throws:
Exception
-
setupVaadin
protected void setupVaadin(org.junit.jupiter.api.extension.ExtensionContext context) -
registerViewBasePackages
protected void registerViewBasePackages(org.junit.jupiter.api.extension.ExtensionContext context) -
createViewControllersConfiguration
protected ViewControllersConfiguration createViewControllersConfiguration(org.springframework.context.ApplicationContext applicationContext, List<String> viewBasePackages) -
registerViewRoutes
-
getParentChain
-
getDefaultParentChain
-
isClassInPackages
-
setupAuthentication
protected void setupAuthentication(org.junit.jupiter.api.extension.ExtensionContext context) -
removeAuthentication
protected void removeAuthentication(org.junit.jupiter.api.extension.ExtensionContext context) -
clearViewBasePackages
protected void clearViewBasePackages(org.junit.jupiter.api.extension.ExtensionContext context) -
closeOpenedNotifications
protected void closeOpenedNotifications(org.junit.jupiter.api.extension.ExtensionContext context) -
closeOpenedDialogs
protected void closeOpenedDialogs(org.junit.jupiter.api.extension.ExtensionContext context) -
getTestAuthenticatorFromAnnotation
@Nullable protected UiTestAuthenticator getTestAuthenticatorFromAnnotation(org.junit.jupiter.api.extension.ExtensionContext context) -
getInitialViewFromAnnotation
-
getViewBasePackagesToRegister
protected String[] getViewBasePackagesToRegister(org.junit.jupiter.api.extension.ExtensionContext context) -
setViewControllersConfigurations
protected void setViewControllersConfigurations(org.junit.jupiter.api.extension.ExtensionContext context, List<ViewControllersConfiguration> configurations) -
getApplicationContext
protected org.springframework.context.ApplicationContext getApplicationContext(org.junit.jupiter.api.extension.ExtensionContext context) -
getDefaultInitialViewClass
-