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 TestLessThanTag 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 COMPARE_VAL = "4"; 40 protected final static String COMPARE_TO_VAL = "5"; 41 42 43 48 public TestLessThanTag(String theName) { 49 super(theName); 50 } 51 52 57 public static void main(String [] theArgs) { 58 junit.awtui.TestRunner.main(new String [] {TestLessThanTag.class.getName()}); 59 } 60 61 65 public static Test suite() { 66 return new TestSuite(TestLessThanTag.class); 68 } 69 70 72 75 public void beginCookieLessThan(WebRequest testRequest) { 76 testRequest.addCookie(COOKIE_KEY, COMPARE_VAL); 77 } 78 79 82 public void beginHeaderLessThan(WebRequest testRequest) { 83 testRequest.addHeader(HEADER_KEY, COMPARE_VAL); 84 } 85 86 89 public void beginParameterLessThan(WebRequest testRequest) { 90 testRequest.addParameter(PARAMETER_KEY, COMPARE_VAL); 91 } 92 93 96 public void testCookieLessThan() throws ServletException , JspException { 97 LessThanTag ge = new LessThanTag(); 98 ge.setPageContext(pageContext); 99 ge.setCookie(COOKIE_KEY); 100 ge.setValue(COMPARE_TO_VAL); 101 102 assertTrue( 103 "Cookie Value (" + COMPARE_VAL + ") is less than value (" + COMPARE_TO_VAL + ")", 104 ge.condition()); 105 } 106 107 110 public void testHeaderLessThan() throws ServletException , JspException { 111 LessThanTag ge = new LessThanTag(); 112 ge.setPageContext(pageContext); 113 ge.setHeader(HEADER_KEY); 114 ge.setValue(COMPARE_TO_VAL); 115 116 assertTrue( 117 "Header Value (" + COMPARE_VAL + ") is less than value (" + COMPARE_TO_VAL + ")", 118 ge.condition()); 119 } 120 121 124 public void testParameterLessThan() throws ServletException , JspException { 125 LessThanTag ge = new LessThanTag(); 126 ge.setPageContext(pageContext); 127 ge.setParameter(PARAMETER_KEY); 128 ge.setValue(COMPARE_TO_VAL); 129 130 assertTrue( 131 "Parameter Value (" + COMPARE_VAL + ") is less than value (" + COMPARE_TO_VAL + ")", 132 ge.condition()); 133 } 134 135 136 140 public void testApplicationScopeNameLessThan() 141 throws ServletException , JspException { 142 143 LessThanTag ge = new LessThanTag(); 144 145 String testKey = "testApplicationScopeNameLessThan"; 146 Integer itgr = new Integer (COMPARE_VAL); 147 148 pageContext.setAttribute(testKey, itgr, PageContext.APPLICATION_SCOPE); 149 ge.setPageContext(pageContext); 150 ge.setName(testKey); 151 ge.setScope("application"); 152 ge.setValue(COMPARE_TO_VAL); 153 154 assertTrue( 155 "Application scope value from name (" + COMPARE_VAL + ") is less than value (" + COMPARE_TO_VAL + ")", 156 ge.condition()); 157 } 158 159 163 public void testSessionScopeNameLessThan() 164 throws ServletException , JspException { 165 166 LessThanTag ge = new LessThanTag(); 167 168 String testKey = "testSessionScopeNameLessThan"; 169 Integer itgr = new Integer (COMPARE_VAL); 170 171 pageContext.setAttribute(testKey, itgr, PageContext.SESSION_SCOPE); 172 ge.setPageContext(pageContext); 173 ge.setName(testKey); 174 ge.setScope("session"); 175 ge.setValue(COMPARE_TO_VAL); 176 177 assertTrue( 178 "Session scope value from name (" + COMPARE_VAL + ") is less than value (" + COMPARE_TO_VAL + ")", 179 ge.condition()); 180 } 181 182 186 public void testRequestScopeNameLessThan() 187 throws ServletException , JspException { 188 189 LessThanTag ge = new LessThanTag(); 190 191 String testKey = "testRequestScopeNameLessThan"; 192 Integer itgr = new Integer (COMPARE_VAL); 193 194 pageContext.setAttribute(testKey, itgr, PageContext.REQUEST_SCOPE); 195 ge.setPageContext(pageContext); 196 ge.setName(testKey); 197 ge.setScope("request"); 198 ge.setValue(COMPARE_TO_VAL); 199 200 assertTrue( 201 "Request scope value from name (" + COMPARE_VAL + ") is less than value (" + COMPARE_TO_VAL + ")", 202 ge.condition()); 203 } 204 205 206 207 208 212 public void testApplicationScopePropertyLessThan() 213 throws ServletException , JspException { 214 215 LessThanTag ge = new LessThanTag(); 216 217 String testKey = "testApplicationScopePropertyLessThan"; 218 LabelValueBean lvb = new LabelValueBean("The Key", COMPARE_VAL); 219 220 pageContext.setAttribute(testKey, lvb, PageContext.APPLICATION_SCOPE); 221 ge.setPageContext(pageContext); 222 ge.setName(testKey); 223 ge.setScope("application"); 224 ge.setProperty("value"); 225 ge.setValue(COMPARE_TO_VAL); 226 227 assertTrue( 228 "Value (" + COMPARE_TO_VAL + ") is less than value (" + COMPARE_VAL + ")", 229 ge.condition()); 230 } 231 232 236 public void testSessionScopePropertyLessThan() 237 throws ServletException , JspException { 238 239 LessThanTag ge = new LessThanTag(); 240 241 String testKey = "testSessionScopePropertyLessThan"; 242 LabelValueBean lvb = new LabelValueBean("The Key", COMPARE_VAL); 243 244 pageContext.setAttribute(testKey, lvb, PageContext.SESSION_SCOPE); 245 ge.setPageContext(pageContext); 246 ge.setName(testKey); 247 ge.setScope("session"); 248 ge.setProperty("value"); 249 ge.setValue(COMPARE_TO_VAL); 250 251 assertTrue( 252 "Value (" + COMPARE_TO_VAL + ") is less than value (" + COMPARE_VAL + ")", 253 ge.condition()); 254 } 255 256 260 public void testRequestScopePropertyLessThan() 261 throws ServletException , JspException { 262 263 LessThanTag ge = new LessThanTag(); 264 265 String testKey = "testRequestScopePropertyLessThan"; 266 LabelValueBean lvb = new LabelValueBean("The Key", COMPARE_VAL); 267 268 pageContext.setAttribute(testKey, lvb, PageContext.REQUEST_SCOPE); 269 ge.setPageContext(pageContext); 270 ge.setName(testKey); 271 ge.setScope("request"); 272 ge.setProperty("value"); 273 ge.setValue(COMPARE_TO_VAL); 274 275 assertTrue( 276 "Value (" + COMPARE_TO_VAL + ") is less than value (" + COMPARE_VAL + ")", 277 ge.condition()); 278 } 279 280 281 282 } 283 | Popular Tags |