KickJava   Java API By Example, From Geeks To Geeks.

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


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.Location;
18 import org.apache.tapestry.BindingException;
19 import org.apache.tapestry.IAsset;
20 import org.apache.tapestry.IBinding;
21 import org.apache.tapestry.IComponent;
22 import org.apache.tapestry.coerce.ValueConverter;
23 import org.easymock.MockControl;
24
25 /**
26  * @author Howard M. Lewis Ship
27  * @since 4.0
28  */

29 public class TestAssetBinding extends BindingTestCase
30 {
31
32     public void testGetObject()
33     {
34         IAsset asset = (IAsset) newMock(IAsset.class);
35
36         MockControl componentc = newControl(IComponent.class);
37         IComponent component = (IComponent) componentc.getMock();
38
39         component.getAsset("fred");
40         componentc.setReturnValue(asset);
41
42         Location l = fabricateLocation(22);
43
44         ValueConverter vc = newValueConverter();
45
46         replayControls();
47
48         AssetBinding b = new AssetBinding("parameterName", vc, l, component, "fred");
49
50         assertSame(asset, b.getObject());
51
52         assertSame(l, b.getLocation());
53         assertEquals("parameterName", b.getDescription());
54
55         assertSame(component, b.getComponent());
56
57         verifyControls();
58     }
59
60     public void testAssetMissing()
61     {
62         MockControl componentc = newControl(IComponent.class);
63         IComponent component = (IComponent) componentc.getMock();
64
65         component.getAsset("fred");
66         componentc.setReturnValue(null);
67
68         component.getExtendedId();
69         componentc.setReturnValue("Home/foo");
70
71         Location l = fabricateLocation(22);
72
73         ValueConverter vc = newValueConverter();
74
75         replayControls();
76
77         IBinding b = new AssetBinding("parameterName", vc, l, component, "fred");
78
79         try
80         {
81             b.getObject();
82             unreachable();
83         }
84         catch (BindingException ex)
85         {
86             assertEquals("Component Home/foo does not contain an asset named 'fred'.", ex
87                     .getMessage());
88             assertSame(l, ex.getLocation());
89             assertSame(component, ex.getComponent());
90             assertSame(b, ex.getBinding());
91         }
92
93     }
94 }
Popular Tags