1 7 package com.inversoft.verge.mvc.view.jsp.form.test; 8 9 10 import javax.servlet.ServletException ; 11 import javax.servlet.jsp.JspException ; 12 import javax.servlet.jsp.tagext.Tag ; 13 14 import com.inversoft.junit.JspTestCase; 15 import com.inversoft.junit.internal.http.MockHttpServletRequest; 16 import com.inversoft.verge.config.VergeConfigConstants; 17 import com.inversoft.verge.config.servlet.ConfigServlet; 18 import com.inversoft.verge.mvc.controller.form.FormURLTools; 19 import com.inversoft.verge.mvc.controller.form.config.test.FormMVCBuilderTest2; 20 import com.inversoft.verge.mvc.model.ModelResolution; 21 import com.inversoft.verge.mvc.view.jsp.form.ATag; 22 import com.inversoft.verge.mvc.view.jsp.model.ModelResolutionRegistry; 23 24 25 34 public class ATagTest extends JspTestCase { 35 36 static { 39 FormMVCBuilderTest2 test = new FormMVCBuilderTest2("testValidate"); 41 test.setRequest(new MockHttpServletRequest(null)); test.testValidate(); 43 } 44 45 49 public ATagTest(String name) { 50 super(name); 51 setLocal(true); 52 } 53 54 55 58 public void testSimple() { 59 ATag tag = new ATag(); 60 tag.setPageContext(pageContext); 61 tag.setAction("testAction"); 62 tag.setForm("form1"); 63 tag.setBodyContent(createBodyContent("link")); 64 65 try { 66 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 67 String tagStr = getPageContext().getMockOut().getText(); 68 69 String expected = "<a HREF=\"" + 70 FormURLTools.generateURL("form1", "testAction") + "\">link</a>"; 71 System.out.println("Expected: " + expected); 72 System.out.println("Actual: " + tagStr); 73 assertEquals("Should be the a tag", expected, tagStr); 74 } catch (JspException e) { 75 fail(e.toString()); 76 } 77 } 78 79 82 public void testFormBeans() { 83 if (isLocal()) { 84 getContext().setInitParameter(VergeConfigConstants.CONTEXT_PARAM, 85 "src/com/inversoft/verge/mvc/view/jsp/form/test/test-config.xml"); 86 } 87 88 ConfigServlet cs = new ConfigServlet(); 89 try { 90 cs.init(createConfig("ConfigServlet")); 91 } catch (ServletException se) { 92 fail(se.toString()); 93 } 94 95 ATag tag = new ATag(); 96 tag.setPageContext(pageContext); 97 tag.setAction("testAction"); 98 tag.setForm("testForm"); 99 tag.setBodyContent(createBodyContent("link")); 100 101 try { 102 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 103 String tagStr = getPageContext().getMockOut().getText(); 104 105 String expected = "<a HREF=\"" + 106 FormURLTools.generateURL("testForm", "testAction") + "\">link</a>"; 107 System.out.println("Expected: " + expected); 108 System.out.println("Actual: " + tagStr); 109 assertEquals("Should be the a tag", expected, tagStr); 110 111 ModelResolution mr = ModelResolutionRegistry.lookup("User", pageContext); 112 assertNotNull(mr); 113 } catch (JspException e) { 114 fail(e.toString()); 115 } 116 } 117 118 121 public void testWithoutForm() { 122 if (isLocal()) { 123 getContext().setInitParameter(VergeConfigConstants.CONTEXT_PARAM, 124 "src/com/inversoft/verge/mvc/view/jsp/form/test/test-config.xml"); 125 } 126 127 ConfigServlet cs = new ConfigServlet(); 128 try { 129 cs.init(createConfig("ConfigServlet")); 130 } catch (ServletException se) { 131 fail(se.toString()); 132 } 133 134 ATag tag = new ATag(); 135 tag.setPageContext(pageContext); 136 tag.setAction("testAction"); 137 tag.setBodyContent(createBodyContent("link")); 138 139 try { 140 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 141 String tagStr = getPageContext().getMockOut().getText(); 142 143 String expected = "<a HREF=\"" + 144 FormURLTools.generateURL(null, "testAction") + "\">link</a>"; 145 System.out.println("Expected: " + expected); 146 System.out.println("Actual: " + tagStr); 147 assertEquals("Should be the a tag", expected, tagStr); 148 } catch (JspException e) { 149 fail(e.toString()); 150 } 151 } 152 } | Popular Tags |