?? testiteratetag.java
字號:
//fix for introduced carriage return / line feeds
output = replace(compare,"\r","");
output = replace(output,"\n","");
assertEquals(compare, output);
}
// ========= Session
public void testSessionScopePropertyIterateMap()
throws ServletException, JspException, IOException {
String testKey = "testSessionScopePropertyIterateMap";
HashMap map = new HashMap();
for (int i = 0; i < iterations; i++) {
map.put("test" + i,"test" + i);
}
SimpleBeanForTesting sbft = new SimpleBeanForTesting();
sbft.setMap(map);
pageContext.setAttribute(testKey, sbft,
PageContext.SESSION_SCOPE);
IterateTag tag = new IterateTag();
tag.setPageContext(pageContext);
tag.setId("theId");
tag.setName(testKey);
tag.setScope("session");
tag.setProperty("map");
int iteration = 0;
tag.doStartTag();
tag.doInitBody();
do
{
out.print(pageContext.getAttribute("theId"));
iteration++;
} while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG);
tag.doEndTag();
assertEquals(iterations, iteration);
}
public void endSessionScopePropertyIterateMap (WebResponse response){
String output = response.getText();
String compare = "";
for (int i = 0; i < iterations; i++) {
compare += "test" + i;
}
//fix for introduced carriage return / line feeds
output = replace(compare,"\r","");
output = replace(output,"\n","");
assertEquals(compare, output);
}
// ========= Request
public void testRequestScopePropertyIterateMap()
throws ServletException, JspException, IOException {
String testKey = "testRequestScopePropertyIterateMap";
HashMap map = new HashMap();
for (int i = 0; i < iterations; i++) {
map.put("test" + i,"test" + i);
}
SimpleBeanForTesting sbft = new SimpleBeanForTesting();
sbft.setMap(map);
pageContext.setAttribute(testKey, sbft,
PageContext.REQUEST_SCOPE);
IterateTag tag = new IterateTag();
tag.setPageContext(pageContext);
tag.setId("theId");
tag.setName(testKey);
tag.setScope("request");
tag.setProperty("map");
int iteration = 0;
tag.doStartTag();
tag.doInitBody();
do
{
out.print(pageContext.getAttribute("theId"));
iteration++;
} while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG);
tag.doEndTag();
assertEquals(iterations, iteration);
}
public void endRequestScopePropertyIterateMap (WebResponse response){
String output = response.getText();
String compare = "";
for (int i = 0; i < iterations; i++) {
compare += "test" + i;
}
//fix for introduced carriage return / line feeds
output = replace(compare,"\r","");
output = replace(output,"\n","");
assertEquals(compare, output);
}
/**
* Testing <code>IterateTag</code> using name attribute in
* the application scope.
*
* Tests the equivalent of this tag in a jsp:
* <logic:iterate id="theId" name="testApplicationScopeNameIterateArray"
* scope="application">
*
*/
// ========= Application
public void testApplicationScopeNameIterateArray()
throws ServletException, JspException, IOException {
String testKey = "testApplicationScopeNameIterateArray";
String[] tst = new String[iterations];
for (int i = 0; i < tst.length; i++) {
tst[i] = "test" + i;
}
pageContext.setAttribute(testKey, tst,
PageContext.APPLICATION_SCOPE);
IterateTag tag = new IterateTag();
tag.setPageContext(pageContext);
tag.setId("theId");
tag.setName(testKey);
tag.setScope("application");
int iteration = 0;
tag.doStartTag();
tag.doInitBody();
do
{
out.print(pageContext.getAttribute("theId"));
iteration++;
} while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG);
tag.doEndTag();
assertEquals(iterations, iteration);
}
public void endApplicationScopeNameIterateArray (WebResponse response){
String output = response.getText();
String[] tst = new String[iterations];
for (int i = 0; i < tst.length; i++) {
tst[i] = "test" + i;
}
String compare = "";
for (int i = 0; i < iterations; i++) {
compare += tst[i];
}
//fix for introduced carriage return / line feeds
output = replace(compare,"\r","");
output = replace(output,"\n","");
assertEquals(compare, output);
}
// ========= Session
public void testSessionScopeNameIterateArray()
throws ServletException, JspException, IOException {
String testKey = "testSessionScopeNameIterateArray";
String[] tst = new String[iterations];
for (int i = 0; i < tst.length; i++) {
tst[i] = "test" + i;
}
pageContext.setAttribute(testKey, tst,
PageContext.SESSION_SCOPE);
IterateTag tag = new IterateTag();
tag.setPageContext(pageContext);
tag.setId("theId");
tag.setName(testKey);
tag.setScope("session");
int iteration = 0;
tag.doStartTag();
tag.doInitBody();
do
{
out.print(pageContext.getAttribute("theId"));
iteration++;
} while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG);
tag.doEndTag();
assertEquals(iterations, iteration);
}
public void endSessionScopeNameIterateArray (WebResponse response){
String output = response.getText();
String[] tst = new String[iterations];
for (int i = 0; i < tst.length; i++) {
tst[i] = "test" + i;
}
String compare = "";
for (int i = 0; i < iterations; i++) {
compare += tst[i];
}
//fix for introduced carriage return / line feeds
output = replace(compare,"\r","");
output = replace(output,"\n","");
assertEquals(compare, output);
}
// ========= Request
public void testRequestScopeNameIterateArray()
throws ServletException, JspException, IOException {
String testKey = "testRequestScopeNameIterateArray";
String[] tst = new String[iterations];
for (int i = 0; i < tst.length; i++) {
tst[i] = "test" + i;
}
pageContext.setAttribute(testKey, tst,
PageContext.REQUEST_SCOPE);
IterateTag tag = new IterateTag();
tag.setPageContext(pageContext);
tag.setId("theId");
tag.setName(testKey);
tag.setScope("request");
int iteration = 0;
tag.doStartTag();
tag.doInitBody();
do
{
out.print(pageContext.getAttribute("theId"));
iteration++;
} while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG);
tag.doEndTag();
assertEquals(iterations, iteration);
}
public void endRequestScopeNameIterateArray (WebResponse response){
String output = response.getText();
String[] tst = new String[iterations];
for (int i = 0; i < tst.length; i++) {
tst[i] = "test" + i;
}
String compare = "";
for (int i = 0; i < iterations; i++) {
compare += tst[i];
}
//fix for introduced carriage return / line feeds
output = replace(compare,"\r","");
output = replace(output,"\n","");
assertEquals(compare, output);
}
/**
* Testing <code>IterateTag</code> using property attribute in
* the application scope.
*
* Tests the equivalent of this tag in a jsp:
* <logic:iterate id="theId" name="testApplicationScopePropertyIterateArray"
* scope="application">
*
*/
// ========= Application
public void testApplicationScopePropertyIterateArray()
throws ServletException, JspException, IOException {
String testKey = "testApplicationScopePropertyIterateArray";
String[] tst = new String[iterations];
for (int i = 0; i < tst.length; i++) {
tst[i] = "test" + i;
}
SimpleBeanForTesting sbft = new SimpleBeanForTesting();
sbft.setArray(tst);
pageContext.setAttribute(testKey, sbft,
PageContext.APPLICATION_SCOPE);
IterateTag tag = new IterateTag();
tag.setPageContext(pageContext);
tag.setId("theId");
tag.setName(testKey);
tag.setScope("application");
tag.setProperty("array");
int iteration = 0;
tag.doStartTag();
tag.doInitBody();
do
{
out.print(pageContext.getAttribute("theId"));
iteration++;
} while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG);
tag.doEndTag();
assertEquals(iterations, iteration);
}
public void endApplicationScopePropertyIterateArray (WebResponse response){
String output = response.getText();
String[] tst = new String[iterations];
for (int i = 0; i < tst.length; i++) {
tst[i] = "test" + i;
}
String compare = "";
for (int i = 0; i < iterations; i++) {
compare += tst[i];
}
//fix for introduced carriage return / line feeds
output = replace(compare,"\r","");
output = replace(output,"\n","");
assertEquals(compare, output);
}
// ========= Session
public void testSessionScopePropertyIterateArray()
throws ServletException, JspException, IOException {
String testKey = "testSessionScopePropertyIterateArray";
String[] tst = new String[iterations];
for (int i = 0; i < tst.length; i++) {
tst[i] = "test" + i;
}
SimpleBeanForTesting sbft = new SimpleBeanForTesting();
sbft.setArray(tst);
pageContext.setAttribute(testKey, sbft,
PageContext.SESSION_SCOPE);
IterateTag tag = new IterateTag();
tag.setPageContext(pageContext);
tag.setId("theId");
tag.setName(testKey);
tag.setScope("session");
tag.setProperty("array");
int iteration = 0;
tag.doStartTag();
tag.doInitBody();
do
{
out.print(pageContext.getAttribute("theId"));
iteration++;
} while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG);
tag.doEndTag();
assertEquals(iterations, iteration);
}
public void endSessionScopePropertyIterateArray (WebResponse response){
String output = response.getText();
String[] tst = new String[iterations];
for (int i = 0; i < tst.length; i++) {
tst[i] = "test" + i;
}
String compare = "";
for (int i = 0; i < iterations; i++) {
compare += tst[i];
}
//fix for introduced carriage return / line feeds
output = replace(compare,"\r","");
output = replace(output,"\n","");
assertEquals(compare, output);
}
// ========= Request
public void testRequestScopePropertyIterateArray()
throws ServletException, JspException, IOException {
String testKey = "testRequestScopePropertyIterateArray";
String[] tst = new String[iterations];
for (int i = 0; i < tst.length; i++) {
tst[i] = "test" + i;
}
SimpleBeanForTesting sbft = new SimpleBeanForTesting();
sbft.setArray(tst);
pageContext.setAttribute(testKey, sbft,
PageContext.REQUEST_SCOPE);
IterateTag tag = new IterateTag();
tag.setPageContext(pageContext);
tag.setId("theId");
tag.setName(testKey);
tag.setScope("request");
tag.setProperty("array");
int iteration = 0;
tag.doStartTag();
tag.doInitBody();
do
{
out.print(pageContext.getAttribute("theId"));
iteration++;
} while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG);
tag.doEndTag();
assertEquals(iterations, iteration);
}
public void endRequestScopePropertyIterateArray (WebResponse response){
String output = response.getText();
String[] tst = new String[iterations];
for (int i = 0; i < tst.length; i++) {
tst[i] = "test" + i;
}
String compare = "";
for (int i = 0; i < iterations; i++) {
compare += tst[i];
}
//fix for introduced carriage return / line feeds
output = replace(compare,"\r","");
output = replace(output,"\n","");
assertEquals(compare, output);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -