Search in sources :

Example 6 with DebugInterceptor

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

the class AbstractAopProxyTests method testProxyIsBoundBeforeTargetSourceInvoked.

@Test
public void testProxyIsBoundBeforeTargetSourceInvoked() {
    final TestBean target = new TestBean();
    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvice(new DebugInterceptor());
    pf.setExposeProxy(true);
    final ITestBean proxy = (ITestBean) createProxy(pf);
    Advised config = (Advised) proxy;
    // This class just checks proxy is bound before getTarget() call
    config.setTargetSource(new TargetSource() {

        @Override
        public Class<?> getTargetClass() {
            return TestBean.class;
        }

        @Override
        public boolean isStatic() {
            return false;
        }

        @Override
        public Object getTarget() throws Exception {
            assertEquals(proxy, AopContext.currentProxy());
            return target;
        }

        @Override
        public void releaseTarget(Object target) throws Exception {
        }
    });
    // Just test anything: it will fail if context wasn't found
    assertEquals(0, proxy.getAge());
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) TargetSource(org.springframework.aop.TargetSource) HotSwappableTargetSource(org.springframework.aop.target.HotSwappableTargetSource) SingletonTargetSource(org.springframework.aop.target.SingletonTargetSource) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) DebugInterceptor(org.springframework.aop.interceptor.DebugInterceptor) FileNotFoundException(java.io.FileNotFoundException) SQLException(java.sql.SQLException) MarshalException(java.rmi.MarshalException) IOException(java.io.IOException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) LockedException(test.mixin.LockedException) Test(org.junit.Test)

Example 7 with DebugInterceptor

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

the class ObjenesisProxyTests method appliesAspectToClassWithComplexConstructor.

@Test
public void appliesAspectToClassWithComplexConstructor() {
    @SuppressWarnings("resource") ApplicationContext context = new ClassPathXmlApplicationContext("ObjenesisProxyTests-context.xml", getClass());
    ClassWithComplexConstructor bean = context.getBean(ClassWithComplexConstructor.class);
    bean.method();
    DebugInterceptor interceptor = context.getBean(DebugInterceptor.class);
    assertThat(interceptor.getCount(), is(1L));
    assertThat(bean.getDependency().getValue(), is(1));
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DebugInterceptor(org.springframework.aop.interceptor.DebugInterceptor) Test(org.junit.Test)

Aggregations

DebugInterceptor (org.springframework.aop.interceptor.DebugInterceptor)7 Test (org.junit.Test)5 ITestBean (org.springframework.tests.sample.beans.ITestBean)4 TestBean (org.springframework.tests.sample.beans.TestBean)3 DefaultIntroductionAdvisor (org.springframework.aop.support.DefaultIntroductionAdvisor)2 TimeStamped (org.springframework.tests.TimeStamped)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 MarshalException (java.rmi.MarshalException)1 SQLException (java.sql.SQLException)1 TargetSource (org.springframework.aop.TargetSource)1 HotSwappableTargetSource (org.springframework.aop.target.HotSwappableTargetSource)1 SingletonTargetSource (org.springframework.aop.target.SingletonTargetSource)1 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)1 ApplicationContext (org.springframework.context.ApplicationContext)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1 TimestampIntroductionInterceptor (org.springframework.tests.aop.interceptor.TimestampIntroductionInterceptor)1 LockedException (test.mixin.LockedException)1