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 32 public class TestNotEqualTag extends JspTestCase { 33 protected final static String COOKIE_KEY = "org.apache.struts.taglib.logic.COOKIE_KEY"; 34 protected final static String HEADER_KEY = "org.apache.struts.taglib.logic.HEADER_KEY"; 35 protected final static String PARAMETER_KEY = "org.apache.struts.taglib.logic.PARAMETER_KEY"; 36 protected NotEqualTag net = null; 37 protected static String testStringKey; 38 protected static String testStringValue; 39 protected static String testStringValue1; 40 protected static String testIntegerKey; 41 protected static Integer testIntegerValue; 42 protected static Integer testIntegerValue1; 43 44 49 public TestNotEqualTag(String theName) { 50 super(theName); 51 } 52 53 58 public static void main(String [] theArgs) { 59 junit.awtui.TestRunner.main(new String [] {TestEqualTag.class.getName()}); 60 } 61 62 66 public static Test suite() { 67 return new TestSuite(TestNotEqualTag.class); 69 } 70 71 public void setUp() 72 { 73 testStringKey = "testString"; 74 testStringValue = "abc"; 75 testStringValue1 = "abcd"; 76 testIntegerKey = "testInteger"; 77 testIntegerValue = new Integer (21); 78 testIntegerValue1 = new Integer (testIntegerValue.intValue() + 1); 79 80 net = new NotEqualTag(); 81 net.setPageContext(pageContext); 82 } 83 84 public void tearDown() 85 { 86 net = null; 87 } 88 89 92 104 105 108 public void beginCookieStringNotEquals(WebRequest testRequest) { 109 testRequest.addCookie(COOKIE_KEY, "abc"); 110 } 111 112 public void testCookieStringNotEquals() throws ServletException , javax.servlet.jsp.JspException { 113 net.setCookie(COOKIE_KEY); 114 net.setValue(testStringValue1); 115 116 assertEquals("Cookie string not equals comparison", false, net.condition(0, 0)); 117 } 118 119 122 public void beginHeaderStringEquals(WebRequest testRequest) { 123 testRequest.addHeader(COOKIE_KEY, "abc"); 124 } 125 126 public void testHeaderStringEquals() throws ServletException , javax.servlet.jsp.JspException { 127 net.setHeader(COOKIE_KEY); 128 net.setValue(testStringValue); 129 130 assertEquals("Header string equals comparison", true, net.condition(0, 0)); 131 } 132 133 136 public void beginHeaderStringNotEquals(WebRequest testRequest) { 137 testRequest.addHeader(COOKIE_KEY, "abc"); 138 } 139 140 public void testHeaderStringNotEquals() throws ServletException , javax.servlet.jsp.JspException { 141 net.setHeader(COOKIE_KEY); 142 net.setValue(testStringValue1); 143 144 assertEquals("Header string not equals comparison", false, net.condition(0, 0)); 145 } 146 147 150 public void beginParameterStringEquals(WebRequest testRequest) { 151 testRequest.addParameter(PARAMETER_KEY, "abc"); 152 } 153 154 public void testParameterStringEquals() throws ServletException , javax.servlet.jsp.JspException { 155 net.setParameter(PARAMETER_KEY); 156 net.setValue(testStringValue); 157 158 assertEquals("Parameter string equals comparison", true, net.condition(0, 0)); 159 } 160 161 164 public void beginParameterStringNotEquals(WebRequest testRequest) { 165 testRequest.addParameter(PARAMETER_KEY, "abc"); 166 } 167 168 public void testParameterStringNotEquals() throws ServletException , javax.servlet.jsp.JspException { 169 net.setParameter(PARAMETER_KEY); 170 net.setValue(testStringValue1); 171 172 assertEquals("Parameter string not equals comparison", false, net.condition(0, 0)); 173 } 174 175 178 public void testStringEquals() throws ServletException , javax.servlet.jsp.JspException { 179 request.setAttribute(testStringKey, testStringValue); 180 net.setName(testStringKey); 181 net.setValue(testStringValue); 182 System.out.println("testing"); 183 assertEquals("String equals comparison", true, net.condition(0, 0)); 184 } 185 186 189 public void testStringNotEquals() throws ServletException , javax.servlet.jsp.JspException { 190 request.setAttribute(testStringKey, testStringValue); 191 net.setName(testStringKey); 192 net.setValue(testStringValue1); 193 194 assertEquals("String not equals comparison", false, net.condition(0, 0)); 195 } 196 197 201 public void testIntegerEquals() throws ServletException , javax.servlet.jsp.JspException { 202 request.setAttribute(testIntegerKey, testIntegerValue); 203 net.setName(testIntegerKey); 204 net.setValue(testIntegerValue.toString()); 205 206 assertEquals("Integer equals comparison", true, net.condition(0, 0)); 207 } 208 209 212 public void testIntegerNotEquals() throws ServletException , javax.servlet.jsp.JspException { 213 request.setAttribute(testIntegerKey, testIntegerValue); 214 net.setName(testIntegerKey); 215 net.setValue(testIntegerValue1.toString()); 216 217 assertEquals("Integer equals comparison", false, net.condition(0, 0)); 218 } 219 220 223 public void testApplicationScopeStringEquals() throws ServletException , javax.servlet.jsp.JspException { 224 String testKey = "testApplicationScopeStringEquals"; 225 226 pageContext.setAttribute(testKey, testStringValue, PageContext.APPLICATION_SCOPE); 227 net.setPageContext(pageContext); 228 net.setName(testKey); 229 net.setScope("application"); 230 net.setValue(testStringValue); 231 232 assertEquals("String in application scope equals", true, net.condition(0, 0)); 233 } 234 235 238 public void testApplicationScopeStringNotEquals() throws ServletException , javax.servlet.jsp.JspException { 239 String testKey = "testApplicationScopeStringNotEquals"; 240 241 pageContext.setAttribute(testKey, testStringValue, PageContext.APPLICATION_SCOPE); 242 net.setPageContext(pageContext); 243 net.setName(testKey); 244 net.setScope("application"); 245 net.setValue(testStringValue1); 246 247 assertEquals("String in application scope not equals", false, net.condition(0, 0)); 248 } 249 250 } 251 | Popular Tags |