Esempio n. 1
0
  public void testDoEndTag() throws JspException {
    tag.setValue("url/path");

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

    assertEquals(Tag.EVAL_PAGE, action);
  }
Esempio n. 2
0
  public void testCreateUrlRelative() throws JspException {
    tag.setValue("url/path");

    tag.doStartTag();

    String uri = invokeCreateUrl(tag);

    assertEquals("url/path", uri);
  }
Esempio n. 3
0
  public void testVarDefaultScope() throws JspException {
    tag.setValue("url/path");
    tag.setVar("var");

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

    assertEquals("url/path", context.getAttribute("var", PageContext.PAGE_SCOPE));
  }
Esempio n. 4
0
  public void testVarExplicitScope() 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));
  }
Esempio n. 5
0
  public void testCreateUrlRemoteServer() throws JspException {
    tag.setValue("http://www.springframework.org/");

    tag.doStartTag();

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

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

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

    tag.doStartTag();

    String uri = invokeCreateUrl(tag);

    assertEquals("/app-context/url/path", uri);
  }
Esempio n. 7
0
  @Test
  public void createUrlRemoteContextSingleSlash() throws JspException {
    ((MockHttpServletRequest) context.getRequest()).setContextPath("/app-context");

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

    tag.doStartTag();

    String uri = invokeCreateUrl(tag);

    assertEquals("/url/path", uri);
  }
Esempio n. 8
0
  public void testCreateUrlWithParamAndExsistingQueryString() 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);
  }
Esempio n. 9
0
  public void testCreateQueryStringNoParams() throws JspException {
    List<Param> params = new LinkedList<Param>();
    Set<String> usedParams = new HashSet<String>();

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

    assertEquals("", queryString);
  }
Esempio n. 10
0
  public void testReplaceUriTemplateParamsTemplateWithoutParamMatch() 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());
  }
Esempio n. 11
0
  @Test
  public void replaceUriTemplateParamsNoParams() 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());
  }
Esempio n. 12
0
  public void testCreateUrlWithTemplateParams() 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);
  }
Esempio n. 13
0
  @Test
  public void createUrlWithParams() throws JspException {
    tag.setValue("url/path");

    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/path?name=value&n%20me=v%20lue", uri);
  }
Esempio n. 14
0
  public void testCreateQueryStringOneParamForExsistingQueryString() 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);
  }
Esempio n. 15
0
  public void testCreateQueryStringParamEmptyName() 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);
  }
Esempio n. 16
0
  @Test
  public void createQueryStringOneParamNullValue() throws JspException {
    List<Param> params = new LinkedList<Param>();
    Set<String> usedParams = new HashSet<String>();

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

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

    assertEquals("?name", queryString);
  }
Esempio n. 17
0
  public void testReplaceUriTemplateParamsTemplateWithParamMatchValueEncoded() throws JspException {
    List<Param> params = new LinkedList<Param>();
    Set<String> usedParams = new HashSet<String>();

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

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

    assertEquals("url/v%20lue", uri);
    assertEquals(1, usedParams.size());
    assertTrue(usedParams.contains("name"));
  }
Esempio n. 18
0
  @Test
  public void replaceUriTemplateParamsTemplateWithPathSegment() 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%2FId", uri);
    assertEquals(1, usedParams.size());
    assertTrue(usedParams.contains("name"));
  }
Esempio n. 19
0
  public void testCreateQueryStringUrlEncoding() 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);
  }
Esempio n. 20
0
  public void testSetHtmlAndJavaScriptEscapeTrue() 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"));
  }
Esempio n. 21
0
  @Test
  public void setHtmlEscapeFalse() throws JspException {
    tag.setValue("url/path");
    tag.setVar("var");
    tag.setHtmlEscape(false);

    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"));
  }
Esempio n. 22
0
 private String invokeCreateUrl(UrlTag tag) {
   Method createUrl = ReflectionUtils.findMethod(tag.getClass(), "createUrl");
   ReflectionUtils.makeAccessible(createUrl);
   return (String) ReflectionUtils.invokeMethod(createUrl, tag);
 }
Esempio n. 23
0
  @Test
  public void doStartTag() throws JspException {
    int action = tag.doStartTag();

    assertEquals(Tag.EVAL_BODY_INCLUDE, action);
  }
Esempio n. 24
0
 @Override
 protected void setUp() throws Exception {
   context = createPageContext();
   tag = new UrlTag();
   tag.setPageContext(context);
 }
Esempio n. 25
0
 @Before
 public void setUp() throws Exception {
   context = createPageContext();
   tag = new UrlTag();
   tag.setPageContext(context);
 }