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 TestLessEqualTag 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 TestLessEqualTag(String theName) { 49 super(theName); 50 } 51 52 57 public static void main(String [] theArgs) { 58 junit.awtui.TestRunner.main(new String [] {TestLessEqualTag.class.getName()}); 59 } 60 61 65 public static Test suite() { 66 return new TestSuite(TestLessEqualTag.class); 68 } 69 70 72 75 public void beginCookieLessEqual(WebRequest testRequest) { 76 testRequest.addCookie(COOKIE_KEY, GREATER_VAL); 77 } 78 79 82 public void beginHeaderLessEqual(WebRequest testRequest) { 83 testRequest.addHeader(HEADER_KEY, GREATER_VAL); 84 } 85 86 89 public void beginParameterLessEqual(WebRequest testRequest) { 90 testRequest.addParameter(PARAMETER_KEY, GREATER_VAL); 91 } 92 93 96 public void testCookieLessEqual() throws ServletException , JspException { 97 LessEqualTag ge = new LessEqualTag(); 98 ge.setPageContext(pageContext); 99 ge.setCookie(COOKIE_KEY); 100 ge.setValue(LESSER_VAL); 101 102 assertTrue( 103 "Cookie Value (" + GREATER_VAL + ") is less than or equal to value (" + LESSER_VAL + ")", 104 ge.condition()); 105 } 106 107 110 public void testHeaderLessEqual() throws ServletException , JspException { 111 LessEqualTag ge = new LessEqualTag(); 112 ge.setPageContext(pageContext); 113 ge.setHeader(HEADER_KEY); 114 ge.setValue(LESSER_VAL); 115 116 assertTrue( 117 "Header Value (" + GREATER_VAL + ") is less than or equal to value (" + LESSER_VAL + ")", 118 ge.condition()); 119 } 120 121 124 public void testParameterLessEqual() throws ServletException , JspException { 125 LessEqualTag ge = new LessEqualTag(); 126 ge.setPageContext(pageContext); 127 ge.setParameter(PARAMETER_KEY); 128 ge.setValue(LESSER_VAL); 129 130 assertTrue( 131 "Parameter Value (" + GREATER_VAL + ") is less than or equal to value (" + LESSER_VAL + ")", 132 ge.condition()); 133 } 134 135 136 140 public void testApplicationScopeNameLessEqual() 141 throws ServletException , JspException { 142 143 LessEqualTag ge = new LessEqualTag(); 144 145 String testKey = "testApplicationScopeNameLessEqual"; 146 Integer itgr = new Integer (GREATER_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(LESSER_VAL); 153 154 assertTrue( 155 "Application scope value from name (" + GREATER_VAL + ") is less than or equal to value (" + LESSER_VAL + ")", 156 ge.condition()); 157 } 158 159 163 public void testSessionScopeNameLessEqual() 164 throws ServletException , JspException { 165 166 LessEqualTag ge = new LessEqualTag(); 167 168 String testKey = "testSessionScopeNameLessEqual"; 169 Integer itgr = new Integer (GREATER_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(LESSER_VAL); 176 177 assertTrue( 178 "Session scope value from name (" + GREATER_VAL + ") is less than or equal to value (" + LESSER_VAL + ")", 179 ge.condition()); 180 } 181 182 186 public void testRequestScopeNameLessEqual() 187 throws ServletException , JspException { 188 189 LessEqualTag ge = new LessEqualTag(); 190 191 String testKey = "testRequestScopeNameLessEqual"; 192 Integer itgr = new Integer (GREATER_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(LESSER_VAL); 199 200 assertTrue( 201 "Request scope value from name (" + GREATER_VAL + ") is less than or equal to value (" + LESSER_VAL + ")", 202 ge.condition()); 203 } 204 205 206 207 208 212 public void testApplicationScopePropertyLessEqual() 213 throws ServletException , JspException { 214 215 LessEqualTag ge = new LessEqualTag(); 216 217 String testKey = "testApplicationScopePropertyLessEqual"; 218 LabelValueBean lvb = new LabelValueBean("The Key", GREATER_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(LESSER_VAL); 226 227 assertTrue( 228 "Value (" + LESSER_VAL + ") is less than or equal to value (" + GREATER_VAL + ")", 229 ge.condition()); 230 } 231 232 236 public void testSessionScopePropertyLessEqual() 237 throws ServletException , JspException { 238 239 LessEqualTag ge = new LessEqualTag(); 240 241 String testKey = "testSessionScopePropertyLessEqual"; 242 LabelValueBean lvb = new LabelValueBean("The Key", GREATER_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(LESSER_VAL); 250 251 assertTrue( 252 "Value (" + LESSER_VAL + ") is less than or equal to value (" + GREATER_VAL + ")", 253 ge.condition()); 254 } 255 256 260 public void testRequestScopePropertyLessEqual() 261 throws ServletException , JspException { 262 263 LessEqualTag ge = new LessEqualTag(); 264 265 String testKey = "testRequestScopePropertyLessEqual"; 266 LabelValueBean lvb = new LabelValueBean("The Key", GREATER_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(LESSER_VAL); 274 275 assertTrue( 276 "Value (" + LESSER_VAL + ") is less than or equal to value (" + GREATER_VAL + ")", 277 ge.condition()); 278 } 279 280 281 282 } 283 | Popular Tags |