Exemplo n.º 1
0
  @Test
  public void doEndTag() throws JspException {
    tag.setValue("url/path");

    tag.doStartTag();
    int action = tag.doEndTag();

    assertEquals(Tag.EVAL_PAGE, action);
  }
Exemplo n.º 2
0
  @Test
  public void varDefaultScope() throws JspException {
    tag.setValue("url/path");
    tag.setVar("var");

    tag.doStartTag();
    tag.doEndTag();

    assertEquals("url/path", context.getAttribute("var", PageContext.PAGE_SCOPE));
  }
Exemplo n.º 3
0
  @Test
  public void createUrlRelative() throws JspException {
    tag.setValue("url/path");

    tag.doStartTag();

    String uri = invokeCreateUrl(tag);

    assertEquals("url/path", uri);
  }
Exemplo n.º 4
0
  @Test
  public void varExplicitScope() throws JspException {
    tag.setValue("url/path");
    tag.setVar("var");
    tag.setScope("request");

    tag.doStartTag();
    tag.doEndTag();

    assertEquals("url/path", context.getAttribute("var", PageContext.REQUEST_SCOPE));
  }
Exemplo n.º 5
0
  @Test
  public void createUrlRemoteServer() throws JspException {
    tag.setValue("http://www.springframework.org/");

    tag.doStartTag();

    // String uri = tag.createUrl();
    String uri = invokeCreateUrl(tag);

    assertEquals("http://www.springframework.org/", uri);
  }
Exemplo n.º 6
0
  @Test
  public void createUrlLocalContext() throws JspException {
    ((MockHttpServletRequest) context.getRequest()).setContextPath("/app-context");

    tag.setValue("/url/path");

    tag.doStartTag();

    String uri = invokeCreateUrl(tag);

    assertEquals("/app-context/url/path", uri);
  }
Exemplo n.º 7
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);
  }
Exemplo n.º 8
0
  @Test
  public void createQueryStringNoParams() throws JspException {
    List<Param> params = new LinkedList<Param>();
    Set<String> usedParams = new HashSet<String>();

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

    assertEquals("", queryString);
  }
Exemplo n.º 9
0
  @Test
  public void replaceUriTemplateParamsTemplateWithoutParamMatch() throws JspException {
    List<Param> params = new LinkedList<Param>();
    Set<String> usedParams = new HashSet<String>();

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

    assertEquals("url/{path}", uri);
    assertEquals(0, usedParams.size());
  }
Exemplo n.º 10
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);
  }
Exemplo n.º 11
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);
  }
Exemplo n.º 12
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);
  }
Exemplo n.º 13
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"));
  }
Exemplo n.º 14
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);
  }
Exemplo n.º 15
0
  @Test
  public void setHtmlAndJavaScriptEscapeTrue() throws JspException {
    tag.setValue("url/path");
    tag.setVar("var");
    tag.setHtmlEscape(true);
    tag.setJavaScriptEscape(true);

    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&amp;name=value2", context.getAttribute("var"));
  }
Exemplo n.º 16
0
 private String invokeCreateUrl(UrlTag tag) {
   Method createUrl = ReflectionUtils.findMethod(tag.getClass(), "createUrl");
   ReflectionUtils.makeAccessible(createUrl);
   return (String) ReflectionUtils.invokeMethod(createUrl, tag);
 }
Exemplo n.º 17
0
  @Test
  public void doStartTag() throws JspException {
    int action = tag.doStartTag();

    assertEquals(Tag.EVAL_BODY_INCLUDE, action);
  }
Exemplo n.º 18
0
 @Before
 public void setUp() throws Exception {
   context = createPageContext();
   tag = new UrlTag();
   tag.setPageContext(context);
 }