KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > faces > test > TestValidator


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

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 /**
11  * Thu, May 15, 2004 @
12  * @author: Tuan Nguyen
13  * @version: $Id: TestUIComponentFactory.java,v 1.4 2004/08/05 14:58:42 tuan08 Exp $
14  * @email: tuan08@yahoo.com
15  */

16 public class TestValidator extends BasicTestCase {
17     
18   public TestValidator(String JavaDoc name) {
19     super(name);
20   }
21
22   public void setUp() throws Exception JavaDoc {
23     
24   }
25   
26   public void tearDown() throws Exception JavaDoc {
27
28   }
29   
30   public void testEmailValidator() throws Exception JavaDoc {
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 JavaDoc 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