Class MockMultipartRequestHandler

java.lang.Object
org.apache.struts.mock.MockMultipartRequestHandler
All Implemented Interfaces:
org.apache.struts.upload.MultipartRequestHandler

public class MockMultipartRequestHandler extends Object implements org.apache.struts.upload.MultipartRequestHandler
Mock MultipartRequestHandler object for unit tests.
  • Field Summary

    Fields inherited from interface org.apache.struts.upload.MultipartRequestHandler

    ATTRIBUTE_MAX_BYTE_LENGTH_EXCEEDED, ATTRIBUTE_MAX_FILE_COUNT_EXCEEDED, ATTRIBUTE_MAX_LENGTH_EXCEEDED, ATTRIBUTE_MAX_STRING_LENGTH_EXCEEDED
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Mock finish() method does nothing.
    This method returns all elements of a multipart request.
    HashMap<String,org.apache.struts.upload.FormFile[]>
    This method is called on to retrieve all the FormFile input elements of the request.
    org.apache.struts.action.ActionMapping
    Get the ActionMapping instance for this mock request.
    org.apache.struts.action.ActionServlet
    Get the mock ActionServlet instance.
    This method is called on to retrieve all the text input elements of the request.
    void
    Mock parsing of the ServletInputStream.
    void
    Mock rollback() method does nothing.
    void
    setMapping(org.apache.struts.action.ActionMapping mapping)
    Convenience method to set a reference to a mock ActionMapping instance.
    void
    setServlet(org.apache.struts.action.ActionServlet servlet)
    Convenience method to set a reference to a mock ActionServlet instance.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MockMultipartRequestHandler

      public MockMultipartRequestHandler()
  • Method Details

    • setServlet

      public void setServlet(org.apache.struts.action.ActionServlet servlet)
      Convenience method to set a reference to a mock ActionServlet instance.
      Specified by:
      setServlet in interface org.apache.struts.upload.MultipartRequestHandler
      Parameters:
      servlet - Mock servlet instance.
    • setMapping

      public void setMapping(org.apache.struts.action.ActionMapping mapping)
      Convenience method to set a reference to a mock ActionMapping instance.
      Specified by:
      setMapping in interface org.apache.struts.upload.MultipartRequestHandler
      Parameters:
      mapping - Mock action mapping instance.
    • getServlet

      public org.apache.struts.action.ActionServlet getServlet()
      Get the mock ActionServlet instance.
      Specified by:
      getServlet in interface org.apache.struts.upload.MultipartRequestHandler
      Returns:
      The mock servlet instance.
    • getMapping

      public org.apache.struts.action.ActionMapping getMapping()
      Get the ActionMapping instance for this mock request.
      Specified by:
      getMapping in interface org.apache.struts.upload.MultipartRequestHandler
      Returns:
      The mock action mapping instance.
    • handleRequest

      public void handleRequest(HttpServletRequest request) throws ServletException
      Mock parsing of the ServletInputStream.

      Constructs a HashMap of elements from the HttpServletRequest's parameters - no FormFile elements are created.

      Specified by:
      handleRequest in interface org.apache.struts.upload.MultipartRequestHandler
      Parameters:
      request - Mock request instance.
      Throws:
      ServletException - If there is a problem with processing the request.
    • getTextElements

      public HashMap<String,String[]> getTextElements()
      This method is called on to retrieve all the text input elements of the request.
      Specified by:
      getTextElements in interface org.apache.struts.upload.MultipartRequestHandler
      Returns:
      A HashMap where the keys and values are the names and values of the request input parameters
    • getFileElements

      public HashMap<String,org.apache.struts.upload.FormFile[]> getFileElements()
      This method is called on to retrieve all the FormFile input elements of the request.
      Specified by:
      getFileElements in interface org.apache.struts.upload.MultipartRequestHandler
      Returns:
      This mock implementation returns an empty HashMap
    • getAllElements

      public HashMap<String,Object> getAllElements()
      This method returns all elements of a multipart request.
      Specified by:
      getAllElements in interface org.apache.struts.upload.MultipartRequestHandler
      Returns:
      This mock implementation returns a HashMap where the keys are input names and values are either Strings (no FormFile elements)
    • rollback

      public void rollback()
      Mock rollback() method does nothing.
      Specified by:
      rollback in interface org.apache.struts.upload.MultipartRequestHandler
    • finish

      public void finish()
      Mock finish() method does nothing.
      Specified by:
      finish in interface org.apache.struts.upload.MultipartRequestHandler