KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > binding > TestComponentBinding


1 // Copyright 2004, 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.binding;
16
17 import org.apache.hivemind.ApplicationRuntimeException;
18 import org.apache.hivemind.Location;
19 import org.apache.tapestry.IComponent;
20 import org.apache.tapestry.coerce.ValueConverter;
21 import org.easymock.MockControl;
22
23 /**
24  * Tests for {@link org.apache.tapestry.binding.ComponentBinding}.
25  *
26  * @author Howard M. Lewis Ship
27  * @since 4.0
28  */

29 public class TestComponentBinding extends BindingTestCase
30 {
31     public void testGetObject()
32     {
33         IComponent nested = newComponent();
34
35         MockControl cc = newControl(IComponent.class);
36         IComponent component = (IComponent) cc.getMock();
37
38         component.getComponent("foo");
39         cc.setReturnValue(nested);
40
41         ValueConverter vc = newValueConverter();
42
43         Location l = newLocation();
44
45         replayControls();
46
47         ComponentBinding b = new ComponentBinding("param", vc, l, component, "foo");
48
49         assertSame(component, b.getComponent());
50         assertSame(nested, b.getObject());
51
52         verifyControls();
53     }
54
55     public void testGetObjectFailure()
56     {
57         MockControl cc = newControl(IComponent.class);
58         IComponent component = (IComponent) cc.getMock();
59
60         Throwable JavaDoc t = new ApplicationRuntimeException("No such component.");
61
62         component.getComponent("foo");
63         cc.setThrowable(t);
64
65         ValueConverter vc = newValueConverter();
66
67         Location l = newLocation();
68
69         replayControls();
70
71         ComponentBinding b = new ComponentBinding("param", vc, l, component, "foo");
72
73         try
74         {
75             b.getObject();
76             unreachable();
77         }
78         catch (ApplicationRuntimeException ex)
79         {
80             assertEquals(t.getMessage(), ex.getMessage());
81             assertSame(t, ex.getRootCause());
82             assertSame(l, ex.getLocation());
83         }
84
85         verifyControls();
86     }
87 }
Popular Tags