1 7 package com.inversoft.verge.mvc.view.jsp.actionflow.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.verge.config.VergeConfigConstants; 16 import com.inversoft.verge.config.servlet.ConfigServlet; 17 import com.inversoft.verge.mvc.controller.actionflow.ActionFlowURLTools; 18 import com.inversoft.verge.mvc.model.ModelResolution; 19 import com.inversoft.verge.mvc.view.jsp.actionflow.ATag; 20 import com.inversoft.verge.mvc.view.jsp.model.ModelResolutionRegistry; 21 22 23 32 public class ATagTest extends JspTestCase { 33 34 38 public ATagTest(String name) { 39 super(name); 40 setLocal(true); 41 } 42 43 44 47 public void testSimple() { 48 ATag tag = new ATag(); 49 tag.setPageContext(pageContext); 50 tag.setAction("testAction"); 51 tag.setNamespace("testNamespace"); 52 tag.setBodyContent(createBodyContent()); 53 54 try { 55 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 56 String tagStr = getPageContext().getMockOut().getText(); 57 58 String expected = "<a HREF=\"" + 59 ActionFlowURLTools.generateURL("testNamespace", null, "testAction", null) + 60 "\"></a>"; 61 System.out.println("Expected: " + expected); 62 System.out.println("Actual: " + tagStr); 63 assertEquals("Should be the a tag", expected, tagStr); 64 } catch (JspException e) { 65 fail(e.toString()); 66 } 67 } 68 69 72 public void testComplex() { 73 ATag tag = new ATag(); 74 tag.setPageContext(pageContext); 75 tag.setAction("testAction"); 76 tag.setNamespace("ns"); 77 tag.setEntry("en"); 78 tag.setBodyContent(createBodyContent()); 79 80 try { 81 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 82 String tagStr = getPageContext().getMockOut().getText(); 83 84 String expected = "<a HREF=\"" + 85 ActionFlowURLTools.generateURL("ns", null, "testAction", "en") + 86 "\"></a>"; 87 System.out.println("Expected: " + expected); 88 System.out.println("Actual: " + tagStr); 89 assertEquals("Should be the a tag", expected, tagStr); 90 } catch (JspException e) { 91 fail(e.toString()); 92 } 93 } 94 95 98 public void testFormBeans() { 99 if (isLocal()) { 100 getContext().setInitParameter(VergeConfigConstants.CONTEXT_PARAM, 101 "src/com/inversoft/verge/mvc/view/jsp/actionflow/test/test-config.xml"); 102 } 103 104 ConfigServlet cs = new ConfigServlet(); 105 try { 106 cs.init(createConfig("ConfigServlet")); 107 } catch (ServletException se) { 108 fail(se.toString()); 109 } 110 111 ATag tag = new ATag(); 112 tag.setPageContext(pageContext); 113 tag.setAction("testAction"); 114 tag.setNamespace("testNS"); 115 tag.setEntry("en"); 116 tag.setForm("testForm"); 117 tag.setBodyContent(createBodyContent("link")); 118 119 try { 120 assertEquals("Should return EVAL_PAGE", runTag(tag), Tag.EVAL_PAGE); 121 String tagStr = getPageContext().getMockOut().getText(); 122 123 String expected = "<a HREF=\"" + 124 ActionFlowURLTools.generateURL("testNS", "testForm", "testAction", "en") + 125 "\">link</a>"; 126 System.out.println("Expected: " + expected); 127 System.out.println("Actual: " + tagStr); 128 assertEquals("Should be the a tag", expected, tagStr); 129 130 ModelResolution mr = ModelResolutionRegistry.lookup("User", pageContext); 131 assertNotNull(mr); 132 } catch (JspException e) { 133 fail(e.toString()); 134 } 135 } 136 } | Popular Tags |