1 7 package com.inversoft.verge.mvc.view.jsp.actionflow.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.MVCRegistry; 17 import com.inversoft.verge.mvc.controller.actionflow.ActionFlowURLTools; 18 import com.inversoft.verge.mvc.controller.actionflow.config.test.ActionFlowConfigBuilderTest; 19 import com.inversoft.verge.mvc.model.ModelResolution; 20 import com.inversoft.verge.mvc.view.jsp.actionflow.FormTag; 21 import com.inversoft.verge.mvc.view.jsp.model.ModelResolutionRegistry; 22 23 24 33 public class FormTagTest extends JspTestCase { 34 35 39 public FormTagTest(String name) { 40 super(name); 41 setLocal(true); 42 } 43 44 45 48 public void testForm() { 49 FormTag tag = new FormTag(); 50 tag.setPageContext(pageContext); 51 tag.setNamespace("ns"); 52 tag.setAction("Should-be-overwritten"); 53 54 try { 55 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 56 String tagStr = getPageContext().getMockOut().getText(); 57 58 String expected = "<form action=\"" + 59 ActionFlowURLTools.generateURL("ns", null, null, null) + "\">" + 60 "<input type=\"hidden\" name=\"_v_h1\" value=\"\"/>" + 61 "<input type=\"hidden\" name=\"_v_h2\" value=\"\"/></form>"; 62 System.out.println("Expected: " + expected); 63 System.out.println("Actual: " + tagStr); 64 assertEquals("Should have tag", expected, tagStr); 65 } catch (JspException e) { 66 fail(e.toString()); 67 } 68 } 69 70 public void beginAction(Request request) { 71 URL url = new URL("MyContext", null, "https", null, "www.inversoft.com", null); 72 request.setURL(url); 73 } 74 75 78 public void testAction() { 79 FormTag tag = new FormTag(); 80 tag.setPageContext(pageContext); 81 tag.setNamespace("ns"); 82 tag.setAction("/testAction"); 84 try { 85 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 86 String tagStr = getPageContext().getMockOut().getText(); 87 String expected = "<form action=\"/MyContext" + 88 ActionFlowURLTools.generateURL("ns", null, null, null) + "\">" + 89 "<input type=\"hidden\" name=\"_v_h1\" value=\"\"/>" + 90 "<input type=\"hidden\" name=\"_v_h2\" value=\"\"/></form>"; 91 System.out.println("Form tag: " + tagStr); 92 System.out.println("Expected: " + expected); 93 assertEquals("Should have tag", tagStr, expected); 94 } catch (JspException e) { 95 fail(e.toString()); 96 } 97 } 98 99 102 public void testFailure() { 103 FormTag tag = new FormTag(); 104 tag.setPageContext(pageContext); 105 tag.setAction("Should-be-overwritten"); 106 107 try { 108 runTag(tag); 109 fail("Should have failed"); 110 } catch (Exception e) { 111 System.out.println(e.toString()); 112 } 113 } 114 115 118 public void testFormModel() { 119 120 ActionFlowConfigBuilderTest test = new ActionFlowConfigBuilderTest(""); 121 test.setRequest(request); 122 test.setResponse(response); 123 test.setContext(context); 124 test.testConfigBuilderSimple(); 125 126 FormTag tag = new FormTag(); 127 tag.setPageContext(pageContext); 128 tag.setForm("loginForm"); 129 tag.setNamespace("namespace"); 130 tag.setAction("Should-be-overwritten"); 131 132 try { 133 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 134 String tagStr = getPageContext().getMockOut().getText(); 135 136 String expected = "<form action=\"" + 137 ActionFlowURLTools.generateURL("namespace", "loginForm", null, null) + 138 "\" name=\"loginForm\">" + 139 "<input type=\"hidden\" name=\"_v_h1\" value=\"\"/>" + 140 "<input type=\"hidden\" name=\"_v_h2\" value=\"\"/></form>"; 141 System.out.println("Expected: " + expected); 142 System.out.println("Actual: " + tagStr); 143 assertEquals("Should have tag", expected, tagStr); 144 assertNotNull(ModelResolutionRegistry.lookup("loginBean", pageContext)); 145 assertNotNull(ModelResolutionRegistry.lookup("loginBean2", pageContext)); 146 147 ModelResolution mr = ModelResolutionRegistry.lookup("loginBean", pageContext); 148 assertEquals(request.getSession().getAttribute("loginBean"), mr.getModel()); 149 assertEquals("loginBean", mr.getMetaData().getID()); 150 assertEquals("actionflow", mr.getMetaData().getModelSystem()); 151 assertEquals(MVCRegistry.lookupModelHandler("actionflow"), 152 mr.getMetaData().getModelHandler()); 153 154 mr = ModelResolutionRegistry.lookup("loginBean2", pageContext); 155 assertEquals(request.getAttribute("loginBean2"), mr.getModel()); 156 assertEquals("loginBean2", mr.getMetaData().getID()); 157 assertEquals("actionflow", mr.getMetaData().getModelSystem()); 158 assertEquals(MVCRegistry.lookupModelHandler("actionflow"), 159 mr.getMetaData().getModelHandler()); 160 } catch (JspException e) { 161 fail(e.toString()); 162 } 163 } 164 } | Popular Tags |