Class ServletTestUtils

java.lang.Object
io.microsphere.spring.test.util.ServletTestUtils

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

    Modifier and Type
    Method
    Description
    static jakarta.servlet.FilterRegistration.Dynamic
    addTestFilter(jakarta.servlet.ServletContext servletContext)
    Adds a test filter to the provided ServletContext.
    static jakarta.servlet.ServletRegistration.Dynamic
    addTestServlet(jakarta.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 Details

    • addTestServlet

      public static jakarta.servlet.ServletRegistration.Dynamic addTestServlet(jakarta.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, jakarta.servlet.Servlet)
    • addTestFilter

      public static jakarta.servlet.FilterRegistration.Dynamic addTestFilter(jakarta.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, jakarta.servlet.Filter)