1 18 package org.apache.struts.taglib.logic; 19 20 import javax.servlet.ServletException ; 21 import javax.servlet.jsp.JspException ; 22 import javax.servlet.jsp.PageContext ; 23 import junit.framework.Test; 24 import junit.framework.TestSuite; 25 import org.apache.cactus.JspTestCase; 26 import org.apache.cactus.WebRequest; 27 import org.apache.struts.util.LabelValueBean; 28 29 34 public class TestGreaterEqualTag extends JspTestCase { 35 36 protected final static String COOKIE_KEY = "org.apache.struts.taglib.logic.COOKIE_KEY"; 37 protected final static String HEADER_KEY = "org.apache.struts.taglib.logic.HEADER_KEY"; 38 protected final static String PARAMETER_KEY = "org.apache.struts.taglib.logic.PARAMETER_KEY"; 39 protected final static String GREATER_VAL = "5"; 40 protected final static String LESSER_VAL = "5"; 41 42 43 48 public TestGreaterEqualTag(String theName) { 49 super(theName); 50 } 51 52 57 public static void main(String [] theArgs) { 58 junit.awtui.TestRunner.main(new String [] {TestGreaterEqualTag.class.getName()}); 59 } 60 61 65 public static Test suite() { 66 return new TestSuite(TestGreaterEqualTag.class); 68 } 69 70 72 75 80 81 84 public void beginHeaderGreaterEqual(WebRequest testRequest) { 85 testRequest.addHeader(HEADER_KEY, GREATER_VAL); 86 } 87 88 91 public void beginParameterGreaterEqual(WebRequest testRequest) { 92 testRequest.addParameter(PARAMETER_KEY, GREATER_VAL); 93 } 94 95 98 110 111 114 public void testHeaderGreaterEqual() throws ServletException , JspException { 115 GreaterEqualTag ge = new GreaterEqualTag(); 116 ge.setPageContext(pageContext); 117 ge.setHeader(HEADER_KEY); 118 ge.setValue(LESSER_VAL); 119 120 assertTrue( 121 "Header Value (" + GREATER_VAL + ") is greater than or equal to value (" + LESSER_VAL + ")", 122 ge.condition()); 123 } 124 125 128 public void testParameterGreaterEqual() throws ServletException , JspException { 129 GreaterEqualTag ge = new GreaterEqualTag(); 130 ge.setPageContext(pageContext); 131 ge.setParameter(PARAMETER_KEY); 132 ge.setValue(LESSER_VAL); 133 134 assertTrue( 135 "Parameter Value (" + GREATER_VAL + ") is greater than or equal to value (" + LESSER_VAL + ")", 136 ge.condition()); 137 } 138 139 140 144 public void testApplicationScopeNameGreaterEqual() 145 throws ServletException , JspException { 146 147 GreaterEqualTag ge = new GreaterEqualTag(); 148 149 String testKey = "testApplicationScopeNameGreaterEqual"; 150 Integer itgr = new Integer (GREATER_VAL); 151 152 pageContext.setAttribute(testKey, itgr, PageContext.APPLICATION_SCOPE); 153 ge.setPageContext(pageContext); 154 ge.setName(testKey); 155 ge.setScope("application"); 156 ge.setValue(LESSER_VAL); 157 158 assertTrue( 159 "Application scope value from name (" + GREATER_VAL + ") is greater than or equal to value (" + LESSER_VAL + ")", 160 ge.condition()); 161 } 162 163 167 public void testSessionScopeNameGreaterEqual() 168 throws ServletException , JspException { 169 170 GreaterEqualTag ge = new GreaterEqualTag(); 171 172 String testKey = "testSessionScopeNameGreaterEqual"; 173 Integer itgr = new Integer (GREATER_VAL); 174 175 pageContext.setAttribute(testKey, itgr, PageContext.SESSION_SCOPE); 176 ge.setPageContext(pageContext); 177 ge.setName(testKey); 178 ge.setScope("session"); 179 ge.setValue(LESSER_VAL); 180 181 assertTrue( 182 "Session scope value from name (" + GREATER_VAL + ") is greater than or equal to value (" + LESSER_VAL + ")", 183 ge.condition()); 184 } 185 186 190 public void testRequestScopeNameGreaterEqual() 191 throws ServletException , JspException { 192 193 GreaterEqualTag ge = new GreaterEqualTag(); 194 195 String testKey = "testRequestScopeNameGreaterEqual"; 196 Integer itgr = new Integer (GREATER_VAL); 197 198 pageContext.setAttribute(testKey, itgr, PageContext.REQUEST_SCOPE); 199 ge.setPageContext(pageContext); 200 ge.setName(testKey); 201 ge.setScope("request"); 202 ge.setValue(LESSER_VAL); 203 204 assertTrue( 205 "Request scope value from name (" + GREATER_VAL + ") is greater than or equal to value (" + LESSER_VAL + ")", 206 ge.condition()); 207 } 208 209 210 211 212 216 public void testApplicationScopePropertyGreaterEqual() 217 throws ServletException , JspException { 218 219 GreaterEqualTag ge = new GreaterEqualTag(); 220 221 String testKey = "testApplicationScopePropertyGreaterEqual"; 222 LabelValueBean lvb = new LabelValueBean("The Key", GREATER_VAL); 223 224 pageContext.setAttribute(testKey, lvb, PageContext.APPLICATION_SCOPE); 225 ge.setPageContext(pageContext); 226 ge.setName(testKey); 227 ge.setScope("application"); 228 ge.setProperty("value"); 229 ge.setValue(LESSER_VAL); 230 231 assertTrue( 232 "Value (" + LESSER_VAL + ") is greater than or equal to value (" + GREATER_VAL + ")", 233 ge.condition()); 234 } 235 236 240 public void testSessionScopePropertyGreaterEqual() 241 throws ServletException , JspException { 242 243 GreaterEqualTag ge = new GreaterEqualTag(); 244 245 String testKey = "testSessionScopePropertyGreaterEqual"; 246 LabelValueBean lvb = new LabelValueBean("The Key", GREATER_VAL); 247 248 pageContext.setAttribute(testKey, lvb, PageContext.SESSION_SCOPE); 249 ge.setPageContext(pageContext); 250 ge.setName(testKey); 251 ge.setScope("session"); 252 ge.setProperty("value"); 253 ge.setValue(LESSER_VAL); 254 255 assertTrue( 256 "Value (" + LESSER_VAL + ") is greater than or equal to value (" + GREATER_VAL + ")", 257 ge.condition()); 258 } 259 260 264 public void testRequestScopePropertyGreaterEqual() 265 throws ServletException , JspException { 266 267 GreaterEqualTag ge = new GreaterEqualTag(); 268 269 String testKey = "testRequestScopePropertyGreaterEqual"; 270 LabelValueBean lvb = new LabelValueBean("The Key", GREATER_VAL); 271 272 pageContext.setAttribute(testKey, lvb, PageContext.REQUEST_SCOPE); 273 ge.setPageContext(pageContext); 274 ge.setName(testKey); 275 ge.setScope("request"); 276 ge.setProperty("value"); 277 ge.setValue(LESSER_VAL); 278 279 assertTrue( 280 "Value (" + LESSER_VAL + ") is greater than or equal to value (" + GREATER_VAL + ")", 281 ge.condition()); 282 } 283 284 285 286 } 287 | Popular Tags |