KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > form > validator > TestValidatorsBinding


1 // Copyright 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// 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.form.validator;
16
17 import java.util.List JavaDoc;
18
19 import org.apache.hivemind.ApplicationRuntimeException;
20 import org.apache.hivemind.Location;
21 import org.apache.tapestry.IBinding;
22 import org.apache.tapestry.binding.BindingTestCase;
23 import org.apache.tapestry.coerce.ValueConverter;
24 import org.easymock.MockControl;
25
26 /**
27  * Tests for {@link org.apache.tapestry.form.validator.ValidatorsBinding} and
28  * {@link org.apache.tapestry.form.validator.ValidatorsBindingFactory}.
29  *
30  * @author Howard Lewis Ship
31  * @since 4.0
32  */

33 public class TestValidatorsBinding extends BindingTestCase
34 {
35     public void testSuccess()
36     {
37         Location l = newLocation();
38         List JavaDoc validators = (List JavaDoc) newMock(List JavaDoc.class);
39         ValueConverter vc = newValueConverter();
40
41         MockControl control = newControl(ValidatorFactory.class);
42         ValidatorFactory vf = (ValidatorFactory) control.getMock();
43
44         vf.constructValidatorList("required");
45         control.setReturnValue(validators);
46
47         replayControls();
48
49         ValidatorsBindingFactory factory = new ValidatorsBindingFactory();
50         factory.setValueConverter(vc);
51         factory.setValidatorFactory(vf);
52
53         IBinding binding = factory.createBinding(null, "my desc", "required", l);
54
55         assertSame(validators, binding.getObject());
56         assertSame(l, binding.getLocation());
57         assertEquals("my desc", binding.getDescription());
58
59         verifyControls();
60     }
61
62     public void testFailure()
63     {
64         Throwable JavaDoc t = new RuntimeException JavaDoc("Boom!");
65         Location l = newLocation();
66
67         ValueConverter vc = newValueConverter();
68
69         MockControl control = newControl(ValidatorFactory.class);
70         ValidatorFactory vf = (ValidatorFactory) control.getMock();
71
72         vf.constructValidatorList("required");
73         control.setThrowable(t);
74
75         replayControls();
76
77         ValidatorsBindingFactory factory = new ValidatorsBindingFactory();
78         factory.setValueConverter(vc);
79         factory.setValidatorFactory(vf);
80
81         try
82         {
83             factory.createBinding(null, "my desc", "required", l);
84             unreachable();
85         }
86         catch (ApplicationRuntimeException ex)
87         {
88             assertEquals("Boom!", ex.getMessage());
89             assertSame(t, ex.getRootCause());
90             assertSame(l, ex.getLocation());
91         }
92
93         verifyControls();
94     }
95 }
96
Popular Tags