* Test method for
* 'org.groovymud.object.registry.MudObjectAttendant.load(String, boolean)'
*/
public void testLoadAsBean() throws ResourceException, ScriptException, InstantiationException, IllegalAccessException, CompilationFailedException, FileNotFoundException, MalformedURLException {
final String scriptName = "/mockScriptName.groovy";
final MudObject mudObject = (MudObject) ctrl.getMock();
MockControl ctxCtrl = MockControl.createControl(ApplicationContext.class);
final ApplicationContext mockApplicationContext = (ApplicationContext) ctxCtrl.getMock();
mockApplicationContext.containsBean("beanId");
ctxCtrl.setReturnValue(false);
mockApplicationContext.getBean("beanId");
ctxCtrl.setDefaultReturnValue(mudObject);
mockApplicationContext.containsBean("beanId");
ctxCtrl.setReturnValue(true);
ctxCtrl.replay();
MockControl regCtrl = MockClassControl.createControl(Registry.class);
final Registry reg = (Registry) regCtrl.getMock();
reg.getMudObject("beanId");
regCtrl.setDefaultReturnValue(null);
regCtrl.replay();
MudObjectAttendant attnd = new MudObjectAttendant() {
@Override
protected void loadDefinition(String scriptLocation) {
assertEquals(scriptName, scriptLocation);
}
@Override
public ApplicationContext getApplicationContext() {
// TODO Auto-generated method stub
return mockApplicationContext;
}
@Override
public Registry getObjectRegistry() {
// TODO Auto-generated method stub
return reg;
}
};
ObjectLocation location = new ObjectLocation();
location.setDefinition(scriptName);
location.setBeanId("beanId");
MudObject myObj = attnd.load(location);
assertEquals(mudObject.getClass(), myObj.getClass());
ctxCtrl.verify();
regCtrl.verify();
}