Package org.springframework.aop.interceptor

Examples of org.springframework.aop.interceptor.NopInterceptor


    JmxTestBean bean = new JmxTestBean();
    bean.setName("Rob Harrop");

    ProxyFactory factory = new ProxyFactory();
    factory.setTarget(bean);
    factory.addAdvice(new NopInterceptor());
    factory.setInterfaces(new Class[]{IJmxTestBean.class});

    IJmxTestBean proxy = (IJmxTestBean) factory.getProxy();
    String name = "bean:mmm=whatever";
View Full Code Here


* @author Rod Johnson
*/
public class NeverMatchAdvisor extends StaticMethodMatcherPointcutAdvisor {
 
  public NeverMatchAdvisor() {
    super(new NopInterceptor());
  }
View Full Code Here

    Pointcut no = new TestPointcut();
    assertFalse(AopUtils.canApply(no, Object.class));
  }

  public void testPointcutAlwaysApplies() {
    assertTrue(AopUtils.canApply(new DefaultPointcutAdvisor(new NopInterceptor()), Object.class));
    assertTrue(AopUtils.canApply(new DefaultPointcutAdvisor(new NopInterceptor()), TestBean.class));
  }
View Full Code Here

    assertEquals("doubleJdk", tb.getName());
  }

  public void testJdkIntroduction() {
    ITestBean tb = (ITestBean) beanFactory.getBean("introductionUsingJdk");
    NopInterceptor nop = (NopInterceptor) beanFactory.getBean("introductionNopInterceptor");
    assertEquals(0, nop.getCount());
    assertTrue(AopUtils.isJdkDynamicProxy(tb));
    int age = 5;
    tb.setAge(age);
    assertEquals(age, tb.getAge());
    assertTrue("Introduction was made", tb instanceof TimeStamped);
    assertEquals(0, ((TimeStamped) tb).getTimeStamp());
    assertEquals(3, nop.getCount());   
    assertEquals("introductionUsingJdk", tb.getName());

    ITestBean tb2 = (ITestBean) beanFactory.getBean("second-introductionUsingJdk");

    // Check two per-instance mixins were distinct
View Full Code Here

    }
  }

  public void testJdkIntroductionAppliesToCreatedObjectsNotFactoryBean() {
    ITestBean tb = (ITestBean) beanFactory.getBean("factory-introductionUsingJdk");
    NopInterceptor nop = (NopInterceptor) beanFactory.getBean("introductionNopInterceptor");
    assertEquals("NOP should not have done any work yet", 0, nop.getCount());
    assertTrue(AopUtils.isJdkDynamicProxy(tb));
    int age = 5;
    tb.setAge(age);
    assertEquals(age, tb.getAge());
    assertTrue("Introduction was made", tb instanceof TimeStamped);
    assertEquals(0, ((TimeStamped) tb).getTimeStamp());
    assertEquals(3, nop.getCount());   
 
    ITestBean tb2 = (ITestBean) beanFactory.getBean("second-introductionUsingJdk");
     
    // Check two per-instance mixins were distinct
    Lockable lockable1 = (Lockable) tb;
View Full Code Here

    ITestBean testBean = (ITestBean) beanFactory.getBean("frozenBean");
    assertTrue(((Advised)testBean).isFrozen());
  }

  private void jdkAssertions(ITestBean tb, int nopInterceptorCount)  {
    NopInterceptor nop = (NopInterceptor) beanFactory.getBean("nopInterceptor");
    assertEquals(0, nop.getCount());
    assertTrue(AopUtils.isJdkDynamicProxy(tb));
    int age = 5;
    tb.setAge(age);
    assertEquals(age, tb.getAge());
    assertEquals(2 * nopInterceptorCount, nop.getCount());
  }
View Full Code Here

  /**
   * Also has counting before advice.
   */
  private void cglibAssertions(TestBean tb) {
    CountingBeforeAdvice cba = (CountingBeforeAdvice) beanFactory.getBean("countingBeforeAdvice");
    NopInterceptor nop = (NopInterceptor) beanFactory.getBean("nopInterceptor");
    assertEquals(0, cba.getCalls());
    assertEquals(0, nop.getCount());
    assertTrue(AopUtils.isCglibProxy(tb));
    int age = 5;
    tb.setAge(age);
    assertEquals(age, tb.getAge());
    assertEquals(2, nop.getCount());
    assertEquals(2, cba.getCalls());   
  }
View Full Code Here

  }
 
  public void testMatches() {
    TestBean target = new TestBean();
    target.setAge(27);
    NopInterceptor nop = new NopInterceptor();
    ControlFlowPointcut cflow = new ControlFlowPointcut(One.class, "getAge");
    ProxyFactory pf = new ProxyFactory(target);
    ITestBean proxied = (ITestBean) pf.getProxy();
    pf.addAdvisor(new DefaultPointcutAdvisor(cflow, nop));
   
    // Not advised, not under One
    assertEquals(target.getAge(), proxied.getAge());
    assertEquals(0, nop.getCount());
   
    // Will be advised
    assertEquals(target.getAge(), new One().getAge(proxied));
    assertEquals(1, nop.getCount());
   
    // Won't be advised
    assertEquals(target.getAge(), new One().nomatch(proxied));
    assertEquals(1, nop.getCount());
    assertEquals(3, cflow.getEvaluations());
  }
View Full Code Here

   * expensive.
   */
  public void testSelectiveApplication() {
    TestBean target = new TestBean();
    target.setAge(27);
    NopInterceptor nop = new NopInterceptor();
    ControlFlowPointcut cflow = new ControlFlowPointcut(One.class);
    Pointcut settersUnderOne = Pointcuts.intersection(Pointcuts.SETTERS, cflow);
    ProxyFactory pf = new ProxyFactory(target);
    ITestBean proxied = (ITestBean) pf.getProxy();
    pf.addAdvisor(new DefaultPointcutAdvisor(settersUnderOne, nop));
 
    // Not advised, not under One
    target.setAge(16);
    assertEquals(0, nop.getCount());
 
    // Not advised; under One but not a setter
    assertEquals(16, new One().getAge(proxied));
    assertEquals(0, nop.getCount());
 
    // Won't be advised
    new One().set(proxied);
    assertEquals(1, nop.getCount());
   
    // We saved most evaluations
    assertEquals(1, cflow.getEvaluations());
  }
View Full Code Here

  public void testSinglePattern() throws Throwable {
    BeanFactory bf = new ClassPathXmlApplicationContext("org/springframework/aop/support/regexpSetterTests.xml");
    ITestBean advised = (ITestBean) bf.getBean("settersAdvised");
    // Interceptor behind regexp advisor
    NopInterceptor nop = (NopInterceptor) bf.getBean("nopInterceptor");
    assertEquals(0, nop.getCount());
   
    int newAge = 12;
    // Not advised
    advised.exceptional(null);
    assertEquals(0, nop.getCount());
    advised.setAge(newAge);
    assertEquals(newAge, advised.getAge());
    // Only setter fired
    assertEquals(1, nop.getCount());
  }
View Full Code Here

TOP

Related Classes of org.springframework.aop.interceptor.NopInterceptor

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.