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
public class MockVaadinServlet
extends com.vaadin.flow.server.VaadinServlet
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(com.vaadin.flow.server.VaadinService service, com.vaadin.flow.server.VaadinSession session) Applies the service's session lock check strategy to the given session, as Flow does for a session it creates itself.protected com.vaadin.flow.function.DeploymentConfigurationprotected com.vaadin.flow.server.VaadinServletServicecreateServletService(com.vaadin.flow.function.DeploymentConfiguration deploymentConfiguration) static com.vaadin.flow.server.VaadinSessioncreateVaadinSession(com.vaadin.flow.server.VaadinService service, com.vaadin.flow.server.VaadinRequest request) Creates a session by calling the protectedVaadinService.createVaadinSession(VaadinRequest).static com.vaadin.flow.server.WebBrowsercreateWebBrowser(com.vaadin.flow.server.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 com.vaadin.flow.function.DeploymentConfiguration createDeploymentConfiguration() throws jakarta.servlet.ServletException- Overrides:
createDeploymentConfigurationin classcom.vaadin.flow.server.VaadinServlet- Throws:
jakarta.servlet.ServletException
-
createServletService
protected com.vaadin.flow.server.VaadinServletService createServletService(com.vaadin.flow.function.DeploymentConfiguration deploymentConfiguration) throws com.vaadin.flow.server.ServiceException - Overrides:
createServletServicein classcom.vaadin.flow.server.VaadinServlet- Throws:
com.vaadin.flow.server.ServiceException
-
createWebBrowser
public static com.vaadin.flow.server.WebBrowser createWebBrowser(com.vaadin.flow.server.VaadinRequest request) 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
public static com.vaadin.flow.server.VaadinSession createVaadinSession(com.vaadin.flow.server.VaadinService service, com.vaadin.flow.server.VaadinRequest request) 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
public static void applySessionLockCheckStrategy(com.vaadin.flow.server.VaadinService service, com.vaadin.flow.server.VaadinSession session) 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
-