Search in sources :

Example 1 with DelegatingIntroductionInterceptor

use of cn.taketoday.aop.support.DelegatingIntroductionInterceptor in project today-infrastructure by TAKETODAY.

the class AbstractAopProxyTests method testIntroductionThrowsUncheckedException.

/**
 * Note that an introduction can't throw an unexpected checked exception,
 * as it's constrained by the interface.
 */
@Test
public void testIntroductionThrowsUncheckedException() throws Throwable {
    TestBean target = new TestBean();
    target.setAge(21);
    ProxyFactory pc = new ProxyFactory(target);
    @SuppressWarnings("serial")
    class MyDi extends DelegatingIntroductionInterceptor implements TimeStamped {

        /**
         * @see TimeStamped#getTimeStamp()
         */
        @Override
        public long getTimeStamp() {
            throw new UnsupportedOperationException();
        }
    }
    pc.addAdvisor(new DefaultIntroductionAdvisor(new MyDi()));
    TimeStamped ts = (TimeStamped) createProxy(pc);
    assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(ts::getTimeStamp);
}
Also used : DelegatingIntroductionInterceptor(cn.taketoday.aop.support.DelegatingIntroductionInterceptor) TimeStamped(cn.taketoday.core.testfixture.TimeStamped) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) DefaultIntroductionAdvisor(cn.taketoday.aop.support.DefaultIntroductionAdvisor) Pointcuts(cn.taketoday.aop.support.Pointcuts) Test(org.junit.jupiter.api.Test)

Example 2 with DelegatingIntroductionInterceptor

use of cn.taketoday.aop.support.DelegatingIntroductionInterceptor in project today-framework by TAKETODAY.

the class AbstractAopProxyTests method testAdviceImplementsIntroductionInfo.

@Test
public void testAdviceImplementsIntroductionInfo() throws Throwable {
    TestBean tb = new TestBean();
    String name = "tony";
    tb.setName(name);
    ProxyFactory pc = new ProxyFactory(tb);
    NopInterceptor di = new NopInterceptor();
    pc.addAdvice(di);
    final long ts = 37;
    pc.addAdvice(new DelegatingIntroductionInterceptor(new TimeStamped() {

        @Override
        public long getTimeStamp() {
            return ts;
        }
    }));
    ITestBean proxied = (ITestBean) createProxy(pc);
    assertThat(proxied.getName()).isEqualTo(name);
    TimeStamped intro = (TimeStamped) proxied;
    assertThat(intro.getTimeStamp()).isEqualTo(ts);
}
Also used : DelegatingIntroductionInterceptor(cn.taketoday.aop.support.DelegatingIntroductionInterceptor) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) NopInterceptor(cn.taketoday.aop.NopInterceptor) SerializableNopInterceptor(cn.taketoday.aop.SerializableNopInterceptor) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) ProxyFactory(cn.taketoday.aop.framework.ProxyFactory) Test(org.junit.jupiter.api.Test)

Example 3 with DelegatingIntroductionInterceptor

use of cn.taketoday.aop.support.DelegatingIntroductionInterceptor in project today-framework by TAKETODAY.

the class AbstractAopProxyTests method testAdviceImplementsIntroductionInfo.

@Test
public void testAdviceImplementsIntroductionInfo() throws Throwable {
    TestBean tb = new TestBean();
    String name = "tony";
    tb.setName(name);
    ProxyFactory pc = new ProxyFactory(tb);
    NopInterceptor di = new NopInterceptor();
    pc.addAdvice(di);
    final long ts = 37;
    pc.addAdvice(new DelegatingIntroductionInterceptor((TimeStamped) () -> ts));
    ITestBean proxied = (ITestBean) createProxy(pc);
    assertThat(proxied.getName()).isEqualTo(name);
    TimeStamped intro = (TimeStamped) proxied;
    assertThat(intro.getTimeStamp()).isEqualTo(ts);
}
Also used : DelegatingIntroductionInterceptor(cn.taketoday.aop.support.DelegatingIntroductionInterceptor) TimeStamped(cn.taketoday.core.testfixture.TimeStamped) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) NopInterceptor(cn.taketoday.aop.testfixture.interceptor.NopInterceptor) SerializableNopInterceptor(cn.taketoday.aop.testfixture.interceptor.SerializableNopInterceptor) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) Test(org.junit.jupiter.api.Test)

Example 4 with DelegatingIntroductionInterceptor

use of cn.taketoday.aop.support.DelegatingIntroductionInterceptor in project today-framework by TAKETODAY.

the class AbstractAopProxyTests method testIntroductionThrowsUncheckedException.

/**
 * Note that an introduction can't throw an unexpected checked exception,
 * as it's constrained by the interface.
 */
@Test
public void testIntroductionThrowsUncheckedException() throws Throwable {
    TestBean target = new TestBean();
    target.setAge(21);
    ProxyFactory pc = new ProxyFactory(target);
    @SuppressWarnings("serial")
    class MyDi extends DelegatingIntroductionInterceptor implements TimeStamped {

        /**
         * @see TimeStamped#getTimeStamp()
         */
        @Override
        public long getTimeStamp() {
            throw new UnsupportedOperationException();
        }
    }
    pc.addAdvisor(new DefaultIntroductionAdvisor(new MyDi()));
    TimeStamped ts = (TimeStamped) createProxy(pc);
    assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(ts::getTimeStamp);
}
Also used : DelegatingIntroductionInterceptor(cn.taketoday.aop.support.DelegatingIntroductionInterceptor) TimeStamped(cn.taketoday.core.testfixture.TimeStamped) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) DefaultIntroductionAdvisor(cn.taketoday.aop.support.DefaultIntroductionAdvisor) Pointcuts(cn.taketoday.aop.support.Pointcuts) Test(org.junit.jupiter.api.Test)

Example 5 with DelegatingIntroductionInterceptor

use of cn.taketoday.aop.support.DelegatingIntroductionInterceptor in project today-infrastructure by TAKETODAY.

the class AbstractAopProxyTests method testAdviceImplementsIntroductionInfo.

@Test
public void testAdviceImplementsIntroductionInfo() throws Throwable {
    TestBean tb = new TestBean();
    String name = "tony";
    tb.setName(name);
    ProxyFactory pc = new ProxyFactory(tb);
    NopInterceptor di = new NopInterceptor();
    pc.addAdvice(di);
    final long ts = 37;
    pc.addAdvice(new DelegatingIntroductionInterceptor((TimeStamped) () -> ts));
    ITestBean proxied = (ITestBean) createProxy(pc);
    assertThat(proxied.getName()).isEqualTo(name);
    TimeStamped intro = (TimeStamped) proxied;
    assertThat(intro.getTimeStamp()).isEqualTo(ts);
}
Also used : DelegatingIntroductionInterceptor(cn.taketoday.aop.support.DelegatingIntroductionInterceptor) TimeStamped(cn.taketoday.core.testfixture.TimeStamped) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) NopInterceptor(cn.taketoday.aop.testfixture.interceptor.NopInterceptor) SerializableNopInterceptor(cn.taketoday.aop.testfixture.interceptor.SerializableNopInterceptor) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) Test(org.junit.jupiter.api.Test)

Aggregations

DelegatingIntroductionInterceptor (cn.taketoday.aop.support.DelegatingIntroductionInterceptor)6 ITestBean (cn.taketoday.beans.testfixture.beans.ITestBean)6 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)6 Test (org.junit.jupiter.api.Test)6 TimeStamped (cn.taketoday.core.testfixture.TimeStamped)4 DefaultIntroductionAdvisor (cn.taketoday.aop.support.DefaultIntroductionAdvisor)3 Pointcuts (cn.taketoday.aop.support.Pointcuts)3 ProxyFactory (cn.taketoday.aop.framework.ProxyFactory)2 NopInterceptor (cn.taketoday.aop.testfixture.interceptor.NopInterceptor)2 SerializableNopInterceptor (cn.taketoday.aop.testfixture.interceptor.SerializableNopInterceptor)2 NopInterceptor (cn.taketoday.aop.NopInterceptor)1 SerializableNopInterceptor (cn.taketoday.aop.SerializableNopInterceptor)1