001: /*
002: * Copyright 2006 Dan Shellman
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.iscreen.impl;
017:
018: import java.util.Locale;
019:
020: import junit.framework.TestCase;
021:
022: import org.iscreen.ValidationException;
023:
024: /**
025: *
026: * @author Shellman, Dan
027: */
028: public class BaseValidationServiceTest extends TestCase {
029: /**
030: * Default constructor.
031: */
032: public BaseValidationServiceTest(String name) {
033: super (name);
034: } //end BaseValidationServiceTest()
035:
036: /**
037: * Tests the ensure that all validators are called.
038: */
039: public void testCallingValidators() throws Exception {
040: MockValidationService service;
041: MockValidatorWrapper wrapper1;
042: MockValidatorWrapper wrapper2;
043:
044: service = new MockValidationService("some id", Locale
045: .getDefault());
046: wrapper1 = new MockValidatorWrapper(false, false);
047: wrapper2 = new MockValidatorWrapper(false, false);
048: service.addValidator(wrapper1);
049: service.addValidator(wrapper2);
050:
051: service.validate("foo");
052:
053: assertTrue(wrapper1.wasValidateCalled());
054: assertTrue(wrapper2.wasValidateCalled());
055: } //end testCallingValidators()
056:
057: /**
058: * Tests to ensure that a fail-fast check is made.
059: */
060: public void testFailFastCheck() throws Exception {
061: MockValidationService service;
062: MockValidatorWrapper wrapper1;
063: MockValidatorWrapper wrapper2;
064:
065: service = new MockValidationService("some id", Locale
066: .getDefault());
067: wrapper1 = new MockValidatorWrapper(false, true);
068: wrapper2 = new MockValidatorWrapper(false, false);
069: service.addValidator(wrapper1);
070: service.addValidator(wrapper2);
071:
072: service.validate("foo");
073:
074: assertTrue(wrapper1.wasValidateCalled());
075: assertTrue(!wrapper2.wasValidateCalled());
076: } //end testFailFastCheck()
077:
078: /**
079: * Tests to ensure that an exception is thrown when a failure is found.
080: */
081: public void testThrowException() {
082: MockValidationService service;
083: MockValidatorWrapper wrapper1;
084: MockValidatorWrapper wrapper2;
085:
086: service = new MockValidationService("some id", Locale
087: .getDefault());
088: wrapper1 = new MockValidatorWrapper(true, false);
089: wrapper2 = new MockValidatorWrapper(false, false);
090: service.addValidator(wrapper1);
091: service.addValidator(wrapper2);
092:
093: try {
094: service.validate("foo");
095: fail("Expected a validation failure");
096: } catch (ValidationException e) {
097: }
098:
099: assertTrue(wrapper1.wasValidateCalled());
100: assertTrue(wrapper2.wasValidateCalled());
101: } //end testThrowException()
102: } //end BaseValidationServiceTest
|