Class MockServletContextImpl
java.lang.Object
io.github.cdiunit.internal.servlet5.MockServletContextImpl
- All Implemented Interfaces:
jakarta.servlet.ServletContext
Shamlessly ripped from mockrunner.
- Author:
- Various
-
Field Summary
Fields inherited from interface jakarta.servlet.ServletContext
ORDERED_LIBS, TEMPDIR
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAttributeListener
(jakarta.servlet.ServletContextAttributeListener listener) jakarta.servlet.FilterRegistration.Dynamic
jakarta.servlet.FilterRegistration.Dynamic
jakarta.servlet.FilterRegistration.Dynamic
jakarta.servlet.ServletRegistration.Dynamic
addJspFile
(String servletName, String jspFile) void
addListener
(Class<? extends EventListener> listenerClass) void
addListener
(String className) <T extends EventListener>
voidaddListener
(T t) void
addResourcePath
(String path, String resourcePath) void
addResourcePaths
(String path, Collection pathes) jakarta.servlet.ServletRegistration.Dynamic
addServlet
(String servletName, jakarta.servlet.Servlet servlet) jakarta.servlet.ServletRegistration.Dynamic
addServlet
(String servletName, Class<? extends jakarta.servlet.Servlet> servletClass) jakarta.servlet.ServletRegistration.Dynamic
addServlet
(String servletName, String className) void
void
Clears the init parameters.void
Clears the map ofRequestDispatcher
objects.<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) void
declareRoles
(String... roleNames) getAttribute
(String key) jakarta.servlet.ServletContext
getContext
(String url) Set<jakarta.servlet.SessionTrackingMode>
int
int
Set<jakarta.servlet.SessionTrackingMode>
jakarta.servlet.FilterRegistration
getFilterRegistration
(String filterName) getInitParameter
(String name) jakarta.servlet.descriptor.JspConfigDescriptor
int
getMimeType
(String file) int
jakarta.servlet.RequestDispatcher
getNamedDispatcher
(String name) getRealPath
(String path) jakarta.servlet.RequestDispatcher
getRequestDispatcher
(String path) Returns the map ofRequestDispatcher
objects.getResource
(String path) getResourceAsStream
(String path) getResourcePaths
(String path) jakarta.servlet.Servlet
getServlet
(String arg0) jakarta.servlet.ServletRegistration
getServletRegistration
(String servletName) jakarta.servlet.SessionCookieConfig
int
void
void
void
void
removeAttribute
(String key) void
resetAll()
Resets the state of this object to the default valuesvoid
setAttribute
(String key, Object value) void
setContext
(String url, jakarta.servlet.ServletContext context) Sets aServletContext
that will be returned when callinggetContext(java.lang.String)
void
setContextPath
(String contextPath) void
setEffectiveMajorVersion
(int effectiveMajorVersion) void
setEffectiveMinorVersion
(int effectiveMinorVersion) boolean
setInitParameter
(String name, String value) Sets an init parameter.void
setInitParameters
(Map parameters) Sets several init parameters.void
setMajorVersion
(int majorVersion) void
setMimeType
(String file, String type) void
setMinorVersion
(int minorVersion) void
setRealPath
(String path, String realPath) void
setRequestCharacterEncoding
(String encoding) void
setRequestDispatcher
(String path, jakarta.servlet.RequestDispatcher dispatcher) Sets aRequestDispatcher
that will be returned when callinggetRequestDispatcher(java.lang.String)
orgetNamedDispatcher(java.lang.String)
with the specified path or name.void
setResource
(String path, URL url) void
setResourceAsStream
(String path, byte[] data) void
setResourceAsStream
(String path, InputStream inputStream) void
setResponseCharacterEncoding
(String encoding) void
setServletContextName
(String servletContextName) void
setSessionTimeout
(int sessionTimeout) void
setSessionTrackingModes
(Set<jakarta.servlet.SessionTrackingMode> sessionTrackingModes)
-
Constructor Details
-
MockServletContextImpl
public MockServletContextImpl()
-
-
Method Details
-
resetAll
public void resetAll()Resets the state of this object to the default values -
addAttributeListener
public void addAttributeListener(jakarta.servlet.ServletContextAttributeListener listener) -
clearAttributes
public void clearAttributes() -
getAttribute
- Specified by:
getAttribute
in interfacejakarta.servlet.ServletContext
-
getAttributeNames
- Specified by:
getAttributeNames
in interfacejakarta.servlet.ServletContext
-
removeAttribute
- Specified by:
removeAttribute
in interfacejakarta.servlet.ServletContext
-
setAttribute
- Specified by:
setAttribute
in interfacejakarta.servlet.ServletContext
-
getNamedDispatcher
- Specified by:
getNamedDispatcher
in interfacejakarta.servlet.ServletContext
-
getRequestDispatcher
- Specified by:
getRequestDispatcher
in interfacejakarta.servlet.ServletContext
-
getRequestDispatcherMap
Returns the map ofRequestDispatcher
objects. The specified path maps to the correspondingRequestDispatcher
object.- Returns:
- the map of
RequestDispatcher
objects
-
clearRequestDispatcherMap
public void clearRequestDispatcherMap()Clears the map ofRequestDispatcher
objects. -
setRequestDispatcher
Sets aRequestDispatcher
that will be returned when callinggetRequestDispatcher(java.lang.String)
orgetNamedDispatcher(java.lang.String)
with the specified path or name. If noRequestDispatcher
is set for the specified path,getRequestDispatcher(java.lang.String)
andgetNamedDispatcher(java.lang.String)
automatically create a new one.- Parameters:
path
- the path for theRequestDispatcher
dispatcher
- theRequestDispatcher
object
-
getContext
- Specified by:
getContext
in interfacejakarta.servlet.ServletContext
-
setContext
Sets aServletContext
that will be returned when callinggetContext(java.lang.String)
- Parameters:
url
- the URLcontext
- theServletContext
-
clearInitParameters
public void clearInitParameters()Clears the init parameters. -
getInitParameter
- Specified by:
getInitParameter
in interfacejakarta.servlet.ServletContext
-
setInitParameter
Sets an init parameter. This method does not overwrite existing init parameters.- Specified by:
setInitParameter
in interfacejakarta.servlet.ServletContext
- Parameters:
name
- the namevalue
- the value- Returns:
false
if the parameter was not settrue
otherwise
-
setInitParameters
Sets several init parameters. This method does overwrite existing init parameters.- Parameters:
parameters
- the parameter map
-
getInitParameterNames
- Specified by:
getInitParameterNames
in interfacejakarta.servlet.ServletContext
-
getMajorVersion
public int getMajorVersion()- Specified by:
getMajorVersion
in interfacejakarta.servlet.ServletContext
-
setMajorVersion
public void setMajorVersion(int majorVersion) -
getMinorVersion
public int getMinorVersion()- Specified by:
getMinorVersion
in interfacejakarta.servlet.ServletContext
-
setMinorVersion
public void setMinorVersion(int minorVersion) -
getEffectiveMajorVersion
public int getEffectiveMajorVersion()- Specified by:
getEffectiveMajorVersion
in interfacejakarta.servlet.ServletContext
-
setEffectiveMajorVersion
public void setEffectiveMajorVersion(int effectiveMajorVersion) -
getEffectiveMinorVersion
public int getEffectiveMinorVersion()- Specified by:
getEffectiveMinorVersion
in interfacejakarta.servlet.ServletContext
-
setEffectiveMinorVersion
public void setEffectiveMinorVersion(int effectiveMinorVersion) -
getMimeType
- Specified by:
getMimeType
in interfacejakarta.servlet.ServletContext
-
setMimeType
-
getRealPath
- Specified by:
getRealPath
in interfacejakarta.servlet.ServletContext
-
setRealPath
-
getResource
- Specified by:
getResource
in interfacejakarta.servlet.ServletContext
- Throws:
MalformedURLException
-
setResource
-
getResourceAsStream
- Specified by:
getResourceAsStream
in interfacejakarta.servlet.ServletContext
-
setResourceAsStream
-
setResourceAsStream
-
getResourcePaths
- Specified by:
getResourcePaths
in interfacejakarta.servlet.ServletContext
-
addResourcePaths
-
addResourcePath
-
getServerInfo
- Specified by:
getServerInfo
in interfacejakarta.servlet.ServletContext
-
getServlet
- Specified by:
getServlet
in interfacejakarta.servlet.ServletContext
- Throws:
jakarta.servlet.ServletException
-
getServletContextName
- Specified by:
getServletContextName
in interfacejakarta.servlet.ServletContext
-
setServletContextName
-
getContextPath
- Specified by:
getContextPath
in interfacejakarta.servlet.ServletContext
-
setContextPath
-
getServletNames
- Specified by:
getServletNames
in interfacejakarta.servlet.ServletContext
-
getServlets
- Specified by:
getServlets
in interfacejakarta.servlet.ServletContext
-
log
- Specified by:
log
in interfacejakarta.servlet.ServletContext
-
log
- Specified by:
log
in interfacejakarta.servlet.ServletContext
-
log
- Specified by:
log
in interfacejakarta.servlet.ServletContext
-
addServlet
- Specified by:
addServlet
in interfacejakarta.servlet.ServletContext
-
addServlet
public jakarta.servlet.ServletRegistration.Dynamic addServlet(String servletName, jakarta.servlet.Servlet servlet) - Specified by:
addServlet
in interfacejakarta.servlet.ServletContext
-
addServlet
public jakarta.servlet.ServletRegistration.Dynamic addServlet(String servletName, Class<? extends jakarta.servlet.Servlet> servletClass) - Specified by:
addServlet
in interfacejakarta.servlet.ServletContext
-
addJspFile
- Specified by:
addJspFile
in interfacejakarta.servlet.ServletContext
-
createServlet
public <T extends jakarta.servlet.Servlet> T createServlet(Class<T> clazz) throws jakarta.servlet.ServletException - Specified by:
createServlet
in interfacejakarta.servlet.ServletContext
- Throws:
jakarta.servlet.ServletException
-
getServletRegistration
- Specified by:
getServletRegistration
in interfacejakarta.servlet.ServletContext
-
getServletRegistrations
- Specified by:
getServletRegistrations
in interfacejakarta.servlet.ServletContext
-
addFilter
- Specified by:
addFilter
in interfacejakarta.servlet.ServletContext
-
addFilter
public jakarta.servlet.FilterRegistration.Dynamic addFilter(String filterName, jakarta.servlet.Filter filter) - Specified by:
addFilter
in interfacejakarta.servlet.ServletContext
-
addFilter
public jakarta.servlet.FilterRegistration.Dynamic addFilter(String filterName, Class<? extends jakarta.servlet.Filter> filterClass) - Specified by:
addFilter
in interfacejakarta.servlet.ServletContext
-
createFilter
public <T extends jakarta.servlet.Filter> T createFilter(Class<T> clazz) throws jakarta.servlet.ServletException - Specified by:
createFilter
in interfacejakarta.servlet.ServletContext
- Throws:
jakarta.servlet.ServletException
-
getFilterRegistration
- Specified by:
getFilterRegistration
in interfacejakarta.servlet.ServletContext
-
getFilterRegistrations
- Specified by:
getFilterRegistrations
in interfacejakarta.servlet.ServletContext
-
getSessionCookieConfig
public jakarta.servlet.SessionCookieConfig getSessionCookieConfig()- Specified by:
getSessionCookieConfig
in interfacejakarta.servlet.ServletContext
-
setSessionTrackingModes
- Specified by:
setSessionTrackingModes
in interfacejakarta.servlet.ServletContext
-
getDefaultSessionTrackingModes
- Specified by:
getDefaultSessionTrackingModes
in interfacejakarta.servlet.ServletContext
-
getEffectiveSessionTrackingModes
- Specified by:
getEffectiveSessionTrackingModes
in interfacejakarta.servlet.ServletContext
-
addListener
- Specified by:
addListener
in interfacejakarta.servlet.ServletContext
-
addListener
- Specified by:
addListener
in interfacejakarta.servlet.ServletContext
-
addListener
- Specified by:
addListener
in interfacejakarta.servlet.ServletContext
-
createListener
public <T extends EventListener> T createListener(Class<T> clazz) throws jakarta.servlet.ServletException - Specified by:
createListener
in interfacejakarta.servlet.ServletContext
- Throws:
jakarta.servlet.ServletException
-
getJspConfigDescriptor
public jakarta.servlet.descriptor.JspConfigDescriptor getJspConfigDescriptor()- Specified by:
getJspConfigDescriptor
in interfacejakarta.servlet.ServletContext
-
getClassLoader
- Specified by:
getClassLoader
in interfacejakarta.servlet.ServletContext
-
declareRoles
- Specified by:
declareRoles
in interfacejakarta.servlet.ServletContext
-
getVirtualServerName
- Specified by:
getVirtualServerName
in interfacejakarta.servlet.ServletContext
-
getSessionTimeout
public int getSessionTimeout()- Specified by:
getSessionTimeout
in interfacejakarta.servlet.ServletContext
-
setSessionTimeout
public void setSessionTimeout(int sessionTimeout) - Specified by:
setSessionTimeout
in interfacejakarta.servlet.ServletContext
-
getRequestCharacterEncoding
- Specified by:
getRequestCharacterEncoding
in interfacejakarta.servlet.ServletContext
-
setRequestCharacterEncoding
- Specified by:
setRequestCharacterEncoding
in interfacejakarta.servlet.ServletContext
-
getResponseCharacterEncoding
- Specified by:
getResponseCharacterEncoding
in interfacejakarta.servlet.ServletContext
-
setResponseCharacterEncoding
- Specified by:
setResponseCharacterEncoding
in interfacejakarta.servlet.ServletContext
-