1 7 package com.inversoft.verge.mvc.view.jsp.html.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.view.jsp.html.CheckboxTag; 15 import com.inversoft.verge.mvc.view.jsp.html.FormTag; 16 17 18 27 public class CheckboxTagTest extends JspTestCase { 28 29 33 public CheckboxTagTest(String name) { 34 super(name); 35 setLocal(true); 36 } 37 38 39 42 public void testId() { 43 FormTag parent = new FormTag(); 44 CheckboxTag tag = new CheckboxTag(); 45 tag.setParent(parent); 46 tag.setPageContext(pageContext); 47 tag.setId("test"); 48 49 try { 50 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 51 String tagStr = getPageContext().getMockOut().getText(); 52 53 System.out.println("Checkbox tag: " + tagStr); 54 assertTrue("Should start with input", tagStr.startsWith( 55 "<input type=\"checkbox\" id=\"test\"")); 56 } catch (JspException e) { 57 fail(e.toString()); 58 } 59 } 60 61 64 public void testName() { 65 FormTag parent = new FormTag(); 66 CheckboxTag tag = new CheckboxTag(); 67 tag.setParent(parent); 68 tag.setPageContext(pageContext); 69 tag.setName("test"); 70 71 try { 72 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 73 String tagStr = getPageContext().getMockOut().getText(); 74 75 System.out.println("Checkbox tag: " + tagStr); 76 assertTrue("Should start with input", tagStr.startsWith( 77 "<input type=\"checkbox\" name=\"test\"")); 78 } catch (JspException e) { 79 fail(e.toString()); 80 } 81 } 82 83 86 public void testChecked() { 87 FormTag parent = new FormTag(); 88 CheckboxTag tag = new CheckboxTag(); 89 tag.setParent(parent); 90 tag.setPageContext(pageContext); 91 tag.setName("test"); 92 tag.setChecked(Boolean.TRUE); 93 94 try { 95 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 96 String tagStr = getPageContext().getMockOut().getText(); 97 98 System.out.println("Checkbox tag: " + tagStr); 99 assertTrue("Should start with input", tagStr.startsWith( 100 "<input type=\"checkbox\" name=\"test\"")); 101 assertTrue("Should end with checked", tagStr.endsWith( 102 "checked/>")); 103 } catch (JspException e) { 104 fail(e.toString()); 105 } 106 } 107 } | Popular Tags |