1 7 package com.inversoft.util.typevalidator.test; 8 9 10 import junit.framework.TestCase; 11 12 import com.inversoft.beans.BeanException; 13 import com.inversoft.error.BasicError; 14 import com.inversoft.error.PropertyError; 15 import com.inversoft.util.typevalidator.EmailTypeValidator; 16 17 18 28 public class BaseTypeValidatorTest extends TestCase { 29 30 35 public BaseTypeValidatorTest(String name) { 36 super(name); 37 } 38 39 40 43 public void testSuccess() { 44 BasicError be = null; 45 EmailTypeValidator tv = new EmailTypeValidator(); 46 47 be = tv.validate("brian@yahoo.com", null, "error {0}", new Object []{"foo"}); 48 assertNull(be); 49 50 be = tv.validate("brian@yahoo.com", null, 51 "com.inversoft.util.typevalidator.test.bundle", "error", null, null, 52 this); 53 assertNull(be); 54 55 be = tv.validate("email", "brian@inversoft.com", null, "error", null); 56 assertNull(be); 57 58 be = tv.validate("email", "good@email.address.com", null, 59 "com.inversoft.util.typevalidator.test.bundle", "error", null, null, 60 this); 61 assertNull(be); 62 63 try { 64 be = tv.fetchAndValidate("goodEmail", new Bean(), null, "error", null); 65 assertNull(be); 66 } catch (BeanException e) { 67 fail(e.toString()); 68 } 69 70 try { 71 be = tv.fetchAndValidate("goodEmail", new Bean(), null, 72 "com.inversoft.util.typevalidator.test.bundle", "error", null, null, 73 this); 74 assertNull(be); 75 } catch (BeanException e) { 76 fail(e.toString()); 77 } 78 } 79 80 83 public void testFailures() { 84 BasicError be = null; 85 EmailTypeValidator tv = new EmailTypeValidator(); 86 87 be = tv.validate("@yahoo.com", null, "error {0}", new Object []{"foo"}); 88 assertNotNull(be); 89 assertEquals("error foo", be.getMessage()); 90 91 be = tv.validate("brian yahoo.com", null, 92 "com.inversoft.util.typevalidator.test.bundle", "error", null, null, 93 this); 94 assertNotNull(be); 95 assertEquals("Some error", be.getMessage()); 96 97 be = tv.validate("email", "bad email.address.com", null, "error", null); 98 assertNotNull(be); 99 assertEquals("error", be.getMessage()); 100 assertEquals("email", ((PropertyError) be).getProperty()); 101 102 be = tv.validate("email", "bad email.address.com", null, 103 "com.inversoft.util.typevalidator.test.bundle", "error", null, 104 null, this); 105 assertNotNull(be); 106 assertEquals("Some error", be.getMessage()); 107 assertEquals("email", ((PropertyError) be).getProperty()); 108 109 try { 110 be = tv.fetchAndValidate("badEmail", new Bean(), null, "error", null); 111 assertNotNull(be); 112 assertEquals("error", be.getMessage()); 113 assertEquals("badEmail", ((PropertyError) be).getProperty()); 114 } catch (BeanException e) { 115 fail(e.toString()); 116 } 117 118 try { 119 be = tv.fetchAndValidate("badEmail", new Bean(), null, 120 "com.inversoft.util.typevalidator.test.bundle", "error", null, null, 121 this); 122 assertNotNull(be); 123 assertEquals("Some error", be.getMessage()); 124 assertEquals("badEmail", ((PropertyError) be).getProperty()); 125 } catch (BeanException e) { 126 fail(e.toString()); 127 } 128 } 129 } | Popular Tags |