1 15 package org.apache.hivemind.service.impl; 16 17 import org.apache.commons.logging.Log; 18 import org.apache.hivemind.ApplicationRuntimeException; 19 import org.apache.hivemind.ErrorLog; 20 import org.apache.hivemind.Location; 21 import org.apache.hivemind.Registry; 22 import org.apache.hivemind.ServiceImplementationFactoryParameters; 23 import org.apache.hivemind.internal.Module; 24 import org.apache.hivemind.test.AggregateArgumentsMatcher; 25 import org.apache.hivemind.test.ArgumentMatcher; 26 import org.apache.hivemind.test.TypeMatcher; 27 import org.apache.hivemind.xml.XmlTestCase; 28 import org.easymock.MockControl; 29 30 36 public class TestBuilderFactory extends XmlTestCase 37 { 38 44 public void testErrorInInitializer() throws Exception 45 { 46 Location l = newLocation(); 47 48 MockControl fpc = newControl(ServiceImplementationFactoryParameters.class); 49 ServiceImplementationFactoryParameters fp = (ServiceImplementationFactoryParameters) fpc 50 .getMock(); 51 52 Log log = (Log) newMock(Log.class); 53 54 MockControl mc = newControl(Module.class); 55 Module module = (Module) mc.getMock(); 56 57 MockControl errorLogc = newControl(ErrorLog.class); 58 ErrorLog errorLog = (ErrorLog) errorLogc.getMock(); 59 60 fp.getLog(); 61 fpc.setReturnValue(log); 62 63 fp.getServiceId(); 64 fpc.setReturnValue("foo.Bar"); 65 66 fp.getInvokingModule(); 67 fpc.setReturnValue(module); 68 69 module.resolveType("org.apache.hivemind.service.impl.InitializerErrorRunnable"); 70 mc.setReturnValue(InitializerErrorRunnable.class); 71 72 fp.getErrorLog(); 73 fpc.setReturnValue(errorLog); 74 75 Throwable cause = new ApplicationRuntimeException("Failure in initializeService()."); 76 77 String message = ServiceMessages.unableToInitializeService( 78 "foo.Bar", 79 "initializeService", 80 InitializerErrorRunnable.class, 81 cause); 82 83 errorLog.error(message, l, new ApplicationRuntimeException("")); 84 errorLogc.setMatcher(new AggregateArgumentsMatcher(new ArgumentMatcher[] 85 { null, null, new TypeMatcher() })); 86 87 BuilderParameter p = new BuilderParameter(); 88 p.setClassName(InitializerErrorRunnable.class.getName()); 89 p.setLocation(l); 90 91 replayControls(); 92 93 BuilderFactoryLogic logic = new BuilderFactoryLogic(fp, p); 94 95 assertNotNull(logic.createService()); 96 97 verifyControls(); 98 } 99 100 public void testListPropertyAutowire() throws Exception 101 { 102 final Registry reg = buildFrameworkRegistry( "ListProperty.xml" ); 103 ListPropertyBean bean = ( ListPropertyBean )reg.getService( ListPropertyBean.class ); 104 assertNull( bean.getList() ); 105 106 } 107 } | Popular Tags |