Search in sources :

Example 1 with NamedBean

use of org.springframework.beans.factory.NamedBean in project spring-framework by spring-projects.

the class ExposeBeanNameAdvisorsTests method testWithIntroduction.

@Test
public void testWithIntroduction() {
    String beanName = "foo";
    TestBean target = new RequiresBeanNameBoundTestBean(beanName);
    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
    pf.addAdvisor(ExposeBeanNameAdvisors.createAdvisorIntroducingNamedBean(beanName));
    ITestBean proxy = (ITestBean) pf.getProxy();
    assertTrue("Introduction was made", proxy instanceof NamedBean);
    // Requires binding
    proxy.getAge();
    NamedBean nb = (NamedBean) proxy;
    assertEquals("Name returned correctly", beanName, nb.getBeanName());
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) NamedBean(org.springframework.beans.factory.NamedBean) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) ProxyFactory(org.springframework.aop.framework.ProxyFactory) Test(org.junit.Test)

Example 2 with NamedBean

use of org.springframework.beans.factory.NamedBean in project spring-framework by spring-projects.

the class ExposeBeanNameAdvisorsTests method testNoIntroduction.

@Test
public void testNoIntroduction() {
    String beanName = "foo";
    TestBean target = new RequiresBeanNameBoundTestBean(beanName);
    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
    pf.addAdvisor(ExposeBeanNameAdvisors.createAdvisorWithoutIntroduction(beanName));
    ITestBean proxy = (ITestBean) pf.getProxy();
    assertFalse("No introduction", proxy instanceof NamedBean);
    // Requires binding
    proxy.getAge();
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) NamedBean(org.springframework.beans.factory.NamedBean) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) ProxyFactory(org.springframework.aop.framework.ProxyFactory) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 ProxyFactory (org.springframework.aop.framework.ProxyFactory)2 NamedBean (org.springframework.beans.factory.NamedBean)2 ITestBean (org.springframework.tests.sample.beans.ITestBean)2 TestBean (org.springframework.tests.sample.beans.TestBean)2