01: // Copyright 2006, 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.ioc.MessageFormatter;
20: import org.apache.tapestry.test.TapestryTestCase;
21: import org.testng.annotations.Test;
22:
23: public class RequiredTest extends TapestryTestCase {
24: @Test
25: public void null_value() {
26: Field field = mockFieldWithLabel("My Field");
27: MessageFormatter formatter = mockMessageFormatter();
28:
29: train_format(formatter, "{message}", "My Field");
30:
31: replay();
32:
33: try {
34: new Required().validate(field, null, formatter, null);
35: unreachable();
36: } catch (ValidationException ex) {
37: assertEquals(ex.getMessage(), "{message}");
38: }
39:
40: verify();
41: }
42:
43: @Test
44: public void blank_value() {
45: MessageFormatter formatter = mockMessageFormatter();
46: Field field = mockFieldWithLabel("My Field");
47:
48: train_format(formatter, "{message}", "My Field");
49:
50: replay();
51:
52: try {
53: new Required().validate(field, null, formatter, "");
54: unreachable();
55: } catch (ValidationException ex) {
56: assertEquals(ex.getMessage(), "{message}");
57: }
58:
59: verify();
60: }
61:
62: @Test
63: public void non_blank_value() throws Exception {
64: MessageFormatter formatter = mockMessageFormatter();
65: Field field = mockField();
66:
67: replay();
68:
69: new Required().validate(field, null, formatter, "not null");
70:
71: verify();
72: }
73: }
|