1 15 package hivemind.test.lib; 16 17 import org.apache.hivemind.Registry; 18 import org.apache.hivemind.lib.SpringBeanFactoryHolder; 19 import org.apache.hivemind.lib.impl.SpringObjectProvider; 20 import org.apache.hivemind.xml.XmlTestCase; 21 import org.easymock.MockControl; 22 import org.springframework.beans.factory.BeanFactory; 23 import org.springframework.beans.factory.xml.XmlBeanFactory; 24 import org.springframework.core.io.ClassPathResource; 25 26 30 public class TestSpringObjectProvider extends XmlTestCase 31 { 32 public void testBasic() 33 { 34 Object bean = new Object (); 35 MockControl control = newControl(BeanFactory.class); 36 BeanFactory bf = (BeanFactory) control.getMock(); 37 38 bf.getBean("fred"); 39 control.setReturnValue(bean); 40 41 replayControls(); 42 43 SpringObjectProvider p = new SpringObjectProvider(); 44 p.setBeanFactory(bf); 45 46 Object result = p.provideObject(null, null, "fred", null); 47 48 assertSame(bean, result); 49 50 verifyControls(); 51 } 52 53 public void testSpringIntegration() throws Exception 54 { 55 57 ClassPathResource springBeansResource = new ClassPathResource("SpringBeans.xml", 58 TestSpringLookupFactory.class); 59 60 BeanFactory beanFactory = new XmlBeanFactory(springBeansResource); 61 62 Registry r = buildFrameworkRegistry("SpringProvider.xml"); 63 64 SpringBeanFactoryHolder h = (SpringBeanFactoryHolder) r.getService( 65 "hivemind.lib.DefaultSpringBeanFactoryHolder", 66 SpringBeanFactoryHolder.class); 67 68 h.setBeanFactory(beanFactory); 69 70 SimpleService a = (SimpleService) r.getService( 71 "hivemind.test.lib.Adder", 72 SimpleService.class); 73 74 assertEquals(17, a.add(9, 8)); 75 } 76 } | Popular Tags |