1 7 package com.inversoft.verge.mvc.view.jsp.form.test; 8 9 10 import javax.servlet.ServletException ; 11 import javax.servlet.jsp.tagext.TagData ; 12 import javax.servlet.jsp.tagext.VariableInfo ; 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.view.jsp.form.ATei; 18 19 20 29 public class ATeiTest extends JspTestCase { 30 31 36 public ATeiTest(String name) { 37 super(name); 38 setLocal(true); 39 } 40 41 42 45 public void testWithForm() { 46 if (isLocal()) { 47 getContext().setInitParameter(VergeConfigConstants.CONTEXT_PARAM, 48 "src/com/inversoft/verge/mvc/view/jsp/form/test/test-config.xml"); 49 } 50 51 ConfigServlet cs = new ConfigServlet(); 52 try { 53 cs.init(createConfig("ConfigServlet")); 54 } catch (ServletException se) { 55 fail(se.toString()); 56 } 57 58 ATei tei = new ATei(); 59 Object [][] params = {{"form", "testForm"}, {"action", "testAction"}}; 60 TagData data = new TagData (params); 61 assertTrue(tei.isValid(data)); 62 63 VariableInfo [] infos = tei.getVariableInfo(data); 64 assertEquals(1, infos.length); 65 assertEquals("User", infos[0].getVarName()); 66 assertEquals(VariableInfo.NESTED, infos[0].getScope()); 67 } 68 69 72 public void testWithoutForm() { 73 if (isLocal()) { 74 getContext().setInitParameter(VergeConfigConstants.CONTEXT_PARAM, 75 "src/com/inversoft/verge/mvc/view/jsp/form/test/test-config.xml"); 76 } 77 78 ConfigServlet cs = new ConfigServlet(); 79 try { 80 cs.init(createConfig("ConfigServlet")); 81 } catch (ServletException se) { 82 fail(se.toString()); 83 } 84 85 ATei tei = new ATei(); 86 Object [][] params = new Object [][]{{"action", "globalAction1"}}; 87 TagData data = new TagData (params); 88 assertTrue(tei.isValid(data)); 89 90 try { 91 tei.getVariableInfo(data); 92 } catch (IllegalArgumentException iae) { 93 fail(iae.toString()); 94 } 95 } 96 97 100 public void testActionFailure() { 101 if (isLocal()) { 102 getContext().setInitParameter(VergeConfigConstants.CONTEXT_PARAM, 103 "src/com/inversoft/verge/mvc/view/jsp/form/test/test-config.xml"); 104 } 105 106 ConfigServlet cs = new ConfigServlet(); 107 try { 108 cs.init(createConfig("ConfigServlet")); 109 } catch (ServletException se) { 110 fail(se.toString()); 111 } 112 113 ATei tei = new ATei(); 114 Object [][] params = null; 115 TagData data = new TagData (params); 116 assertFalse(tei.isValid(data)); 117 118 try { 119 tei.getVariableInfo(data); 120 } catch (IllegalArgumentException iae) { 121 fail("Should not have failed without form"); 123 } 124 } 125 126 129 public void testFormFailure() { 130 if (isLocal()) { 131 getContext().setInitParameter(VergeConfigConstants.CONTEXT_PARAM, 132 "src/com/inversoft/verge/mvc/view/jsp/form/test/test-config.xml"); 133 } 134 135 ConfigServlet cs = new ConfigServlet(); 136 try { 137 cs.init(createConfig("ConfigServlet")); 138 } catch (ServletException se) { 139 fail(se.toString()); 140 } 141 142 ATei tei = new ATei(); 143 Object [][] params = null; 144 TagData data = new TagData (params); 145 assertFalse(tei.isValid(data)); 146 147 try { 148 tei.getVariableInfo(data); 149 } catch (IllegalArgumentException iae) { 150 fail("Should not have failed without form"); 152 } 153 } 154 155 158 public void testFormActionFailure() { 159 if (isLocal()) { 160 getContext().setInitParameter(VergeConfigConstants.CONTEXT_PARAM, 161 "src/com/inversoft/verge/mvc/view/jsp/form/test/test-config.xml"); 162 } 163 164 ConfigServlet cs = new ConfigServlet(); 165 try { 166 cs.init(createConfig("ConfigServlet")); 167 } catch (ServletException se) { 168 fail(se.toString()); 169 } 170 171 ATei tei = new ATei(); 172 Object [][] params = {{"form", "badForm"}, {"action", "badAction"}}; 173 TagData data = new TagData (params); 174 assertFalse(tei.isValid(data)); 175 176 try { 177 tei.getVariableInfo(data); 178 fail("This should have failed"); 179 } catch (IllegalArgumentException iae) { 180 } 182 183 params = new Object [][]{{"form", "testForm"}, {"action", "badAction"}}; 184 data = new TagData (params); 185 assertFalse(tei.isValid(data)); 186 187 try { 188 tei.getVariableInfo(data); 189 } catch (IllegalArgumentException iae) { 190 fail(iae.toString()); 191 } 192 } 193 } | Popular Tags |