001 // Copyright 2004, 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.tapestry.binding; 016 017 import org.apache.hivemind.Location; 018 import org.apache.tapestry.BindingException; 019 import org.apache.tapestry.IAsset; 020 import org.apache.tapestry.IBinding; 021 import org.apache.tapestry.IComponent; 022 import org.apache.tapestry.coerce.ValueConverter; 023 import static org.easymock.EasyMock.expect; 024 import org.testng.annotations.Test; 025 026 /** 027 * @author Howard M. Lewis Ship 028 * @since 4.0 029 */ 030 @Test 031 public class TestAssetBinding extends BindingTestCase 032 { 033 034 public void testGetObject() 035 { 036 IAsset asset = newMock(IAsset.class); 037 IComponent component = newMock(IComponent.class); 038 039 expect(component.getAsset("fred")).andReturn(asset); 040 041 Location l = fabricateLocation(22); 042 043 ValueConverter vc = newValueConverter(); 044 045 replay(); 046 047 AssetBinding b = new AssetBinding("parameterName", vc, l, component, "fred"); 048 049 assertSame(asset, b.getObject()); 050 051 assertSame(l, b.getLocation()); 052 assertEquals("fred", b.getDescription()); 053 054 assertSame(component, b.getComponent()); 055 056 verify(); 057 } 058 059 public void testAssetMissing() 060 { 061 IComponent component = newMock(IComponent.class); 062 063 expect(component.getAsset("fred")).andReturn(null); 064 065 expect(component.getExtendedId()).andReturn("Home/foo"); 066 067 Location l = fabricateLocation(22); 068 069 ValueConverter vc = newValueConverter(); 070 071 replay(); 072 073 IBinding b = new AssetBinding("parameterName", vc, l, component, "fred"); 074 075 try 076 { 077 b.getObject(); 078 unreachable(); 079 } 080 catch (BindingException ex) 081 { 082 assertEquals("Component Home/foo does not contain an asset named 'fred'.", ex 083 .getMessage()); 084 assertSame(l, ex.getLocation()); 085 assertSame(component, ex.getComponent()); 086 assertSame(b, ex.getBinding()); 087 } 088 089 } 090 }