001: // Copyright 2007 The Apache Software Foundation
002: //
003: // Licensed under the Apache License, Version 2.0 (the "License");
004: // you may not use this file except in compliance with the License.
005: // You may obtain a copy of the License at
006: //
007: // http://www.apache.org/licenses/LICENSE-2.0
008: //
009: // Unless required by applicable law or agreed to in writing, software
010: // distributed under the License is distributed on an "AS IS" BASIS,
011: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: // See the License for the specific language governing permissions and
013: // limitations under the License.
014:
015: package org.apache.tapestry.internal.services;
016:
017: import org.apache.tapestry.Field;
018: import org.apache.tapestry.FieldValidator;
019: import org.apache.tapestry.Validator;
020: import org.apache.tapestry.internal.test.InternalBaseTestCase;
021: import org.apache.tapestry.ioc.MessageFormatter;
022: import org.testng.annotations.Test;
023:
024: /**
025: * Tests a few outlier cases not covered by {@link FieldValidatorSourceImplTest}.
026: */
027: public class FieldValidatorImplTest extends InternalBaseTestCase {
028: @SuppressWarnings("unchecked")
029: @Test
030: public void null_value_skipped() throws Exception {
031: Field field = mockField();
032: MessageFormatter formatter = mockMessageFormatter();
033: Validator validator = mockValidator();
034:
035: train_invokeIfBlank(validator, false);
036:
037: replay();
038:
039: FieldValidator fv = new FieldValidatorImpl(field, null,
040: formatter, validator, null);
041:
042: fv.validate(null);
043:
044: verify();
045: }
046:
047: @SuppressWarnings("unchecked")
048: @Test
049: public void blank_value_skipped() throws Exception {
050: Field field = mockField();
051: MessageFormatter formatter = mockMessageFormatter();
052: Validator validator = mockValidator();
053:
054: train_invokeIfBlank(validator, false);
055:
056: replay();
057:
058: FieldValidator fv = new FieldValidatorImpl(field, null,
059: formatter, validator, null);
060:
061: fv.validate("");
062:
063: verify();
064: }
065:
066: @SuppressWarnings("unchecked")
067: @Test
068: public void nonmatching_value_type_skipped() throws Exception {
069: Field field = mockField();
070: MessageFormatter formatter = mockMessageFormatter();
071: Validator validator = mockValidator();
072: Integer value = 15;
073:
074: train_invokeIfBlank(validator, true);
075: train_getValueType(validator, String.class);
076:
077: replay();
078:
079: FieldValidator fv = new FieldValidatorImpl(field, null,
080: formatter, validator, null);
081:
082: fv.validate(value);
083:
084: verify();
085: }
086:
087: @SuppressWarnings("unchecked")
088: @Test
089: public void value_type_check_skipped_for_null_values()
090: throws Exception {
091: Field field = mockField();
092: MessageFormatter formatter = mockMessageFormatter();
093: Validator validator = mockValidator();
094:
095: train_invokeIfBlank(validator, true);
096:
097: validator.validate(field, null, formatter, null);
098:
099: replay();
100:
101: FieldValidator fv = new FieldValidatorImpl(field, null,
102: formatter, validator, null);
103:
104: fv.validate(null);
105:
106: verify();
107: }
108: }
|