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.FormTag; 15 import com.inversoft.verge.mvc.view.jsp.html.TextTag; 16 17 18 27 public class TextTagTest extends JspTestCase { 28 29 33 public TextTagTest(String name) { 34 super(name); 35 setLocal(true); 36 } 37 38 39 42 public void testAll() { 43 FormTag parent = new FormTag(); 44 TextTag tag = new TextTag(); 45 tag.setParent(parent); 46 tag.setPageContext(pageContext); 47 tag.setId("test"); 48 tag.setName("test"); 49 50 try { 51 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 52 String tagStr = getPageContext().getMockOut().getText(); 53 54 System.out.println("Text tag: " + tagStr); 55 assertEquals("Should be text tag", tagStr, 56 "<input type=\"text\" id=\"test\" name=\"test\"/>"); 57 } catch (JspException e) { 58 fail(e.toString()); 59 } 60 } 61 62 65 public void testNameGeneration() { 66 FormTag parent = new FormTag(); 67 TextTag tag = new TextTag(); 68 tag.setParent(parent); 69 tag.setPageContext(pageContext); 70 73 try { 74 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 75 String tagStr = getPageContext().getMockOut().getText(); 76 77 System.out.println("Text tag: " + tagStr); 78 assertEquals("Should be text tag with name", tagStr, 79 "<input type=\"text\" name=\"_input-0\"/>"); 80 81 getPageContext().clearMockOut(); 84 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 85 tagStr = getPageContext().getMockOut().getText(); 86 87 System.out.println("Text tag: " + tagStr); 88 assertEquals("Should be text tag with name", tagStr, 89 "<input type=\"text\" name=\"_input-1\"/>"); 90 } catch (JspException e) { 91 fail(e.toString()); 92 } 93 } 94 95 98 public void testValue() { 99 FormTag parent = new FormTag(); 100 TextTag tag = new TextTag(); 101 tag.setParent(parent); 102 tag.setPageContext(pageContext); 103 tag.setName("test"); 104 tag.setValue("${requestScope.test}"); 105 106 try { 107 request.setAttribute("test", "TestValue"); 108 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 109 String tagStr = getPageContext().getMockOut().getText(); 110 111 System.out.println("Text tag: " + tagStr); 112 assertEquals("Should be text tag with name", tagStr, 113 "<input type=\"text\" name=\"test\" value=\"TestValue\"/>"); 114 115 getPageContext().clearMockOut(); 118 tag.setName("test"); 119 tag.setValue("${requestScope.test}"); 120 request.setAttribute("test", "TestValue2"); 121 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 122 tagStr = getPageContext().getMockOut().getText(); 123 124 System.out.println("Text tag: " + tagStr); 125 assertEquals("Should be text tag with name", tagStr, 126 "<input type=\"text\" name=\"test\" value=\"TestValue2\"/>"); 127 } catch (JspException e) { 128 fail(e.toString()); 129 } 130 } 131 } | Popular Tags |