Package io.microsphere.spring.test.util
Class ServletTestUtils
java.lang.Object
io.microsphere.spring.test.util.ServletTestUtils
The utility class for Servlet Testing
- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
-
ServletContext
-
Method Summary
Modifier and TypeMethodDescriptionstatic jakarta.servlet.FilterRegistration.DynamicaddTestFilter(jakarta.servlet.ServletContext servletContext) Adds a test filter to the providedServletContext.static jakarta.servlet.ServletRegistration.DynamicaddTestServlet(jakarta.servlet.ServletContext servletContext) Adds a test servlet to the providedServletContext.
-
Method Details
-
addTestServlet
public static jakarta.servlet.ServletRegistration.Dynamic addTestServlet(jakarta.servlet.ServletContext servletContext) Adds a test servlet to the providedServletContext.This method registers a
TestServletwith 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- theServletContextto which the test servlet will be added.- Returns:
- the
ServletRegistration.Dynamicfor the added servlet. - See Also:
-
TestServletServletContext.addServlet(String, jakarta.servlet.Servlet)
-
addTestFilter
public static jakarta.servlet.FilterRegistration.Dynamic addTestFilter(jakarta.servlet.ServletContext servletContext) Adds a test filter to the providedServletContext.This method registers a
TestFilterwith 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- theServletContextto which the test filter will be added.- Returns:
- the
FilterRegistration.Dynamicfor the added filter. - See Also:
-
TestFilterServletContext.addFilter(String, jakarta.servlet.Filter)
-