Search in sources :

Example 1 with NameMatchMethodPointcut

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

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);
    assertFalse("Opaque defaults to false", pc.isOpaque());
    pc.setOpaque(true);
    assertTrue("Opaque now true for this config", pc.isOpaque());
    ITestBean proxied = (ITestBean) createProxy(pc);
    proxied.setAge(10);
    assertEquals(10, proxied.getAge());
    assertEquals(1, mba.getCalls());
    assertFalse("Cannot be cast to Advised", proxied instanceof Advised);
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) SerializableNopInterceptor(org.springframework.tests.aop.interceptor.SerializableNopInterceptor) NopInterceptor(org.springframework.tests.aop.interceptor.NopInterceptor) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) StaticMethodMatcherPointcutAdvisor(org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor) LockMixinAdvisor(test.mixin.LockMixinAdvisor) DefaultPointcutAdvisor(org.springframework.aop.support.DefaultPointcutAdvisor) Advisor(org.springframework.aop.Advisor) DefaultIntroductionAdvisor(org.springframework.aop.support.DefaultIntroductionAdvisor) DefaultPointcutAdvisor(org.springframework.aop.support.DefaultPointcutAdvisor) CountingBeforeAdvice(org.springframework.tests.aop.advice.CountingBeforeAdvice) NameMatchMethodPointcut(org.springframework.aop.support.NameMatchMethodPointcut) Test(org.junit.Test)

Example 2 with NameMatchMethodPointcut

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

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();
    assertTrue(proxyConfigString.contains(advisor.toString()));
    assertTrue(proxyConfigString.contains("1 interface"));
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) SerializableNopInterceptor(org.springframework.tests.aop.interceptor.SerializableNopInterceptor) NopInterceptor(org.springframework.tests.aop.interceptor.NopInterceptor) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) MethodBeforeAdvice(org.springframework.aop.MethodBeforeAdvice) StaticMethodMatcherPointcutAdvisor(org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor) LockMixinAdvisor(test.mixin.LockMixinAdvisor) DefaultPointcutAdvisor(org.springframework.aop.support.DefaultPointcutAdvisor) Advisor(org.springframework.aop.Advisor) DefaultIntroductionAdvisor(org.springframework.aop.support.DefaultIntroductionAdvisor) DefaultPointcutAdvisor(org.springframework.aop.support.DefaultPointcutAdvisor) CountingBeforeAdvice(org.springframework.tests.aop.advice.CountingBeforeAdvice) NameMatchMethodPointcut(org.springframework.aop.support.NameMatchMethodPointcut) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 Advisor (org.springframework.aop.Advisor)2 DefaultIntroductionAdvisor (org.springframework.aop.support.DefaultIntroductionAdvisor)2 DefaultPointcutAdvisor (org.springframework.aop.support.DefaultPointcutAdvisor)2 NameMatchMethodPointcut (org.springframework.aop.support.NameMatchMethodPointcut)2 StaticMethodMatcherPointcutAdvisor (org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor)2 CountingBeforeAdvice (org.springframework.tests.aop.advice.CountingBeforeAdvice)2 NopInterceptor (org.springframework.tests.aop.interceptor.NopInterceptor)2 SerializableNopInterceptor (org.springframework.tests.aop.interceptor.SerializableNopInterceptor)2 ITestBean (org.springframework.tests.sample.beans.ITestBean)2 TestBean (org.springframework.tests.sample.beans.TestBean)2 LockMixinAdvisor (test.mixin.LockMixinAdvisor)2 MethodBeforeAdvice (org.springframework.aop.MethodBeforeAdvice)1