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.BeforeAllCallback,org.junit.jupiter.api.extension.BeforeEachCallback,org.junit.jupiter.api.extension.Extension
public class JmixUiTestExtension
extends Object
implements org.junit.jupiter.api.extension.BeforeAllCallback, 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 = ViewsHelper.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
FieldsModifier and TypeFieldDescriptionprotected com.vaadin.flow.component.UIprotected UiTestAuthenticatorprotected com.vaadin.flow.server.VaadinSessionstatic final Stringprotected String[] -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidafterEach(org.junit.jupiter.api.extension.ExtensionContext context) voidbeforeAll(org.junit.jupiter.api.extension.ExtensionContext context) voidbeforeEach(org.junit.jupiter.api.extension.ExtensionContext context) protected org.springframework.context.ApplicationContextgetApplicationContext(org.junit.jupiter.api.extension.ExtensionContext context) protected org.junit.jupiter.api.extension.ExtensionContext.StoregetStore(org.junit.jupiter.api.extension.ExtensionContext context) protected UiTestAuthenticatorgetTestAuthenticatorFromAnnotation(org.junit.jupiter.api.extension.ExtensionContext context) String[]protected booleanisClassInPackages(String classPackage, String[] viewBasePackages) protected voidregisterViewBasePackages(org.junit.jupiter.api.extension.ExtensionContext context) protected voidregisterViewRoutes(String[] viewBasePackages, org.junit.jupiter.api.extension.ExtensionContext context) protected voidremoveAuthentication(org.junit.jupiter.api.extension.ExtensionContext context) protected voidsetupAuthentication(org.junit.jupiter.api.extension.ExtensionContext context) protected voidsetupVaadin(org.junit.jupiter.api.extension.ExtensionContext context) 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
-
VIEW_PACKAGES
- See Also:
-
viewBasePackages
-
vaadinSession
protected com.vaadin.flow.server.VaadinSession vaadinSession -
ui
protected com.vaadin.flow.component.UI ui -
uiTestAuthenticator
-
-
Constructor Details
-
JmixUiTestExtension
public JmixUiTestExtension()
-
-
Method Details
-
getViewBasePackages
- Returns:
- view base packages or
nullif 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
nullif not set
-
withTestAuthenticator
Sets authentication management provider that will be used in tests before/after each test.Provided authenticator will override a bean implementing
UiTestAuthenticatorfor the test class.- Parameters:
uiTestAuthenticator- authenticator to set- Returns:
- current instance of extension
- See Also:
-
beforeAll
- Specified by:
beforeAllin interfaceorg.junit.jupiter.api.extension.BeforeAllCallback- Throws:
Exception
-
beforeEach
- Specified by:
beforeEachin interfaceorg.junit.jupiter.api.extension.BeforeEachCallback- Throws:
Exception
-
afterEach
- Specified by:
afterEachin 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) -
registerViewRoutes
protected void registerViewRoutes(String[] viewBasePackages, org.junit.jupiter.api.extension.ExtensionContext context) -
isClassInPackages
-
setupAuthentication
protected void setupAuthentication(org.junit.jupiter.api.extension.ExtensionContext context) -
removeAuthentication
protected void removeAuthentication(org.junit.jupiter.api.extension.ExtensionContext context) -
getTestAuthenticatorFromAnnotation
@Nullable protected UiTestAuthenticator getTestAuthenticatorFromAnnotation(org.junit.jupiter.api.extension.ExtensionContext context) -
getStore
protected org.junit.jupiter.api.extension.ExtensionContext.Store getStore(org.junit.jupiter.api.extension.ExtensionContext context) -
getApplicationContext
protected org.springframework.context.ApplicationContext getApplicationContext(org.junit.jupiter.api.extension.ExtensionContext context)
-