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

📄 testiteratetag.java

📁 这是STRUTS1.2。6的开发包。。这是我从芝APACHE网站下下来
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		output = replace(output,"\n","");

	    assertEquals(compare, output);
	}

	// ========= Session
    public void testSessionScopeNameIterateEnumeration() 
    	throws ServletException,  JspException, IOException {
		
		String testKey = "testSessionScopeNameIterateEnumeration";
		
		StringTokenizer st = new StringTokenizer("Session Scope Name Iterate Enumeration");

		pageContext.setAttribute(testKey, st, 
									PageContext.SESSION_SCOPE);

        IterateTag tag = new IterateTag();
		tag.setPageContext(pageContext);
        tag.setId("theId");
        tag.setName(testKey);
        tag.setScope("session");
		
		tag.doStartTag();
		tag.doInitBody();
		do
		{
			out.print((String)pageContext.getAttribute("theId"));
		
		} while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG);
		tag.doEndTag();

	}

	public void endSessionScopeNameIterateEnumeration (WebResponse response){
	    String output = response.getText();
	    StringTokenizer st = new StringTokenizer("Session Scope Name Iterate Enumeration");
	    String compare = "";
	    
	    while (st.hasMoreTokens()) {
        	compare += st.nextToken();
     	}
	    
		//fix for introduced carriage return / line feeds
		output = replace(compare,"\r","");
		output = replace(output,"\n","");

	    assertEquals(compare, output);
	}

	// ========= Request
    public void testRequestScopeNameIterateEnumeration() 
    	throws ServletException,  JspException, IOException {
		
		String testKey = "testRequestScopeNameIterateEnumeration";
		
		StringTokenizer st = new StringTokenizer("Request Scope Name Iterate Enumeration");

		pageContext.setAttribute(testKey, st, 
									PageContext.REQUEST_SCOPE);

        IterateTag tag = new IterateTag();
		tag.setPageContext(pageContext);
        tag.setId("theId");
        tag.setName(testKey);
        tag.setScope("request");
		
		tag.doStartTag();
		tag.doInitBody();
		do
		{
			out.print((String)pageContext.getAttribute("theId"));
		
		} while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG);
		tag.doEndTag();

	}

	public void endRequestScopeNameIterateEnumeration (WebResponse response){
	    String output = response.getText();
	    StringTokenizer st = new StringTokenizer("Request Scope Name Iterate Enumeration");
	    String compare = "";
	    
	    while (st.hasMoreTokens()) {
        	compare += st.nextToken();
     	}
	    
		//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="testApplicationScopePropertyIterateEnumeration"
	 * 		scope="application">
     * 
     */

	// ========= Application
    public void testApplicationScopePropertyIterateEnumeration() 
    	throws ServletException,  JspException, IOException {
		
		String testKey = "testApplicationScopePropertyIterateEnumeration";
		
		StringTokenizer st = new StringTokenizer("Application Scope Property Iterate Enumeration");

		SimpleBeanForTesting sbft = new SimpleBeanForTesting();
		sbft.setEnumeration(st);

		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("enumeration");
		
		tag.doStartTag();
		tag.doInitBody();
		do
		{
			out.print((String)pageContext.getAttribute("theId"));
		
		} while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG);
		tag.doEndTag();

	}

	public void endApplicationScopePropertyIterateEnumeration (WebResponse response){
	    String output = response.getText();
	    StringTokenizer st = new StringTokenizer("Application Scope Property Iterate Enumeration");
	    String compare = "";
	    
	    while (st.hasMoreTokens()) {
        	compare += st.nextToken();
     	}
	    
		//fix for introduced carriage return / line feeds
		output = replace(compare,"\r","");
		output = replace(output,"\n","");

	    assertEquals(compare, output);
	}

	// ========= Session
    public void testSessionScopePropertyIterateEnumeration() 
    	throws ServletException,  JspException, IOException {
		
		String testKey = "testSessionScopePropertyIterateEnumeration";
		
		StringTokenizer st = new StringTokenizer("Session Scope Property Iterate Enumeration");

		SimpleBeanForTesting sbft = new SimpleBeanForTesting();
		sbft.setEnumeration(st);

		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("enumeration");
		
		tag.doStartTag();
		tag.doInitBody();
		do
		{
			out.print((String)pageContext.getAttribute("theId"));
		
		} while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG);
		tag.doEndTag();

	}

	public void endSessionScopePropertyIterateEnumeration (WebResponse response){
	    String output = response.getText();
	    StringTokenizer st = new StringTokenizer("Session Scope Property Iterate Enumeration");
	    String compare = "";
	    
	    while (st.hasMoreTokens()) {
        	compare += st.nextToken();
     	}
	    
		//fix for introduced carriage return / line feeds
		output = replace(compare,"\r","");
		output = replace(output,"\n","");

	    assertEquals(compare, output);
	}

	// ========= Request
    public void testRequestScopePropertyIterateEnumeration() 
    	throws ServletException,  JspException, IOException {
		
		String testKey = "testRequestScopePropertyIterateEnumeration";
		
		StringTokenizer st = new StringTokenizer("Request Scope Property Iterate Enumeration");

		SimpleBeanForTesting sbft = new SimpleBeanForTesting();
		sbft.setEnumeration(st);

		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("enumeration");
		
		tag.doStartTag();
		tag.doInitBody();
		do
		{
			out.print((String)pageContext.getAttribute("theId"));
		
		} while (tag.doAfterBody() == IterateTag.EVAL_BODY_TAG);
		tag.doEndTag();

	}

	public void endRequestScopePropertyIterateEnumeration (WebResponse response){
	    String output = response.getText();
	    StringTokenizer st = new StringTokenizer("Request Scope Property Iterate Enumeration");
	    String compare = "";
	    
	    while (st.hasMoreTokens()) {
        	compare += st.nextToken();
     	}
	    
		//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="testApplicationScopeNameIterateMap"
	 * 		scope="application">
     * 
     */

	// ========= Application
    public void testApplicationScopeNameIterateMap() 
    	throws ServletException,  JspException, IOException {
		
		String testKey = "testApplicationScopeNameIterateMap";

        HashMap map = new HashMap();
        for (int i = 0; i < iterations; i++) {
	        map.put("test" + i,"test" + i);
		}
		
		pageContext.setAttribute(testKey, map, 
									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 endApplicationScopeNameIterateMap (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);
	}
	
	// ========= Session
    public void testSessionScopeNameIterateMap() 
    	throws ServletException,  JspException, IOException {
		
		String testKey = "testSessionScopeNameIterateMap";

        HashMap map = new HashMap();
        for (int i = 0; i < iterations; i++) {
	        map.put("test" + i,"test" + i);
		}
		
		pageContext.setAttribute(testKey, map, 
									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 endSessionScopeNameIterateMap (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 testRequestScopeNameIterateMap() 
    	throws ServletException,  JspException, IOException {
		
		String testKey = "testRequestScopeNameIterateMap";

        HashMap map = new HashMap();
        for (int i = 0; i < iterations; i++) {
	        map.put("test" + i,"test" + i);
		}
		
		pageContext.setAttribute(testKey, map, 
									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 endRequestScopeNameIterateMap (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 property attribute in
     * the application scope.
     * 
	 * Tests the equivalent of this tag in a jsp:
	 *   <logic:iterate id="theId" name="testApplicationScopePropertyIterateMap"
	 * 		scope="application">
     * 
     */

	// ========= Application
    public void testApplicationScopePropertyIterateMap() 
    	throws ServletException,  JspException, IOException {
		
		String testKey = "testApplicationScopePropertyIterateMap";

        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.APPLICATION_SCOPE);

        IterateTag tag = new IterateTag();
		tag.setPageContext(pageContext);
        tag.setId("theId");
        tag.setName(testKey);
        tag.setScope("application");
        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 endApplicationScopePropertyIterateMap (WebResponse response){
	    String output = response.getText();
	    String compare = "";
	    for (int i = 0; i < iterations; i++) {
			compare += "test" + i;
		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -