01: /**
02: * Copyright 2006 Webmedia Group Ltd.
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: **/package org.araneaframework.tests.constraints.helper;
16:
17: import org.araneaframework.uilib.form.Constraint;
18: import org.araneaframework.uilib.form.FormElement;
19: import org.araneaframework.uilib.form.FormWidget;
20:
21: /**
22: * Helper for testing {@link Constraint}s on a {@link FormWidget} with exactly one
23: * {@link FormElement}.
24: *
25: * @author Taimo Peelo (taimo@araneaframework.org)
26: */
27: public class ConstraintTestHelper {
28: private FormWidget form;
29: private FormElement element;
30:
31: public ConstraintTestHelper(FormWidget form, FormElement element) {
32: org.araneaframework.core.Assert
33: .notNullParam(this , form, "form");
34: org.araneaframework.core.Assert.notNullParam(this , element,
35: "element");
36:
37: this .form = form;
38: this .element = element;
39: }
40:
41: /**
42: * Tests validness of {@link FormWidget} and {@link FormElement}, after
43: * {@link FormElement} value is set.
44: */
45: public void testConstraintValidness(Constraint constraint,
46: Object value, boolean valid) throws Exception {
47: element.setConstraint(constraint);
48: element.setValue(value);
49:
50: junit.framework.Assert.assertEquals(valid, element.validate());
51: form.clearErrors();
52: junit.framework.Assert.assertEquals(valid, form.validate());
53: form.clearErrors(); // allows using more than once per setUp()
54: }
55: }
|