1 18 package org.apache.struts.taglib.logic; 19 20 import javax.servlet.ServletException ; 21 import javax.servlet.http.Cookie ; 22 import javax.servlet.jsp.JspException ; 23 import junit.framework.Test; 24 import junit.framework.TestSuite; 25 26 import org.apache.cactus.JspTestCase; 27 import org.apache.cactus.WebRequest; 28 29 34 public class TestEqualTag extends JspTestCase { 35 36 protected final static String COOKIE_KEY = 37 "org.apache.struts.taglib.logic.COOKIE_KEY"; 38 protected final static String HEADER_KEY = 39 "org.apache.struts.taglib.logic.HEADER_KEY"; 40 protected final static String PARAMETER_KEY = 41 "org.apache.struts.taglib.logic.PARAMETER_KEY"; 42 43 protected final static String testStringKey = "testString"; 44 protected final static String testStringValue = "abc"; 45 protected final static String testStringValue1 = "abcd"; 46 protected final static String testIntegerKey = "testInteger"; 47 protected final static Integer testIntegerValue = new Integer (21); 48 protected final static Integer testIntegerValue1 = 49 new Integer (testIntegerValue.intValue() + 1); 50 51 protected EqualTag et = null; 52 53 58 public TestEqualTag(String theName) { 59 super(theName); 60 } 61 62 67 public static void main(String [] theArgs) { 68 junit.awtui.TestRunner.main(new String [] {TestEqualTag.class.getName()}); 69 } 70 71 75 public static Test suite() { 76 return new TestSuite(TestEqualTag.class); 78 } 79 80 public void setUp() { 81 et = new EqualTag(); 82 et.setPageContext(pageContext); 83 84 } 85 86 public void tearDown() { 87 et = null; 88 } 89 90 91 92 94 95 114 115 116 118 119 public void beginCookieStringNotEquals(WebRequest testRequest) { 120 121 testRequest.addCookie(COOKIE_KEY, "abc"); 122 123 } 124 125 126 public void testCookieStringNotEquals() 127 throws ServletException , JspException { 128 129 et.setCookie(COOKIE_KEY); 130 et.setValue(testStringValue1); 131 132 assertEquals("Cookie string not equals comparison", false, 133 et.condition(0, 0)); 134 135 } 136 137 138 140 141 public void beginHeaderStringEquals(WebRequest testRequest) { 142 143 testRequest.addHeader(HEADER_KEY, "abc"); 144 145 } 146 147 148 public void testHeaderStringEquals() 149 throws ServletException , JspException { 150 151 et.setHeader(HEADER_KEY); 152 et.setValue(testStringValue); 153 154 assertEquals("Header string equals comparison", true, 155 et.condition(0, 0)); 156 157 } 158 159 160 162 163 public void beginHeaderStringNotEquals(WebRequest testRequest) { 164 165 testRequest.addHeader(HEADER_KEY, "abc"); 166 167 } 168 169 170 public void testHeaderStringNotEquals() 171 throws ServletException , JspException { 172 173 et.setHeader(HEADER_KEY); 174 et.setValue(testStringValue1); 175 176 assertEquals("Header string not equals comparison", false, 177 et.condition(0, 0)); 178 179 } 180 181 182 184 185 public void testIntegerEquals() 186 throws ServletException , JspException { 187 188 request.setAttribute(testIntegerKey, testIntegerValue); 189 et.setName(testIntegerKey); 190 et.setValue(testIntegerValue.toString()); 191 192 assertEquals("Integer equals comparison", true, 193 et.condition(0, 0)); 194 195 } 196 197 198 200 201 public void testIntegerNotEquals() 202 throws ServletException , JspException { 203 204 request.setAttribute(testIntegerKey, testIntegerValue); 205 et.setName(testIntegerKey); 206 et.setValue(testIntegerValue1.toString()); 207 208 assertEquals("Integer not equals comparison", false, 209 et.condition(0, 0)); 210 211 } 212 213 214 216 217 public void beginParameterStringEquals(WebRequest testRequest) { 218 219 testRequest.addParameter(PARAMETER_KEY, "abc"); 220 221 } 222 223 224 public void testParameterStringEquals() 225 throws ServletException , JspException { 226 227 et.setParameter(PARAMETER_KEY); 228 et.setValue(testStringValue); 229 230 assertEquals("Parameter string equals comparison", true, 231 et.condition(0, 0)); 232 233 } 234 235 236 238 239 public void beginParameterStringNotEquals(WebRequest testRequest) { 240 241 testRequest.addParameter(PARAMETER_KEY, "abc"); 242 243 } 244 245 246 public void testParameterStringNotEquals() 247 throws ServletException , JspException { 248 249 et.setParameter(PARAMETER_KEY); 250 et.setValue(testStringValue1); 251 252 assertEquals("Parameter string not equals comparison", false, 253 et.condition(0, 0)); 254 255 } 256 257 258 260 261 public void testStringEquals() 262 throws ServletException , JspException { 263 264 request.setAttribute(testStringKey, testStringValue); 265 et.setName(testStringKey); 266 et.setValue(testStringValue); 267 268 assertEquals("String equals comparison", true, 269 et.condition(0, 0)); 270 271 } 272 273 274 276 277 public void testStringNotEquals() 278 throws ServletException , JspException { 279 280 request.setAttribute(testStringKey, testStringValue); 281 et.setName(testStringKey); 282 et.setValue(testStringValue1); 283 284 assertEquals("String not equals comparison", false, 285 et.condition(0, 0)); 286 287 } 288 289 290 291 } 292 | Popular Tags |