01: /*
02: * Copyright 2006 Dan Shellman
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.iscreen.impl;
17:
18: import org.iscreen.FailureMessage;
19: import org.iscreen.SimpleBean;
20: import org.iscreen.Validator;
21: import org.iscreen.ValidatorContext;
22:
23: /**
24: * A mock Validator for testing purposes.
25: *
26: * @author Shellman, Dan
27: */
28: public class MockValidator implements Validator {
29: private String testConstraint;
30: private FailureMessage testMessage;
31: private Object testService;
32: private boolean reportFailure = false;
33: private Object beanToValidate;
34:
35: /**
36: * Default constructor.
37: */
38: public MockValidator() {
39: } //end MockValidator()
40:
41: public void validate(ValidatorContext context, Object beanToValidate) {
42: if (reportFailure) {
43: context.reportFailure(testMessage);
44: }
45: } //end validate()
46:
47: public void setReportFailureFlag(boolean flag) {
48: reportFailure = flag;
49: } //end setReportFailureFlag()
50:
51: public Object constructBeanToValidate() {
52: if (beanToValidate == null) {
53: return new SimpleBean();
54: }
55:
56: return beanToValidate;
57: } //end constructBeanToValidate()
58:
59: public void defineBeanToValidate(Object obj) {
60: beanToValidate = obj;
61: } //end defineBeanToValidate()
62:
63: public void setTestConstraint(String constraint) {
64: testConstraint = constraint;
65: } //end setTestConstraint()
66:
67: public String getTestConstraint() {
68: return testConstraint;
69: } //end getTestConstraint()
70:
71: public void setTestMessage(FailureMessage message) {
72: testMessage = message;
73: } //end setTestMessage()
74:
75: public FailureMessage getTestMessage() {
76: return testMessage;
77: } //end getTestMessage()
78:
79: public void setTestService(Object service) {
80: testService = service;
81: } //end setTestService()
82:
83: public Object getTestService() {
84: return testService;
85: } //end getTestService()
86: } //end MockValidator
|