1 18 package org.apache.struts.taglib.logic; 19 20 import javax.servlet.ServletException ; 21 import javax.servlet.jsp.PageContext ; 22 import junit.framework.Test; 23 import junit.framework.TestSuite; 24 25 import org.apache.cactus.JspTestCase; 26 import org.apache.cactus.WebRequest; 27 28 33 public class TestNotPresentTag extends JspTestCase { 34 protected final static String COOKIE_KEY = "org.apache.struts.taglib.logic.COOKIE_KEY"; 35 protected final static String HEADER_KEY = "org.apache.struts.taglib.logic.HEADER_KEY"; 36 protected final static String PARAMETER_KEY = "org.apache.struts.taglib.logic.PARAMETER_KEY"; 37 38 43 public TestNotPresentTag(String theName) { 44 super(theName); 45 } 46 47 52 public static void main(String [] theArgs) { 53 junit.awtui.TestRunner.main(new String [] {TestNotPresentTag.class.getName()}); 54 } 55 56 60 public static Test suite() { 61 return new TestSuite(TestNotPresentTag.class); 63 } 64 65 67 70 public void testApplicationScopeObjectPresent() throws ServletException , javax.servlet.jsp.JspException { 71 NotPresentTag npt = new NotPresentTag(); 72 String testKey = "testApplicationScopePresent"; 73 String testStringValue = "abc"; 74 75 pageContext.setAttribute(testKey, testStringValue, PageContext.APPLICATION_SCOPE); 76 npt.setPageContext(pageContext); 77 npt.setName(testKey); 78 npt.setScope("application"); 79 80 assertEquals("Value present (not null)", false, npt.condition(false)); 81 } 82 83 86 public void testApplicationScopeObjectNotPresent() throws ServletException , javax.servlet.jsp.JspException { 87 NotPresentTag npt = new NotPresentTag(); 88 String testKey = "testApplicationScopeNotPresent"; 89 90 npt.setPageContext(pageContext); 91 npt.setName(testKey); 92 npt.setScope("application"); 93 94 95 assertEquals("Value not present (null)", true, npt.condition(false)); 96 } 97 98 101 public void testSessionScopeObjectPresent() throws ServletException , javax.servlet.jsp.JspException { 102 NotPresentTag npt = new NotPresentTag(); 103 String testKey = "testSessionScopePresent"; 104 String testStringValue = "abc"; 105 106 pageContext.setAttribute(testKey, testStringValue, PageContext.SESSION_SCOPE); 107 npt.setPageContext(pageContext); 108 npt.setName(testKey); 109 npt.setScope("session"); 110 111 assertEquals("Value present (not null)", false, npt.condition(false)); 112 } 113 114 117 public void testSessionScopeObjectNotPresent() throws ServletException , javax.servlet.jsp.JspException { 118 NotPresentTag npt = new NotPresentTag(); 119 String testKey = "testSessionScopeNotPresent"; 120 121 npt.setPageContext(pageContext); 122 npt.setName(testKey); 123 npt.setScope("session"); 124 125 assertEquals("Value present (not null)", true, npt.condition(false)); 126 } 127 128 131 public void testRequestScopeObjectPresent() throws ServletException , javax.servlet.jsp.JspException { 132 NotPresentTag npt = new NotPresentTag(); 133 String testKey = "testRequestScopePresent"; 134 String testStringValue = "abc"; 135 npt.setScope("request"); 136 137 pageContext.setAttribute(testKey, testStringValue, PageContext.REQUEST_SCOPE); 138 npt.setPageContext(pageContext); 139 npt.setName(testKey); 140 141 assertEquals("Value present (not null)", false, npt.condition(false)); 142 } 143 144 147 public void testRequestScopeObjectNotPresent() throws ServletException , javax.servlet.jsp.JspException { 148 NotPresentTag npt = new NotPresentTag(); 149 String testKey = "testRequestScopeNotPresent"; 150 151 npt.setPageContext(pageContext); 152 npt.setName(testKey); 153 npt.setScope("request"); 154 155 assertEquals("Value not present (null)", true, npt.condition(false)); 156 } 157 158 161 public void testPageScopeObjectPresent() throws ServletException , javax.servlet.jsp.JspException { 162 NotPresentTag npt = new NotPresentTag(); 163 String testKey = "testPageScopePresent"; 164 String testStringValue = "abc"; 165 npt.setScope("page"); 166 167 pageContext.setAttribute(testKey, testStringValue, PageContext.PAGE_SCOPE); 168 npt.setPageContext(pageContext); 169 npt.setName(testKey); 170 171 assertEquals("Value present (not null)", false, npt.condition(false)); 172 } 173 174 177 public void testPageScopeObjectNotPresent() throws ServletException , javax.servlet.jsp.JspException { 178 NotPresentTag npt = new NotPresentTag(); 179 String testKey = "testPageScopeNotPresent"; 180 181 npt.setPageContext(pageContext); 182 npt.setName(testKey); 183 npt.setScope("page"); 184 185 assertEquals("Value not present (null)", true, npt.condition(false)); 186 } 187 188 191 196 197 200 210 211 214 public void testCookieNotPresent() throws ServletException , javax.servlet.jsp.JspException { 215 NotPresentTag npt = new NotPresentTag(); 216 217 npt.setPageContext(pageContext); 218 npt.setCookie(COOKIE_KEY); 219 220 assertEquals("Cookie not present", true, npt.condition(false)); 221 } 222 223 226 public void beginHeaderPresent(WebRequest testRequest) { 227 testRequest.addHeader(HEADER_KEY, "header value"); 228 } 229 230 233 public void testHeaderPresent() throws ServletException , javax.servlet.jsp.JspException { 234 NotPresentTag npt = new NotPresentTag(); 235 236 npt.setPageContext(pageContext); 237 npt.setHeader(HEADER_KEY); 238 239 assertEquals("Header present", false, npt.condition(false)); 240 } 241 242 245 public void testHeaderNotPresent() throws ServletException , javax.servlet.jsp.JspException { 246 NotPresentTag npt = new NotPresentTag(); 247 248 npt.setPageContext(pageContext); 249 npt.setHeader(HEADER_KEY); 250 251 assertEquals("Header not present", true, npt.condition(false)); 252 } 253 254 257 public void beginParameterPresent(WebRequest testRequest) { 258 testRequest.addParameter(PARAMETER_KEY, "parameter value"); 259 } 260 261 264 public void testParameterPresent() throws ServletException , javax.servlet.jsp.JspException { 265 NotPresentTag npt = new NotPresentTag(); 266 267 npt.setPageContext(pageContext); 268 npt.setParameter(PARAMETER_KEY); 269 270 assertEquals("Parameter present", false, npt.condition(false)); 271 } 272 273 276 public void testParameterNotPresent() throws ServletException , javax.servlet.jsp.JspException { 277 NotPresentTag npt = new NotPresentTag(); 278 279 npt.setPageContext(pageContext); 280 npt.setParameter(PARAMETER_KEY); 281 282 assertEquals("Parameter not present", true, npt.condition(false)); 283 } 284 285 } 286 | Popular Tags |