1 5 package org.exoplatform.faces.test; 6 7 import org.exoplatform.test.BasicTestCase; 8 import org.exoplatform.faces.core.validator.*; 9 import org.exoplatform.faces.core.component.UIStringInput; 10 16 public class TestValidator extends BasicTestCase { 17 18 public TestValidator(String name) { 19 super(name); 20 } 21 22 public void setUp() throws Exception { 23 24 } 25 26 public void tearDown() throws Exception { 27 28 } 29 30 public void testEmailValidator() throws Exception { 31 UIStringInput uiComponent = new UIStringInput("name", "value") ; 32 EmailAddressValidator validator = new EmailAddressValidator() ; 33 assertTrue("valid ", validate(uiComponent, validator, "test@localhost")) ; 34 assertTrue("valid ", validate(uiComponent, validator, "test@localhost.com")) ; 35 assertTrue("valid ", validate(uiComponent, validator, "test.test@localhost.com")) ; 36 assertTrue("valid ", validate(uiComponent, validator, "test.test@localhost.abc.com")) ; 37 assertTrue("valid ", validate(uiComponent, validator, "test-test@localhost.com")) ; 38 assertTrue("valid ", validate(uiComponent, validator, "test_test@localhost.com")) ; 39 assertTrue("valid ", validate(uiComponent, validator, "test.test.test@localhost.com")) ; 40 assertTrue("valid ", validate(uiComponent, validator, "test-test-test@localhost.com")) ; 41 assertTrue("valid ", validate(uiComponent, validator, "test_test_test@localhost.com")) ; 42 43 assertTrue("invalid ", !validate(uiComponent, validator, "test@localhost.")) ; 44 assertTrue("invalid ", !validate(uiComponent, validator, "test__@localhost.")) ; 45 assertTrue("invalid ", !validate(uiComponent, validator, "test..oan@localhost.com")) ; 46 assertTrue("invalid ", !validate(uiComponent, validator, "test--oan@localhost.com")) ; 47 } 48 49 private boolean validate(UIStringInput input, EmailAddressValidator validator, String s ) { 50 try { 51 validator.validate(null, input, s); 52 return true ; 53 } catch (javax.faces.validator.ValidatorException ex) { 54 return false ; 55 } 56 } 57 } | Popular Tags |