Class MockContext
- All Implemented Interfaces:
jakarta.servlet.ServletContext,Serializable
ServletContext, backed by the build output of the module
under test.
It models the three things Vaadin asks a context for: init parameters and
attributes, which are held in memory and are where the Lookup and the
ApplicationConfiguration end up; resource lookup, which serves the
files a deployed war would have; and logging, which goes to SLF4J.
Resources are resolved the way a war layout would resolve them, in this
order: the realPathRoots of the current module, then
META-INF/resources on the classpath (which is where a jar contributes
static files), then, for a /VAADIN/ path, the classpath root. A
/VAADIN/../ path is normalized and refused, as a container refuses to
serve outside the exposed directory.
Everything a test has no use for — servlet, filter and listener registration,
request dispatch, session tracking configuration — throws
UnsupportedOperationException rather than pretending to succeed, so a
test that needs one fails loudly instead of running against a fiction. The
reported servlet API version is 3.0, which is what Vaadin's own version
checks accept.
For internal use only. May be renamed or removed in a future release.
- See Also:
-
Field Summary
Fields inherited from interface jakarta.servlet.ServletContext
ORDERED_LIBS, TEMPDIR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionjakarta.servlet.FilterRegistration.Dynamicjakarta.servlet.FilterRegistration.Dynamicjakarta.servlet.FilterRegistration.Dynamicjakarta.servlet.ServletRegistration.DynamicaddJspFile(String servletName, String jspFile) voidaddListener(Class<? extends EventListener> listenerClass) voidaddListener(String className) <T extends EventListener>
voidaddListener(T t) jakarta.servlet.ServletRegistration.DynamicaddServlet(String servletName, jakarta.servlet.Servlet servlet) jakarta.servlet.ServletRegistration.DynamicaddServlet(String servletName, Class<? extends jakarta.servlet.Servlet> servletClass) jakarta.servlet.ServletRegistration.DynamicaddServlet(String servletName, String className) <T extends jakarta.servlet.Filter>
TcreateFilter(Class<T> clazz) <T extends EventListener>
TcreateListener(Class<T> clazz) <T extends jakarta.servlet.Servlet>
TcreateServlet(Class<T> clazz) voiddeclareRoles(String... roleNames) getAttribute(String name) jakarta.servlet.ServletContextgetContext(String uripath) Set<jakarta.servlet.SessionTrackingMode> intintSet<jakarta.servlet.SessionTrackingMode> jakarta.servlet.FilterRegistrationgetFilterRegistration(String filterName) getInitParameter(String name) Returns the context init parameters, live and directly modifiable.jakarta.servlet.descriptor.JspConfigDescriptorintgetMimeType(String file) intjakarta.servlet.RequestDispatchergetNamedDispatcher(String name) getRealPath(String path) Returns the module-relative foldersgetRealPath(String)resolves a path against, in order; the first one holding the file wins.jakarta.servlet.RequestDispatchergetRequestDispatcher(String path) getResource(String path) getResourceAsStream(String path) getResourcePaths(String path) jakarta.servlet.ServletRegistrationgetServletRegistration(String servletName) jakarta.servlet.SessionCookieConfigintvoidvoidvoidremoveAttribute(String name) voidsetAttribute(String name, Object value) booleansetInitParameter(String name, String value) voidsetRealPathRoots(List<String> realPathRoots) Replaces the foldersgetRealPath(String)resolves against.voidsetRequestCharacterEncoding(String encoding) voidsetResponseCharacterEncoding(String encoding) voidsetSessionTimeout(int sessionTimeout) voidsetSessionTrackingModes(Set<jakarta.servlet.SessionTrackingMode> sessionTrackingModes) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface jakarta.servlet.ServletContext
setRequestCharacterEncoding, setResponseCharacterEncoding
-
Constructor Details
-
MockContext
public MockContext()Creates an empty context.
-
-
Method Details
-
createServlet
- Specified by:
createServletin interfacejakarta.servlet.ServletContext
-
getEffectiveMajorVersion
public int getEffectiveMajorVersion()- Specified by:
getEffectiveMajorVersionin interfacejakarta.servlet.ServletContext
-
getResource
- Specified by:
getResourcein interfacejakarta.servlet.ServletContext- Throws:
MalformedURLException
-
addListener
- Specified by:
addListenerin interfacejakarta.servlet.ServletContext
-
addListener
- Specified by:
addListenerin interfacejakarta.servlet.ServletContext
-
addListener
- Specified by:
addListenerin interfacejakarta.servlet.ServletContext
-
getClassLoader
- Specified by:
getClassLoaderin interfacejakarta.servlet.ServletContext
-
getAttributeNames
- Specified by:
getAttributeNamesin interfacejakarta.servlet.ServletContext
-
getMajorVersion
public int getMajorVersion()- Specified by:
getMajorVersionin interfacejakarta.servlet.ServletContext
-
log
- Specified by:
login interfacejakarta.servlet.ServletContext
-
log
- Specified by:
login interfacejakarta.servlet.ServletContext
-
getFilterRegistration
- Specified by:
getFilterRegistrationin interfacejakarta.servlet.ServletContext
-
setSessionTrackingModes
- Specified by:
setSessionTrackingModesin interfacejakarta.servlet.ServletContext
-
setInitParameter
- Specified by:
setInitParameterin interfacejakarta.servlet.ServletContext
-
getResourceAsStream
- Specified by:
getResourceAsStreamin interfacejakarta.servlet.ServletContext
-
getNamedDispatcher
- Specified by:
getNamedDispatcherin interfacejakarta.servlet.ServletContext
-
getFilterRegistrations
- Specified by:
getFilterRegistrationsin interfacejakarta.servlet.ServletContext
-
getDefaultSessionTrackingModes
- Specified by:
getDefaultSessionTrackingModesin interfacejakarta.servlet.ServletContext
-
getMimeType
- Specified by:
getMimeTypein interfacejakarta.servlet.ServletContext
-
declareRoles
- Specified by:
declareRolesin interfacejakarta.servlet.ServletContext
-
createFilter
- Specified by:
createFilterin interfacejakarta.servlet.ServletContext
-
getRealPathRoots
Returns the module-relative foldersgetRealPath(String)resolves a path against, in order; the first one holding the file wins.These stand in for the war root of a deployed application. Defaults to
src/main/webapp/frontendandsrc/main/webapp.- Returns:
- the folders searched for a real path
-
setRealPathRoots
Replaces the foldersgetRealPath(String)resolves against. Point them elsewhere for a project that keeps its static files in another place.- Parameters:
realPathRoots- the module-relative folders to search, in order
-
getRealPath
- Specified by:
getRealPathin interfacejakarta.servlet.ServletContext
-
getInitParameters
Returns the context init parameters, live and directly modifiable.Writing here is not the same as calling
setInitParameter(String, String), which follows the servlet contract and refuses to overwrite a parameter that is already set. Most parameters are read once, whenApplicationConfigurationis first created and cached, so a value that has to be seen must be in place before anything else touches the context.- Returns:
- the init parameters
-
getInitParameter
- Specified by:
getInitParameterin interfacejakarta.servlet.ServletContext
-
getMinorVersion
public int getMinorVersion()- Specified by:
getMinorVersionin interfacejakarta.servlet.ServletContext
-
getJspConfigDescriptor
public jakarta.servlet.descriptor.JspConfigDescriptor getJspConfigDescriptor()- Specified by:
getJspConfigDescriptorin interfacejakarta.servlet.ServletContext
-
removeAttribute
- Specified by:
removeAttributein interfacejakarta.servlet.ServletContext
-
getServletContextName
- Specified by:
getServletContextNamein interfacejakarta.servlet.ServletContext
-
addFilter
- Specified by:
addFilterin interfacejakarta.servlet.ServletContext
-
addFilter
public jakarta.servlet.FilterRegistration.Dynamic addFilter(String filterName, jakarta.servlet.Filter filter) - Specified by:
addFilterin interfacejakarta.servlet.ServletContext
-
addFilter
public jakarta.servlet.FilterRegistration.Dynamic addFilter(String filterName, Class<? extends jakarta.servlet.Filter> filterClass) - Specified by:
addFilterin interfacejakarta.servlet.ServletContext
-
getContextPath
- Specified by:
getContextPathin interfacejakarta.servlet.ServletContext
-
getSessionCookieConfig
public jakarta.servlet.SessionCookieConfig getSessionCookieConfig()- Specified by:
getSessionCookieConfigin interfacejakarta.servlet.ServletContext
-
getVirtualServerName
- Specified by:
getVirtualServerNamein interfacejakarta.servlet.ServletContext
-
getSessionTimeout
public int getSessionTimeout()- Specified by:
getSessionTimeoutin interfacejakarta.servlet.ServletContext
-
setSessionTimeout
public void setSessionTimeout(int sessionTimeout) - Specified by:
setSessionTimeoutin interfacejakarta.servlet.ServletContext
-
getRequestCharacterEncoding
- Specified by:
getRequestCharacterEncodingin interfacejakarta.servlet.ServletContext
-
setRequestCharacterEncoding
- Specified by:
setRequestCharacterEncodingin interfacejakarta.servlet.ServletContext
-
getResponseCharacterEncoding
- Specified by:
getResponseCharacterEncodingin interfacejakarta.servlet.ServletContext
-
setResponseCharacterEncoding
- Specified by:
setResponseCharacterEncodingin interfacejakarta.servlet.ServletContext
-
getContext
- Specified by:
getContextin interfacejakarta.servlet.ServletContext
-
getRequestDispatcher
- Specified by:
getRequestDispatcherin interfacejakarta.servlet.ServletContext
-
getAttribute
- Specified by:
getAttributein interfacejakarta.servlet.ServletContext
-
setAttribute
- Specified by:
setAttributein interfacejakarta.servlet.ServletContext
-
getServletRegistration
- Specified by:
getServletRegistrationin interfacejakarta.servlet.ServletContext
-
createListener
- Specified by:
createListenerin interfacejakarta.servlet.ServletContext
-
addServlet
- Specified by:
addServletin interfacejakarta.servlet.ServletContext
-
addServlet
public jakarta.servlet.ServletRegistration.Dynamic addServlet(String servletName, jakarta.servlet.Servlet servlet) - Specified by:
addServletin interfacejakarta.servlet.ServletContext
-
addServlet
public jakarta.servlet.ServletRegistration.Dynamic addServlet(String servletName, Class<? extends jakarta.servlet.Servlet> servletClass) - Specified by:
addServletin interfacejakarta.servlet.ServletContext
-
addJspFile
- Specified by:
addJspFilein interfacejakarta.servlet.ServletContext
-
getEffectiveMinorVersion
public int getEffectiveMinorVersion()- Specified by:
getEffectiveMinorVersionin interfacejakarta.servlet.ServletContext
-
getServletRegistrations
- Specified by:
getServletRegistrationsin interfacejakarta.servlet.ServletContext
-
getResourcePaths
- Specified by:
getResourcePathsin interfacejakarta.servlet.ServletContext
-
getInitParameterNames
- Specified by:
getInitParameterNamesin interfacejakarta.servlet.ServletContext
-
getServerInfo
- Specified by:
getServerInfoin interfacejakarta.servlet.ServletContext
-
getEffectiveSessionTrackingModes
- Specified by:
getEffectiveSessionTrackingModesin interfacejakarta.servlet.ServletContext
-