|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2015 the original author or authors. |
|
|
|
* Copyright 2002-2016 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -16,7 +16,6 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.web.servlet.tags; |
|
|
|
package org.springframework.web.servlet.tags; |
|
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Method; |
|
|
|
|
|
|
|
import java.util.HashSet; |
|
|
|
import java.util.HashSet; |
|
|
|
import java.util.LinkedList; |
|
|
|
import java.util.LinkedList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
@ -30,7 +29,6 @@ import org.junit.Test; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.mock.web.test.MockHttpServletRequest; |
|
|
|
import org.springframework.mock.web.test.MockHttpServletRequest; |
|
|
|
import org.springframework.mock.web.test.MockPageContext; |
|
|
|
import org.springframework.mock.web.test.MockPageContext; |
|
|
|
import org.springframework.util.ReflectionUtils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.hamcrest.Matchers.*; |
|
|
|
import static org.hamcrest.Matchers.*; |
|
|
|
import static org.junit.Assert.*; |
|
|
|
import static org.junit.Assert.*; |
|
|
|
@ -44,13 +42,15 @@ public class UrlTagTests extends AbstractTagTests { |
|
|
|
|
|
|
|
|
|
|
|
private MockPageContext context; |
|
|
|
private MockPageContext context; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Before |
|
|
|
@Before |
|
|
|
public void setUp() throws Exception { |
|
|
|
public void setup() throws Exception { |
|
|
|
context = createPageContext(); |
|
|
|
context = createPageContext(); |
|
|
|
tag = new UrlTag(); |
|
|
|
tag = new UrlTag(); |
|
|
|
tag.setPageContext(context); |
|
|
|
tag.setPageContext(context); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void paramSupport() { |
|
|
|
public void paramSupport() { |
|
|
|
assertThat(tag, instanceOf(ParamAware.class)); |
|
|
|
assertThat(tag, instanceOf(ParamAware.class)); |
|
|
|
@ -66,7 +66,6 @@ public class UrlTagTests extends AbstractTagTests { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void doEndTag() throws JspException { |
|
|
|
public void doEndTag() throws JspException { |
|
|
|
tag.setValue("url/path"); |
|
|
|
tag.setValue("url/path"); |
|
|
|
|
|
|
|
|
|
|
|
tag.doStartTag(); |
|
|
|
tag.doStartTag(); |
|
|
|
int action = tag.doEndTag(); |
|
|
|
int action = tag.doEndTag(); |
|
|
|
|
|
|
|
|
|
|
|
@ -77,12 +76,10 @@ public class UrlTagTests extends AbstractTagTests { |
|
|
|
public void varDefaultScope() throws JspException { |
|
|
|
public void varDefaultScope() throws JspException { |
|
|
|
tag.setValue("url/path"); |
|
|
|
tag.setValue("url/path"); |
|
|
|
tag.setVar("var"); |
|
|
|
tag.setVar("var"); |
|
|
|
|
|
|
|
|
|
|
|
tag.doStartTag(); |
|
|
|
tag.doStartTag(); |
|
|
|
tag.doEndTag(); |
|
|
|
tag.doEndTag(); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("url/path", context.getAttribute("var", |
|
|
|
assertEquals("url/path", context.getAttribute("var", PageContext.PAGE_SCOPE)); |
|
|
|
PageContext.PAGE_SCOPE)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -90,19 +87,16 @@ public class UrlTagTests extends AbstractTagTests { |
|
|
|
tag.setValue("url/path"); |
|
|
|
tag.setValue("url/path"); |
|
|
|
tag.setVar("var"); |
|
|
|
tag.setVar("var"); |
|
|
|
tag.setScope("request"); |
|
|
|
tag.setScope("request"); |
|
|
|
|
|
|
|
|
|
|
|
tag.doStartTag(); |
|
|
|
tag.doStartTag(); |
|
|
|
tag.doEndTag(); |
|
|
|
tag.doEndTag(); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("url/path", context.getAttribute("var", |
|
|
|
assertEquals("url/path", context.getAttribute("var", PageContext.REQUEST_SCOPE)); |
|
|
|
PageContext.REQUEST_SCOPE)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void setHtmlEscapeDefault() throws JspException { |
|
|
|
public void setHtmlEscapeDefault() throws JspException { |
|
|
|
tag.setValue("url/path"); |
|
|
|
tag.setValue("url/path"); |
|
|
|
tag.setVar("var"); |
|
|
|
tag.setVar("var"); |
|
|
|
|
|
|
|
|
|
|
|
tag.doStartTag(); |
|
|
|
tag.doStartTag(); |
|
|
|
|
|
|
|
|
|
|
|
Param param = new Param(); |
|
|
|
Param param = new Param(); |
|
|
|
@ -116,9 +110,7 @@ public class UrlTagTests extends AbstractTagTests { |
|
|
|
tag.addParam(param); |
|
|
|
tag.addParam(param); |
|
|
|
|
|
|
|
|
|
|
|
tag.doEndTag(); |
|
|
|
tag.doEndTag(); |
|
|
|
|
|
|
|
assertEquals("url/path?n%20me=v%26l%3De&name=value2", context.getAttribute("var")); |
|
|
|
assertEquals("url/path?n%20me=v%26l%3De&name=value2", context |
|
|
|
|
|
|
|
.getAttribute("var")); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -140,9 +132,7 @@ public class UrlTagTests extends AbstractTagTests { |
|
|
|
tag.addParam(param); |
|
|
|
tag.addParam(param); |
|
|
|
|
|
|
|
|
|
|
|
tag.doEndTag(); |
|
|
|
tag.doEndTag(); |
|
|
|
|
|
|
|
assertEquals("url/path?n%20me=v%26l%3De&name=value2", context.getAttribute("var")); |
|
|
|
assertEquals("url/path?n%20me=v%26l%3De&name=value2", context |
|
|
|
|
|
|
|
.getAttribute("var")); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -150,7 +140,6 @@ public class UrlTagTests extends AbstractTagTests { |
|
|
|
tag.setValue("url/path"); |
|
|
|
tag.setValue("url/path"); |
|
|
|
tag.setVar("var"); |
|
|
|
tag.setVar("var"); |
|
|
|
tag.setHtmlEscape(true); |
|
|
|
tag.setHtmlEscape(true); |
|
|
|
|
|
|
|
|
|
|
|
tag.doStartTag(); |
|
|
|
tag.doStartTag(); |
|
|
|
|
|
|
|
|
|
|
|
Param param = new Param(); |
|
|
|
Param param = new Param(); |
|
|
|
@ -164,9 +153,7 @@ public class UrlTagTests extends AbstractTagTests { |
|
|
|
tag.addParam(param); |
|
|
|
tag.addParam(param); |
|
|
|
|
|
|
|
|
|
|
|
tag.doEndTag(); |
|
|
|
tag.doEndTag(); |
|
|
|
|
|
|
|
assertEquals("url/path?n%20me=v%26l%3De&name=value2", context.getAttribute("var")); |
|
|
|
assertEquals("url/path?n%20me=v%26l%3De&name=value2", context |
|
|
|
|
|
|
|
.getAttribute("var")); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -174,7 +161,6 @@ public class UrlTagTests extends AbstractTagTests { |
|
|
|
tag.setValue("url/path"); |
|
|
|
tag.setValue("url/path"); |
|
|
|
tag.setVar("var"); |
|
|
|
tag.setVar("var"); |
|
|
|
tag.setJavaScriptEscape(true); |
|
|
|
tag.setJavaScriptEscape(true); |
|
|
|
|
|
|
|
|
|
|
|
tag.doStartTag(); |
|
|
|
tag.doStartTag(); |
|
|
|
|
|
|
|
|
|
|
|
Param param = new Param(); |
|
|
|
Param param = new Param(); |
|
|
|
@ -188,9 +174,7 @@ public class UrlTagTests extends AbstractTagTests { |
|
|
|
tag.addParam(param); |
|
|
|
tag.addParam(param); |
|
|
|
|
|
|
|
|
|
|
|
tag.doEndTag(); |
|
|
|
tag.doEndTag(); |
|
|
|
|
|
|
|
assertEquals("url\\/path?n%20me=v%26l%3De&name=value2", context.getAttribute("var")); |
|
|
|
assertEquals("url\\/path?n%20me=v%26l%3De&name=value2", context |
|
|
|
|
|
|
|
.getAttribute("var")); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -199,7 +183,6 @@ public class UrlTagTests extends AbstractTagTests { |
|
|
|
tag.setVar("var"); |
|
|
|
tag.setVar("var"); |
|
|
|
tag.setHtmlEscape(true); |
|
|
|
tag.setHtmlEscape(true); |
|
|
|
tag.setJavaScriptEscape(true); |
|
|
|
tag.setJavaScriptEscape(true); |
|
|
|
|
|
|
|
|
|
|
|
tag.doStartTag(); |
|
|
|
tag.doStartTag(); |
|
|
|
|
|
|
|
|
|
|
|
Param param = new Param(); |
|
|
|
Param param = new Param(); |
|
|
|
@ -213,25 +196,22 @@ public class UrlTagTests extends AbstractTagTests { |
|
|
|
tag.addParam(param); |
|
|
|
tag.addParam(param); |
|
|
|
|
|
|
|
|
|
|
|
tag.doEndTag(); |
|
|
|
tag.doEndTag(); |
|
|
|
|
|
|
|
assertEquals("url\\/path?n%20me=v%26l%3De&name=value2", context.getAttribute("var")); |
|
|
|
assertEquals("url\\/path?n%20me=v%26l%3De&name=value2", context |
|
|
|
|
|
|
|
.getAttribute("var")); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void createQueryStringNoParams() throws JspException { |
|
|
|
public void createQueryStringNoParams() throws JspException { |
|
|
|
List<Param> params = new LinkedList<Param>(); |
|
|
|
List<Param> params = new LinkedList<>(); |
|
|
|
Set<String> usedParams = new HashSet<String>(); |
|
|
|
Set<String> usedParams = new HashSet<>(); |
|
|
|
|
|
|
|
|
|
|
|
String queryString = tag.createQueryString(params, usedParams, true); |
|
|
|
String queryString = tag.createQueryString(params, usedParams, true); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("", queryString); |
|
|
|
assertEquals("", queryString); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void createQueryStringOneParam() throws JspException { |
|
|
|
public void createQueryStringOneParam() throws JspException { |
|
|
|
List<Param> params = new LinkedList<Param>(); |
|
|
|
List<Param> params = new LinkedList<>(); |
|
|
|
Set<String> usedParams = new HashSet<String>(); |
|
|
|
Set<String> usedParams = new HashSet<>(); |
|
|
|
|
|
|
|
|
|
|
|
Param param = new Param(); |
|
|
|
Param param = new Param(); |
|
|
|
param.setName("name"); |
|
|
|
param.setName("name"); |
|
|
|
@ -239,15 +219,13 @@ public class UrlTagTests extends AbstractTagTests { |
|
|
|
params.add(param); |
|
|
|
params.add(param); |
|
|
|
|
|
|
|
|
|
|
|
String queryString = tag.createQueryString(params, usedParams, true); |
|
|
|
String queryString = tag.createQueryString(params, usedParams, true); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("?name=value", queryString); |
|
|
|
assertEquals("?name=value", queryString); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void createQueryStringOneParamForExsistingQueryString() |
|
|
|
public void createQueryStringOneParamForExsistingQueryString() throws JspException { |
|
|
|
throws JspException { |
|
|
|
List<Param> params = new LinkedList<>(); |
|
|
|
List<Param> params = new LinkedList<Param>(); |
|
|
|
Set<String> usedParams = new HashSet<>(); |
|
|
|
Set<String> usedParams = new HashSet<String>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Param param = new Param(); |
|
|
|
Param param = new Param(); |
|
|
|
param.setName("name"); |
|
|
|
param.setName("name"); |
|
|
|
@ -255,14 +233,13 @@ public class UrlTagTests extends AbstractTagTests { |
|
|
|
params.add(param); |
|
|
|
params.add(param); |
|
|
|
|
|
|
|
|
|
|
|
String queryString = tag.createQueryString(params, usedParams, false); |
|
|
|
String queryString = tag.createQueryString(params, usedParams, false); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("&name=value", queryString); |
|
|
|
assertEquals("&name=value", queryString); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void createQueryStringOneParamEmptyValue() throws JspException { |
|
|
|
public void createQueryStringOneParamEmptyValue() throws JspException { |
|
|
|
List<Param> params = new LinkedList<Param>(); |
|
|
|
List<Param> params = new LinkedList<>(); |
|
|
|
Set<String> usedParams = new HashSet<String>(); |
|
|
|
Set<String> usedParams = new HashSet<>(); |
|
|
|
|
|
|
|
|
|
|
|
Param param = new Param(); |
|
|
|
Param param = new Param(); |
|
|
|
param.setName("name"); |
|
|
|
param.setName("name"); |
|
|
|
@ -270,14 +247,13 @@ public class UrlTagTests extends AbstractTagTests { |
|
|
|
params.add(param); |
|
|
|
params.add(param); |
|
|
|
|
|
|
|
|
|
|
|
String queryString = tag.createQueryString(params, usedParams, true); |
|
|
|
String queryString = tag.createQueryString(params, usedParams, true); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("?name=", queryString); |
|
|
|
assertEquals("?name=", queryString); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void createQueryStringOneParamNullValue() throws JspException { |
|
|
|
public void createQueryStringOneParamNullValue() throws JspException { |
|
|
|
List<Param> params = new LinkedList<Param>(); |
|
|
|
List<Param> params = new LinkedList<>(); |
|
|
|
Set<String> usedParams = new HashSet<String>(); |
|
|
|
Set<String> usedParams = new HashSet<>(); |
|
|
|
|
|
|
|
|
|
|
|
Param param = new Param(); |
|
|
|
Param param = new Param(); |
|
|
|
param.setName("name"); |
|
|
|
param.setName("name"); |
|
|
|
@ -285,31 +261,28 @@ public class UrlTagTests extends AbstractTagTests { |
|
|
|
params.add(param); |
|
|
|
params.add(param); |
|
|
|
|
|
|
|
|
|
|
|
String queryString = tag.createQueryString(params, usedParams, true); |
|
|
|
String queryString = tag.createQueryString(params, usedParams, true); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("?name", queryString); |
|
|
|
assertEquals("?name", queryString); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void createQueryStringOneParamAlreadyUsed() throws JspException { |
|
|
|
public void createQueryStringOneParamAlreadyUsed() throws JspException { |
|
|
|
List<Param> params = new LinkedList<Param>(); |
|
|
|
List<Param> params = new LinkedList<>(); |
|
|
|
Set<String> usedParams = new HashSet<String>(); |
|
|
|
Set<String> usedParams = new HashSet<>(); |
|
|
|
|
|
|
|
|
|
|
|
Param param = new Param(); |
|
|
|
Param param = new Param(); |
|
|
|
param.setName("name"); |
|
|
|
param.setName("name"); |
|
|
|
param.setValue("value"); |
|
|
|
param.setValue("value"); |
|
|
|
params.add(param); |
|
|
|
params.add(param); |
|
|
|
|
|
|
|
|
|
|
|
usedParams.add("name"); |
|
|
|
usedParams.add("name"); |
|
|
|
|
|
|
|
|
|
|
|
String queryString = tag.createQueryString(params, usedParams, true); |
|
|
|
String queryString = tag.createQueryString(params, usedParams, true); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("", queryString); |
|
|
|
assertEquals("", queryString); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void createQueryStringTwoParams() throws JspException { |
|
|
|
public void createQueryStringTwoParams() throws JspException { |
|
|
|
List<Param> params = new LinkedList<Param>(); |
|
|
|
List<Param> params = new LinkedList<>(); |
|
|
|
Set<String> usedParams = new HashSet<String>(); |
|
|
|
Set<String> usedParams = new HashSet<>(); |
|
|
|
|
|
|
|
|
|
|
|
Param param = new Param(); |
|
|
|
Param param = new Param(); |
|
|
|
param.setName("name"); |
|
|
|
param.setName("name"); |
|
|
|
@ -322,14 +295,13 @@ public class UrlTagTests extends AbstractTagTests { |
|
|
|
params.add(param); |
|
|
|
params.add(param); |
|
|
|
|
|
|
|
|
|
|
|
String queryString = tag.createQueryString(params, usedParams, true); |
|
|
|
String queryString = tag.createQueryString(params, usedParams, true); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("?name=value&name=value2", queryString); |
|
|
|
assertEquals("?name=value&name=value2", queryString); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void createQueryStringUrlEncoding() throws JspException { |
|
|
|
public void createQueryStringUrlEncoding() throws JspException { |
|
|
|
List<Param> params = new LinkedList<Param>(); |
|
|
|
List<Param> params = new LinkedList<>(); |
|
|
|
Set<String> usedParams = new HashSet<String>(); |
|
|
|
Set<String> usedParams = new HashSet<>(); |
|
|
|
|
|
|
|
|
|
|
|
Param param = new Param(); |
|
|
|
Param param = new Param(); |
|
|
|
param.setName("n me"); |
|
|
|
param.setName("n me"); |
|
|
|
@ -342,14 +314,13 @@ public class UrlTagTests extends AbstractTagTests { |
|
|
|
params.add(param); |
|
|
|
params.add(param); |
|
|
|
|
|
|
|
|
|
|
|
String queryString = tag.createQueryString(params, usedParams, true); |
|
|
|
String queryString = tag.createQueryString(params, usedParams, true); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("?n%20me=v%26l%3De&name=value2", queryString); |
|
|
|
assertEquals("?n%20me=v%26l%3De&name=value2", queryString); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void createQueryStringParamNullName() throws JspException { |
|
|
|
public void createQueryStringParamNullName() throws JspException { |
|
|
|
List<Param> params = new LinkedList<Param>(); |
|
|
|
List<Param> params = new LinkedList<>(); |
|
|
|
Set<String> usedParams = new HashSet<String>(); |
|
|
|
Set<String> usedParams = new HashSet<>(); |
|
|
|
|
|
|
|
|
|
|
|
Param param = new Param(); |
|
|
|
Param param = new Param(); |
|
|
|
param.setName(null); |
|
|
|
param.setName(null); |
|
|
|
@ -357,14 +328,13 @@ public class UrlTagTests extends AbstractTagTests { |
|
|
|
params.add(param); |
|
|
|
params.add(param); |
|
|
|
|
|
|
|
|
|
|
|
String queryString = tag.createQueryString(params, usedParams, true); |
|
|
|
String queryString = tag.createQueryString(params, usedParams, true); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("", queryString); |
|
|
|
assertEquals("", queryString); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void createQueryStringParamEmptyName() throws JspException { |
|
|
|
public void createQueryStringParamEmptyName() throws JspException { |
|
|
|
List<Param> params = new LinkedList<Param>(); |
|
|
|
List<Param> params = new LinkedList<>(); |
|
|
|
Set<String> usedParams = new HashSet<String>(); |
|
|
|
Set<String> usedParams = new HashSet<>(); |
|
|
|
|
|
|
|
|
|
|
|
Param param = new Param(); |
|
|
|
Param param = new Param(); |
|
|
|
param.setName(""); |
|
|
|
param.setName(""); |
|
|
|
@ -372,78 +342,65 @@ public class UrlTagTests extends AbstractTagTests { |
|
|
|
params.add(param); |
|
|
|
params.add(param); |
|
|
|
|
|
|
|
|
|
|
|
String queryString = tag.createQueryString(params, usedParams, true); |
|
|
|
String queryString = tag.createQueryString(params, usedParams, true); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("", queryString); |
|
|
|
assertEquals("", queryString); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void replaceUriTemplateParamsNoParams() throws JspException { |
|
|
|
public void replaceUriTemplateParamsNoParams() throws JspException { |
|
|
|
List<Param> params = new LinkedList<Param>(); |
|
|
|
List<Param> params = new LinkedList<>(); |
|
|
|
Set<String> usedParams = new HashSet<String>(); |
|
|
|
Set<String> usedParams = new HashSet<>(); |
|
|
|
|
|
|
|
|
|
|
|
String uri = tag.replaceUriTemplateParams("url/path", params, |
|
|
|
|
|
|
|
usedParams); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String uri = tag.replaceUriTemplateParams("url/path", params, usedParams); |
|
|
|
assertEquals("url/path", uri); |
|
|
|
assertEquals("url/path", uri); |
|
|
|
assertEquals(0, usedParams.size()); |
|
|
|
assertEquals(0, usedParams.size()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void replaceUriTemplateParamsTemplateWithoutParamMatch() |
|
|
|
public void replaceUriTemplateParamsTemplateWithoutParamMatch() throws JspException { |
|
|
|
throws JspException { |
|
|
|
List<Param> params = new LinkedList<>(); |
|
|
|
List<Param> params = new LinkedList<Param>(); |
|
|
|
Set<String> usedParams = new HashSet<>(); |
|
|
|
Set<String> usedParams = new HashSet<String>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String uri = tag.replaceUriTemplateParams("url/{path}", params, |
|
|
|
|
|
|
|
usedParams); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String uri = tag.replaceUriTemplateParams("url/{path}", params, usedParams); |
|
|
|
assertEquals("url/{path}", uri); |
|
|
|
assertEquals("url/{path}", uri); |
|
|
|
assertEquals(0, usedParams.size()); |
|
|
|
assertEquals(0, usedParams.size()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void replaceUriTemplateParamsTemplateWithParamMatch() |
|
|
|
public void replaceUriTemplateParamsTemplateWithParamMatch() throws JspException { |
|
|
|
throws JspException { |
|
|
|
List<Param> params = new LinkedList<>(); |
|
|
|
List<Param> params = new LinkedList<Param>(); |
|
|
|
Set<String> usedParams = new HashSet<>(); |
|
|
|
Set<String> usedParams = new HashSet<String>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Param param = new Param(); |
|
|
|
Param param = new Param(); |
|
|
|
param.setName("name"); |
|
|
|
param.setName("name"); |
|
|
|
param.setValue("value"); |
|
|
|
param.setValue("value"); |
|
|
|
params.add(param); |
|
|
|
params.add(param); |
|
|
|
|
|
|
|
|
|
|
|
String uri = tag.replaceUriTemplateParams("url/{name}", params, |
|
|
|
String uri = tag.replaceUriTemplateParams("url/{name}", params, usedParams); |
|
|
|
usedParams); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals("url/value", uri); |
|
|
|
assertEquals("url/value", uri); |
|
|
|
assertEquals(1, usedParams.size()); |
|
|
|
assertEquals(1, usedParams.size()); |
|
|
|
assertTrue(usedParams.contains("name")); |
|
|
|
assertTrue(usedParams.contains("name")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void replaceUriTemplateParamsTemplateWithParamMatchNamePreEncoding() |
|
|
|
public void replaceUriTemplateParamsTemplateWithParamMatchNamePreEncoding() throws JspException { |
|
|
|
throws JspException { |
|
|
|
List<Param> params = new LinkedList<>(); |
|
|
|
List<Param> params = new LinkedList<Param>(); |
|
|
|
Set<String> usedParams = new HashSet<>(); |
|
|
|
Set<String> usedParams = new HashSet<String>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Param param = new Param(); |
|
|
|
Param param = new Param(); |
|
|
|
param.setName("n me"); |
|
|
|
param.setName("n me"); |
|
|
|
param.setValue("value"); |
|
|
|
param.setValue("value"); |
|
|
|
params.add(param); |
|
|
|
params.add(param); |
|
|
|
|
|
|
|
|
|
|
|
String uri = tag.replaceUriTemplateParams("url/{n me}", params, |
|
|
|
String uri = tag.replaceUriTemplateParams("url/{n me}", params, usedParams); |
|
|
|
usedParams); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals("url/value", uri); |
|
|
|
assertEquals("url/value", uri); |
|
|
|
assertEquals(1, usedParams.size()); |
|
|
|
assertEquals(1, usedParams.size()); |
|
|
|
assertTrue(usedParams.contains("n me")); |
|
|
|
assertTrue(usedParams.contains("n me")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void replaceUriTemplateParamsTemplateWithParamMatchValueEncoded() |
|
|
|
public void replaceUriTemplateParamsTemplateWithParamMatchValueEncoded() throws JspException { |
|
|
|
throws JspException { |
|
|
|
List<Param> params = new LinkedList<>(); |
|
|
|
List<Param> params = new LinkedList<Param>(); |
|
|
|
Set<String> usedParams = new HashSet<>(); |
|
|
|
Set<String> usedParams = new HashSet<String>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Param param = new Param(); |
|
|
|
Param param = new Param(); |
|
|
|
param.setName("name"); |
|
|
|
param.setName("name"); |
|
|
|
@ -458,13 +415,10 @@ public class UrlTagTests extends AbstractTagTests { |
|
|
|
assertTrue(usedParams.contains("name")); |
|
|
|
assertTrue(usedParams.contains("name")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// SPR-11401
|
|
|
|
@Test // SPR-11401
|
|
|
|
|
|
|
|
public void replaceUriTemplateParamsTemplateWithPathSegment() throws JspException { |
|
|
|
@Test |
|
|
|
List<Param> params = new LinkedList<>(); |
|
|
|
public void replaceUriTemplateParamsTemplateWithPathSegment() |
|
|
|
Set<String> usedParams = new HashSet<>(); |
|
|
|
throws JspException { |
|
|
|
|
|
|
|
List<Param> params = new LinkedList<Param>(); |
|
|
|
|
|
|
|
Set<String> usedParams = new HashSet<String>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Param param = new Param(); |
|
|
|
Param param = new Param(); |
|
|
|
param.setName("name"); |
|
|
|
param.setName("name"); |
|
|
|
@ -479,10 +433,9 @@ public class UrlTagTests extends AbstractTagTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void replaceUriTemplateParamsTemplateWithPath() |
|
|
|
public void replaceUriTemplateParamsTemplateWithPath() throws JspException { |
|
|
|
throws JspException { |
|
|
|
List<Param> params = new LinkedList<>(); |
|
|
|
List<Param> params = new LinkedList<Param>(); |
|
|
|
Set<String> usedParams = new HashSet<>(); |
|
|
|
Set<String> usedParams = new HashSet<String>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Param param = new Param(); |
|
|
|
Param param = new Param(); |
|
|
|
param.setName("name"); |
|
|
|
param.setName("name"); |
|
|
|
@ -490,7 +443,6 @@ public class UrlTagTests extends AbstractTagTests { |
|
|
|
params.add(param); |
|
|
|
params.add(param); |
|
|
|
|
|
|
|
|
|
|
|
String uri = tag.replaceUriTemplateParams("url/{name}", params, usedParams); |
|
|
|
String uri = tag.replaceUriTemplateParams("url/{name}", params, usedParams); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("url/my/Id", uri); |
|
|
|
assertEquals("url/my/Id", uri); |
|
|
|
assertEquals(1, usedParams.size()); |
|
|
|
assertEquals(1, usedParams.size()); |
|
|
|
assertTrue(usedParams.contains("name")); |
|
|
|
assertTrue(usedParams.contains("name")); |
|
|
|
@ -499,89 +451,71 @@ public class UrlTagTests extends AbstractTagTests { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void createUrlRemoteServer() throws JspException { |
|
|
|
public void createUrlRemoteServer() throws JspException { |
|
|
|
tag.setValue("http://www.springframework.org/"); |
|
|
|
tag.setValue("http://www.springframework.org/"); |
|
|
|
|
|
|
|
|
|
|
|
tag.doStartTag(); |
|
|
|
tag.doStartTag(); |
|
|
|
|
|
|
|
|
|
|
|
// String uri = tag.createUrl();
|
|
|
|
String uri = tag.createUrl(); |
|
|
|
String uri = invokeCreateUrl(tag); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals("http://www.springframework.org/", uri); |
|
|
|
assertEquals("http://www.springframework.org/", uri); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void createUrlRelative() throws JspException { |
|
|
|
public void createUrlRelative() throws JspException { |
|
|
|
tag.setValue("url/path"); |
|
|
|
tag.setValue("url/path"); |
|
|
|
|
|
|
|
|
|
|
|
tag.doStartTag(); |
|
|
|
tag.doStartTag(); |
|
|
|
|
|
|
|
|
|
|
|
String uri = invokeCreateUrl(tag); |
|
|
|
String uri = tag.createUrl(); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("url/path", uri); |
|
|
|
assertEquals("url/path", uri); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void createUrlLocalContext() throws JspException { |
|
|
|
public void createUrlLocalContext() throws JspException { |
|
|
|
((MockHttpServletRequest) context.getRequest()) |
|
|
|
((MockHttpServletRequest) context.getRequest()).setContextPath("/app-context"); |
|
|
|
.setContextPath("/app-context"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tag.setValue("/url/path"); |
|
|
|
tag.setValue("/url/path"); |
|
|
|
|
|
|
|
|
|
|
|
tag.doStartTag(); |
|
|
|
tag.doStartTag(); |
|
|
|
|
|
|
|
|
|
|
|
String uri = invokeCreateUrl(tag); |
|
|
|
String uri = tag.createUrl(); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("/app-context/url/path", uri); |
|
|
|
assertEquals("/app-context/url/path", uri); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void createUrlRemoteContext() throws JspException { |
|
|
|
public void createUrlRemoteContext() throws JspException { |
|
|
|
((MockHttpServletRequest) context.getRequest()) |
|
|
|
((MockHttpServletRequest) context.getRequest()).setContextPath("/app-context"); |
|
|
|
.setContextPath("/app-context"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tag.setValue("/url/path"); |
|
|
|
tag.setValue("/url/path"); |
|
|
|
tag.setContext("some-other-context"); |
|
|
|
tag.setContext("some-other-context"); |
|
|
|
|
|
|
|
|
|
|
|
tag.doStartTag(); |
|
|
|
tag.doStartTag(); |
|
|
|
|
|
|
|
|
|
|
|
String uri = invokeCreateUrl(tag); |
|
|
|
String uri = tag.createUrl(); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("/some-other-context/url/path", uri); |
|
|
|
assertEquals("/some-other-context/url/path", uri); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void createUrlRemoteContextWithSlash() throws JspException { |
|
|
|
public void createUrlRemoteContextWithSlash() throws JspException { |
|
|
|
((MockHttpServletRequest) context.getRequest()) |
|
|
|
((MockHttpServletRequest) context.getRequest()).setContextPath("/app-context"); |
|
|
|
.setContextPath("/app-context"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tag.setValue("/url/path"); |
|
|
|
tag.setValue("/url/path"); |
|
|
|
tag.setContext("/some-other-context"); |
|
|
|
tag.setContext("/some-other-context"); |
|
|
|
|
|
|
|
|
|
|
|
tag.doStartTag(); |
|
|
|
tag.doStartTag(); |
|
|
|
|
|
|
|
|
|
|
|
String uri = invokeCreateUrl(tag); |
|
|
|
String uri = tag.createUrl(); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("/some-other-context/url/path", uri); |
|
|
|
assertEquals("/some-other-context/url/path", uri); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void createUrlRemoteContextSingleSlash() throws JspException { |
|
|
|
public void createUrlRemoteContextSingleSlash() throws JspException { |
|
|
|
((MockHttpServletRequest) context.getRequest()) |
|
|
|
((MockHttpServletRequest) context.getRequest()).setContextPath("/app-context"); |
|
|
|
.setContextPath("/app-context"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tag.setValue("/url/path"); |
|
|
|
tag.setValue("/url/path"); |
|
|
|
tag.setContext("/"); |
|
|
|
tag.setContext("/"); |
|
|
|
|
|
|
|
|
|
|
|
tag.doStartTag(); |
|
|
|
tag.doStartTag(); |
|
|
|
|
|
|
|
|
|
|
|
String uri = invokeCreateUrl(tag); |
|
|
|
String uri = tag.createUrl(); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("/url/path", uri); |
|
|
|
assertEquals("/url/path", uri); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void createUrlWithParams() throws JspException { |
|
|
|
public void createUrlWithParams() throws JspException { |
|
|
|
tag.setValue("url/path"); |
|
|
|
tag.setValue("url/path"); |
|
|
|
|
|
|
|
|
|
|
|
tag.doStartTag(); |
|
|
|
tag.doStartTag(); |
|
|
|
|
|
|
|
|
|
|
|
Param param = new Param(); |
|
|
|
Param param = new Param(); |
|
|
|
@ -594,15 +528,13 @@ public class UrlTagTests extends AbstractTagTests { |
|
|
|
param.setValue("v lue"); |
|
|
|
param.setValue("v lue"); |
|
|
|
tag.addParam(param); |
|
|
|
tag.addParam(param); |
|
|
|
|
|
|
|
|
|
|
|
String uri = invokeCreateUrl(tag); |
|
|
|
String uri = tag.createUrl(); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("url/path?name=value&n%20me=v%20lue", uri); |
|
|
|
assertEquals("url/path?name=value&n%20me=v%20lue", uri); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void createUrlWithTemplateParams() throws JspException { |
|
|
|
public void createUrlWithTemplateParams() throws JspException { |
|
|
|
tag.setValue("url/{name}"); |
|
|
|
tag.setValue("url/{name}"); |
|
|
|
|
|
|
|
|
|
|
|
tag.doStartTag(); |
|
|
|
tag.doStartTag(); |
|
|
|
|
|
|
|
|
|
|
|
Param param = new Param(); |
|
|
|
Param param = new Param(); |
|
|
|
@ -615,16 +547,13 @@ public class UrlTagTests extends AbstractTagTests { |
|
|
|
param.setValue("v lue"); |
|
|
|
param.setValue("v lue"); |
|
|
|
tag.addParam(param); |
|
|
|
tag.addParam(param); |
|
|
|
|
|
|
|
|
|
|
|
String uri = invokeCreateUrl(tag); |
|
|
|
String uri = tag.createUrl(); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("url/value?n%20me=v%20lue", uri); |
|
|
|
assertEquals("url/value?n%20me=v%20lue", uri); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void createUrlWithParamAndExsistingQueryString() |
|
|
|
public void createUrlWithParamAndExistingQueryString() throws JspException { |
|
|
|
throws JspException { |
|
|
|
|
|
|
|
tag.setValue("url/path?foo=bar"); |
|
|
|
tag.setValue("url/path?foo=bar"); |
|
|
|
|
|
|
|
|
|
|
|
tag.doStartTag(); |
|
|
|
tag.doStartTag(); |
|
|
|
|
|
|
|
|
|
|
|
Param param = new Param(); |
|
|
|
Param param = new Param(); |
|
|
|
@ -632,29 +561,8 @@ public class UrlTagTests extends AbstractTagTests { |
|
|
|
param.setValue("value"); |
|
|
|
param.setValue("value"); |
|
|
|
tag.addParam(param); |
|
|
|
tag.addParam(param); |
|
|
|
|
|
|
|
|
|
|
|
String uri = invokeCreateUrl(tag); |
|
|
|
String uri = tag.createUrl(); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("url/path?foo=bar&name=value", uri); |
|
|
|
assertEquals("url/path?foo=bar&name=value", uri); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void jspWriterOutput() { |
|
|
|
|
|
|
|
// TODO assert that the output to the JspWriter is the expected output
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void servletRepsonseEncodeUrl() { |
|
|
|
|
|
|
|
// TODO assert that HttpServletResponse.encodeURL(String) is invoked for
|
|
|
|
|
|
|
|
// non absolute urls
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// support methods
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String invokeCreateUrl(UrlTag tag) { |
|
|
|
|
|
|
|
Method createUrl = ReflectionUtils.findMethod(tag.getClass(), |
|
|
|
|
|
|
|
"createUrl"); |
|
|
|
|
|
|
|
ReflectionUtils.makeAccessible(createUrl); |
|
|
|
|
|
|
|
return (String) ReflectionUtils.invokeMethod(createUrl, tag); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|