Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't think that can be done. HttpUnit does not provide setAttribute method for WebRequest, which makes sense, since attributes can only be set from within the container.</p> <p>However, what you can do (and possibly even should) is to test both individually in separate tests - that filter puts the parameters to the request, and servlet works if parameters are set up correctly. The way to do it would be creating a mock request for the servlet, setting the attributes for that, and running a regular unit test for that. Same approach applies for the filter.</p> <p>Here's an example of doing it with a filter:</p> <pre><code>@Test public void testDefaultRequestEncoding() throws ServletException, IOException { CharacterEncodingFilter filter = new CharacterEncodingFilter(); filter.setEncoding(CONFIGURED_ENCODING_UTF8); filter.setForceEncoding(ENFORCE_ENCODING_TRUE); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); FilterChain filterChain = new MockFilterChain(); request.setCharacterEncoding(TEST_ENCODING_ISO_8859_15); filter.doFilter(request, response, filterChain); assertEquals(CONFIGURED_ENCODING_UTF8, request.getCharacterEncoding()); assertEquals(CONFIGURED_ENCODING_UTF8, response.getCharacterEncoding()); } </code></pre> <p>Mock* objects are from Spring. If your framework does not have them, you can create them by using some mock library, or use the ones that can be seen from Spring sources.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload