Update of /cvsroot/mockobjects/mockobjects-java/src/j2ee/1.3/com/mockobjects/helpers
In directory sc8-pr-cvs1:/tmp/cvs-serv3334/src/j2ee/1.3/com/mockobjects/helpers
Modified Files:
TagTestHelper.java
Log Message:
Added test method to help testing iterator tags
Index: TagTestHelper.java
===================================================================
RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/1.3/com/mockobjects/helpers/TagTestHelper.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TagTestHelper.java 14 May 2003 15:15:11 -0000 1.2
+++ TagTestHelper.java 12 Aug 2003 13:32:18 -0000 1.3
@@ -9,13 +9,16 @@
import javax.servlet.jsp.tagext.BodyTag;
import javax.servlet.jsp.tagext.IterationTag;
import javax.servlet.jsp.tagext.Tag;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpSession;
/**
* Sets up mock tag objects in a common configuration.
* MockHttpServletRequest, MockServletContext and MockHttpSession are attached to MockPageContext
- * @see com.mockobjects.servlet.MockPageContext#setRequest();
- * @see com.mockobjects.servlet.MockPageContext#setServletContext();
- * @see com.mockobjects.servlet.MockPageContext#setSession();
+ * @see MockPageContext#setRequest(ServletRequest)
+ * @see MockPageContext#setServletContext(ServletContext)
+ * @see MockPageContext#setSession(HttpSession)
*/
public class TagTestHelper extends AbstractServletTestHelper {
private final MockPageContext pageContext = new MockPageContext();
@@ -112,4 +115,39 @@
Assert.assertEquals("doEndTag returned unexpected value" + getReturnValueName(expectedValue),
expectedValue, testSubject.doEndTag());
}
+
+ /**
+ * Executes a test vistor against the test subject empulating the use of an iterator tag in a JSP engine.
+ * @param test testcase to be run for each iteration
+ * @param iterations total number of expected iterations
+ * @throws Exception
+ */
+ public void testIteration(IterationTest test, int iterations) throws Exception {
+
+ this.assertDoStartTag(BodyTag.EVAL_BODY_INCLUDE);
+ this.testDoInitBody();
+
+ int iteration = 0;
+ for (; iteration < iterations - 1; iteration++) {
+ test.doTest(iteration);
+ this.assertDoAfterBody(BodyTag.EVAL_BODY_AGAIN);
+ }
+ test.doTest(iteration);
+ this.assertDoAfterBody(BodyTag.SKIP_BODY);
+
+ this.assertDoEndTag(BodyTag.EVAL_PAGE);
+ }
+
+ /**
+ * Vistor used for testing IteratorTags
+ */
+ public interface IterationTest {
+ /**
+ * Test method called for each iteration
+ * @param iteration index of the current iteration
+ * @throws Exception
+ */
+ public void doTest(int iteration) throws Exception;
+ }
+
}
|