SpringServiceManager implements ServiceManagerSystem { @Override public void registerService(String name, Object service) { if (name == null || service == null) { throw new IllegalArgumentException("name and service must not be null for service registration"); } try { applicationContext.getBeanFactory().autowireBean(service); } catch (BeansException e) { throw new IllegalArgumentException("Invalid service ("+service+") with name ("+name+") registration: " + e.getMessage(), e); } registerBean(name, 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 testRegisterService() { ssm.startup(); String name = "myNewService"; ssm.registerService(name, "AZ"); String service = ssm.getServiceByName(name, String.class); assertNotNull(service); assertEquals("AZ", service); try { ssm.registerService("fakey", (Object)null); fail("should have thrown exception"); } catch (IllegalArgumentException e) { assertNotNull(e.getMessage()); } }