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.junit.Request; 15 import com.inversoft.junit.URL; 16 import com.inversoft.verge.mvc.view.jsp.html.FormTag; 17 18 19 28 public class FormTagTest extends JspTestCase { 29 30 34 public FormTagTest(String name) { 35 super(name); 36 setLocal(true); 37 } 38 39 42 public void testAction() { 43 FormTag tag = new FormTag(); 44 tag.setPageContext(pageContext); 45 tag.setAction("testAction"); 46 47 try { 48 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 49 String tagStr = getPageContext().getMockOut().getText(); 50 51 System.out.println("Form tag: " + tagStr); 52 assertEquals("Should have tag", tagStr, 53 "<form action=\"testAction\"></form>"); 54 } catch (JspException e) { 55 fail(e.toString()); 56 } 57 } 58 59 public void beginAction2(Request request) { 60 URL url = new URL("MyContext", null, "https", null, "www.inversoft.com", null); 61 request.setURL(url); 62 } 63 64 67 public void testAction2() { 68 FormTag tag = new FormTag(); 69 tag.setPageContext(pageContext); 70 tag.setAction("/testAction"); 71 72 try { 73 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 74 String tagStr = getPageContext().getMockOut().getText(); 75 String expected = "<form action=\"/MyContext/testAction\"></form>"; 76 System.out.println("Form tag: " + tagStr); 77 System.out.println("Expected: " + expected); 78 assertEquals("Should have tag", tagStr, expected); 79 } catch (JspException e) { 80 fail(e.toString()); 81 } 82 } 83 84 87 public void testNameMethod() { 88 FormTag tag = new FormTag(); 89 tag.setPageContext(pageContext); 90 tag.setName("testName"); 91 tag.setMethod("post"); 92 95 try { 96 tag.doStartTag(); 97 String tagStr = getPageContext().getMockOut().getText(); 98 99 System.out.println("Form tag: " + tagStr); 100 assertEquals("Should have tag", tagStr, 101 "<form name=\"testName\" method=\"post\">"); 102 103 tag.doEndTag(); 104 tagStr = getPageContext().getMockOut().getText(); 105 106 System.out.println("Form tag: " + tagStr); 107 assertEquals("Should have tag", tagStr, 108 "<form name=\"testName\" method=\"post\"></form>"); 109 } catch (JspException e) { 110 fail(e.toString()); 111 } 112 } 113 114 117 public void testJS() { 118 FormTag tag = new FormTag(); 119 tag.setPageContext(pageContext); 120 tag.setOnsubmit("testOnsubmit"); 123 125 try { 126 tag.doStartTag(); 127 String tagStr = getPageContext().getMockOut().getText(); 128 129 System.out.println("Form tag: " + tagStr); 130 assertEquals("Should have tag", tagStr, 131 "<form onsubmit=\"testOnsubmit\">"); 132 133 tag.doEndTag(); 134 tagStr = getPageContext().getMockOut().getText(); 135 136 System.out.println("Form tag: " + tagStr); 137 assertEquals("Should have tag", tagStr, 138 "<form onsubmit=\"testOnsubmit\"></form>"); 139 } catch (JspException e) { 140 fail(e.toString()); 141 } 142 143 tag = new FormTag(); 144 tag.setPageContext(pageContext); 145 tag.setOnreset("testOnreset"); 147 148 try { 149 getPageContext().getMockOut().clear(); 150 tag.doStartTag(); 151 String tagStr = getPageContext().getMockOut().getText(); 152 153 System.out.println("Form tag: " + tagStr); 154 assertEquals("Should have tag", tagStr, 155 "<form onreset=\"testOnreset\">"); 156 157 tag.doEndTag(); 158 tagStr = getPageContext().getMockOut().getText(); 159 160 System.out.println("Form tag: " + tagStr); 161 assertEquals("Should have tag", tagStr, 162 "<form onreset=\"testOnreset\"></form>"); 163 } catch (JspException e) { 164 fail(e.toString()); 165 } 166 } 167 } | Popular Tags |