You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by jm...@apache.org on 2003/10/12 01:18:17 UTC

cvs commit: jakarta-struts/web/test/test/org/apache/struts/taglib/bean TestIncludeTag.jsp

jmitchell    2003/10/11 16:18:17

  Modified:    src/test/org/apache/struts/taglib/bean TestIncludeTag.java
               web/test/test/org/apache/struts/taglib/bean
                        TestIncludeTag.jsp
  Log:
  Modified to fit the latest testing schema that guarantees a success or failure
  and (I'm 99.5% sure) will not give false positives.
  
  There are other tags that need this change, but I'm working on bigger fish at
  the moment.  (The testing container port issue)
  
  The tests are still failing and that's my top priority (at the moment)
  
  Revision  Changes    Path
  1.7       +12 -30    jakarta-struts/src/test/org/apache/struts/taglib/bean/TestIncludeTag.java
  
  Index: TestIncludeTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/test/org/apache/struts/taglib/bean/TestIncludeTag.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestIncludeTag.java	30 Sep 2003 00:15:47 -0000	1.6
  +++ TestIncludeTag.java	11 Oct 2003 23:18:17 -0000	1.7
  @@ -63,8 +63,6 @@
   import junit.framework.TestSuite;
   
   import org.apache.cactus.JspTestCase;
  -import org.apache.cactus.WebResponse;
  -import org.apache.commons.lang.StringUtils;
   
   /**
    * Suite of unit tests for the
  @@ -74,8 +72,6 @@
    */
   public class TestIncludeTag extends JspTestCase {
   	
  -    protected final static String TEST_VAL = "Test Value";
  -
       /**
        * Defines the testcase name for JUnit.
        *
  @@ -108,52 +104,38 @@
       private void runMyTest(String whichTest){
   		request.setAttribute("runTest", whichTest);
           try {
  -			pageContext.forward("/test/org/apache/struts/taglib/bean/TestIncludeTag.jsp");
  +			pageContext.forward(
  +				request.getRequestURI() + "/org/apache/struts/taglib/bean/TestIncludeTag.jsp");
   		}
   		catch (Exception e) {
   			e.printStackTrace();
   			fail("There is a problem that is preventing the tests to continue!");
   		}
       }
  -    
  -	private void formatAndTest(String compare, String output) {
  -		//fix for introduced carriage return / line feeds
  -		output = StringUtils.replace(output,"\r","");
  -		output = StringUtils.replace(output,"\n","");
  -		output = output.trim();
  -		//System.out.println("Testing [" + compare + "] == [" + output + "]");
  -	    assertEquals(compare, output);
  -	}
  -
   
       /*
  -     * Testing IncludeTag using forward="something"
  +     * Testing IncludeTag using the forward attribute.
        */
       public void testIncludeTagForward(){ 
  +//		System.out.println("[TestIncludeTag.java]========>request.getServerPort():" + request.getServerPort());
  +//		System.out.println("[TestIncludeTag.java]========>request.getRequestURI():" + request.getRequestURI());
  +//		System.out.println("[TestIncludeTag.java]========>request.getRequestURL():" + request.getRequestURL());
  +//		System.out.println("[TestIncludeTag.java]========>request.getQueryString():" + request.getQueryString());
       	runMyTest("testIncludeTagForward");
   	}
  -	public void endIncludeTagForward(WebResponse response){
  -		formatAndTest(TEST_VAL, response.getText());
  -	}
   
       /*
  -     * Testing IncludeTag
  +     * Testing IncludeTag using the href attribute.
        */
       public void testIncludeTagHref(){ 
       	runMyTest("testIncludeTagHref");
   	}
  -	public void endIncludeTagHref(WebResponse response){
  -		formatAndTest(TEST_VAL, response.getText());
  -	}
   
       /*
  -     * Testing IncludeTag using page="/something"
  +     * Testing IncludeTag using the page attribute
        */
       public void testIncludeTagPage(){ 
       	runMyTest("testIncludeTagPage");
  -	}
  -	public void endIncludeTagPage(WebResponse response){
  -		formatAndTest(TEST_VAL, response.getText());
   	}
   
   
  
  
  
  1.3       +48 -8     jakarta-struts/web/test/test/org/apache/struts/taglib/bean/TestIncludeTag.jsp
  
  Index: TestIncludeTag.jsp
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/web/test/test/org/apache/struts/taglib/bean/TestIncludeTag.jsp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestIncludeTag.jsp	9 Mar 2003 16:04:52 -0000	1.2
  +++ TestIncludeTag.jsp	11 Oct 2003 23:18:17 -0000	1.3
  @@ -1,25 +1,65 @@
   <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  +<%@page import="junit.framework.Assert"%>
   <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
   <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
   <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
   
   <logic:equal name="runTest" value="testIncludeTagForward">
  -	<bean:include id="INCLUDE_TAG_KEY" forward="testIncludeTagForward"/>
  -</logic:equal>
  +	<bean:define id="TEST_RESULTS" toScope="page">
  +		<bean:include id="INCLUDE_TAG_KEY" forward="testIncludeTagForward"/>
  +		<bean:write name="INCLUDE_TAG_KEY"/>
  +	</bean:define>
  +	<bean:define id="EXPECTED_RESULTS" toScope="page">
  +		Test Value
  +	</bean:define>
   
  +<%
  +System.out.println("=========>Request:" + request);
  +System.out.println("=========>request.getServerPort():" + request.getServerPort());
  +System.out.println("=========>request.getRequestURI():" + request.getRequestURI());
  +System.out.println("=========>INCLUDE_TAG_KEY:" + pageContext.getAttribute("INCLUDE_TAG_KEY"));
  +System.out.println("=========>EXPECTED_RESULTS:" + pageContext.getAttribute("EXPECTED_RESULTS"));
  +
  +if (true)
  +	throw new Exception();
  +%>
  +
  +</logic:equal>
   
   <logic:equal name="runTest" value="testIncludeTagHref">
  -	<bean:define id="serverAddress">
  -	http://<%=request.getServerName()%>:<%=request.getServerPort()%><html:rewrite page="/test/org/apache/struts/taglib/bean/resources/IncludeTagTest.jsp"/>
  +	<bean:define id="TEST_RESULTS" toScope="page">
  +		<bean:include id="INCLUDE_TAG_KEY" href="<%=request.getContextPath() + "/test/org/apache/struts/taglib/bean/resources/IncludeTagTest.jsp"%>"/>
  +		<bean:write name="INCLUDE_TAG_KEY"/>
  +	</bean:define>
  +	<bean:define id="EXPECTED_RESULTS" toScope="page">
  +		Test Value
   	</bean:define>
  -	<bean:include id="INCLUDE_TAG_KEY" href="<%=serverAddress%>"/>
   </logic:equal>
   
  -
   <logic:equal name="runTest" value="testIncludeTagPage">
  -	<bean:include id="INCLUDE_TAG_KEY" page="/test/org/apache/struts/taglib/bean/resources/IncludeTagTest.jsp"/>
  +	<bean:define id="TEST_RESULTS" toScope="page">
  +		<bean:include id="INCLUDE_TAG_KEY" page="/test/org/apache/struts/taglib/bean/resources/IncludeTagTest.jsp"/>
  +		<bean:write name="INCLUDE_TAG_KEY"/>
  +	</bean:define>
  +	<bean:define id="EXPECTED_RESULTS" toScope="page">
  +		Test Value
  +	</bean:define>
   </logic:equal>
   
   
   
  -<bean:write name="INCLUDE_TAG_KEY"/>
  +<% 
  +String expected = "";
  +String compareTo = "";
  +
  +if (pageContext.getAttribute("EXPECTED_RESULTS") == null){
  +    throw new javax.servlet.jsp.JspException("No tests on this page were called.  Please verify that you've setup the tests correctly.");
  +}else{
  +	expected=pageContext.getAttribute("TEST_RESULTS").toString();
  +}
  +if (pageContext.getAttribute("TEST_RESULTS") != null){
  +	compareTo=pageContext.getAttribute("EXPECTED_RESULTS").toString();
  +}
  +
  +Assert.assertEquals(compareTo, expected);
  +%>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org