コード例 #1
0
  @Test
  public void createQueryStringParamEmptyName() throws JspException {
    List<Param> params = new LinkedList<Param>();
    Set<String> usedParams = new HashSet<String>();

    Param param = new Param();
    param.setName("");
    param.setValue("value");
    params.add(param);

    String queryString = tag.createQueryString(params, usedParams, true);

    assertEquals("", queryString);
  }
コード例 #2
0
  @Test
  public void createQueryStringOneParamForExsistingQueryString() throws JspException {
    List<Param> params = new LinkedList<Param>();
    Set<String> usedParams = new HashSet<String>();

    Param param = new Param();
    param.setName("name");
    param.setValue("value");
    params.add(param);

    String queryString = tag.createQueryString(params, usedParams, false);

    assertEquals("&name=value", queryString);
  }
コード例 #3
0
  @Test
  public void createUrlWithParamAndExsistingQueryString() throws JspException {
    tag.setValue("url/path?foo=bar");

    tag.doStartTag();

    Param param = new Param();
    param.setName("name");
    param.setValue("value");
    tag.addParam(param);

    String uri = invokeCreateUrl(tag);

    assertEquals("url/path?foo=bar&name=value", uri);
  }
コード例 #4
0
  @Test
  public void replaceUriTemplateParamsTemplateWithPath() throws JspException {
    List<Param> params = new LinkedList<Param>();
    Set<String> usedParams = new HashSet<String>();

    Param param = new Param();
    param.setName("name");
    param.setValue("my/Id");
    params.add(param);

    String uri = tag.replaceUriTemplateParams("url/{name}", params, usedParams);

    assertEquals("url/my/Id", uri);
    assertEquals(1, usedParams.size());
    assertTrue(usedParams.contains("name"));
  }
コード例 #5
0
  @Test
  public void createQueryStringUrlEncoding() throws JspException {
    List<Param> params = new LinkedList<Param>();
    Set<String> usedParams = new HashSet<String>();

    Param param = new Param();
    param.setName("n me");
    param.setValue("v&l=e");
    params.add(param);

    param = new Param();
    param.setName("name");
    param.setValue("value2");
    params.add(param);

    String queryString = tag.createQueryString(params, usedParams, true);

    assertEquals("?n%20me=v%26l%3De&name=value2", queryString);
  }
コード例 #6
0
  @Test
  public void createUrlWithTemplateParams() throws JspException {
    tag.setValue("url/{name}");

    tag.doStartTag();

    Param param = new Param();
    param.setName("name");
    param.setValue("value");
    tag.addParam(param);

    param = new Param();
    param.setName("n me");
    param.setValue("v lue");
    tag.addParam(param);

    String uri = invokeCreateUrl(tag);

    assertEquals("url/value?n%20me=v%20lue", uri);
  }
コード例 #7
0
  @Test
  public void setHtmlEscapeDefault() throws JspException {
    tag.setValue("url/path");
    tag.setVar("var");

    tag.doStartTag();

    Param param = new Param();
    param.setName("n me");
    param.setValue("v&l=e");
    tag.addParam(param);

    param = new Param();
    param.setName("name");
    param.setValue("value2");
    tag.addParam(param);

    tag.doEndTag();

    assertEquals("url/path?n%20me=v%26l%3De&name=value2", context.getAttribute("var"));
  }