org.springframework.tests.sample.beans.CountingTestBean Java Examples

The following examples show how to use org.springframework.tests.sample.beans.CountingTestBean. 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: TypePatternClassFilterTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testSubclassMatching() {
	TypePatternClassFilter tpcf = new TypePatternClassFilter("org.springframework.tests.sample.beans.ITestBean+");
	assertTrue("Must match: in package", tpcf.matches(TestBean.class));
	assertTrue("Must match: in package", tpcf.matches(ITestBean.class));
	assertTrue("Must match: in package", tpcf.matches(CountingTestBean.class));
	assertFalse("Must be excluded: not subclass", tpcf.matches(IOther.class));
	assertFalse("Must be excluded: not subclass", tpcf.matches(DefaultListableBeanFactory.class));
}
 
Example #2
Source File: AdvisorAutoProxyCreatorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testCustomPrototypeTargetSource() throws Exception {
	CountingTestBean.count = 0;
	BeanFactory bf = new ClassPathXmlApplicationContext(CUSTOM_TARGETSOURCE_CONTEXT, CLASS);
	ITestBean test = (ITestBean) bf.getBean("prototypeTest");
	assertTrue(AopUtils.isAopProxy(test));
	Advised advised = (Advised) test;
	assertTrue(advised.getTargetSource() instanceof PrototypeTargetSource);
	assertEquals("Rod", test.getName());
	// Check that references survived prototype creation
	assertEquals("Kerry", test.getSpouse().getName());
	assertEquals("Only 2 CountingTestBeans instantiated", 2, CountingTestBean.count);
	CountingTestBean.count = 0;
}
 
Example #3
Source File: AdvisorAutoProxyCreatorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testLazyInitTargetSource() throws Exception {
	CountingTestBean.count = 0;
	BeanFactory bf = new ClassPathXmlApplicationContext(CUSTOM_TARGETSOURCE_CONTEXT, CLASS);
	ITestBean test = (ITestBean) bf.getBean("lazyInitTest");
	assertTrue(AopUtils.isAopProxy(test));
	Advised advised = (Advised) test;
	assertTrue(advised.getTargetSource() instanceof LazyInitTargetSource);
	assertEquals("No CountingTestBean instantiated yet", 0, CountingTestBean.count);
	assertEquals("Rod", test.getName());
	assertEquals("Kerry", test.getSpouse().getName());
	assertEquals("Only 1 CountingTestBean instantiated", 1, CountingTestBean.count);
	CountingTestBean.count = 0;
}
 
Example #4
Source File: TypePatternClassFilterTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testSubclassMatching() {
	TypePatternClassFilter tpcf = new TypePatternClassFilter("org.springframework.tests.sample.beans.ITestBean+");
	assertTrue("Must match: in package", tpcf.matches(TestBean.class));
	assertTrue("Must match: in package", tpcf.matches(ITestBean.class));
	assertTrue("Must match: in package", tpcf.matches(CountingTestBean.class));
	assertFalse("Must be excluded: not subclass", tpcf.matches(IOther.class));
	assertFalse("Must be excluded: not subclass", tpcf.matches(DefaultListableBeanFactory.class));
}
 
Example #5
Source File: AdvisorAutoProxyCreatorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testCustomPrototypeTargetSource() throws Exception {
	CountingTestBean.count = 0;
	BeanFactory bf = new ClassPathXmlApplicationContext(CUSTOM_TARGETSOURCE_CONTEXT, CLASS);
	ITestBean test = (ITestBean) bf.getBean("prototypeTest");
	assertTrue(AopUtils.isAopProxy(test));
	Advised advised = (Advised) test;
	assertTrue(advised.getTargetSource() instanceof PrototypeTargetSource);
	assertEquals("Rod", test.getName());
	// Check that references survived prototype creation
	assertEquals("Kerry", test.getSpouse().getName());
	assertEquals("Only 2 CountingTestBeans instantiated", 2, CountingTestBean.count);
	CountingTestBean.count = 0;
}
 
Example #6
Source File: AdvisorAutoProxyCreatorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testLazyInitTargetSource() throws Exception {
	CountingTestBean.count = 0;
	BeanFactory bf = new ClassPathXmlApplicationContext(CUSTOM_TARGETSOURCE_CONTEXT, CLASS);
	ITestBean test = (ITestBean) bf.getBean("lazyInitTest");
	assertTrue(AopUtils.isAopProxy(test));
	Advised advised = (Advised) test;
	assertTrue(advised.getTargetSource() instanceof LazyInitTargetSource);
	assertEquals("No CountingTestBean instantiated yet", 0, CountingTestBean.count);
	assertEquals("Rod", test.getName());
	assertEquals("Kerry", test.getSpouse().getName());
	assertEquals("Only 1 CountingTestBean instantiated", 1, CountingTestBean.count);
	CountingTestBean.count = 0;
}
 
Example #7
Source File: TypePatternClassFilterTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testSubclassMatching() {
	TypePatternClassFilter tpcf = new TypePatternClassFilter("org.springframework.tests.sample.beans.ITestBean+");
	assertTrue("Must match: in package", tpcf.matches(TestBean.class));
	assertTrue("Must match: in package", tpcf.matches(ITestBean.class));
	assertTrue("Must match: in package", tpcf.matches(CountingTestBean.class));
	assertFalse("Must be excluded: not subclass", tpcf.matches(IOther.class));
	assertFalse("Must be excluded: not subclass", tpcf.matches(DefaultListableBeanFactory.class));
}
 
Example #8
Source File: AdvisorAutoProxyCreatorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testCustomPrototypeTargetSource() throws Exception {
	CountingTestBean.count = 0;
	BeanFactory bf = new ClassPathXmlApplicationContext(CUSTOM_TARGETSOURCE_CONTEXT, CLASS);
	ITestBean test = (ITestBean) bf.getBean("prototypeTest");
	assertTrue(AopUtils.isAopProxy(test));
	Advised advised = (Advised) test;
	assertTrue(advised.getTargetSource() instanceof PrototypeTargetSource);
	assertEquals("Rod", test.getName());
	// Check that references survived prototype creation
	assertEquals("Kerry", test.getSpouse().getName());
	assertEquals("Only 2 CountingTestBeans instantiated", 2, CountingTestBean.count);
	CountingTestBean.count = 0;
}
 
Example #9
Source File: AdvisorAutoProxyCreatorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testLazyInitTargetSource() throws Exception {
	CountingTestBean.count = 0;
	BeanFactory bf = new ClassPathXmlApplicationContext(CUSTOM_TARGETSOURCE_CONTEXT, CLASS);
	ITestBean test = (ITestBean) bf.getBean("lazyInitTest");
	assertTrue(AopUtils.isAopProxy(test));
	Advised advised = (Advised) test;
	assertTrue(advised.getTargetSource() instanceof LazyInitTargetSource);
	assertEquals("No CountingTestBean instantiated yet", 0, CountingTestBean.count);
	assertEquals("Rod", test.getName());
	assertEquals("Kerry", test.getSpouse().getName());
	assertEquals("Only 1 CountingTestBean instantiated", 1, CountingTestBean.count);
	CountingTestBean.count = 0;
}