SpringServiceManager implements ServiceManagerSystem { @SuppressWarnings("unchecked") @Override public <T> T registerServiceClass(String name, Class<T> type) { if (name == null || type == null) { throw new IllegalArgumentException("name and type must not be null for service registration"); } T service; try { service = (T) applicationContext.getBeanFactory().autowire(type, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true); registerBean(name, service); } catch (BeansException e) { throw new IllegalArgumentException("Invalid service class ("+type+") with name ("+name+") registration: " + e.getMessage(), e); } return service; } SpringServiceManager(ServiceManagerSystem parent, DSpaceConfigurationService configurationService, boolean testMode, boolean developmentMode, String... configPaths); ClassPathXmlApplicationContext getApplicationContext(); ListableBeanFactory getBeanFactory(); @SuppressWarnings("unchecked") @Override T getServiceByName(String name, Class<T> type); @SuppressWarnings("unchecked") @Override List<T> getServicesByType(Class<T> type); @Override void shutdown(); @Override void startup(); @SuppressWarnings("unchecked") @Override T registerServiceClass(String name, Class<T> type); @Override void registerService(String name, Object service); @Override void registerServiceNoAutowire(String name, Object service); @Override void unregisterService(String name); @Override List<String> getServicesNames(); @Override boolean isServiceExists(String name); @Override Map<String, Object> getServices(); @Override void pushConfig(Map<String, Object> settings); static final String configPath; static final String coreResourcePath; static final String addonResourcePath; }
@Test public void testRegisterServiceClass() { ssm.startup(); SampleAnnotationBean sab = ssm.registerServiceClass("newAnnote", SampleAnnotationBean.class); assertNotNull(sab); sab = null; List<SampleAnnotationBean> l = ssm.getServicesByType(SampleAnnotationBean.class); assertNotNull(l); assertEquals(2, l.size()); l = null; try { ssm.registerService("fakey", (Class<?>)null); fail("should have thrown exception"); } catch (IllegalArgumentException e) { assertNotNull(e.getMessage()); } }