📄 testtagutils.java
字号:
Map map = null;
try {
map = tagutils.computeParameters(pageContext, null, null, null,
null, "attr", "mapProperty", "request", false);
} catch (JspException e) {
fail("JspException: " + e);
}
assertNotNull("Map is not null", map);
assertEquals("Two parameter in the returned map", 2, map.size());
assertTrue("Parameter foo1 present", map.containsKey("foo1"));
assertEquals("Parameter foo1 value", "bar1", (String) map.get("foo1"));
assertTrue("Parameter foo2 present", map.containsKey("foo2"));
assertEquals("Parameter foo2 value", "bar2", (String) map.get("foo2"));
}
// Provided map -- name with one key and two values
public void testComputeParameters2d() {
Map map = new HashMap();
map.put("foo", new String[] { "bar1", "bar2" });
request.getSession().setAttribute("attr", map);
try {
map = tagutils.computeParameters(pageContext, null, null, null,
null, "attr", null, null, false);
} catch (JspException e) {
fail("JspException: " + e);
}
assertNotNull("Map is not null", map);
assertEquals("One parameter in the returned map", 1, map.size());
assertTrue("Parameter foo present", map.containsKey("foo"));
assertTrue("Parameter foo value type",
map.get("foo") instanceof String[]);
String[] values = (String[]) map.get("foo");
assertEquals("Values count", 2, values.length);
}
// Kitchen sink combination of parameters with a merge
public void testComputeParameters3a() {
request.setAttribute("attr", new MockFormBean("bar3"));
request.getSession().setAttribute(Globals.TRANSACTION_TOKEN_KEY, "token");
Map map = null;
try {
map = tagutils.computeParameters(pageContext, "foo1", "attr",
"stringProperty", "request", "attr", "mapProperty",
"request", true);
} catch (JspException e) {
fail("JspException: " + e);
}
assertNotNull("Map is not null", map);
assertEquals("Three parameter in the returned map", 3, map.size());
assertTrue("Parameter foo1 present", map.containsKey("foo1"));
assertTrue("Parameter foo1 value type",
map.get("foo1") instanceof String[]);
String[] values = (String[]) map.get("foo1");
assertEquals("Values count", 2, values.length);
assertTrue("Parameter foo2 present", map.containsKey("foo2"));
assertEquals("Parameter foo2 value", "bar2", (String) map.get("foo2"));
assertTrue("Transaction token parameter present",
map.containsKey(Constants.TOKEN_KEY));
assertEquals("Transaction token parameter value", "token",
(String) map.get(Constants.TOKEN_KEY));
}
// Kitchen sink combination of parameters with a merge
// with array values in map
public void testComputeParameters3aa() {
request.setAttribute("attr", new MockFormBean("bar3"));
request.getSession().setAttribute(Globals.TRANSACTION_TOKEN_KEY, "token");
Map map = null;
try {
map = tagutils.computeParameters(pageContext, "foo1", "attr",
"stringProperty", "request", "attr",
"mapPropertyArrayValues", "request", true);
} catch (JspException e) {
fail("JspException: " + e);
}
assertNotNull("Map is not null", map);
assertEquals("Three parameter in the returned map", 3, map.size());
assertTrue("Parameter foo1 present", map.containsKey("foo1"));
assertTrue("Parameter foo1 value type",
map.get("foo1") instanceof String[]);
String[] values = (String[]) map.get("foo1");
assertEquals("Values count", 3, values.length);
assertTrue("Parameter foo2 present", map.containsKey("foo2"));
String[] arrayValues = (String[]) map.get("foo2");
String val = arrayValues[0];
assertEquals("Parameter foo2 value", "bar2", val);
assertTrue("Transaction token parameter present",
map.containsKey(Constants.TOKEN_KEY));
assertEquals("Transaction token parameter value", "token",
(String) map.get(Constants.TOKEN_KEY));
}
// Kitchen sink combination of parameters with a merge
public void testComputeParameters3b() {
request.setAttribute("attr", new MockFormBean("bar3"));
request.getSession().setAttribute(Globals.TRANSACTION_TOKEN_KEY, "token");
Map map = null;
try {
map = tagutils.computeParameters(pageContext, "foo1", "attr",
"stringProperty", "request", "attr", "mapProperty",
"request", true);
} catch (JspException e) {
fail("JspException: " + e);
}
assertNotNull("Map is not null", map);
assertEquals("Three parameter in the returned map", 3, map.size());
assertTrue("Parameter foo1 present", map.containsKey("foo1"));
assertTrue("Parameter foo1 value type",
map.get("foo1") instanceof String[]);
String[] values = (String[]) map.get("foo1");
assertEquals("Values count", 2, values.length);
assertTrue("Parameter foo2 present", map.containsKey("foo2"));
assertEquals("Parameter foo2 value", "bar2", (String) map.get("foo2"));
assertTrue("Transaction token parameter present",
map.containsKey(Constants.TOKEN_KEY));
assertEquals("Transaction token parameter value", "token",
(String) map.get(Constants.TOKEN_KEY));
}
// ----------------------------------------------------------- computeURL()
// Default module -- Forward only
public void testComputeURL1a() {
request.setPathElements("/myapp", "/action.do", null, null);
String url = null;
try {
url = tagutils.computeURL(pageContext, "foo", null, null, null,
null, null, null, false);
} catch (MalformedURLException e) {
fail("MalformedURLException: " + e);
}
assertNotNull("url present", url);
assertEquals("url value", "/myapp/bar.jsp", url);
}
// Default module -- Href only
public void testComputeURL1b() {
request.setPathElements("/myapp", "/action.do", null, null);
String url = null;
try {
url = tagutils.computeURL(pageContext, null, "http://foo.com/bar",
null, null, null, null, null, false);
} catch (MalformedURLException e) {
fail("MalformedURLException: " + e);
}
assertNotNull("url present", url);
assertEquals("url value", "http://foo.com/bar", url);
}
// Default module -- Page only
public void testComputeURL1c() {
request.setPathElements("/myapp", "/action.do", null, null);
String url = null;
try {
url = tagutils.computeURL(pageContext, null, null, "/bar", null,
null, null, null, false);
} catch (MalformedURLException e) {
fail("MalformedURLException: " + e);
}
assertNotNull("url present", url);
assertEquals("url value", "/myapp/bar", url);
}
// Default module -- Forward with pattern
public void testComputeURL1d() {
moduleConfig.getControllerConfig().setForwardPattern("$C/WEB-INF/pages$M$P");
request.setPathElements("/myapp", "/action.do", null, null);
String url = null;
try {
url = tagutils.computeURL(pageContext, "foo", null, null, null,
null, null, null, false);
} catch (MalformedURLException e) {
fail("MalformedURLException: " + e);
}
assertNotNull("url present", url);
assertEquals("url value", "/myapp/WEB-INF/pages/bar.jsp", url);
}
// Default module -- Page with pattern
public void testComputeURL1e() {
moduleConfig.getControllerConfig().setPagePattern("$C/WEB-INF/pages$M$P");
request.setPathElements("/myapp", "/action.do", null, null);
String url = null;
try {
url = tagutils.computeURL(pageContext, null, null, "/bar", null,
null, null, null, false);
} catch (MalformedURLException e) {
fail("MalformedURLException: " + e);
}
assertNotNull("url present", url);
assertEquals("url value", "/myapp/WEB-INF/pages/bar", url);
}
// Default module -- Forward with relative path (non-context-relative)
public void testComputeURL1f() {
request.setPathElements("/myapp", "/action.do", null, null);
String url = null;
try {
url = tagutils.computeURL(pageContext, "relative1", null, null,
null, null, null, null, false);
} catch (MalformedURLException e) {
fail("MalformedURLException: " + e);
}
assertNotNull("url present", url);
assertEquals("url value",
// "/myapp/relative.jsp",
"relative.jsp", url);
}
// Default module -- Forward with relative path (context-relative)
public void testComputeURL1g() {
request.setPathElements("/myapp", "/action.do", null, null);
String url = null;
try {
url = tagutils.computeURL(pageContext, "relative2", null, null,
null, null, null, null, false);
} catch (MalformedURLException e) {
fail("MalformedURLException: " + e);
}
assertNotNull("url present", url);
assertEquals("url value",
// "/myapp/relative.jsp",
"relative.jsp", url);
}
// Default module -- Forward with external path
public void testComputeURL1h() {
request.setPathElements("/myapp", "/action.do", null, null);
String url = null;
try {
url = tagutils.computeURL(pageContext, "external", null, null,
null, null, null, null, false);
} catch (MalformedURLException e) {
fail("MalformedURLException: " + e);
}
assertNotNull("url present", url);
assertEquals("url value", "http://struts.apache.org/", url);
}
// Second module -- Forward only
public void testComputeURL2a() {
request.setAttribute(Globals.MODULE_KEY, moduleConfig2);
request.setPathElements("/myapp", "/2/action.do", null, null);
String url = null;
try {
url = tagutils.computeURL(pageContext, "foo", null, null, null,
null, null, null, false);
} catch (MalformedURLException e) {
fail("MalformedURLException: " + e);
}
assertNotNull("url present", url);
assertEquals("url value", "/myapp/2/baz.jsp", url);
}
// Second module -- Href only
public void testComputeURL2b() {
request.setAttribute(Globals.MODULE_KEY, moduleConfig2);
request.setPathElements("/myapp", "/2/action.do", null, null);
String url = null;
try {
url = tagutils.computeURL(pageContext, null, "http://foo.com/bar",
null, null, null, null, null, false);
} catch (MalformedURLException e) {
fail("MalformedURLException: " + e);
}
assertNotNull("url present", url);
assertEquals("url value", "http://foo.com/bar", url);
}
// Second module -- Page only
public void testComputeURL2c() {
request.setAttribute(Globals.MODULE_KEY, moduleConfig2);
request.setPathElements("/myapp", "/2/action.do", null, null);
String url = null;
try {
url = tagutils.computeURL(pageContext, null, null, "/bar", null,
null, null, null, false);
} catch (MalformedURLException e) {
fail("MalformedURLException: " + e);
}
assertNotNull("url present", url);
assertEquals("url value", "/myapp/2/bar", url);
}
// Default module -- Forward with pattern
public void testComputeURL2d() {
request.setAttribute(Globals.MODULE_KEY, moduleConfig2);
moduleConfig2.getControllerConfig().setForwardPattern("$C/WEB-INF/pages$M$P");
request.setPathElements("/myapp", "/2/action.do", null, null);
String url = null;
try {
url = tagutils.computeURL(pageContext, "foo", null, null, null,
null, null, null, false);
} catch (MalformedURLException e) {
fail("MalformedURLException: " + e);
}
assertNotNull("url present", url);
assertEquals("url value", "/myapp/WEB-INF/pages/2/baz.jsp", url);
}
// Second module -- Page with pattern
public void testComputeURL2e() {
moduleConfig2.getControllerConfig().setPagePattern("$C/WEB-INF/pages$M$P");
request.setAttribute(Globals.MODULE_KEY, moduleConfig2);
request.setPathElements("/myapp", "/2/action.do", null, null);
String url = null;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -