Search in sources :

Example 51 with ITestBean

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);
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) Test(org.junit.Test)

Example 52 with ITestBean

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));
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) BeanFactory(org.springframework.beans.factory.BeanFactory) Test(org.junit.Test)

Example 53 with ITestBean

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);
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) CallCountingTransactionManager(org.springframework.tests.transaction.CallCountingTransactionManager) BeanFactory(org.springframework.beans.factory.BeanFactory) Test(org.junit.Test)

Example 54 with ITestBean

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);
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) MockHttpSession(org.springframework.mock.web.MockHttpSession) Test(org.junit.Test)

Example 55 with ITestBean

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());
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) Test(org.junit.Test)

Aggregations

ITestBean (org.springframework.tests.sample.beans.ITestBean)221 Test (org.junit.Test)205 TestBean (org.springframework.tests.sample.beans.TestBean)127 NopInterceptor (org.springframework.tests.aop.interceptor.NopInterceptor)37 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)29 SerializableNopInterceptor (org.springframework.tests.aop.interceptor.SerializableNopInterceptor)24 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)21 IOException (java.io.IOException)15 Advisor (org.springframework.aop.Advisor)15 DefaultIntroductionAdvisor (org.springframework.aop.support.DefaultIntroductionAdvisor)15 Method (java.lang.reflect.Method)14 ProxyFactory (org.springframework.aop.framework.ProxyFactory)14 DerivedTestBean (org.springframework.tests.sample.beans.DerivedTestBean)14 DefaultPointcutAdvisor (org.springframework.aop.support.DefaultPointcutAdvisor)13 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)13 MethodInvocation (org.aopalliance.intercept.MethodInvocation)12 Advised (org.springframework.aop.framework.Advised)12 MethodInterceptor (org.aopalliance.intercept.MethodInterceptor)11 LockedException (test.mixin.LockedException)11 IndexedTestBean (org.springframework.tests.sample.beans.IndexedTestBean)10