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    package org.apache.tapestry.binding;
015    
016    import static org.easymock.EasyMock.expect;
017    
018    import org.apache.hivemind.Location;
019    import org.apache.tapestry.IComponent;
020    import org.apache.tapestry.coerce.ValueConverter;
021    import org.apache.tapestry.services.ComponentPropertySource;
022    import org.testng.annotations.Test;
023    
024    /**
025     * Tests functionality of {@link MetaBinding}.
026     */
027    @Test
028    public class TestMetaBinding extends BindingTestCase
029    {
030        
031        public void test_Create()
032        {
033            IComponent component = newMock(IComponent.class);
034            ValueConverter vc = newValueConverter();
035            Location l = fabricateLocation(12);
036            ComponentPropertySource src = newMock(ComponentPropertySource.class);
037            
038            expect(src.getComponentProperty(component, "key")).andReturn("wiggle");
039            
040            replay();
041    
042            MetaBinding b = new MetaBinding("param", vc, l, component, src, "key");
043            
044            assertSame(component, b.getComponent());
045            assertEquals(b.getObject(), "wiggle");
046    
047            verify();
048        }
049    
050        public void test_To_String()
051        {
052            IComponent component = newComponent();
053            ValueConverter vc = newValueConverter();
054            Location l = fabricateLocation(12);
055            ComponentPropertySource src = newMock(ComponentPropertySource.class);
056            
057            expect(component.getExtendedId()).andReturn("Foo/bar.baz");
058            
059            replay();
060    
061            MetaBinding b = new MetaBinding("param", vc, l, component, src, "key");
062            
063            assertEquals(b.toString(), "MetaBinding[Foo/bar.baz key]");
064    
065            verify();
066        }
067    }