1 20 package org.enhydra.barracuda.core.forms.validators; 21 22 import java.io.*; 23 import java.util.*; 24 25 import org.w3c.dom.*; 26 import junit.framework.*; 27 28 import org.enhydra.barracuda.core.forms.*; 29 import org.apache.log4j.*; 30 import org.enhydra.barracuda.plankton.data.*; 31 import org.enhydra.barracuda.testbed.*; 32 33 34 37 public class TestNotNullValidator extends ValidatorTestCase { 38 private static String testClass = TestNotNullValidator.class.getName(); 40 private static Logger logger = Logger.getLogger("test."+testClass); 41 42 44 48 public TestNotNullValidator(String name) { 49 super(name); 50 } 51 52 59 public static void main(String args[]) { 60 TestUtil.parseParams(args); 62 63 if (TestUtil.BATCH_MODE) junit.textui.TestRunner.main(new String [] {testClass}); 65 else junit.swingui.TestRunner.main(new String [] {testClass}); 66 } 67 68 69 75 78 public void testString() { 79 NotNullValidator v = new NotNullValidator(); 81 DefaultFormElement el = new DefaultFormElement("key", FormType.STRING); 82 83 DefaultStateMap sm = new DefaultStateMap(); 86 87 sm.putState("invalid not null1", null); 88 sm.putState("invalid not null2", ""); 89 sm.putState("invalid not null3", " "); 90 assertAllInvalid(v, sm, FormType.STRING); 91 92 sm = null; 93 sm = new DefaultStateMap(); 94 sm.putState("valid not null", "foofoo"); 95 assertAllValid(v, sm, FormType.STRING); 96 97 99 100 108 } 110 111 116 public void testBoolean() { 117 NotNullValidator v = new NotNullValidator(); 119 DefaultFormElement el = new DefaultFormElement("key", FormType.BOOLEAN); 120 121 DefaultStateMap sm = new DefaultStateMap(); 124 125 sm.putState("invalid not null1", null); 126 assertAllInvalid(v, sm, FormType.BOOLEAN); 127 128 sm = null; 129 sm = new DefaultStateMap(); 130 sm.putState("valid not null1", new Boolean (true)); 131 sm.putState("valid not null2", new Boolean (false)); 132 assertAllValid(v, sm, FormType.BOOLEAN); 133 134 136 137 144 } 146 147 150 public void testInteger() { 151 NotNullValidator v = new NotNullValidator(); 153 DefaultFormElement el = new DefaultFormElement("key", FormType.INTEGER); 154 Integer i1 = new Integer (123); 155 156 DefaultStateMap sm = new DefaultStateMap(); 159 160 sm.putState("invalid not null1", null); 161 assertAllInvalid(v, sm, FormType.INTEGER); 162 163 sm = null; 164 sm = new DefaultStateMap(); 165 sm.putState("valid not null1", i1); 166 assertAllValid(v, sm, FormType.INTEGER); 167 168 170 171 177 } 179 180 184 public void testDate() { 185 NotNullValidator v = new NotNullValidator(); 187 DefaultFormElement el = new DefaultFormElement("key", FormType.DATE); 188 Date d = new Date(); 189 190 DefaultStateMap sm = new DefaultStateMap(); 193 194 sm.putState("invalid not null1", null); 195 assertAllInvalid(v, sm, FormType.DATE); 196 197 sm = null; 198 sm = new DefaultStateMap(); 199 sm.putState("valid not null1", d); 200 assertAllValid(v, sm, FormType.DATE); 201 202 204 205 211 } 213 214 217 public void testLong() { 218 NotNullValidator v = new NotNullValidator(); 220 DefaultFormElement el = new DefaultFormElement("key", FormType.LONG); 221 Long l1 = new Long (123); 222 223 DefaultStateMap sm = new DefaultStateMap(); 226 227 sm.putState("invalid not null1", null); 228 assertAllInvalid(v, sm, FormType.LONG); 229 230 sm = null; 231 sm = new DefaultStateMap(); 232 sm.putState("valid not null1", l1); 233 assertAllValid(v, sm, FormType.LONG); 234 235 237 238 244 } 246 247 250 public void testShort() { 251 NotNullValidator v = new NotNullValidator(); 253 DefaultFormElement el = new DefaultFormElement("key", FormType.SHORT); 254 Short s1 = new Short ((short)123); 255 256 DefaultStateMap sm = new DefaultStateMap(); 259 260 sm.putState("invalid not null1", null); 261 assertAllInvalid(v, sm, FormType.SHORT); 262 263 sm = null; 264 sm = new DefaultStateMap(); 265 sm.putState("valid not null1", s1); 266 assertAllValid(v, sm, FormType.SHORT); 267 268 270 271 277 } 279 280 283 public void testDouble() { 284 NotNullValidator v = new NotNullValidator(); 286 DefaultFormElement el = new DefaultFormElement("key", FormType.DOUBLE); 287 Double d1 = new Double (123); 288 289 DefaultStateMap sm = new DefaultStateMap(); 292 293 sm.putState("invalid not null1", null); 294 assertAllInvalid(v, sm, FormType.DOUBLE); 295 296 sm = null; 297 sm = new DefaultStateMap(); 298 sm.putState("valid not null1", d1); 299 assertAllValid(v, sm, FormType.DOUBLE); 300 301 303 304 310 } 312 313 316 public void testFloat() { 317 NotNullValidator v = new NotNullValidator(); 319 DefaultFormElement el = new DefaultFormElement("key", FormType.FLOAT); 320 Float f1 = new Float (123); 321 322 DefaultStateMap sm = new DefaultStateMap(); 325 326 sm.putState("invalid not null1", null); 327 assertAllInvalid(v, sm, FormType.FLOAT); 328 329 sm = null; 330 sm = new DefaultStateMap(); 331 sm.putState("valid not null1", f1); 332 assertAllValid(v, sm, FormType.FLOAT); 333 334 336 337 343 } 345 346 } 347 | Popular Tags |