001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: TestValidationRuleEmail.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.site;
009:
010: import junit.framework.TestCase;
011:
012: public class TestValidationRuleEmail extends TestCase {
013: public TestValidationRuleEmail(String name) {
014: super (name);
015: }
016:
017: public void testInstantiation() {
018: Bean bean = new Bean("email@domain.com");
019: ValidationRuleEmail rule = new ValidationRuleEmail("property")
020: .setBean(bean);
021: assertNotNull(rule);
022: }
023:
024: public void testValid() {
025: Bean bean = new Bean("email@domain.com");
026: ValidationRuleEmail rule = new ValidationRuleEmail("property")
027: .setBean(bean);
028: assertTrue(rule.validate());
029: }
030:
031: public void testValidArray() {
032: Bean bean = new Bean(new String[] { "email@domain.com",
033: "you@mymail.org" });
034: ValidationRuleEmail rule = new ValidationRuleEmail(
035: "arrayProperty").setBean(bean);
036: assertTrue(rule.validate());
037: }
038:
039: public void testInvalid() {
040: Bean bean = new Bean("email@dom@ain.com");
041: ValidationRuleEmail rule = new ValidationRuleEmail("property")
042: .setBean(bean);
043: assertFalse(rule.validate());
044: }
045:
046: public void testInvalidArray() {
047: Bean bean = new Bean(new String[] { "you@mymail.org",
048: "email@dom@ain.com", "email@domain.com" });
049: ValidationRuleEmail rule = new ValidationRuleEmail(
050: "arrayProperty").setBean(bean);
051: assertFalse(rule.validate());
052: }
053:
054: public void testInvalid2() {
055: Bean bean = new Bean("someone@hotmail..com");
056: ValidationRuleEmail rule = new ValidationRuleEmail("property")
057: .setBean(bean);
058: assertFalse(rule.validate());
059: }
060:
061: public void testUnknownProperty() {
062: Bean bean = new Bean("email@domain.com");
063: ValidationRuleEmail rule = new ValidationRuleEmail(
064: "unknown_property").setBean(bean);
065: assertTrue(rule.validate());
066: }
067:
068: public void testGetError() {
069: Bean bean = new Bean("email@domain.com");
070: ValidationRuleEmail rule = new ValidationRuleEmail("property")
071: .setBean(bean);
072: ValidationError error = rule.getError();
073: assertEquals(ValidationError.IDENTIFIER_INVALID, error
074: .getIdentifier());
075: assertEquals("property", error.getSubject());
076: assertEquals(rule.getSubject(), error.getSubject());
077: }
078:
079: public class Bean {
080: private String mProperty = null;
081: private String[] mArrayProperty = null;
082:
083: public Bean(String property) {
084: mProperty = property;
085: }
086:
087: public Bean(String[] arrayProperty) {
088: mArrayProperty = arrayProperty;
089: }
090:
091: public void setArrayProperty(String[] arrayProperty) {
092: mArrayProperty = arrayProperty;
093: }
094:
095: public String[] getArrayProperty() {
096: return mArrayProperty;
097: }
098:
099: public void setProperty(String property) {
100: mProperty = property;
101: }
102:
103: public String getProperty() {
104: return mProperty;
105: }
106: }
107: }
|