Package com.vaadin.testbench.unit.mocks
Class MockSpringServlet
java.lang.Object
jakarta.servlet.GenericServlet
jakarta.servlet.http.HttpServlet
com.vaadin.flow.server.VaadinServlet
com.vaadin.flow.spring.SpringServlet
com.vaadin.testbench.unit.mocks.MockSpringServlet
- All Implemented Interfaces:
jakarta.servlet.Servlet
,jakarta.servlet.ServletConfig
,Serializable
Makes sure that the
routes
are properly registered, and that
MockSpringServletService
is used instead of vanilla
SpringVaadinServletService
.- Author:
- mavi
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal org.springframework.context.ApplicationContext
final com.vaadin.testbench.unit.internal.Routes
final kotlin.jvm.functions.Function0<UI>
Fields inherited from class com.vaadin.flow.spring.SpringServlet
PROPERTY_NAMES
Fields inherited from class com.vaadin.flow.server.VaadinServlet
INTERNAL_VAADIN_SERVLET_VITE_DEV_MODE_FRONTEND_PATH
Fields inherited from class jakarta.servlet.http.HttpServlet
LEGACY_DO_HEAD
-
Constructor Summary
ConstructorsConstructorDescriptionMockSpringServlet
(com.vaadin.testbench.unit.internal.Routes routes, org.springframework.context.ApplicationContext ctx, kotlin.jvm.functions.Function0<UI> uiFactory) -
Method Summary
Modifier and TypeMethodDescriptionstatic void
applySpringSecurityIfPresent
(com.vaadin.testbench.unit.mocks.MockRequest request) Augments the mock HTTP request backed by Vaadin request, with authentication information provided by Spring Security framework.protected DeploymentConfiguration
Creates a deployment configuration to be used for the creation of aVaadinService
.protected VaadinServletService
createServletService
(DeploymentConfiguration deploymentConfiguration) Creates a vaadin servlet service.protected VaadinServletRequest
createVaadinRequest
(jakarta.servlet.http.HttpServletRequest request) Creates a Vaadin request for a http servlet request.Methods inherited from class com.vaadin.flow.spring.SpringServlet
createDeploymentConfiguration, service
Methods inherited from class com.vaadin.flow.server.VaadinServlet
createServletService, createStaticFileHandler, destroy, getCurrent, getFrontendMapping, getLastPathParameter, getService, getServletConfig, handleContextOrServletRootWithoutSlash, init, serveStaticOrWebJarRequest, servletInitialized, whenFrontendMappingAvailable
Methods inherited from class jakarta.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
Methods inherited from class jakarta.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletContext, getServletInfo, getServletName, init, log, log
-
Field Details
-
routes
@NotNull public final com.vaadin.testbench.unit.internal.Routes routes -
ctx
@NotNull public final org.springframework.context.ApplicationContext ctx -
uiFactory
-
-
Constructor Details
-
MockSpringServlet
public MockSpringServlet(@NotNull com.vaadin.testbench.unit.internal.Routes routes, @NotNull org.springframework.context.ApplicationContext ctx, @NotNull kotlin.jvm.functions.Function0<UI> uiFactory)
-
-
Method Details
-
createDeploymentConfiguration
protected DeploymentConfiguration createDeploymentConfiguration() throws jakarta.servlet.ServletExceptionDescription copied from class:VaadinServlet
Creates a deployment configuration to be used for the creation of aVaadinService
. Intended to be used by dependency injection frameworks.- Overrides:
createDeploymentConfiguration
in classVaadinServlet
- Returns:
- the created deployment configuration
- Throws:
jakarta.servlet.ServletException
-
createServletService
protected VaadinServletService createServletService(DeploymentConfiguration deploymentConfiguration) throws ServiceException Description copied from class:VaadinServlet
Creates a vaadin servlet service.- Overrides:
createServletService
in classSpringServlet
- Parameters:
deploymentConfiguration
- the deployment configuration to be used- Returns:
- the created vaadin servlet service
- Throws:
ServiceException
- if creating the vaadin servlet service fails
-
createVaadinRequest
Description copied from class:VaadinServlet
Creates a Vaadin request for a http servlet request. This method can be overridden if the Vaadin request should have special properties.- Overrides:
createVaadinRequest
in classVaadinServlet
- Parameters:
request
- the original http servlet request- Returns:
- a Vaadin request for the original request
-
applySpringSecurityIfPresent
public static void applySpringSecurityIfPresent(com.vaadin.testbench.unit.mocks.MockRequest request) Augments the mock HTTP request backed by Vaadin request, with authentication information provided by Spring Security framework. Nothing is done if Spring Security is not present on classpath.- Parameters:
request
- the mock request instance
-