Class MockServletContext

    • Constructor Detail

      • MockServletContext

        protected MockServletContext​(@Nullable
                                     String sContextPath,
                                     @Nullable
                                     String sResourceBasePath,
                                     @Nullable
                                     com.helger.commons.io.resourceprovider.IReadableResourceProvider aResourceLoader,
                                     @Nullable
                                     Map<String,​String> aInitParams)
        Create a new MockServletContext.
        Parameters:
        sContextPath - The context path to use
        sResourceBasePath - the WAR root directory (should not end with a slash)
        aResourceLoader - the IReadableResourceProvider to use (or null for the default)
        aInitParams - Optional map with initialization parameters
    • Method Detail

      • isReThrowListenerException

        public static boolean isReThrowListenerException()
        Returns:
        true if runtime exceptions from context listeners should be propagated to the outside or if they should be logged and processing should continue. Default is false.
      • setReThrowListenerException

        public static void setReThrowListenerException​(boolean bReThrowListenerException)
        Parameters:
        bReThrowListenerException - true to re-throw listener exceptions (on context inited and destroyed)
      • initListeners

        @OverrideOnDemand
        protected void initListeners()
      • getResourceLocation

        @Nonnull
        protected String getResourceLocation​(@Nonnull
                                             String sPath)
        Build a full resource location for the given path, prepending the resource base path of this MockServletContext.
        Parameters:
        sPath - the path as specified
        Returns:
        the full resource path
      • setContextPath

        public final void setContextPath​(@Nullable
                                         String sContextPath)
      • getContextPath

        @Nonnull
        public String getContextPath()
        Specified by:
        getContextPath in interface jakarta.servlet.ServletContext
      • registerContext

        public void registerContext​(@Nonnull
                                    String sContextPath,
                                    @Nonnull
                                    jakarta.servlet.ServletContext aContext)
      • getContext

        @Nullable
        public jakarta.servlet.ServletContext getContext​(@Nullable
                                                         String sContextPath)
        Specified by:
        getContext in interface jakarta.servlet.ServletContext
      • getMajorVersion

        @Nonnegative
        public int getMajorVersion()
        Specified by:
        getMajorVersion in interface jakarta.servlet.ServletContext
      • getMinorVersion

        @Nonnegative
        public int getMinorVersion()
        Specified by:
        getMinorVersion in interface jakarta.servlet.ServletContext
      • getMimeType

        @Nullable
        public String getMimeType​(@Nonnull
                                  String sFilename)
        Specified by:
        getMimeType in interface jakarta.servlet.ServletContext
      • getResourcePaths

        @UnsupportedOperation
        @Deprecated(forRemoval=false)
        public com.helger.commons.collection.impl.ICommonsSet<String> getResourcePaths​(String sPath)
        Deprecated.
        Specified by:
        getResourcePaths in interface jakarta.servlet.ServletContext
      • getResourceAsStream

        @Nullable
        public InputStream getResourceAsStream​(@Nonnull
                                               String sPath)
        Specified by:
        getResourceAsStream in interface jakarta.servlet.ServletContext
      • getRequestDispatcher

        @Nonnull
        public jakarta.servlet.RequestDispatcher getRequestDispatcher​(@Nonnull
                                                                      String sPath)
        Specified by:
        getRequestDispatcher in interface jakarta.servlet.ServletContext
      • getNamedDispatcher

        @Nullable
        @Deprecated(forRemoval=false)
        public jakarta.servlet.RequestDispatcher getNamedDispatcher​(@Nullable
                                                                    String sPath)
        Deprecated.
        Specified by:
        getNamedDispatcher in interface jakarta.servlet.ServletContext
      • getServlet

        @Deprecated(forRemoval=false)
        public jakarta.servlet.Servlet getServlet​(@Nullable
                                                  String sName)
        Deprecated.
        Specified by:
        getServlet in interface jakarta.servlet.ServletContext
      • log

        public void log​(@Nullable
                        String sMessage)
        Specified by:
        log in interface jakarta.servlet.ServletContext
      • getRealPath

        @Nonnull
        public String getRealPath​(@Nonnull
                                  String sPath)
        Specified by:
        getRealPath in interface jakarta.servlet.ServletContext
      • getServerInfo

        @Nonnull
        @Nonempty
        public String getServerInfo()
        Specified by:
        getServerInfo in interface jakarta.servlet.ServletContext
      • getInitParameter

        @Nullable
        public String getInitParameter​(@Nonnull
                                       String sName)
        Specified by:
        getInitParameter in interface jakarta.servlet.ServletContext
      • getInitParameterNames

        @Nonnull
        public Enumeration<String> getInitParameterNames()
        Specified by:
        getInitParameterNames in interface jakarta.servlet.ServletContext
      • getAttribute

        @Nullable
        public Object getAttribute​(@Nonnull
                                   String sName)
        Specified by:
        getAttribute in interface jakarta.servlet.ServletContext
      • getAttributeNames

        @Nonnull
        public Enumeration<String> getAttributeNames()
        Specified by:
        getAttributeNames in interface jakarta.servlet.ServletContext
      • setAttribute

        public final void setAttribute​(@Nonnull
                                       String sName,
                                       @Nullable
                                       Object aValue)
        Specified by:
        setAttribute in interface jakarta.servlet.ServletContext
      • removeAttribute

        public void removeAttribute​(@Nonnull
                                    String sName)
        Specified by:
        removeAttribute in interface jakarta.servlet.ServletContext
      • setServletContextName

        public void setServletContextName​(@Nullable
                                          String sServletContextName)
      • getServletContextName

        @Nullable
        public String getServletContextName()
        Specified by:
        getServletContextName in interface jakarta.servlet.ServletContext
      • getServletPool

        @Nonnull
        public MockServletPool getServletPool()
        Returns:
        The servlet pool for registering mock servlets.
      • invalidate

        public void invalidate()
      • getEffectiveMajorVersion

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

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

        public boolean setInitParameter​(String sName,
                                        String sValue)
        Specified by:
        setInitParameter in interface jakarta.servlet.ServletContext
      • addServlet

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

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

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

        @UnsupportedOperation
        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

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

        @UnsupportedOperation
        public com.helger.commons.collection.impl.ICommonsMap<String,​? extends jakarta.servlet.ServletRegistration> getServletRegistrations()
        Specified by:
        getServletRegistrations in interface jakarta.servlet.ServletContext
      • addFilter

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

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

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

        @UnsupportedOperation
        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

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

        @UnsupportedOperation
        public com.helger.commons.collection.impl.ICommonsMap<String,​? extends jakarta.servlet.FilterRegistration> getFilterRegistrations()
        Specified by:
        getFilterRegistrations in interface jakarta.servlet.ServletContext
      • getSessionCookieConfig

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

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

        @UnsupportedOperation
        public com.helger.commons.collection.impl.ICommonsSet<jakarta.servlet.SessionTrackingMode> getDefaultSessionTrackingModes()
        Specified by:
        getDefaultSessionTrackingModes in interface jakarta.servlet.ServletContext
      • getEffectiveSessionTrackingModes

        @UnsupportedOperation
        public com.helger.commons.collection.impl.ICommonsSet<jakarta.servlet.SessionTrackingMode> getEffectiveSessionTrackingModes()
        Specified by:
        getEffectiveSessionTrackingModes in interface jakarta.servlet.ServletContext
      • addListener

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

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

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

        @UnsupportedOperation
        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

        @UnsupportedOperation
        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

        @UnsupportedOperation
        public void declareRoles​(String... roleNames)
        Specified by:
        declareRoles in interface jakarta.servlet.ServletContext
      • create

        @Nonnull
        public static MockServletContext create​(@Nullable
                                                String sContextPath,
                                                @Nullable
                                                String sResourceBasePath)
        Create a new MockServletContext using the provided context path and resource base oath. The initialization listeners are triggered automatically.
        Parameters:
        sContextPath - The context path to use. May be null.
        sResourceBasePath - the WAR root directory (should not end with a slash). May be null.
        Returns:
        The created MockServletContext
      • create

        @Nonnull
        public static MockServletContext create​(@Nullable
                                                String sContextPath,
                                                @Nullable
                                                String sResourceBasePath,
                                                @Nullable
                                                com.helger.commons.io.resourceprovider.IReadableResourceProvider aResourceLoader,
                                                @Nullable
                                                Map<String,​String> aInitParams)
        Create a new MockServletContext with all possible parameters.
        Parameters:
        sContextPath - The context path to use. May be null.
        sResourceBasePath - the WAR root directory (should not end with a slash). May be null.
        aResourceLoader - the IReadableResourceProvider to use. May be null.
        aInitParams - Optional map with initialization parameters. May be null.
        Returns:
        The created MockServletContext