001 // Copyright 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.IBinding; 021 import org.apache.tapestry.coerce.ValueConverter; 022 import org.apache.tapestry.services.InjectedValueProvider; 023 import org.testng.annotations.Test; 024 025 /** 026 * Tests for {@link org.apache.tapestry.binding.HiveMindBinding}and 027 * {@link org.apache.tapestry.binding.HiveMindBindingFactory}. 028 * 029 * @author Howard M. Lewis Ship 030 * @since 4.0 031 */ 032 @Test 033 public class TestHiveMindBinding extends BindingTestCase 034 { 035 private IBinding newBinding(ValueConverter converter, InjectedValueProvider provider, 036 String objectReference, Location location) 037 { 038 HiveMindBindingFactory factory = new HiveMindBindingFactory(); 039 040 factory.setValueConverter(converter); 041 factory.setInjectedValueProvider(provider); 042 043 return factory.createBinding(null, "binding description", objectReference, location); 044 } 045 046 public void testSuccess() 047 { 048 Object injectedValue = new Object(); 049 Location l = fabricateLocation(12); 050 051 InjectedValueProvider provider = newMock(InjectedValueProvider.class); 052 053 expect(provider.obtainValue("spring:bean", l)).andReturn(injectedValue); 054 055 ValueConverter converter = newValueConverter(); 056 057 replay(); 058 059 IBinding binding = newBinding(converter, provider, "spring:bean", l); 060 061 assertSame(injectedValue, binding.getObject()); 062 063 verify(); 064 } 065 }