use of org.springframework.tests.sample.beans.ITestBean in project spring-framework by spring-projects.
the class OverloadLookup method testAutoProxiedLookup.
@Test
public void testAutoProxiedLookup() {
OverloadLookup olup = (OverloadLookup) applicationContext.getBean("autoProxiedOverload");
ITestBean jenny = olup.newTestBean();
assertEquals("Jenny", jenny.getName());
assertEquals("foo", olup.testMethod());
assertInterceptorCount(2);
}
use of org.springframework.tests.sample.beans.ITestBean in project spring-framework by spring-projects.
the class Rollback method testTxIsProxied.
@Test
public void testTxIsProxied() throws Exception {
BeanFactory bf = getBeanFactory();
ITestBean test = (ITestBean) bf.getBean("test");
assertTrue(AopUtils.isAopProxy(test));
}
use of org.springframework.tests.sample.beans.ITestBean in project spring-framework by spring-projects.
the class Rollback method testTransactionAttributeOnMethod.
@Test
public void testTransactionAttributeOnMethod() throws Exception {
BeanFactory bf = getBeanFactory();
ITestBean test = (ITestBean) bf.getBean("test");
CallCountingTransactionManager txMan = (CallCountingTransactionManager) bf.getBean(TXMANAGER_BEAN_NAME);
OrderedTxCheckAdvisor txc = (OrderedTxCheckAdvisor) bf.getBean("orderedBeforeTransaction");
assertEquals(0, txc.getCountingBeforeAdvice().getCalls());
assertEquals(0, txMan.commits);
assertEquals("Initial value was correct", 4, test.getAge());
int newAge = 5;
test.setAge(newAge);
assertEquals(1, txc.getCountingBeforeAdvice().getCalls());
assertEquals("New value set correctly", newAge, test.getAge());
assertEquals("Transaction counts match", 1, txMan.commits);
}
use of org.springframework.tests.sample.beans.ITestBean in project spring-framework by spring-projects.
the class AopNamespaceHandlerScopeIntegrationTests method testSessionScoping.
@Test
public void testSessionScoping() throws Exception {
MockHttpSession oldSession = new MockHttpSession();
MockHttpSession newSession = new MockHttpSession();
MockHttpServletRequest request = new MockHttpServletRequest();
request.setSession(oldSession);
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
ITestBean scoped = (ITestBean) this.context.getBean("sessionScoped");
assertTrue("Should be AOP proxy", AopUtils.isAopProxy(scoped));
assertFalse("Should not be target class proxy", scoped instanceof TestBean);
ITestBean scopedAlias = (ITestBean) this.context.getBean("sessionScopedAlias");
assertSame(scoped, scopedAlias);
ITestBean testBean = (ITestBean) this.context.getBean("testBean");
assertTrue("Should be AOP proxy", AopUtils.isAopProxy(testBean));
assertFalse("Regular bean should be JDK proxy", testBean instanceof TestBean);
String rob = "Rob Harrop";
String bram = "Bram Smeets";
assertEquals(rob, scoped.getName());
scoped.setName(bram);
request.setSession(newSession);
assertEquals(rob, scoped.getName());
request.setSession(oldSession);
assertEquals(bram, scoped.getName());
assertTrue("Should have advisors", ((Advised) scoped).getAdvisors().length > 0);
}
use of org.springframework.tests.sample.beans.ITestBean in project spring-framework by spring-projects.
the class AopNamespaceHandlerScopeIntegrationTests method testSingletonScoping.
@Test
public void testSingletonScoping() throws Exception {
ITestBean scoped = (ITestBean) this.context.getBean("singletonScoped");
assertTrue("Should be AOP proxy", AopUtils.isAopProxy(scoped));
assertTrue("Should be target class proxy", scoped instanceof TestBean);
String rob = "Rob Harrop";
String bram = "Bram Smeets";
assertEquals(rob, scoped.getName());
scoped.setName(bram);
assertEquals(bram, scoped.getName());
ITestBean deserialized = (ITestBean) SerializationTestUtils.serializeAndDeserialize(scoped);
assertEquals(bram, deserialized.getName());
}
Aggregations