List of usage examples for javax.servlet.http HttpServletRequestWrapper getParameterMap
public Map<String, String[]> getParameterMap()
From source file:org.primeframework.mvc.parameter.RequestBodyWorkflowTest.java
@Test public void parse() throws IOException, ServletException { HttpServletRequest request = createStrictMock(HttpServletRequest.class); expect(request.getParameterMap()).andReturn(new HashMap<>()); expect(request.getContentType()).andReturn("application/x-www-form-urlencoded"); String body = "param1=value1¶m2=value2¶m+space+key=param+space+value¶m%2Bencoded%2Bkey=param%2Bencoded%2Bvalue"; expect(request.getInputStream()).andReturn(new MockServletInputStream(body.getBytes())); expect(request.getContentLength()).andReturn(body.getBytes().length); expect(request.getCharacterEncoding()).andReturn("UTF-8"); replay(request);//from w w w. java 2s . c o m WorkflowChain chain = createStrictMock(WorkflowChain.class); chain.continueWorkflow(); replay(chain); HttpServletRequestWrapper wrapper = new HttpServletRequestWrapper(request); RequestBodyWorkflow workflow = new RequestBodyWorkflow(wrapper); workflow.perform(chain); @SuppressWarnings("unchecked") Map<String, String[]> actual = wrapper.getParameterMap(); Map<String, String[]> expected = MapBuilder.<String, String[]>map().put("param1", new String[] { "value1" }) .put("param2", new String[] { "value2" }) .put("param space key", new String[] { "param space value" }) .put("param+encoded+key", new String[] { "param+encoded+value" }).done(); assertParameterMapsEquals(actual, expected); verify(request, chain); }
From source file:org.primeframework.mvc.parameter.RequestBodyWorkflowTest.java
@Test public void parseCombine() throws IOException, ServletException { Map<String, String[]> oldParams = new HashMap<>(); oldParams.put("param1", new String[] { "oldvalue1", "oldvalue2" }); oldParams.put("param2", new String[] { "oldvalue3" }); String body = "param1=value1¶m1=value2¶m2=value3"; HttpServletRequest request = createStrictMock(HttpServletRequest.class); expect(request.getParameterMap()).andReturn(oldParams); expect(request.getContentType()).andReturn("application/x-www-form-urlencoded"); expect(request.getInputStream()).andReturn(new MockServletInputStream(body.getBytes())); expect(request.getContentLength()).andReturn(body.getBytes().length); expect(request.getCharacterEncoding()).andReturn("UTF-8"); replay(request);//from w w w.j ava 2s. co m WorkflowChain chain = createStrictMock(WorkflowChain.class); chain.continueWorkflow(); replay(chain); HttpServletRequestWrapper wrapper = new HttpServletRequestWrapper(request); RequestBodyWorkflow workflow = new RequestBodyWorkflow(wrapper); workflow.perform(chain); @SuppressWarnings("unchecked") Map<String, String[]> actual = wrapper.getParameterMap(); Map<String, String[]> expected = MapBuilder.<String, String[]>map() .put("param1", new String[] { "oldvalue1", "oldvalue2", "value1", "value2" }) .put("param2", new String[] { "oldvalue3", "value3" }).done(); assertParameterMapsEquals(actual, expected); verify(request, chain); }
From source file:org.primeframework.mvc.parameter.RequestBodyWorkflowTest.java
@Test public void parseMultiple() throws IOException, ServletException { String body = "param1=value1¶m1=value2¶m2=value3"; HttpServletRequest request = createStrictMock(HttpServletRequest.class); expect(request.getParameterMap()).andReturn(new HashMap<>()); expect(request.getContentType()).andReturn("application/x-www-form-urlencoded"); expect(request.getInputStream()).andReturn(new MockServletInputStream(body.getBytes())); expect(request.getContentLength()).andReturn(body.getBytes().length); expect(request.getCharacterEncoding()).andReturn("UTF-8"); replay(request);/*from ww w . j av a 2 s .c o m*/ WorkflowChain chain = createStrictMock(WorkflowChain.class); chain.continueWorkflow(); replay(chain); HttpServletRequestWrapper wrapper = new HttpServletRequestWrapper(request); RequestBodyWorkflow workflow = new RequestBodyWorkflow(wrapper); workflow.perform(chain); @SuppressWarnings("unchecked") Map<String, String[]> actual = wrapper.getParameterMap(); Map<String, String[]> expected = MapBuilder.<String, String[]>map() .put("param1", new String[] { "value1", "value2" }).put("param2", new String[] { "value3" }).done(); assertParameterMapsEquals(actual, expected); verify(request, chain); }