public void testGetServiceByExportTypes() throws Exception {
classes = new Class[]{String.class};
final StringFactoryBean factoryBean = new StringFactoryBean();
factoryBean.setValue("some service");
registryaddService("bean1", "module1", factoryBean, classLoader);
try {
registry.getService(null, classes, false);
fail();
}
catch (IllegalArgumentException e) {
assertEquals("Either bean name must be not null, or export types must be non-empty", e.getMessage());
}
try {
registry.getService(null, new Class[0], false);
fail();
}
catch (IllegalArgumentException e) {
assertEquals("Either bean name must be not null, or export types must be non-empty", e.getMessage());
}
try {
registry.getServices((String)null, classes, false);
fail();
}
catch (IllegalArgumentException e) {
assertEquals("Either bean name must be not null, or export types must be non-empty", e.getMessage());
}
try {
registry.getServices((String)null, new Class[0], false);
fail();
}
catch (IllegalArgumentException e) {
assertEquals("Either bean name must be not null, or export types must be non-empty", e.getMessage());
}
//not registered under any export types
assertNull(registry.getService("bean1", classes, true));
assertNull(registry.getService(null, classes, true));
assertTrue(registry.getServices("bean1", classes, true).isEmpty());
assertTrue(registry.getServices((String)null, classes, true).isEmpty());
//now register bean with export types
List<Class<?>> list = Collections.<Class<?>>singletonList(String.class);
registryaddService(null, "module1", factoryBean.getObject(), list, null, classLoader);
assertNotNull(registry.getService(null, classes, true));
assertNull(registry.getService("bean1", classes, true));
assertFalse(registry.getServices((String)null, classes, true).isEmpty());
assertTrue(registry.getServices("bean1", classes, true).isEmpty());
registryaddService("bean2", "module1", factoryBean.getObject(), list, null, classLoader);
assertNotNull(registry.getService("bean2", classes, true));
assertFalse(registry.getServices("bean2", classes, true).isEmpty());
}