Java Code Examples for org.springframework.beans.factory.support.StaticListableBeanFactory#addBean()

The following examples show how to use org.springframework.beans.factory.support.StaticListableBeanFactory#addBean() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModuleServiceBaseTest.java    From rice with Educational Community License v2.0 6 votes vote down vote up
@Before
public void initGRL() throws Exception {
    GlobalResourceLoader.stop();
    SimpleConfig config = new SimpleConfig();
    config.putProperty(CoreConstants.Config.APPLICATION_ID, "APPID");
    ConfigContext.init(config);

    StaticListableBeanFactory testBf = new StaticListableBeanFactory();
    when(kualiModuleService.getInstalledModuleServices()).thenReturn(installedModuleServices);

    testBf.addBean(KRADServiceLocator.PROVIDER_REGISTRY, mock(ProviderRegistry.class));
    testBf.addBean(KRADServiceLocatorWeb.KUALI_MODULE_SERVICE, kualiModuleService);

    ResourceLoader rl = new BeanFactoryResourceLoader(new QName("moduleservicebase-unittest"), testBf);
    GlobalResourceLoader.addResourceLoader(rl);
    GlobalResourceLoader.start();
}
 
Example 2
Source File: KualiModuleServiceImplTest.java    From rice with Educational Community License v2.0 6 votes vote down vote up
@Before
public void installRiceKualiModuleService() throws Exception {
    GlobalResourceLoader.stop();
    SimpleConfig config = new SimpleConfig();
    config.putProperty(CoreConstants.Config.APPLICATION_ID, "APPID");
    ConfigContext.init(config);

    StaticListableBeanFactory testBf = new StaticListableBeanFactory();

    KualiModuleService riceKualiModuleService = mock(KualiModuleService.class);
    when(riceKualiModuleService.getInstalledModuleServices()).thenReturn(riceModuleServices);

    testBf.addBean(KRADServiceLocatorWeb.KUALI_MODULE_SERVICE, riceKualiModuleService);

    ResourceLoader rl = new BeanFactoryResourceLoader(new QName("moduleservicebase-unittest"), testBf);
    GlobalResourceLoader.addResourceLoader(rl);
    GlobalResourceLoader.start();
}
 
Example 3
Source File: BeanFactoryUtilsTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testHierarchicalCountBeansWithNonHierarchicalFactory() {
	StaticListableBeanFactory lbf = new StaticListableBeanFactory();
	lbf.addBean("t1", new TestBean());
	lbf.addBean("t2", new TestBean());
	assertTrue(BeanFactoryUtils.countBeansIncludingAncestors(lbf) == 2);
}
 
Example 4
Source File: BeanFactoryUtilsTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testNoBeansOfType() {
	StaticListableBeanFactory lbf = new StaticListableBeanFactory();
	lbf.addBean("foo", new Object());
	Map<String, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, false);
	assertTrue(beans.isEmpty());
}
 
Example 5
Source File: BeanFactoryUtilsTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testFindsBeansOfTypeWithStaticFactory() {
	StaticListableBeanFactory lbf = new StaticListableBeanFactory();
	TestBean t1 = new TestBean();
	TestBean t2 = new TestBean();
	DummyFactory t3 = new DummyFactory();
	DummyFactory t4 = new DummyFactory();
	t4.setSingleton(false);
	lbf.addBean("t1", t1);
	lbf.addBean("t2", t2);
	lbf.addBean("t3", t3);
	lbf.addBean("t4", t4);

	Map<String, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, true);
	assertEquals(4, beans.size());
	assertEquals(t1, beans.get("t1"));
	assertEquals(t2, beans.get("t2"));
	assertEquals(t3.getObject(), beans.get("t3"));
	assertTrue(beans.get("t4") instanceof TestBean);

	beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, DummyFactory.class, true, true);
	assertEquals(2, beans.size());
	assertEquals(t3, beans.get("&t3"));
	assertEquals(t4, beans.get("&t4"));

	beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, FactoryBean.class, true, true);
	assertEquals(2, beans.size());
	assertEquals(t3, beans.get("&t3"));
	assertEquals(t4, beans.get("&t4"));
}
 
Example 6
Source File: BeanFactoryUtilsTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testHierarchicalCountBeansWithNonHierarchicalFactory() {
	StaticListableBeanFactory lbf = new StaticListableBeanFactory();
	lbf.addBean("t1", new TestBean());
	lbf.addBean("t2", new TestBean());
	assertTrue(BeanFactoryUtils.countBeansIncludingAncestors(lbf) == 2);
}
 
Example 7
Source File: BeanFactoryUtilsTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testNoBeansOfType() {
	StaticListableBeanFactory lbf = new StaticListableBeanFactory();
	lbf.addBean("foo", new Object());
	Map<String, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, false);
	assertTrue(beans.isEmpty());
}
 
Example 8
Source File: BeanFactoryUtilsTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testFindsBeansOfTypeWithStaticFactory() {
	StaticListableBeanFactory lbf = new StaticListableBeanFactory();
	TestBean t1 = new TestBean();
	TestBean t2 = new TestBean();
	DummyFactory t3 = new DummyFactory();
	DummyFactory t4 = new DummyFactory();
	t4.setSingleton(false);
	lbf.addBean("t1", t1);
	lbf.addBean("t2", t2);
	lbf.addBean("t3", t3);
	lbf.addBean("t4", t4);

	Map<String, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, true);
	assertEquals(4, beans.size());
	assertEquals(t1, beans.get("t1"));
	assertEquals(t2, beans.get("t2"));
	assertEquals(t3.getObject(), beans.get("t3"));
	assertTrue(beans.get("t4") instanceof TestBean);

	beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, DummyFactory.class, true, true);
	assertEquals(2, beans.size());
	assertEquals(t3, beans.get("&t3"));
	assertEquals(t4, beans.get("&t4"));

	beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, FactoryBean.class, true, true);
	assertEquals(2, beans.size());
	assertEquals(t3, beans.get("&t3"));
	assertEquals(t4, beans.get("&t4"));
}
 
Example 9
Source File: BeanFactoryUtilsTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testHierarchicalCountBeansWithNonHierarchicalFactory() {
	StaticListableBeanFactory lbf = new StaticListableBeanFactory();
	lbf.addBean("t1", new TestBean());
	lbf.addBean("t2", new TestBean());
	assertTrue(BeanFactoryUtils.countBeansIncludingAncestors(lbf) == 2);
}
 
Example 10
Source File: BeanFactoryUtilsTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoBeansOfType() {
	StaticListableBeanFactory lbf = new StaticListableBeanFactory();
	lbf.addBean("foo", new Object());
	Map<String, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, false);
	assertTrue(beans.isEmpty());
}
 
Example 11
Source File: BeanFactoryUtilsTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testFindsBeansOfTypeWithStaticFactory() {
	StaticListableBeanFactory lbf = new StaticListableBeanFactory();
	TestBean t1 = new TestBean();
	TestBean t2 = new TestBean();
	DummyFactory t3 = new DummyFactory();
	DummyFactory t4 = new DummyFactory();
	t4.setSingleton(false);
	lbf.addBean("t1", t1);
	lbf.addBean("t2", t2);
	lbf.addBean("t3", t3);
	lbf.addBean("t4", t4);

	Map<String, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, true);
	assertEquals(4, beans.size());
	assertEquals(t1, beans.get("t1"));
	assertEquals(t2, beans.get("t2"));
	assertEquals(t3.getObject(), beans.get("t3"));
	assertTrue(beans.get("t4") instanceof TestBean);

	beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, DummyFactory.class, true, true);
	assertEquals(2, beans.size());
	assertEquals(t3, beans.get("&t3"));
	assertEquals(t4, beans.get("&t4"));

	beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, FactoryBean.class, true, true);
	assertEquals(2, beans.size());
	assertEquals(t3, beans.get("&t3"));
	assertEquals(t4, beans.get("&t4"));
}
 
Example 12
Source File: ModuleConfigurationTest.java    From rice with Educational Community License v2.0 5 votes vote down vote up
@Before
public void initGRL() throws Exception {
    GlobalResourceLoader.stop();
    SimpleConfig config = new SimpleConfig();
    config.putProperty(CoreConstants.Config.APPLICATION_ID, "APPID");
    ConfigContext.init(config);
    StaticListableBeanFactory testBf = new StaticListableBeanFactory();
    testBf.addBean(KRADServiceLocator.PROVIDER_REGISTRY, prMock);
    ResourceLoader rl = new BeanFactoryResourceLoader(new QName("moduleconfiguration-unittest"), testBf);
    GlobalResourceLoader.addResourceLoader(rl);
    GlobalResourceLoader.start();
}
 
Example 13
Source File: LegacyDataAdapterImplTest.java    From rice with Educational Community License v2.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
    GlobalResourceLoader.stop();

    SimpleConfig config = new SimpleConfig();
    config.putProperty(CoreConstants.Config.APPLICATION_ID, getClass().getName());
    ConfigContext.init(config);
    ConfigContext.getCurrentContextConfig().removeProperty(KRADConstants.Config.ENABLE_LEGACY_DATA_FRAMEWORK);
    ConfigContext.getCurrentContextConfig().removeProperty(KRADConstants.Config.KNS_ENABLED);

    StaticListableBeanFactory testBf = new StaticListableBeanFactory();
    testBf.addBean("metadataRepository", metadataRepository);
    testBf.addBean("dataDictionaryService", dataDictionaryService);
    testBf.addBean("knsLegacyDataAdapter", knsLegacyDataAdapter);
    testBf.addBean("kradLegacyDataAdapter", kradLegacyDataAdapter);

    ResourceLoader rl = new BeanFactoryResourceLoader(new QName(getClass().getName()), testBf);
    GlobalResourceLoader.addResourceLoader(rl);
    GlobalResourceLoader.start();

    MetadataManager mm = MetadataManager.getInstance();

    // register Legacy object
    ClassDescriptor legacyDescriptor = new ClassDescriptor(mm.getGlobalRepository());
    legacyDescriptor.setClassOfObject(Legacy.class);
    mm.getGlobalRepository().put(Legacy.class, legacyDescriptor);

    // register LegacyDocument object
    ClassDescriptor legacyDocumentDescriptor = new ClassDescriptor(mm.getGlobalRepository());
    legacyDocumentDescriptor.setClassOfObject(LegacyDocument.class);
    mm.getGlobalRepository().put(LegacyDocument.class, legacyDocumentDescriptor);
}
 
Example 14
Source File: BeanFactoryInvocationHandlerTest.java    From rice with Educational Community License v2.0 5 votes vote down vote up
@Before
public void createBadInstance() {
    StaticListableBeanFactory bf = new StaticListableBeanFactory();
    bf.addBean("bean", "This is a bean");
    bad = (BadInterface)
            Proxy.newProxyInstance(this.getClass().getClassLoader(),
                    new Class[]{BadInterface.class},
                    new BeanFactoryInvocationHandler(bf));
}