Package org.springframework.aop.support

Examples of org.springframework.aop.support.DefaultPointcutAdvisor


  public void testManualProxyJavaWithStaticPointcut() throws Exception {
    TestService target = new TestServiceImpl();
    LogUserAdvice logAdvice = new LogUserAdvice();
    AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
    pointcut.setExpression(String.format("execution(* %s.TestService.*(..))", getClass().getName()));
    testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "TestServiceImpl");
  }
View Full Code Here


  public void testManualProxyJavaWithDynamicPointcut() throws Exception {
    TestService target = new TestServiceImpl();
    LogUserAdvice logAdvice = new LogUserAdvice();
    AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
    pointcut.setExpression(String.format("@within(%s.Log)", getClass().getName()));
    testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "TestServiceImpl");
  }
View Full Code Here

  public void testManualProxyJavaWithDynamicPointcutAndProxyTargetClass() throws Exception {
    TestService target = new TestServiceImpl();
    LogUserAdvice logAdvice = new LogUserAdvice();
    AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
    pointcut.setExpression(String.format("@within(%s.Log)", getClass().getName()));
    testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "TestServiceImpl", true);
  }
View Full Code Here

    LogUserAdvice logAdvice = new LogUserAdvice();
    AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
    pointcut.setExpression(String.format("execution(* %s.TestService.*(..))", getClass().getName()));

    // Test with default class loader first...
    testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, new TestServiceImpl(), "TestServiceImpl");

    // Then try again with a different class loader on the target...
    SimpleThrowawayClassLoader loader = new SimpleThrowawayClassLoader(new TestServiceImpl().getClass().getClassLoader());
    // Make sure the interface is loaded from the  parent class loader
    loader.excludeClass(TestService.class.getName());
    loader.excludeClass(TestException.class.getName());
    TestService other = (TestService) loader.loadClass(TestServiceImpl.class.getName()).newInstance();
    testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, other, "TestServiceImpl");

  }
View Full Code Here

  private TestBean getAdvisedProxy(String pointcutExpression, CallCountingInterceptor interceptor) {
    TestBean target = new TestBean();

    Pointcut pointcut = getPointcut(pointcutExpression);

    DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor();
    advisor.setAdvice(interceptor);
    advisor.setPointcut(pointcut);

    ProxyFactory pf = new ProxyFactory();
    pf.setTarget(target);
    pf.addAdvisor(advisor);
View Full Code Here

  @Test
  public void testIndexOfMethods() {
    TestBean target = new TestBean();
    ProxyFactory pf = new ProxyFactory(target);
    NopInterceptor nop = new NopInterceptor();
    Advisor advisor = new DefaultPointcutAdvisor(new CountingBeforeAdvice());
    Advised advised = (Advised) pf.getProxy();
    // Can use advised and ProxyFactory interchangeably
    advised.addAdvice(nop);
    pf.addAdvisor(advisor);
    assertEquals(-1, pf.indexOf(new NopInterceptor()));
    assertEquals(0, pf.indexOf(nop));
    assertEquals(1, pf.indexOf(advisor));
    assertEquals(-1, advised.indexOf(new DefaultPointcutAdvisor(null)));
  }
View Full Code Here

  public void testRemoveAdvisorByReference() {
    TestBean target = new TestBean();
    ProxyFactory pf = new ProxyFactory(target);
    NopInterceptor nop = new NopInterceptor();
    CountingBeforeAdvice cba = new CountingBeforeAdvice();
    Advisor advisor = new DefaultPointcutAdvisor(cba);
    pf.addAdvice(nop);
    pf.addAdvisor(advisor);
    ITestBean proxied = (ITestBean) pf.getProxy();
    proxied.setAge(5);
    assertEquals(1, cba.getCalls());
    assertEquals(1, nop.getCount());
    assertTrue(pf.removeAdvisor(advisor));
    assertEquals(5, proxied.getAge());
    assertEquals(1, cba.getCalls());
    assertEquals(2, nop.getCount());
    assertFalse(pf.removeAdvisor(new DefaultPointcutAdvisor(null)));
  }
View Full Code Here

  public void testRemoveAdvisorByIndex() {
    TestBean target = new TestBean();
    ProxyFactory pf = new ProxyFactory(target);
    NopInterceptor nop = new NopInterceptor();
    CountingBeforeAdvice cba = new CountingBeforeAdvice();
    Advisor advisor = new DefaultPointcutAdvisor(cba);
    pf.addAdvice(nop);
    pf.addAdvisor(advisor);
    NopInterceptor nop2 = new NopInterceptor();
    pf.addAdvice(nop2);
    ITestBean proxied = (ITestBean) pf.getProxy();
View Full Code Here

    TestBean target = new TestBean();
    ProxyFactory pf = new ProxyFactory(target);
    NopInterceptor nop = new NopInterceptor();
    CountingBeforeAdvice cba1 = new CountingBeforeAdvice();
    CountingBeforeAdvice cba2 = new CountingBeforeAdvice();
    Advisor advisor1 = new DefaultPointcutAdvisor(cba1);
    Advisor advisor2 = new DefaultPointcutAdvisor(cba2);
    pf.addAdvisor(advisor1);
    pf.addAdvice(nop);
    ITestBean proxied = (ITestBean) pf.getProxy();
    // Use the type cast feature
    // Replace etc methods on advised should be same as on ProxyFactory
    Advised advised = (Advised) proxied;
    proxied.setAge(5);
    assertEquals(1, cba1.getCalls());
    assertEquals(0, cba2.getCalls());
    assertEquals(1, nop.getCount());
    assertFalse(advised.replaceAdvisor(new DefaultPointcutAdvisor(new NopInterceptor()), advisor2));
    assertTrue(advised.replaceAdvisor(advisor1, advisor2));
    assertEquals(advisor2, pf.getAdvisors()[0]);
    assertEquals(5, proxied.getAge());
    assertEquals(1, cba1.getCalls());
    assertEquals(2, nop.getCount());
    assertEquals(1, cba2.getCalls());
    assertFalse(pf.replaceAdvisor(new DefaultPointcutAdvisor(null), advisor1));
  }
View Full Code Here

    HotSwappableTargetSource hts = new HotSwappableTargetSource(sp1);
    ProxyFactory pf = new ProxyFactory();
    pf.addInterface(Person.class);
    pf.setTargetSource(hts);
    pf.addAdvisor(new DefaultPointcutAdvisor(new SerializableNopInterceptor()));
    Person p = (Person) pf.getProxy();

    assertEquals(sp1.getName(), p.getName());
    hts.swap(sp2);
    assertEquals(sp2.getName(), p.getName());
View Full Code Here

TOP

Related Classes of org.springframework.aop.support.DefaultPointcutAdvisor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.