Java Code Examples for org.springframework.tests.sample.beans.factory.DummyFactory#reset()

The following examples show how to use org.springframework.tests.sample.beans.factory.DummyFactory#reset() . 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: DefaultListableBeanFactoryTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testFactoryBeanDidNotCreatePrototype() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	Properties p = new Properties();
	p.setProperty("x1.(class)", DummyFactory.class.getName());
	// Reset static state
	DummyFactory.reset();
	p.setProperty("x1.singleton", "false");
	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
	(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
	assertEquals(TestBean.class, lbf.getType("x1"));
	lbf.preInstantiateSingletons();

	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
	lbf.getBean("x1");
	assertEquals(TestBean.class, lbf.getType("x1"));
	assertTrue(lbf.containsBean("x1"));
	assertTrue(lbf.containsBean("&x1"));
	assertTrue("prototype was instantiated", DummyFactory.wasPrototypeCreated());
}
 
Example 2
Source File: DefaultListableBeanFactoryTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testFactoryBeanDidNotCreatePrototype() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	Properties p = new Properties();
	p.setProperty("x1.(class)", DummyFactory.class.getName());
	// Reset static state
	DummyFactory.reset();
	p.setProperty("x1.singleton", "false");
	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
	(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
	assertEquals(TestBean.class, lbf.getType("x1"));
	lbf.preInstantiateSingletons();

	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
	lbf.getBean("x1");
	assertEquals(TestBean.class, lbf.getType("x1"));
	assertTrue(lbf.containsBean("x1"));
	assertTrue(lbf.containsBean("&x1"));
	assertTrue("prototype was instantiated", DummyFactory.wasPrototypeCreated());
}
 
Example 3
Source File: DefaultListableBeanFactoryTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testFactoryBeanDidNotCreatePrototype() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	Properties p = new Properties();
	p.setProperty("x1.(class)", DummyFactory.class.getName());
	// Reset static state
	DummyFactory.reset();
	p.setProperty("x1.singleton", "false");
	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
	(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
	assertEquals(TestBean.class, lbf.getType("x1"));
	lbf.preInstantiateSingletons();

	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
	lbf.getBean("x1");
	assertEquals(TestBean.class, lbf.getType("x1"));
	assertTrue(lbf.containsBean("x1"));
	assertTrue(lbf.containsBean("&x1"));
	assertTrue("prototype was instantiated", DummyFactory.wasPrototypeCreated());
}
 
Example 4
Source File: DefaultListableBeanFactoryTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testPrototypeFactoryBeanIgnoredByNonEagerTypeMatching() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	Properties p = new Properties();
	p.setProperty("x1.(class)", DummyFactory.class.getName());
	// Reset static state
	DummyFactory.reset();
	p.setProperty("x1.(singleton)", "false");
	p.setProperty("x1.singleton", "false");
	(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);

	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
	String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
	assertEquals(0, beanNames.length);
	beanNames = lbf.getBeanNamesForAnnotation(SuppressWarnings.class);
	assertEquals(0, beanNames.length);

	assertFalse(lbf.containsSingleton("x1"));
	assertTrue(lbf.containsBean("x1"));
	assertTrue(lbf.containsBean("&x1"));
	assertFalse(lbf.isSingleton("x1"));
	assertFalse(lbf.isSingleton("&x1"));
	assertTrue(lbf.isPrototype("x1"));
	assertTrue(lbf.isPrototype("&x1"));
	assertTrue(lbf.isTypeMatch("x1", TestBean.class));
	assertFalse(lbf.isTypeMatch("&x1", TestBean.class));
	assertTrue(lbf.isTypeMatch("&x1", DummyFactory.class));
	assertTrue(lbf.isTypeMatch("&x1", ResolvableType.forClass(DummyFactory.class)));
	assertTrue(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, Object.class)));
	assertFalse(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, String.class)));
	assertEquals(TestBean.class, lbf.getType("x1"));
	assertEquals(DummyFactory.class, lbf.getType("&x1"));
	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
}
 
Example 5
Source File: DefaultListableBeanFactoryTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testSingletonFactoryBeanIgnoredByNonEagerTypeMatching() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	Properties p = new Properties();
	p.setProperty("x1.(class)", DummyFactory.class.getName());
	// Reset static state
	DummyFactory.reset();
	p.setProperty("x1.(singleton)", "false");
	p.setProperty("x1.singleton", "true");
	(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);

	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
	String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
	assertEquals(0, beanNames.length);
	beanNames = lbf.getBeanNamesForAnnotation(SuppressWarnings.class);
	assertEquals(0, beanNames.length);

	assertFalse(lbf.containsSingleton("x1"));
	assertTrue(lbf.containsBean("x1"));
	assertTrue(lbf.containsBean("&x1"));
	assertFalse(lbf.isSingleton("x1"));
	assertFalse(lbf.isSingleton("&x1"));
	assertTrue(lbf.isPrototype("x1"));
	assertTrue(lbf.isPrototype("&x1"));
	assertTrue(lbf.isTypeMatch("x1", TestBean.class));
	assertFalse(lbf.isTypeMatch("&x1", TestBean.class));
	assertTrue(lbf.isTypeMatch("&x1", DummyFactory.class));
	assertTrue(lbf.isTypeMatch("&x1", ResolvableType.forClass(DummyFactory.class)));
	assertTrue(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, Object.class)));
	assertFalse(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, String.class)));
	assertEquals(TestBean.class, lbf.getType("x1"));
	assertEquals(DummyFactory.class, lbf.getType("&x1"));
	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
}
 
Example 6
Source File: DefaultListableBeanFactoryTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testNonInitializedFactoryBeanIgnoredByNonEagerTypeMatching() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	Properties p = new Properties();
	p.setProperty("x1.(class)", DummyFactory.class.getName());
	// Reset static state
	DummyFactory.reset();
	p.setProperty("x1.singleton", "false");
	(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);

	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
	String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
	assertEquals(0, beanNames.length);
	beanNames = lbf.getBeanNamesForAnnotation(SuppressWarnings.class);
	assertEquals(0, beanNames.length);

	assertFalse(lbf.containsSingleton("x1"));
	assertTrue(lbf.containsBean("x1"));
	assertTrue(lbf.containsBean("&x1"));
	assertFalse(lbf.isSingleton("x1"));
	assertTrue(lbf.isSingleton("&x1"));
	assertTrue(lbf.isPrototype("x1"));
	assertFalse(lbf.isPrototype("&x1"));
	assertTrue(lbf.isTypeMatch("x1", TestBean.class));
	assertFalse(lbf.isTypeMatch("&x1", TestBean.class));
	assertTrue(lbf.isTypeMatch("&x1", DummyFactory.class));
	assertTrue(lbf.isTypeMatch("&x1", ResolvableType.forClass(DummyFactory.class)));
	assertTrue(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, Object.class)));
	assertFalse(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, String.class)));
	assertEquals(TestBean.class, lbf.getType("x1"));
	assertEquals(DummyFactory.class, lbf.getType("&x1"));
	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
}
 
Example 7
Source File: DefaultListableBeanFactoryTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testPrototypeFactoryBeanIgnoredByNonEagerTypeMatching() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	Properties p = new Properties();
	p.setProperty("x1.(class)", DummyFactory.class.getName());
	// Reset static state
	DummyFactory.reset();
	p.setProperty("x1.(singleton)", "false");
	p.setProperty("x1.singleton", "false");
	(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);

	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
	String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
	assertEquals(0, beanNames.length);
	beanNames = lbf.getBeanNamesForAnnotation(SuppressWarnings.class);
	assertEquals(0, beanNames.length);

	assertFalse(lbf.containsSingleton("x1"));
	assertTrue(lbf.containsBean("x1"));
	assertTrue(lbf.containsBean("&x1"));
	assertFalse(lbf.isSingleton("x1"));
	assertFalse(lbf.isSingleton("&x1"));
	assertTrue(lbf.isPrototype("x1"));
	assertTrue(lbf.isPrototype("&x1"));
	assertTrue(lbf.isTypeMatch("x1", TestBean.class));
	assertFalse(lbf.isTypeMatch("&x1", TestBean.class));
	assertTrue(lbf.isTypeMatch("&x1", DummyFactory.class));
	assertTrue(lbf.isTypeMatch("&x1", ResolvableType.forClass(DummyFactory.class)));
	assertTrue(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, Object.class)));
	assertFalse(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, String.class)));
	assertEquals(TestBean.class, lbf.getType("x1"));
	assertEquals(DummyFactory.class, lbf.getType("&x1"));
	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
}
 
Example 8
Source File: DefaultListableBeanFactoryTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testSingletonFactoryBeanIgnoredByNonEagerTypeMatching() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	Properties p = new Properties();
	p.setProperty("x1.(class)", DummyFactory.class.getName());
	// Reset static state
	DummyFactory.reset();
	p.setProperty("x1.(singleton)", "false");
	p.setProperty("x1.singleton", "true");
	(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);

	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
	String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
	assertEquals(0, beanNames.length);
	beanNames = lbf.getBeanNamesForAnnotation(SuppressWarnings.class);
	assertEquals(0, beanNames.length);

	assertFalse(lbf.containsSingleton("x1"));
	assertTrue(lbf.containsBean("x1"));
	assertTrue(lbf.containsBean("&x1"));
	assertFalse(lbf.isSingleton("x1"));
	assertFalse(lbf.isSingleton("&x1"));
	assertTrue(lbf.isPrototype("x1"));
	assertTrue(lbf.isPrototype("&x1"));
	assertTrue(lbf.isTypeMatch("x1", TestBean.class));
	assertFalse(lbf.isTypeMatch("&x1", TestBean.class));
	assertTrue(lbf.isTypeMatch("&x1", DummyFactory.class));
	assertTrue(lbf.isTypeMatch("&x1", ResolvableType.forClass(DummyFactory.class)));
	assertTrue(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, Object.class)));
	assertFalse(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, String.class)));
	assertEquals(TestBean.class, lbf.getType("x1"));
	assertEquals(DummyFactory.class, lbf.getType("&x1"));
	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
}
 
Example 9
Source File: DefaultListableBeanFactoryTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testNonInitializedFactoryBeanIgnoredByNonEagerTypeMatching() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	Properties p = new Properties();
	p.setProperty("x1.(class)", DummyFactory.class.getName());
	// Reset static state
	DummyFactory.reset();
	p.setProperty("x1.singleton", "false");
	(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);

	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
	String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
	assertEquals(0, beanNames.length);
	beanNames = lbf.getBeanNamesForAnnotation(SuppressWarnings.class);
	assertEquals(0, beanNames.length);

	assertFalse(lbf.containsSingleton("x1"));
	assertTrue(lbf.containsBean("x1"));
	assertTrue(lbf.containsBean("&x1"));
	assertFalse(lbf.isSingleton("x1"));
	assertTrue(lbf.isSingleton("&x1"));
	assertTrue(lbf.isPrototype("x1"));
	assertFalse(lbf.isPrototype("&x1"));
	assertTrue(lbf.isTypeMatch("x1", TestBean.class));
	assertFalse(lbf.isTypeMatch("&x1", TestBean.class));
	assertTrue(lbf.isTypeMatch("&x1", DummyFactory.class));
	assertTrue(lbf.isTypeMatch("&x1", ResolvableType.forClass(DummyFactory.class)));
	assertTrue(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, Object.class)));
	assertFalse(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, String.class)));
	assertEquals(TestBean.class, lbf.getType("x1"));
	assertEquals(DummyFactory.class, lbf.getType("&x1"));
	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
}
 
Example 10
Source File: DefaultListableBeanFactoryTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testPrototypeFactoryBeanIgnoredByNonEagerTypeMatching() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	Properties p = new Properties();
	p.setProperty("x1.(class)", DummyFactory.class.getName());
	// Reset static state
	DummyFactory.reset();
	p.setProperty("x1.(singleton)", "false");
	p.setProperty("x1.singleton", "false");
	(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);

	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
	String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
	assertEquals(0, beanNames.length);
	beanNames = lbf.getBeanNamesForAnnotation(SuppressWarnings.class);
	assertEquals(0, beanNames.length);

	assertFalse(lbf.containsSingleton("x1"));
	assertTrue(lbf.containsBean("x1"));
	assertTrue(lbf.containsBean("&x1"));
	assertFalse(lbf.isSingleton("x1"));
	assertFalse(lbf.isSingleton("&x1"));
	assertTrue(lbf.isPrototype("x1"));
	assertTrue(lbf.isPrototype("&x1"));
	assertTrue(lbf.isTypeMatch("x1", TestBean.class));
	assertFalse(lbf.isTypeMatch("&x1", TestBean.class));
	assertTrue(lbf.isTypeMatch("&x1", DummyFactory.class));
	assertTrue(lbf.isTypeMatch("&x1", ResolvableType.forClass(DummyFactory.class)));
	assertTrue(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, Object.class)));
	assertFalse(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, String.class)));
	assertEquals(TestBean.class, lbf.getType("x1"));
	assertEquals(DummyFactory.class, lbf.getType("&x1"));
	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
}
 
Example 11
Source File: DefaultListableBeanFactoryTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testSingletonFactoryBeanIgnoredByNonEagerTypeMatching() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	Properties p = new Properties();
	p.setProperty("x1.(class)", DummyFactory.class.getName());
	// Reset static state
	DummyFactory.reset();
	p.setProperty("x1.(singleton)", "false");
	p.setProperty("x1.singleton", "true");
	(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);

	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
	String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
	assertEquals(0, beanNames.length);
	beanNames = lbf.getBeanNamesForAnnotation(SuppressWarnings.class);
	assertEquals(0, beanNames.length);

	assertFalse(lbf.containsSingleton("x1"));
	assertTrue(lbf.containsBean("x1"));
	assertTrue(lbf.containsBean("&x1"));
	assertFalse(lbf.isSingleton("x1"));
	assertFalse(lbf.isSingleton("&x1"));
	assertTrue(lbf.isPrototype("x1"));
	assertTrue(lbf.isPrototype("&x1"));
	assertTrue(lbf.isTypeMatch("x1", TestBean.class));
	assertFalse(lbf.isTypeMatch("&x1", TestBean.class));
	assertTrue(lbf.isTypeMatch("&x1", DummyFactory.class));
	assertTrue(lbf.isTypeMatch("&x1", ResolvableType.forClass(DummyFactory.class)));
	assertTrue(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, Object.class)));
	assertFalse(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, String.class)));
	assertEquals(TestBean.class, lbf.getType("x1"));
	assertEquals(DummyFactory.class, lbf.getType("&x1"));
	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
}
 
Example 12
Source File: DefaultListableBeanFactoryTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testNonInitializedFactoryBeanIgnoredByNonEagerTypeMatching() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	Properties p = new Properties();
	p.setProperty("x1.(class)", DummyFactory.class.getName());
	// Reset static state
	DummyFactory.reset();
	p.setProperty("x1.singleton", "false");
	(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);

	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
	String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
	assertEquals(0, beanNames.length);
	beanNames = lbf.getBeanNamesForAnnotation(SuppressWarnings.class);
	assertEquals(0, beanNames.length);

	assertFalse(lbf.containsSingleton("x1"));
	assertTrue(lbf.containsBean("x1"));
	assertTrue(lbf.containsBean("&x1"));
	assertFalse(lbf.isSingleton("x1"));
	assertTrue(lbf.isSingleton("&x1"));
	assertTrue(lbf.isPrototype("x1"));
	assertFalse(lbf.isPrototype("&x1"));
	assertTrue(lbf.isTypeMatch("x1", TestBean.class));
	assertFalse(lbf.isTypeMatch("&x1", TestBean.class));
	assertTrue(lbf.isTypeMatch("&x1", DummyFactory.class));
	assertTrue(lbf.isTypeMatch("&x1", ResolvableType.forClass(DummyFactory.class)));
	assertTrue(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, Object.class)));
	assertFalse(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, String.class)));
	assertEquals(TestBean.class, lbf.getType("x1"));
	assertEquals(DummyFactory.class, lbf.getType("&x1"));
	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
}
 
Example 13
Source File: DefaultListableBeanFactoryTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Test
public void testInitializedFactoryBeanFoundByNonEagerTypeMatching() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	Properties p = new Properties();
	p.setProperty("x1.(class)", DummyFactory.class.getName());
	// Reset static state
	DummyFactory.reset();
	p.setProperty("x1.singleton", "false");
	(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
	lbf.preInstantiateSingletons();

	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
	String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
	assertEquals(1, beanNames.length);
	assertEquals("x1", beanNames[0]);
	assertTrue(lbf.containsSingleton("x1"));
	assertTrue(lbf.containsBean("x1"));
	assertTrue(lbf.containsBean("&x1"));
	assertTrue(lbf.containsLocalBean("x1"));
	assertTrue(lbf.containsLocalBean("&x1"));
	assertFalse(lbf.isSingleton("x1"));
	assertTrue(lbf.isSingleton("&x1"));
	assertTrue(lbf.isPrototype("x1"));
	assertFalse(lbf.isPrototype("&x1"));
	assertTrue(lbf.isTypeMatch("x1", TestBean.class));
	assertFalse(lbf.isTypeMatch("&x1", TestBean.class));
	assertTrue(lbf.isTypeMatch("&x1", DummyFactory.class));
	assertTrue(lbf.isTypeMatch("x1", Object.class));
	assertTrue(lbf.isTypeMatch("&x1", Object.class));
	assertEquals(TestBean.class, lbf.getType("x1"));
	assertEquals(DummyFactory.class, lbf.getType("&x1"));
	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());

	lbf.registerAlias("x1", "x2");
	assertTrue(lbf.containsBean("x2"));
	assertTrue(lbf.containsBean("&x2"));
	assertTrue(lbf.containsLocalBean("x2"));
	assertTrue(lbf.containsLocalBean("&x2"));
	assertFalse(lbf.isSingleton("x2"));
	assertTrue(lbf.isSingleton("&x2"));
	assertTrue(lbf.isPrototype("x2"));
	assertFalse(lbf.isPrototype("&x2"));
	assertTrue(lbf.isTypeMatch("x2", TestBean.class));
	assertFalse(lbf.isTypeMatch("&x2", TestBean.class));
	assertTrue(lbf.isTypeMatch("&x2", DummyFactory.class));
	assertTrue(lbf.isTypeMatch("x2", Object.class));
	assertTrue(lbf.isTypeMatch("&x2", Object.class));
	assertEquals(TestBean.class, lbf.getType("x2"));
	assertEquals(DummyFactory.class, lbf.getType("&x2"));
	assertEquals(1, lbf.getAliases("x1").length);
	assertEquals("x2", lbf.getAliases("x1")[0]);
	assertEquals(1, lbf.getAliases("&x1").length);
	assertEquals("&x2", lbf.getAliases("&x1")[0]);
	assertEquals(1, lbf.getAliases("x2").length);
	assertEquals("x1", lbf.getAliases("x2")[0]);
	assertEquals(1, lbf.getAliases("&x2").length);
	assertEquals("&x1", lbf.getAliases("&x2")[0]);
}
 
Example 14
Source File: DefaultListableBeanFactoryTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Test
public void testInitializedFactoryBeanFoundByNonEagerTypeMatching() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	Properties p = new Properties();
	p.setProperty("x1.(class)", DummyFactory.class.getName());
	// Reset static state
	DummyFactory.reset();
	p.setProperty("x1.singleton", "false");
	(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
	lbf.preInstantiateSingletons();

	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
	String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
	assertEquals(1, beanNames.length);
	assertEquals("x1", beanNames[0]);
	assertTrue(lbf.containsSingleton("x1"));
	assertTrue(lbf.containsBean("x1"));
	assertTrue(lbf.containsBean("&x1"));
	assertTrue(lbf.containsLocalBean("x1"));
	assertTrue(lbf.containsLocalBean("&x1"));
	assertFalse(lbf.isSingleton("x1"));
	assertTrue(lbf.isSingleton("&x1"));
	assertTrue(lbf.isPrototype("x1"));
	assertFalse(lbf.isPrototype("&x1"));
	assertTrue(lbf.isTypeMatch("x1", TestBean.class));
	assertFalse(lbf.isTypeMatch("&x1", TestBean.class));
	assertTrue(lbf.isTypeMatch("&x1", DummyFactory.class));
	assertTrue(lbf.isTypeMatch("x1", Object.class));
	assertTrue(lbf.isTypeMatch("&x1", Object.class));
	assertEquals(TestBean.class, lbf.getType("x1"));
	assertEquals(DummyFactory.class, lbf.getType("&x1"));
	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());

	lbf.registerAlias("x1", "x2");
	assertTrue(lbf.containsBean("x2"));
	assertTrue(lbf.containsBean("&x2"));
	assertTrue(lbf.containsLocalBean("x2"));
	assertTrue(lbf.containsLocalBean("&x2"));
	assertFalse(lbf.isSingleton("x2"));
	assertTrue(lbf.isSingleton("&x2"));
	assertTrue(lbf.isPrototype("x2"));
	assertFalse(lbf.isPrototype("&x2"));
	assertTrue(lbf.isTypeMatch("x2", TestBean.class));
	assertFalse(lbf.isTypeMatch("&x2", TestBean.class));
	assertTrue(lbf.isTypeMatch("&x2", DummyFactory.class));
	assertTrue(lbf.isTypeMatch("x2", Object.class));
	assertTrue(lbf.isTypeMatch("&x2", Object.class));
	assertEquals(TestBean.class, lbf.getType("x2"));
	assertEquals(DummyFactory.class, lbf.getType("&x2"));
	assertEquals(1, lbf.getAliases("x1").length);
	assertEquals("x2", lbf.getAliases("x1")[0]);
	assertEquals(1, lbf.getAliases("&x1").length);
	assertEquals("&x2", lbf.getAliases("&x1")[0]);
	assertEquals(1, lbf.getAliases("x2").length);
	assertEquals("x1", lbf.getAliases("x2")[0]);
	assertEquals(1, lbf.getAliases("&x2").length);
	assertEquals("&x1", lbf.getAliases("&x2")[0]);
}
 
Example 15
Source File: DefaultListableBeanFactoryTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test
public void testInitializedFactoryBeanFoundByNonEagerTypeMatching() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	Properties p = new Properties();
	p.setProperty("x1.(class)", DummyFactory.class.getName());
	// Reset static state
	DummyFactory.reset();
	p.setProperty("x1.singleton", "false");
	(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
	lbf.preInstantiateSingletons();

	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
	String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
	assertEquals(1, beanNames.length);
	assertEquals("x1", beanNames[0]);
	assertTrue(lbf.containsSingleton("x1"));
	assertTrue(lbf.containsBean("x1"));
	assertTrue(lbf.containsBean("&x1"));
	assertTrue(lbf.containsLocalBean("x1"));
	assertTrue(lbf.containsLocalBean("&x1"));
	assertFalse(lbf.isSingleton("x1"));
	assertTrue(lbf.isSingleton("&x1"));
	assertTrue(lbf.isPrototype("x1"));
	assertFalse(lbf.isPrototype("&x1"));
	assertTrue(lbf.isTypeMatch("x1", TestBean.class));
	assertFalse(lbf.isTypeMatch("&x1", TestBean.class));
	assertTrue(lbf.isTypeMatch("&x1", DummyFactory.class));
	assertTrue(lbf.isTypeMatch("x1", Object.class));
	assertTrue(lbf.isTypeMatch("&x1", Object.class));
	assertEquals(TestBean.class, lbf.getType("x1"));
	assertEquals(DummyFactory.class, lbf.getType("&x1"));
	assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());

	lbf.registerAlias("x1", "x2");
	assertTrue(lbf.containsBean("x2"));
	assertTrue(lbf.containsBean("&x2"));
	assertTrue(lbf.containsLocalBean("x2"));
	assertTrue(lbf.containsLocalBean("&x2"));
	assertFalse(lbf.isSingleton("x2"));
	assertTrue(lbf.isSingleton("&x2"));
	assertTrue(lbf.isPrototype("x2"));
	assertFalse(lbf.isPrototype("&x2"));
	assertTrue(lbf.isTypeMatch("x2", TestBean.class));
	assertFalse(lbf.isTypeMatch("&x2", TestBean.class));
	assertTrue(lbf.isTypeMatch("&x2", DummyFactory.class));
	assertTrue(lbf.isTypeMatch("x2", Object.class));
	assertTrue(lbf.isTypeMatch("&x2", Object.class));
	assertEquals(TestBean.class, lbf.getType("x2"));
	assertEquals(DummyFactory.class, lbf.getType("&x2"));
	assertEquals(1, lbf.getAliases("x1").length);
	assertEquals("x2", lbf.getAliases("x1")[0]);
	assertEquals(1, lbf.getAliases("&x1").length);
	assertEquals("&x2", lbf.getAliases("&x1")[0]);
	assertEquals(1, lbf.getAliases("x2").length);
	assertEquals("x1", lbf.getAliases("x2")[0]);
	assertEquals(1, lbf.getAliases("&x2").length);
	assertEquals("&x1", lbf.getAliases("&x2")[0]);
}