Package io.jmix.ui.testassist.junit
Class JmixUiTestExtension
java.lang.Object
io.jmix.ui.testassist.junit.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.ParameterResolver
,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, org.junit.jupiter.api.extension.ParameterResolver
Extension starts Vaadin UI before each test and configures screen packages,
main screen id, username to perform authentication. For instance:
@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {DemoApplication.class, UiTestAssistConfiguration.class}) public class UserBrowseTest { @RegisterExtension protected JmixUiTestExtension uiTestExtension = new JmixUiTestExtension() .withAuthenticatedUser("admin") .withScreenBasePackages("com.company.demo.screen") .withMainScreenId("MainScreen"); @Test protected void openUserBrowse(Screens screens) { UserBrowse screen = screens.create(UserBrowse.class); screen.show(); } }
Screens
bean can be obtained from method parameters or via BeanFactory.getBean(Class)
.- See Also:
-
Field Summary
-
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 org.springframework.context.ApplicationContext
getApplicationContext
(org.junit.jupiter.api.extension.ExtensionContext context) protected AppUI
getAppUI
(org.junit.jupiter.api.extension.ExtensionContext context) String[]
protected org.junit.jupiter.api.extension.ExtensionContext.Store
getStore
(org.junit.jupiter.api.extension.ExtensionContext context) protected void
openMainScreen
(org.junit.jupiter.api.extension.ExtensionContext context) void
postProcessTestInstance
(Object testInstance, org.junit.jupiter.api.extension.ExtensionContext context) protected void
registerScreenBasePackages
(org.junit.jupiter.api.extension.ExtensionContext context) protected void
removeAuthentication
(org.junit.jupiter.api.extension.ExtensionContext context) resolveParameter
(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) protected void
setupAuthentication
(org.junit.jupiter.api.extension.ExtensionContext context) protected void
setupVaadinUi
(org.junit.jupiter.api.extension.ExtensionContext context) boolean
supportsParameter
(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) withAuthenticatedUser
(String username) Sets username that should be authenticated before each test.withMainScreenId
(String mainScreenId) Sets main screen id that should be opened before each test.withScreenBasePackages
(String... screenBasePackages) Sets screen packages.
-
Field Details
-
APP_UI
- See Also:
-
SCREEN_PACKAGES
- See Also:
-
authenticatedUser
-
mainScreenId
-
screenBasePackages
-
-
Constructor Details
-
JmixUiTestExtension
public JmixUiTestExtension()
-
-
Method Details
-
getAuthenticatedUser
- Returns:
- username or
null
if not set
-
withAuthenticatedUser
Sets username that should be authenticated before each test. If username is not set, authentication will be performed by system user.- Parameters:
username
- username- Returns:
- current instance
-
getMainScreenId
- Returns:
- main screen id or
null
if not set
-
withMainScreenId
Sets main screen id that should be opened before each test. The screen with given id should be placed under the package provided bywithScreenBasePackages(String...)
.If main screen id is not set, the
UiProperties.getMainScreenId()
will be used.- Parameters:
mainScreenId
- main screen id- Returns:
- current instance
-
getScreenBasePackages
- Returns:
- screen packages or
null
if not set
-
withScreenBasePackages
Sets screen packages. Screens under these packages will be available in test. If packages are not set, all application screens will be available depending on the test's configuration.- Parameters:
screenBasePackages
- screen packages- Returns:
- current instance
-
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
-
supportsParameter
public boolean supportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException - Specified by:
supportsParameter
in interfaceorg.junit.jupiter.api.extension.ParameterResolver
- Throws:
org.junit.jupiter.api.extension.ParameterResolutionException
-
resolveParameter
public Object resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException - Specified by:
resolveParameter
in interfaceorg.junit.jupiter.api.extension.ParameterResolver
- Throws:
org.junit.jupiter.api.extension.ParameterResolutionException
-
setupAuthentication
protected void setupAuthentication(org.junit.jupiter.api.extension.ExtensionContext context) -
removeAuthentication
protected void removeAuthentication(org.junit.jupiter.api.extension.ExtensionContext context) -
setupVaadinUi
protected void setupVaadinUi(org.junit.jupiter.api.extension.ExtensionContext context) -
getApplicationContext
protected org.springframework.context.ApplicationContext getApplicationContext(org.junit.jupiter.api.extension.ExtensionContext context) -
getStore
protected org.junit.jupiter.api.extension.ExtensionContext.Store getStore(org.junit.jupiter.api.extension.ExtensionContext context) -
getAppUI
-
registerScreenBasePackages
protected void registerScreenBasePackages(org.junit.jupiter.api.extension.ExtensionContext context) -
openMainScreen
protected void openMainScreen(org.junit.jupiter.api.extension.ExtensionContext context) -
postProcessTestInstance
public void postProcessTestInstance(Object testInstance, org.junit.jupiter.api.extension.ExtensionContext context) - Specified by:
postProcessTestInstance
in interfaceorg.junit.jupiter.api.extension.TestInstancePostProcessor
-