1 15 package org.apache.hivemind.lib.factory; 16 17 import org.apache.hivemind.ApplicationRuntimeException; 18 import org.apache.hivemind.Location; 19 import org.apache.hivemind.internal.Module; 20 import org.apache.hivemind.lib.BeanFactory; 21 import org.apache.hivemind.service.ObjectProvider; 22 import org.apache.hivemind.test.HiveMindTestCase; 23 import org.easymock.MockControl; 24 25 30 public class TestBeanFactoryObjectProvider extends HiveMindTestCase 31 { 32 public void testNullInput() 33 { 34 ObjectProvider op = new BeanFactoryObjectProvider(); 35 36 assertNull(op.provideObject(null, null, null, null)); 37 } 38 39 public void testNoServiceId() 40 { 41 ObjectProvider op = new BeanFactoryObjectProvider(); 42 Location l = newLocation(); 43 44 try 45 { 46 op.provideObject(null, null, "foo", l); 47 unreachable(); 48 } 49 catch (ApplicationRuntimeException ex) 50 { 51 assertEquals( 52 "'foo' is not formatted correctly, it should be 'service-id:name[,initializer]'.", 53 ex.getMessage()); 54 55 assertSame(l, ex.getLocation()); 56 } 57 } 58 59 public void testNoLocator() 60 { 61 ObjectProvider op = new BeanFactoryObjectProvider(); 62 Location l = newLocation(); 63 64 try 65 { 66 op.provideObject(null, null, "foo:", l); 67 unreachable(); 68 } 69 catch (ApplicationRuntimeException ex) 70 { 71 assertEquals( 72 "'foo:' is not formatted correctly, it should be 'service-id:name[,initializer]'.", 73 ex.getMessage()); 74 assertSame(l, ex.getLocation()); 75 } 76 } 77 78 public void testSuccess() 79 { 80 String result = "Obtained via BeanFactory."; 81 82 MockControl factoryControl = newControl(BeanFactory.class); 83 BeanFactory factory = (BeanFactory) factoryControl.getMock(); 84 85 MockControl moduleControl = newControl(Module.class); 86 Module module = (Module) moduleControl.getMock(); 87 88 module.getService("factory", BeanFactory.class); 89 moduleControl.setReturnValue(factory); 90 91 factory.get("my-bean,initialized"); 92 factoryControl.setReturnValue(result); 93 94 replayControls(); 95 96 ObjectProvider op = new BeanFactoryObjectProvider(); 97 98 assertSame(result, op.provideObject(module, null, "factory:my-bean,initialized", null)); 99 100 verifyControls(); 101 } 102 } 103 | Popular Tags |