1 7 package com.inversoft.verge.mvc.view.jsp.model.test; 8 9 10 import javax.servlet.jsp.JspException ; 11 import javax.servlet.jsp.tagext.Tag ; 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 28 public class ValidatorTagTest extends JspTestCase { 29 30 35 public ValidatorTagTest(String name) { 36 super(name); 37 setLocal(true); 38 } 39 40 41 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 tagStr = getPageContext().getMockOut().getText(); 54 String 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 e) { 62 fail(e.toString()); 63 } 64 } 65 66 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 e) { 86 System.out.println("Failed with exception: " + e.toString()); 87 } 88 } 89 } | Popular Tags |