コード例 #1
0
  @Test
  public void findParameterValue() {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("myKey1", "myValue1");
    params.put("myKey2_myValue2", "xxx");
    params.put("myKey3_myValue3.x", "xxx");
    params.put("myKey4_myValue4.y", new String[] {"yyy"});

    assertNull(WebUtils.findParameterValue(params, "myKey0"));
    assertEquals("myValue1", WebUtils.findParameterValue(params, "myKey1"));
    assertEquals("myValue2", WebUtils.findParameterValue(params, "myKey2"));
    assertEquals("myValue3", WebUtils.findParameterValue(params, "myKey3"));
    assertEquals("myValue4", WebUtils.findParameterValue(params, "myKey4"));
  }
コード例 #2
0
 private boolean checkOrigin(
     String serverName, int port, String originHeader, List<String> allowed) {
   MockHttpServletRequest servletRequest = new MockHttpServletRequest();
   ServerHttpRequest request = new ServletServerHttpRequest(servletRequest);
   servletRequest.setServerName(serverName);
   if (port != -1) {
     servletRequest.setServerPort(port);
   }
   request.getHeaders().set(HttpHeaders.ORIGIN, originHeader);
   return WebUtils.isValidOrigin(request, allowed);
 }
コード例 #3
0
  @Test
  public void parseMatrixVariablesString() {
    MultiValueMap<String, String> variables;

    variables = WebUtils.parseMatrixVariables(null);
    assertEquals(0, variables.size());

    variables = WebUtils.parseMatrixVariables("year");
    assertEquals(1, variables.size());
    assertEquals("", variables.getFirst("year"));

    variables = WebUtils.parseMatrixVariables("year=2012");
    assertEquals(1, variables.size());
    assertEquals("2012", variables.getFirst("year"));

    variables = WebUtils.parseMatrixVariables("year=2012;colors=red,blue,green");
    assertEquals(2, variables.size());
    assertEquals(Arrays.asList("red", "blue", "green"), variables.get("colors"));
    assertEquals("2012", variables.getFirst("year"));

    variables = WebUtils.parseMatrixVariables(";year=2012;colors=red,blue,green;");
    assertEquals(2, variables.size());
    assertEquals(Arrays.asList("red", "blue", "green"), variables.get("colors"));
    assertEquals("2012", variables.getFirst("year"));

    variables = WebUtils.parseMatrixVariables("colors=red;colors=blue;colors=green");
    assertEquals(1, variables.size());
    assertEquals(Arrays.asList("red", "blue", "green"), variables.get("colors"));
  }
コード例 #4
0
 @Test
 public void extractFilenameFromUrlPath() {
   assertEquals("index", WebUtils.extractFilenameFromUrlPath("index.html"));
   assertEquals("index", WebUtils.extractFilenameFromUrlPath("/index.html"));
   assertEquals("view", WebUtils.extractFilenameFromUrlPath("/products/view.html"));
   assertEquals("view", WebUtils.extractFilenameFromUrlPath("/products/view.html?param=a"));
   assertEquals("view", WebUtils.extractFilenameFromUrlPath("/products/view.html?param=/path/a"));
   assertEquals(
       "view", WebUtils.extractFilenameFromUrlPath("/products/view.html?param=/path/a.do"));
 }