01: // Copyright 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.validator;
16:
17: import org.apache.tapestry.Field;
18: import org.apache.tapestry.ValidationException;
19: import org.apache.tapestry.internal.test.InternalBaseTestCase;
20: import org.apache.tapestry.ioc.MessageFormatter;
21: import org.testng.annotations.Test;
22:
23: public class MaxLengthTest extends InternalBaseTestCase {
24: @Test
25: public void short_enough() throws Exception {
26: Field field = mockField();
27: MessageFormatter formatter = mockMessageFormatter();
28: String value = "Now the student has become the master.";
29:
30: replay();
31:
32: MaxLength validator = new MaxLength();
33:
34: validator.validate(field, value.length(), formatter, value);
35:
36: verify();
37: }
38:
39: @Test
40: public void long_value() throws Exception {
41: String label = "My Field";
42: Field field = mockFieldWithLabel(label);
43: MessageFormatter formatter = mockMessageFormatter();
44: String value = "Now the student has become the master.";
45: String message = "{message}";
46: Integer constraint = value.length() - 1;
47:
48: train_format(formatter, message, constraint, label);
49:
50: replay();
51:
52: MaxLength validator = new MaxLength();
53:
54: try {
55: validator.validate(field, constraint, formatter, value);
56: unreachable();
57: } catch (ValidationException ex) {
58: assertEquals(ex.getMessage(), message);
59: }
60:
61: verify();
62: }
63: }
|