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 static org.easymock.EasyMock.expect;
018    
019    import org.apache.hivemind.Location;
020    import org.apache.tapestry.BaseComponentTestCase;
021    import org.apache.tapestry.IBeanProvider;
022    import org.apache.tapestry.IComponent;
023    import org.apache.tapestry.coerce.ValueConverter;
024    import org.testng.annotations.Test;
025    
026    /**
027     * @author Howard M. Lewis Ship
028     */
029    @Test
030    public class TestBeanBinding extends BaseComponentTestCase
031    {
032        public void testCreate()
033        {
034            ValueConverter vc = newMock(ValueConverter.class);
035            
036            IComponent component = newComponent();
037            
038            IBeanProvider beanProvider = newMock(IBeanProvider.class);
039    
040            Location l = fabricateLocation(21);
041    
042            Object bean = new Object();
043    
044            expect(component.getBeans()).andReturn(beanProvider);
045    
046            expect(beanProvider.getBean("fred")).andReturn(bean);
047    
048            replay();
049    
050            BeanBinding binding = new BeanBinding("param", vc, l, component, "fred");
051    
052            assertSame(bean, binding.getObject());
053    
054            verify();
055    
056            assertSame(component, binding.getComponent());
057            assertSame(l, binding.getLocation());
058            assertEquals("param", binding.getDescription());
059        }
060    
061    }