Package com.vaadin.browserless.mocks
Class MockVaadinServlet
java.lang.Object
jakarta.servlet.GenericServlet
jakarta.servlet.http.HttpServlet
com.vaadin.flow.server.VaadinServlet
com.vaadin.browserless.mocks.MockVaadinServlet
- All Implemented Interfaces:
jakarta.servlet.Servlet,jakarta.servlet.ServletConfig,Serializable
The
VaadinServlet of the mocked environment.
It registers the routes it was given into the route registry, which a
deployment would otherwise populate by classpath scanning at startup, and it
creates a MockService in place of a vanilla
VaadinServletService.
It also carries the static helpers that reach into Flow for things a test
cannot construct directly — a WebBrowser or a VaadinSession.
To use a custom servlet instead of this one, pass it to
MockVaadin.setup(com.vaadin.browserless.internal.Routes, com.vaadin.browserless.internal.UIFactory, java.util.Set<? extends java.lang.Class<?>>, com.vaadin.browserless.BrowserlessConfiguration).
For internal use only. May be renamed or removed in a future release.
- See Also:
-
Field Summary
Fields inherited from class com.vaadin.flow.server.VaadinServlet
INTERNAL_VAADIN_SERVLET_VITE_DEV_MODE_FRONTEND_PATHFields inherited from class jakarta.servlet.http.HttpServlet
LEGACY_DO_HEAD -
Constructor Summary
ConstructorsConstructorDescriptionCreates a servlet with no routes, producingMockedUIinstances.MockVaadinServlet(Routes routes) Creates a servlet serving the given routes, producingMockedUIinstances.MockVaadinServlet(Routes routes, UIFactory uiFactory) Creates a servlet serving the given routes, producing UIs from the given factory. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidapplySessionLockCheckStrategy(VaadinService service, VaadinSession session) Applies the service's session lock check strategy to the given session, as Flow does for a session it creates itself.protected DeploymentConfigurationCreates a deployment configuration to be used for the creation of aVaadinService.protected VaadinServletServicecreateServletService(DeploymentConfiguration deploymentConfiguration) Creates a vaadin servlet service.static VaadinSessioncreateVaadinSession(VaadinService service, VaadinRequest request) Creates a session by calling the protectedVaadinService.createVaadinSession(VaadinRequest).static WebBrowsercreateWebBrowser(VaadinRequest request) Creates the browser details the session reports.Returns the routes this servlet registers.Returns the factory creating theUIof the session that replaces a closed session of this servlet.Methods inherited from class com.vaadin.flow.server.VaadinServlet
createDeploymentConfiguration, createServletService, createStaticFileHandler, createVaadinRequest, destroy, getCurrent, getFrontendMapping, getLastPathParameter, getService, getServletConfig, handleContextOrServletRootWithoutSlash, init, serveStaticOrWebJarRequest, service, servletInitialized, whenFrontendMappingAvailableMethods inherited from class jakarta.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPatch, doPost, doPut, doTrace, getLastModified, isSensitiveHeader, serviceMethods inherited from class jakarta.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletContext, getServletInfo, getServletName, init, log, log
-
Constructor Details
-
MockVaadinServlet
public MockVaadinServlet()Creates a servlet with no routes, producingMockedUIinstances. -
MockVaadinServlet
Creates a servlet serving the given routes, producingMockedUIinstances.- Parameters:
routes- the routes to register
-
MockVaadinServlet
Creates a servlet serving the given routes, producing UIs from the given factory.- Parameters:
routes- the routes to registeruiFactory- creates the UI of the session that replaces a closed session; it must return a fresh instance every time
-
-
Method Details
-
getRoutes
Returns the routes this servlet registers.- Returns:
- the routes
-
getUiFactory
Returns the factory creating theUIof the session that replaces a closed session of this servlet.- Returns:
- the UI factory
-
createDeploymentConfiguration
protected DeploymentConfiguration createDeploymentConfiguration() throws jakarta.servlet.ServletExceptionDescription copied from class:VaadinServletCreates a deployment configuration to be used for the creation of aVaadinService. Intended to be used by dependency injection frameworks.- Overrides:
createDeploymentConfigurationin classVaadinServlet- Returns:
- the created deployment configuration
- Throws:
jakarta.servlet.ServletException- if creating the deployment configuration fails
-
createServletService
protected VaadinServletService createServletService(DeploymentConfiguration deploymentConfiguration) throws ServiceException Description copied from class:VaadinServletCreates a vaadin servlet service.- Overrides:
createServletServicein classVaadinServlet- Parameters:
deploymentConfiguration- the deployment configuration to be used- Returns:
- the created vaadin servlet service
- Throws:
ServiceException- if creating the vaadin servlet service fails
-
createWebBrowser
Creates the browser details the session reports. They are derived from the request'sUser-Agentheader.- Parameters:
request- the request the browser details are taken from- Returns:
- the browser details
-
createVaadinSession
Creates a session by calling the protectedVaadinService.createVaadinSession(VaadinRequest). The session is only constructed: locking it and storing it in the HTTP session are left to the caller.- Parameters:
service- the service the session belongs torequest- the request the session is created for- Returns:
- the new session
-
applySessionLockCheckStrategy
Applies the service's session lock check strategy to the given session, as Flow does for a session it creates itself.- Parameters:
service- the service the session belongs tosession- the session to apply the strategy to
-