Search in sources :

Example 1 with NameMatchMethodPointcut

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

the class AbstractAopProxyTests method testCanPreventCastToAdvisedUsingOpaque.

@Test
public void testCanPreventCastToAdvisedUsingOpaque() {
    TestBean target = new TestBean();
    ProxyFactory pc = new ProxyFactory(target);
    pc.setInterfaces(ITestBean.class);
    pc.addAdvice(new NopInterceptor());
    CountingBeforeAdvice mba = new CountingBeforeAdvice();
    Advisor advisor = new DefaultPointcutAdvisor(new NameMatchMethodPointcut().addMethodName("setAge"), mba);
    pc.addAdvisor(advisor);
    assertThat(pc.isOpaque()).as("Opaque defaults to false").isFalse();
    pc.setOpaque(true);
    assertThat(pc.isOpaque()).as("Opaque now true for this config").isTrue();
    ITestBean proxied = (ITestBean) createProxy(pc);
    proxied.setAge(10);
    assertThat(proxied.getAge()).isEqualTo(10);
    assertThat(mba.getCalls()).isEqualTo(1);
    boolean condition = proxied instanceof Advised;
    assertThat(condition).as("Cannot be cast to Advised").isFalse();
}
Also used : 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) Advised(cn.taketoday.aop.framework.Advised) DefaultPointcutAdvisor(cn.taketoday.aop.support.DefaultPointcutAdvisor) DefaultIntroductionAdvisor(cn.taketoday.aop.support.DefaultIntroductionAdvisor) Advisor(cn.taketoday.aop.Advisor) LockMixinAdvisor(cn.taketoday.aop.mixin.LockMixinAdvisor) StaticMethodMatcherPointcutAdvisor(cn.taketoday.aop.support.StaticMethodMatcherPointcutAdvisor) DefaultPointcutAdvisor(cn.taketoday.aop.support.DefaultPointcutAdvisor) NameMatchMethodPointcut(cn.taketoday.aop.support.NameMatchMethodPointcut) Test(org.junit.jupiter.api.Test)

Example 2 with NameMatchMethodPointcut

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

the class AbstractAopProxyTests method testProxyConfigString.

/**
 * Check that the string is informative.
 */
@Test
public void testProxyConfigString() {
    TestBean target = new TestBean();
    ProxyFactory pc = new ProxyFactory(target);
    pc.setInterfaces(ITestBean.class);
    pc.addAdvice(new NopInterceptor());
    MethodBeforeAdvice mba = new CountingBeforeAdvice();
    Advisor advisor = new DefaultPointcutAdvisor(new NameMatchMethodPointcut(), mba);
    pc.addAdvisor(advisor);
    ITestBean proxied = (ITestBean) createProxy(pc);
    String proxyConfigString = ((Advised) proxied).toProxyConfigString();
    assertThat(proxyConfigString.contains(advisor.toString())).isTrue();
    assertThat(proxyConfigString.contains("1 interface")).isTrue();
}
Also used : 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) MethodBeforeAdvice(cn.taketoday.aop.MethodBeforeAdvice) DefaultPointcutAdvisor(cn.taketoday.aop.support.DefaultPointcutAdvisor) DefaultIntroductionAdvisor(cn.taketoday.aop.support.DefaultIntroductionAdvisor) LockMixinAdvisor(test.mixin.LockMixinAdvisor) Advisor(cn.taketoday.aop.Advisor) StaticMethodMatcherPointcutAdvisor(cn.taketoday.aop.support.StaticMethodMatcherPointcutAdvisor) DefaultPointcutAdvisor(cn.taketoday.aop.support.DefaultPointcutAdvisor) CountingBeforeAdvice(cn.taketoday.aop.testfixture.advice.CountingBeforeAdvice) NameMatchMethodPointcut(cn.taketoday.aop.support.NameMatchMethodPointcut) Test(org.junit.jupiter.api.Test)

Example 3 with NameMatchMethodPointcut

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

the class AbstractAopProxyTests method testCanPreventCastToAdvisedUsingOpaque.

@Test
public void testCanPreventCastToAdvisedUsingOpaque() {
    TestBean target = new TestBean();
    ProxyFactory pc = new ProxyFactory(target);
    pc.setInterfaces(ITestBean.class);
    pc.addAdvice(new NopInterceptor());
    CountingBeforeAdvice mba = new CountingBeforeAdvice();
    Advisor advisor = new DefaultPointcutAdvisor(new NameMatchMethodPointcut().addMethodName("setAge"), mba);
    pc.addAdvisor(advisor);
    assertThat(pc.isOpaque()).as("Opaque defaults to false").isFalse();
    pc.setOpaque(true);
    assertThat(pc.isOpaque()).as("Opaque now true for this config").isTrue();
    ITestBean proxied = (ITestBean) createProxy(pc);
    proxied.setAge(10);
    assertThat(proxied.getAge()).isEqualTo(10);
    assertThat(mba.getCalls()).isEqualTo(1);
    boolean condition = proxied instanceof Advised;
    assertThat(condition).as("Cannot be cast to Advised").isFalse();
}
Also used : 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) DefaultPointcutAdvisor(cn.taketoday.aop.support.DefaultPointcutAdvisor) DefaultIntroductionAdvisor(cn.taketoday.aop.support.DefaultIntroductionAdvisor) LockMixinAdvisor(test.mixin.LockMixinAdvisor) Advisor(cn.taketoday.aop.Advisor) StaticMethodMatcherPointcutAdvisor(cn.taketoday.aop.support.StaticMethodMatcherPointcutAdvisor) DefaultPointcutAdvisor(cn.taketoday.aop.support.DefaultPointcutAdvisor) CountingBeforeAdvice(cn.taketoday.aop.testfixture.advice.CountingBeforeAdvice) NameMatchMethodPointcut(cn.taketoday.aop.support.NameMatchMethodPointcut) Test(org.junit.jupiter.api.Test)

Example 4 with NameMatchMethodPointcut

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

the class AbstractAopProxyTests method testProxyConfigString.

/**
 * Check that the string is informative.
 */
@Test
public void testProxyConfigString() {
    TestBean target = new TestBean();
    ProxyFactory pc = new ProxyFactory(target);
    pc.setInterfaces(ITestBean.class);
    pc.addAdvice(new NopInterceptor());
    MethodBeforeAdvice mba = new CountingBeforeAdvice();
    Advisor advisor = new DefaultPointcutAdvisor(new NameMatchMethodPointcut(), mba);
    pc.addAdvisor(advisor);
    ITestBean proxied = (ITestBean) createProxy(pc);
    String proxyConfigString = ((Advised) proxied).toProxyConfigString();
    assertThat(proxyConfigString.contains(advisor.toString())).isTrue();
    assertThat(proxyConfigString.contains("1 interface")).isTrue();
}
Also used : 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) MethodBeforeAdvice(cn.taketoday.aop.MethodBeforeAdvice) DefaultPointcutAdvisor(cn.taketoday.aop.support.DefaultPointcutAdvisor) DefaultIntroductionAdvisor(cn.taketoday.aop.support.DefaultIntroductionAdvisor) LockMixinAdvisor(test.mixin.LockMixinAdvisor) Advisor(cn.taketoday.aop.Advisor) StaticMethodMatcherPointcutAdvisor(cn.taketoday.aop.support.StaticMethodMatcherPointcutAdvisor) DefaultPointcutAdvisor(cn.taketoday.aop.support.DefaultPointcutAdvisor) CountingBeforeAdvice(cn.taketoday.aop.testfixture.advice.CountingBeforeAdvice) NameMatchMethodPointcut(cn.taketoday.aop.support.NameMatchMethodPointcut) Test(org.junit.jupiter.api.Test)

Example 5 with NameMatchMethodPointcut

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

the class AbstractAopProxyTests method testCanPreventCastToAdvisedUsingOpaque.

@Test
public void testCanPreventCastToAdvisedUsingOpaque() {
    TestBean target = new TestBean();
    ProxyFactory pc = new ProxyFactory(target);
    pc.setInterfaces(ITestBean.class);
    pc.addAdvice(new NopInterceptor());
    CountingBeforeAdvice mba = new CountingBeforeAdvice();
    Advisor advisor = new DefaultPointcutAdvisor(new NameMatchMethodPointcut().addMethodName("setAge"), mba);
    pc.addAdvisor(advisor);
    assertThat(pc.isOpaque()).as("Opaque defaults to false").isFalse();
    pc.setOpaque(true);
    assertThat(pc.isOpaque()).as("Opaque now true for this config").isTrue();
    ITestBean proxied = (ITestBean) createProxy(pc);
    proxied.setAge(10);
    assertThat(proxied.getAge()).isEqualTo(10);
    assertThat(mba.getCalls()).isEqualTo(1);
    boolean condition = proxied instanceof Advised;
    assertThat(condition).as("Cannot be cast to Advised").isFalse();
}
Also used : 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) DefaultPointcutAdvisor(cn.taketoday.aop.support.DefaultPointcutAdvisor) DefaultIntroductionAdvisor(cn.taketoday.aop.support.DefaultIntroductionAdvisor) LockMixinAdvisor(test.mixin.LockMixinAdvisor) Advisor(cn.taketoday.aop.Advisor) StaticMethodMatcherPointcutAdvisor(cn.taketoday.aop.support.StaticMethodMatcherPointcutAdvisor) DefaultPointcutAdvisor(cn.taketoday.aop.support.DefaultPointcutAdvisor) CountingBeforeAdvice(cn.taketoday.aop.testfixture.advice.CountingBeforeAdvice) NameMatchMethodPointcut(cn.taketoday.aop.support.NameMatchMethodPointcut) Test(org.junit.jupiter.api.Test)

Aggregations

Advisor (cn.taketoday.aop.Advisor)6 DefaultIntroductionAdvisor (cn.taketoday.aop.support.DefaultIntroductionAdvisor)6 DefaultPointcutAdvisor (cn.taketoday.aop.support.DefaultPointcutAdvisor)6 NameMatchMethodPointcut (cn.taketoday.aop.support.NameMatchMethodPointcut)6 StaticMethodMatcherPointcutAdvisor (cn.taketoday.aop.support.StaticMethodMatcherPointcutAdvisor)6 ITestBean (cn.taketoday.beans.testfixture.beans.ITestBean)6 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)6 Test (org.junit.jupiter.api.Test)6 CountingBeforeAdvice (cn.taketoday.aop.testfixture.advice.CountingBeforeAdvice)4 NopInterceptor (cn.taketoday.aop.testfixture.interceptor.NopInterceptor)4 SerializableNopInterceptor (cn.taketoday.aop.testfixture.interceptor.SerializableNopInterceptor)4 LockMixinAdvisor (test.mixin.LockMixinAdvisor)4 MethodBeforeAdvice (cn.taketoday.aop.MethodBeforeAdvice)3 NopInterceptor (cn.taketoday.aop.NopInterceptor)2 SerializableNopInterceptor (cn.taketoday.aop.SerializableNopInterceptor)2 Advised (cn.taketoday.aop.framework.Advised)2 ProxyFactory (cn.taketoday.aop.framework.ProxyFactory)2 LockMixinAdvisor (cn.taketoday.aop.mixin.LockMixinAdvisor)2