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: TestValidationRuleUrl.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 TestValidationRuleUrl extends TestCase {
013: public TestValidationRuleUrl(String name) {
014: super (name);
015: }
016:
017: public void testInstantiation() {
018: Bean bean = new Bean("http://www.test.com");
019: ValidationRuleUrl rule = new ValidationRuleUrl("property")
020: .setBean(bean);
021: assertNotNull(rule);
022: }
023:
024: public void testValid() {
025: Bean bean = new Bean("http://www.test.com");
026: ValidationRuleUrl rule = new ValidationRuleUrl("property")
027: .setBean(bean);
028: assertTrue(rule.validate());
029: }
030:
031: public void testValidArray() {
032: Bean bean = new Bean(new String[] { "http://www.test.com",
033: "http://www.uwyn.com", "http://www.rifers.org" });
034: ValidationRuleUrl rule = new ValidationRuleUrl("arrayProperty")
035: .setBean(bean);
036: assertTrue(rule.validate());
037: }
038:
039: public void testInvalid() {
040: Bean bean = new Bean("htt:www/.test.com");
041: ValidationRuleUrl rule = new ValidationRuleUrl("property")
042: .setBean(bean);
043: assertFalse(rule.validate());
044: }
045:
046: public void testInvalidArray() {
047: Bean bean = new Bean(new String[] { "http://www.test.com",
048: "http://www.uwyn.com", "htt:www/.rifersorg" });
049: ValidationRuleUrl rule = new ValidationRuleUrl("arrayProperty")
050: .setBean(bean);
051: assertFalse(rule.validate());
052: }
053:
054: public void testUnknownProperty() {
055: Bean bean = new Bean("http://www.test.com");
056: ValidationRuleUrl rule = new ValidationRuleUrl(
057: "unknown_property").setBean(bean);
058: assertTrue(rule.validate());
059: }
060:
061: public void testGetError() {
062: Bean bean = new Bean("http://www.test.com");
063: ValidationRuleUrl rule = new ValidationRuleUrl("property")
064: .setBean(bean);
065: ValidationError error = rule.getError();
066: assertEquals(ValidationError.IDENTIFIER_INVALID, error
067: .getIdentifier());
068: assertEquals("property", error.getSubject());
069: assertEquals(rule.getSubject(), error.getSubject());
070: }
071:
072: public class Bean {
073: private String mProperty = null;
074: private String[] mArrayProperty = null;
075:
076: public Bean(String property) {
077: mProperty = property;
078: }
079:
080: public Bean(String[] arrayProperty) {
081: mArrayProperty = arrayProperty;
082: }
083:
084: public void setArrayProperty(String[] arrayProperty) {
085: mArrayProperty = arrayProperty;
086: }
087:
088: public String[] getArrayProperty() {
089: return mArrayProperty;
090: }
091:
092: public void setProperty(String property) {
093: mProperty = property;
094: }
095:
096: public String getProperty() {
097: return mProperty;
098: }
099: }
100: }
|