KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > view > jsp > model > test > ValidatorTagTest


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.view.jsp.model.test;
8
9
10 import javax.servlet.jsp.JspException JavaDoc;
11 import javax.servlet.jsp.tagext.Tag JavaDoc;
12
13 import com.inversoft.junit.JspTestCase;
14 import com.inversoft.verge.mvc.validator.ValidatorConstants;
15 import com.inversoft.verge.mvc.view.jsp.html.FormTag;
16 import com.inversoft.verge.mvc.view.jsp.model.ValidatorTag;
17
18
19 /**
20  * <p>
21  * This class has the test cases for the validator tag
22  * </p>
23  *
24  * @author Brian Pontarelli
25  * @since 2.0
26  * @version 2.0
27  */

28 public class ValidatorTagTest extends JspTestCase {
29
30     /**
31      * Constructor for ValidatorTagTest.
32      *
33      * @param name
34      */

35     public ValidatorTagTest(String JavaDoc name) {
36         super(name);
37         setLocal(true);
38     }
39
40
41     /**
42      * Tests the link to a web object
43      */

44     public void testLinkWeb() {
45         FormTag parent = new FormTag();
46         ValidatorTag tag = new ValidatorTag();
47         tag.setParent(parent);
48         tag.setPageContext(pageContext);
49         tag.setValidator("com.inversoft.verge.mvc.model.test.TestValidator");
50
51         try {
52             assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE);
53             String JavaDoc tagStr = getPageContext().getMockOut().getText();
54             String JavaDoc compStr = "<input type=\"hidden\" name=\"" +
55                 ValidatorConstants.VALIDATOR_PARAMETER + "\" value=\"" +
56                 "com.inversoft.verge.mvc.model.test.TestValidator\"/>";
57
58             System.out.println("Validator tag: " + tagStr);
59             System.out.println("Compare string: " + compStr);
60             assertEquals("Should be Validator", tagStr, compStr);
61         } catch (JspException JavaDoc e) {
62             fail(e.toString());
63         }
64     }
65
66     /**
67      * Tests the double validator fails
68      */

69     public void testFailure() {
70         FormTag parent = new FormTag();
71         ValidatorTag tag = new ValidatorTag();
72         tag.setParent(parent);
73         tag.setPageContext(pageContext);
74         tag.setValidator("com.inversoft.verge.mvc.model.test.TestValidator");
75
76         ValidatorTag tag2 = new ValidatorTag();
77         tag2.setParent(parent);
78         tag2.setPageContext(pageContext);
79         tag2.setValidator("com.inversoft.verge.mvc.validator.test.TestValidator2");
80
81         try {
82             assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE);
83             runTag(tag2);
84             fail("Should have failed");
85         } catch (JspException JavaDoc e) {
86             System.out.println("Failed with exception: " + e.toString());
87         }
88     }
89 }
Popular Tags