コード例 #1
0
  public void testAdditionalParameters() {
    TestRequest original = new TestRequest();
    String p0 = "p0";
    String v0 = "v0";
    original.setParameter(p0, v0);
    String p1 = "p1";
    String v1a = "v1a";
    String v1b = "v1b";
    original.addParameter(p1, v1a);
    original.addParameter(p1, v1b);

    Map<String, String[]> paramMap = new HashMap<String, String[]>();
    String p2 = "p2";
    String v2 = "v2";
    String p3 = "p3";
    String v3a = "v3a";
    String v3b = "v3b";
    paramMap.put(p2, new String[] {v2});
    paramMap.put(p3, new String[] {v3a, v3b});
    WrappedRequest wrapper = new WrappedRequest(original, paramMap);

    assertEquals(v0, wrapper.getParameter(p0));
    assertEquals(v1a, wrapper.getParameter(p1));
    assertEquals(v2, wrapper.getParameter(p2));
    assertEquals(v3a, wrapper.getParameter(p3));

    Enumeration parameterNames = wrapper.getParameterNames();
    Set<Object> names = new HashSet<Object>();
    while (parameterNames.hasMoreElements()) {
      names.add(parameterNames.nextElement());
    }
    assertTrue(names.contains(p0));
    assertTrue(names.contains(p1));
    assertTrue(names.contains(p2));
    assertTrue(names.contains(p3));

    assertEquals(v0, wrapper.getParameterValues(p0)[0]);
    assertEquals(v1a, wrapper.getParameterValues(p1)[0]);
    assertEquals(v1b, wrapper.getParameterValues(p1)[1]);
    assertEquals(v2, wrapper.getParameterValues(p2)[0]);
    assertEquals(v3a, wrapper.getParameterValues(p3)[0]);
    assertEquals(v3b, wrapper.getParameterValues(p3)[1]);

    Map parameterMap = wrapper.getParameterMap();
    assertEquals(v0, ((String[]) parameterMap.get(p0))[0]);
    assertEquals(v1a, ((String[]) parameterMap.get(p1))[0]);
    assertEquals(v1b, ((String[]) parameterMap.get(p1))[1]);
    assertEquals(v2, ((String[]) parameterMap.get(p2))[0]);
    assertEquals(v3a, ((String[]) parameterMap.get(p3))[0]);
    assertEquals(v3b, ((String[]) parameterMap.get(p3))[1]);

    try {
      parameterMap.clear();
      fail();
    } catch (UnsupportedOperationException usoe) {
    }
  }
コード例 #2
0
 private static void fakeServletPath(String string) {
   TestRequest request = (TestRequest) ContextProvider.getRequest();
   request.setServletPath(string);
 }