Class MockMvcRequestBuilderUtils


  • public class MockMvcRequestBuilderUtils
    extends Object
    Custom MockMvcRequestBuilder to post an entire form to a given url. Useful to test Spring MVC form validation.
    Author:
    Florian Lopes
    See Also:
    MockMvcRequestBuilders
    • Method Detail

      • registerPropertyEditor

        public static void registerPropertyEditor​(Class type,
                                                  PropertyEditor propertyEditor)
        Register custom property editor for a given type.
        Parameters:
        type - type of the property
        propertyEditor - PropertyEditor to register
      • postForm

        public static org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder postForm​(String url,
                                                                                                          Object form)
        Post a form to the given url. All non-null form fields will be added as HTTP request parameters using POST method
        Parameters:
        url - the URL to post the form to
        form - form object to send using POST method
        Returns:
        mockHttpServletRequestBuilder wrapped mockHttpServletRequestBuilder
      • putForm

        public static org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder putForm​(String url,
                                                                                                         Object form)
        Put a form to the given url. All non-null form fields will be added as HTTP request parameters using PUT method
        Parameters:
        url - the URL to put the form to
        form - form object to send using PUT method
        Returns:
        mockHttpServletRequestBuilder wrapped mockHttpServletRequestBuilder