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 TestGreaterThanTag 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 = "6"; 40 protected final static String LESSER_VAL = "4"; 41 42 43 48 public TestGreaterThanTag(String theName) { 49 super(theName); 50 } 51 52 57 public static void main(String [] theArgs) { 58 junit.awtui.TestRunner.main(new String [] {TestGreaterThanTag.class.getName()}); 59 } 60 61 65 public static Test suite() { 66 return new TestSuite(TestGreaterThanTag.class); 68 } 69 70 72 75 80 81 84 public void beginHeaderGreaterThan(WebRequest testRequest) { 85 testRequest.addHeader(HEADER_KEY, GREATER_VAL); 86 } 87 88 91 public void beginParameterGreaterThan(WebRequest testRequest) { 92 testRequest.addParameter(PARAMETER_KEY, GREATER_VAL); 93 } 94 95 98 110 111 114 public void testHeaderGreaterThan() throws ServletException , JspException { 115 GreaterThanTag gt = new GreaterThanTag(); 116 gt.setPageContext(pageContext); 117 gt.setHeader(HEADER_KEY); 118 gt.setValue(LESSER_VAL); 119 120 assertTrue( 121 "Header Value (" + GREATER_VAL + ") is greater than value (" + LESSER_VAL + ")", 122 gt.condition()); 123 } 124 125 128 public void testParameterGreaterThan() throws ServletException , JspException { 129 GreaterThanTag gt = new GreaterThanTag(); 130 gt.setPageContext(pageContext); 131 gt.setParameter(PARAMETER_KEY); 132 gt.setValue(LESSER_VAL); 133 134 assertTrue( 135 "Parameter Value (" + GREATER_VAL + ") is greater than value (" + LESSER_VAL + ")", 136 gt.condition()); 137 } 138 139 140 144 public void testApplicationScopeNameGreaterThan() 145 throws ServletException , JspException { 146 147 GreaterThanTag gt = new GreaterThanTag(); 148 149 String testKey = "testApplicationScopeNameGreaterThan"; 150 Integer itgr = new Integer (GREATER_VAL); 151 152 pageContext.setAttribute(testKey, itgr, PageContext.APPLICATION_SCOPE); 153 gt.setPageContext(pageContext); 154 gt.setName(testKey); 155 gt.setScope("application"); 156 gt.setValue(LESSER_VAL); 157 158 assertTrue( 159 "Application scope value from name (" + GREATER_VAL + ") is greater than value (" + LESSER_VAL + ")", 160 gt.condition()); 161 } 162 163 167 public void testSessionScopeNameGreaterThan() 168 throws ServletException , JspException { 169 170 GreaterThanTag gt = new GreaterThanTag(); 171 172 String testKey = "testSessionScopeNameGreaterThan"; 173 Integer itgr = new Integer (GREATER_VAL); 174 175 pageContext.setAttribute(testKey, itgr, PageContext.SESSION_SCOPE); 176 gt.setPageContext(pageContext); 177 gt.setName(testKey); 178 gt.setScope("session"); 179 gt.setValue(LESSER_VAL); 180 181 assertTrue( 182 "Session scope value from name (" + GREATER_VAL + ") is greater than value (" + LESSER_VAL + ")", 183 gt.condition()); 184 } 185 186 190 public void testRequestScopeNameGreaterThan() 191 throws ServletException , JspException { 192 193 GreaterThanTag gt = new GreaterThanTag(); 194 195 String testKey = "testRequestScopeNameGreaterThan"; 196 Integer itgr = new Integer (GREATER_VAL); 197 198 pageContext.setAttribute(testKey, itgr, PageContext.REQUEST_SCOPE); 199 gt.setPageContext(pageContext); 200 gt.setName(testKey); 201 gt.setScope("request"); 202 gt.setValue(LESSER_VAL); 203 204 assertTrue( 205 "Request scope value from name (" + GREATER_VAL + ") is greater than value (" + LESSER_VAL + ")", 206 gt.condition()); 207 } 208 209 210 211 212 216 public void testApplicationScopePropertyGreaterThan() 217 throws ServletException , JspException { 218 219 GreaterThanTag gt = new GreaterThanTag(); 220 221 String testKey = "testApplicationScopePropertyGreaterThan"; 222 LabelValueBean lvb = new LabelValueBean("The Key", GREATER_VAL); 223 224 pageContext.setAttribute(testKey, lvb, PageContext.APPLICATION_SCOPE); 225 gt.setPageContext(pageContext); 226 gt.setName(testKey); 227 gt.setScope("application"); 228 gt.setProperty("value"); 229 gt.setValue(LESSER_VAL); 230 231 assertTrue( 232 "Value (" + LESSER_VAL + ") is greater than value (" + GREATER_VAL + ")", 233 gt.condition()); 234 } 235 236 240 public void testSessionScopePropertyGreaterThan() 241 throws ServletException , JspException { 242 243 GreaterThanTag gt = new GreaterThanTag(); 244 245 String testKey = "testSessionScopePropertyGreaterThan"; 246 LabelValueBean lvb = new LabelValueBean("The Key", GREATER_VAL); 247 248 pageContext.setAttribute(testKey, lvb, PageContext.SESSION_SCOPE); 249 gt.setPageContext(pageContext); 250 gt.setName(testKey); 251 gt.setScope("session"); 252 gt.setProperty("value"); 253 gt.setValue(LESSER_VAL); 254 255 assertTrue( 256 "Value (" + LESSER_VAL + ") is greater than value (" + GREATER_VAL + ")", 257 gt.condition()); 258 } 259 260 264 public void testRequestScopePropertyGreaterThan() 265 throws ServletException , JspException { 266 267 GreaterThanTag gt = new GreaterThanTag(); 268 269 String testKey = "testRequestScopePropertyGreaterThan"; 270 LabelValueBean lvb = new LabelValueBean("The Key", GREATER_VAL); 271 272 pageContext.setAttribute(testKey, lvb, PageContext.REQUEST_SCOPE); 273 gt.setPageContext(pageContext); 274 gt.setName(testKey); 275 gt.setScope("request"); 276 gt.setProperty("value"); 277 gt.setValue(LESSER_VAL); 278 279 assertTrue( 280 "Value (" + LESSER_VAL + ") is greater than value (" + GREATER_VAL + ")", 281 gt.condition()); 282 } 283 284 285 286 } 287 | Popular Tags |