1 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 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 |