Search in sources :

Example 21 with Advised

use of org.springframework.aop.framework.Advised in project spring-framework by spring-projects.

the class ScriptingDefaultsTests method defaultRefreshCheckDelay.

@Test
public void defaultRefreshCheckDelay() throws Exception {
    ApplicationContext context = new ClassPathXmlApplicationContext(CONFIG);
    Advised advised = (Advised) context.getBean("testBean");
    AbstractRefreshableTargetSource targetSource = ((AbstractRefreshableTargetSource) advised.getTargetSource());
    Field field = AbstractRefreshableTargetSource.class.getDeclaredField("refreshCheckDelay");
    field.setAccessible(true);
    long delay = ((Long) field.get(targetSource)).longValue();
    assertEquals(5000L, delay);
}
Also used : Field(java.lang.reflect.Field) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Advised(org.springframework.aop.framework.Advised) AbstractRefreshableTargetSource(org.springframework.aop.target.dynamic.AbstractRefreshableTargetSource) Test(org.junit.Test)

Example 22 with Advised

use of org.springframework.aop.framework.Advised in project cxf by apache.

the class SpringAopClassHelper method getRealObjectInternal.

protected Object getRealObjectInternal(Object o) {
    if (o instanceof Advised) {
        try {
            Advised advised = (Advised) o;
            Object target = advised.getTargetSource().getTarget();
            // could be a proxy of a proxy.....
            return getRealObjectInternal(target);
        } catch (Exception ex) {
        // ignore
        }
    }
    return o;
}
Also used : Advised(org.springframework.aop.framework.Advised) BeanCreationException(org.springframework.beans.factory.BeanCreationException)

Example 23 with Advised

use of org.springframework.aop.framework.Advised in project spring-framework by spring-projects.

the class SelectivePrototypeTargetSourceCreator method testCustomPrototypeTargetSource.

@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;
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Advised(org.springframework.aop.framework.Advised) BeanFactory(org.springframework.beans.factory.BeanFactory) PrototypeTargetSource(org.springframework.aop.target.PrototypeTargetSource) Test(org.junit.Test)

Example 24 with Advised

use of org.springframework.aop.framework.Advised in project spring-framework by spring-projects.

the class SelectivePrototypeTargetSourceCreator method testLazyInitTargetSource.

@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;
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Advised(org.springframework.aop.framework.Advised) BeanFactory(org.springframework.beans.factory.BeanFactory) LazyInitTargetSource(org.springframework.aop.target.LazyInitTargetSource) Test(org.junit.Test)

Example 25 with Advised

use of org.springframework.aop.framework.Advised in project spring-framework by spring-projects.

the class CommonsPool2TargetSourceTests method testProxySerializableWithoutConfigMixin.

@Test
public void testProxySerializableWithoutConfigMixin() throws Exception {
    Person pooled = (Person) beanFactory.getBean("pooledPerson");
    //System.out.println(((Advised) pooled).toProxyConfigString());
    assertTrue(((Advised) pooled).getTargetSource() instanceof CommonsPool2TargetSource);
    //((Advised) pooled).setTargetSource(new SingletonTargetSource(new SerializablePerson()));
    Person serialized = (Person) SerializationTestUtils.serializeAndDeserialize(pooled);
    assertTrue(((Advised) serialized).getTargetSource() instanceof SingletonTargetSource);
    serialized.setAge(25);
    assertEquals(25, serialized.getAge());
}
Also used : Advised(org.springframework.aop.framework.Advised) SerializablePerson(org.springframework.tests.sample.beans.SerializablePerson) Person(org.springframework.tests.sample.beans.Person) Test(org.junit.Test)

Aggregations

Advised (org.springframework.aop.framework.Advised)38 Test (org.junit.Test)22 ITestBean (org.springframework.tests.sample.beans.ITestBean)15 Advisor (org.springframework.aop.Advisor)11 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)10 TestBean (org.springframework.tests.sample.beans.TestBean)4 JoinPoint (org.aspectj.lang.JoinPoint)3 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)3 SyntheticInstantiationAdvisor (org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor)3 ProxyFactory (org.springframework.aop.framework.ProxyFactory)3 ApplicationContext (org.springframework.context.ApplicationContext)3 Person (org.springframework.tests.sample.beans.Person)3 StopWatch (org.springframework.util.StopWatch)3 Advice (org.aopalliance.aop.Advice)2 PrototypeTargetSource (org.springframework.aop.target.PrototypeTargetSource)2 BeanCreationException (org.springframework.beans.factory.BeanCreationException)2 BeanFactory (org.springframework.beans.factory.BeanFactory)2 AnotherTestEvent (org.springframework.context.event.test.AnotherTestEvent)2 TestEvent (org.springframework.context.event.test.TestEvent)2 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)2