Class MockServletContextImpl

java.lang.Object
io.github.cdiunit.internal.servlet5.MockServletContextImpl
All Implemented Interfaces:
jakarta.servlet.ServletContext

public class MockServletContextImpl extends Object implements jakarta.servlet.ServletContext
Shamlessly ripped from mockrunner.
Author:
Various
  • 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

      public Object getAttribute(String key)
      Specified by:
      getAttribute in interface jakarta.servlet.ServletContext
    • getAttributeNames

      public Enumeration getAttributeNames()
      Specified by:
      getAttributeNames in interface jakarta.servlet.ServletContext
    • removeAttribute

      public void removeAttribute(String key)
      Specified by:
      removeAttribute in interface jakarta.servlet.ServletContext
    • setAttribute

      public void setAttribute(String key, Object value)
      Specified by:
      setAttribute in interface jakarta.servlet.ServletContext
    • getNamedDispatcher

      public jakarta.servlet.RequestDispatcher getNamedDispatcher(String name)
      Specified by:
      getNamedDispatcher in interface jakarta.servlet.ServletContext
    • getRequestDispatcher

      public jakarta.servlet.RequestDispatcher getRequestDispatcher(String path)
      Specified by:
      getRequestDispatcher in interface jakarta.servlet.ServletContext
    • getRequestDispatcherMap

      public Map getRequestDispatcherMap()
      Returns the map of RequestDispatcher objects. The specified path maps to the corresponding RequestDispatcher object.
      Returns:
      the map of RequestDispatcher objects
    • clearRequestDispatcherMap

      public void clearRequestDispatcherMap()
      Clears the map of RequestDispatcher objects.
    • setRequestDispatcher

      public void setRequestDispatcher(String path, jakarta.servlet.RequestDispatcher dispatcher)
      Sets a RequestDispatcher that will be returned when calling getRequestDispatcher(java.lang.String) or getNamedDispatcher(java.lang.String) with the specified path or name. If no RequestDispatcher is set for the specified path, getRequestDispatcher(java.lang.String) and getNamedDispatcher(java.lang.String) automatically create a new one.
      Parameters:
      path - the path for the RequestDispatcher
      dispatcher - the RequestDispatcher object
    • getContext

      public jakarta.servlet.ServletContext getContext(String url)
      Specified by:
      getContext in interface jakarta.servlet.ServletContext
    • setContext

      public void setContext(String url, jakarta.servlet.ServletContext context)
      Sets a ServletContext that will be returned when calling getContext(java.lang.String)
      Parameters:
      url - the URL
      context - the ServletContext
    • clearInitParameters

      public void clearInitParameters()
      Clears the init parameters.
    • getInitParameter

      public String getInitParameter(String name)
      Specified by:
      getInitParameter in interface jakarta.servlet.ServletContext
    • setInitParameter

      public boolean setInitParameter(String name, String value)
      Sets an init parameter. This method does not overwrite existing init parameters.
      Specified by:
      setInitParameter in interface jakarta.servlet.ServletContext
      Parameters:
      name - the name
      value - the value
      Returns:
      false if the parameter was not set true otherwise
    • setInitParameters

      public void setInitParameters(Map parameters)
      Sets several init parameters. This method does overwrite existing init parameters.
      Parameters:
      parameters - the parameter map
    • getInitParameterNames

      public Enumeration getInitParameterNames()
      Specified by:
      getInitParameterNames in interface jakarta.servlet.ServletContext
    • getMajorVersion

      public int getMajorVersion()
      Specified by:
      getMajorVersion in interface jakarta.servlet.ServletContext
    • setMajorVersion

      public void setMajorVersion(int majorVersion)
    • getMinorVersion

      public int getMinorVersion()
      Specified by:
      getMinorVersion in interface jakarta.servlet.ServletContext
    • setMinorVersion

      public void setMinorVersion(int minorVersion)
    • getEffectiveMajorVersion

      public int getEffectiveMajorVersion()
      Specified by:
      getEffectiveMajorVersion in interface jakarta.servlet.ServletContext
    • setEffectiveMajorVersion

      public void setEffectiveMajorVersion(int effectiveMajorVersion)
    • getEffectiveMinorVersion

      public int getEffectiveMinorVersion()
      Specified by:
      getEffectiveMinorVersion in interface jakarta.servlet.ServletContext
    • setEffectiveMinorVersion

      public void setEffectiveMinorVersion(int effectiveMinorVersion)
    • getMimeType

      public String getMimeType(String file)
      Specified by:
      getMimeType in interface jakarta.servlet.ServletContext
    • setMimeType

      public void setMimeType(String file, String type)
    • getRealPath

      public String getRealPath(String path)
      Specified by:
      getRealPath in interface jakarta.servlet.ServletContext
    • setRealPath

      public void setRealPath(String path, String realPath)
    • getResource

      public URL getResource(String path) throws MalformedURLException
      Specified by:
      getResource in interface jakarta.servlet.ServletContext
      Throws:
      MalformedURLException
    • setResource

      public void setResource(String path, URL url)
    • getResourceAsStream

      public InputStream getResourceAsStream(String path)
      Specified by:
      getResourceAsStream in interface jakarta.servlet.ServletContext
    • setResourceAsStream

      public void setResourceAsStream(String path, InputStream inputStream)
    • setResourceAsStream

      public void setResourceAsStream(String path, byte[] data)
    • getResourcePaths

      public Set getResourcePaths(String path)
      Specified by:
      getResourcePaths in interface jakarta.servlet.ServletContext
    • addResourcePaths

      public void addResourcePaths(String path, Collection pathes)
    • addResourcePath

      public void addResourcePath(String path, String resourcePath)
    • getServerInfo

      public String getServerInfo()
      Specified by:
      getServerInfo in interface jakarta.servlet.ServletContext
    • getServlet

      public jakarta.servlet.Servlet getServlet(String arg0) throws jakarta.servlet.ServletException
      Specified by:
      getServlet in interface jakarta.servlet.ServletContext
      Throws:
      jakarta.servlet.ServletException
    • getServletContextName

      public String getServletContextName()
      Specified by:
      getServletContextName in interface jakarta.servlet.ServletContext
    • setServletContextName

      public void setServletContextName(String servletContextName)
    • getContextPath

      public String getContextPath()
      Specified by:
      getContextPath in interface jakarta.servlet.ServletContext
    • setContextPath

      public void setContextPath(String contextPath)
    • getServletNames

      public Enumeration getServletNames()
      Specified by:
      getServletNames in interface jakarta.servlet.ServletContext
    • getServlets

      public Enumeration getServlets()
      Specified by:
      getServlets in interface jakarta.servlet.ServletContext
    • log

      public void log(Exception exc, String message)
      Specified by:
      log in interface jakarta.servlet.ServletContext
    • log

      public void log(String message, Throwable exc)
      Specified by:
      log in interface jakarta.servlet.ServletContext
    • log

      public void log(String message)
      Specified by:
      log in interface jakarta.servlet.ServletContext
    • addServlet

      public jakarta.servlet.ServletRegistration.Dynamic addServlet(String servletName, String className)
      Specified by:
      addServlet in interface jakarta.servlet.ServletContext
    • addServlet

      public jakarta.servlet.ServletRegistration.Dynamic addServlet(String servletName, jakarta.servlet.Servlet servlet)
      Specified by:
      addServlet in interface jakarta.servlet.ServletContext
    • addServlet

      public jakarta.servlet.ServletRegistration.Dynamic addServlet(String servletName, Class<? extends jakarta.servlet.Servlet> servletClass)
      Specified by:
      addServlet in interface jakarta.servlet.ServletContext
    • addJspFile

      public jakarta.servlet.ServletRegistration.Dynamic addJspFile(String servletName, String jspFile)
      Specified by:
      addJspFile in interface jakarta.servlet.ServletContext
    • createServlet

      public <T extends jakarta.servlet.Servlet> T createServlet(Class<T> clazz) throws jakarta.servlet.ServletException
      Specified by:
      createServlet in interface jakarta.servlet.ServletContext
      Throws:
      jakarta.servlet.ServletException
    • getServletRegistration

      public jakarta.servlet.ServletRegistration getServletRegistration(String servletName)
      Specified by:
      getServletRegistration in interface jakarta.servlet.ServletContext
    • getServletRegistrations

      public Map<String,? extends jakarta.servlet.ServletRegistration> getServletRegistrations()
      Specified by:
      getServletRegistrations in interface jakarta.servlet.ServletContext
    • addFilter

      public jakarta.servlet.FilterRegistration.Dynamic addFilter(String filterName, String className)
      Specified by:
      addFilter in interface jakarta.servlet.ServletContext
    • addFilter

      public jakarta.servlet.FilterRegistration.Dynamic addFilter(String filterName, jakarta.servlet.Filter filter)
      Specified by:
      addFilter in interface jakarta.servlet.ServletContext
    • addFilter

      public jakarta.servlet.FilterRegistration.Dynamic addFilter(String filterName, Class<? extends jakarta.servlet.Filter> filterClass)
      Specified by:
      addFilter in interface jakarta.servlet.ServletContext
    • createFilter

      public <T extends jakarta.servlet.Filter> T createFilter(Class<T> clazz) throws jakarta.servlet.ServletException
      Specified by:
      createFilter in interface jakarta.servlet.ServletContext
      Throws:
      jakarta.servlet.ServletException
    • getFilterRegistration

      public jakarta.servlet.FilterRegistration getFilterRegistration(String filterName)
      Specified by:
      getFilterRegistration in interface jakarta.servlet.ServletContext
    • getFilterRegistrations

      public Map<String,? extends jakarta.servlet.FilterRegistration> getFilterRegistrations()
      Specified by:
      getFilterRegistrations in interface jakarta.servlet.ServletContext
    • getSessionCookieConfig

      public jakarta.servlet.SessionCookieConfig getSessionCookieConfig()
      Specified by:
      getSessionCookieConfig in interface jakarta.servlet.ServletContext
    • setSessionTrackingModes

      public void setSessionTrackingModes(Set<jakarta.servlet.SessionTrackingMode> sessionTrackingModes)
      Specified by:
      setSessionTrackingModes in interface jakarta.servlet.ServletContext
    • getDefaultSessionTrackingModes

      public Set<jakarta.servlet.SessionTrackingMode> getDefaultSessionTrackingModes()
      Specified by:
      getDefaultSessionTrackingModes in interface jakarta.servlet.ServletContext
    • getEffectiveSessionTrackingModes

      public Set<jakarta.servlet.SessionTrackingMode> getEffectiveSessionTrackingModes()
      Specified by:
      getEffectiveSessionTrackingModes in interface jakarta.servlet.ServletContext
    • addListener

      public void addListener(String className)
      Specified by:
      addListener in interface jakarta.servlet.ServletContext
    • addListener

      public <T extends EventListener> void addListener(T t)
      Specified by:
      addListener in interface jakarta.servlet.ServletContext
    • addListener

      public void addListener(Class<? extends EventListener> listenerClass)
      Specified by:
      addListener in interface jakarta.servlet.ServletContext
    • createListener

      public <T extends EventListener> T createListener(Class<T> clazz) throws jakarta.servlet.ServletException
      Specified by:
      createListener in interface jakarta.servlet.ServletContext
      Throws:
      jakarta.servlet.ServletException
    • getJspConfigDescriptor

      public jakarta.servlet.descriptor.JspConfigDescriptor getJspConfigDescriptor()
      Specified by:
      getJspConfigDescriptor in interface jakarta.servlet.ServletContext
    • getClassLoader

      public ClassLoader getClassLoader()
      Specified by:
      getClassLoader in interface jakarta.servlet.ServletContext
    • declareRoles

      public void declareRoles(String... roleNames)
      Specified by:
      declareRoles in interface jakarta.servlet.ServletContext
    • getVirtualServerName

      public String getVirtualServerName()
      Specified by:
      getVirtualServerName in interface jakarta.servlet.ServletContext
    • getSessionTimeout

      public int getSessionTimeout()
      Specified by:
      getSessionTimeout in interface jakarta.servlet.ServletContext
    • setSessionTimeout

      public void setSessionTimeout(int sessionTimeout)
      Specified by:
      setSessionTimeout in interface jakarta.servlet.ServletContext
    • getRequestCharacterEncoding

      public String getRequestCharacterEncoding()
      Specified by:
      getRequestCharacterEncoding in interface jakarta.servlet.ServletContext
    • setRequestCharacterEncoding

      public void setRequestCharacterEncoding(String encoding)
      Specified by:
      setRequestCharacterEncoding in interface jakarta.servlet.ServletContext
    • getResponseCharacterEncoding

      public String getResponseCharacterEncoding()
      Specified by:
      getResponseCharacterEncoding in interface jakarta.servlet.ServletContext
    • setResponseCharacterEncoding

      public void setResponseCharacterEncoding(String encoding)
      Specified by:
      setResponseCharacterEncoding in interface jakarta.servlet.ServletContext