⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testiteratetag.java

📁 这是STRUTS1.2。6的开发包。。这是我从芝APACHE网站下下来
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		//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 + -