Class ServletTestUtils


  • public abstract class ServletTestUtils
    extends java.lang.Object
    The utility class for Servlet Testing
    Since:
    1.0.0
    Author:
    Mercy
    See Also:
    ServletContext
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static javax.servlet.FilterRegistration.Dynamic addTestFilter​(javax.servlet.ServletContext servletContext)
      Adds a test filter to the provided ServletContext.
      static javax.servlet.ServletRegistration.Dynamic addTestServlet​(javax.servlet.ServletContext servletContext)
      Adds a test servlet to the provided ServletContext.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • addTestServlet

        public static javax.servlet.ServletRegistration.Dynamic addTestServlet​(javax.servlet.ServletContext servletContext)
        Adds a test servlet to the provided ServletContext.

        This method registers a TestServlet with the default servlet name "testServlet" and maps it to the default URL pattern "/testServlet".

        Example Usage

        
         ServletContext servletContext = ...; // Obtain the ServletContext
         ServletTestUtils.addTestServlet(servletContext);
         
        Parameters:
        servletContext - the ServletContext to which the test servlet will be added.
        Returns:
        the ServletRegistration.Dynamic for the added servlet.
        See Also:
        TestServlet, ServletContext.addServlet(String, javax.servlet.Servlet)
      • addTestFilter

        public static javax.servlet.FilterRegistration.Dynamic addTestFilter​(javax.servlet.ServletContext servletContext)
        Adds a test filter to the provided ServletContext.

        This method registers a TestFilter with the default filter name "testFilter" and maps it to the default URL pattern "/testFilter". Additionally, it adds a test servlet to ensure the filter can be mapped to it.

        Example Usage

        
         ServletContext servletContext = ...; // Obtain the ServletContext
         ServletTestUtils.addTestFilter(servletContext);
         
        Parameters:
        servletContext - the ServletContext to which the test filter will be added.
        Returns:
        the FilterRegistration.Dynamic for the added filter.
        See Also:
        TestFilter, ServletContext.addFilter(String, javax.servlet.Filter)