Package org.springframework.aop.framework

Examples of org.springframework.aop.framework.CountingBeforeAdvice


  /**
   * 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


    assertTrue("Advisors should not be empty", advisors.length > 0);
  }

  public void testAdviceInvokedCorrectly() throws Exception {
    CountingBeforeAdvice getAgeCounter = (CountingBeforeAdvice) this.context.getBean("getAgeCounter");
    CountingBeforeAdvice getNameCounter = (CountingBeforeAdvice) this.context.getBean("getNameCounter");

    ITestBean bean = getTestBean();

    assertEquals("Incorrect initial getAge count", 0, getAgeCounter.getCalls("getAge"));
    assertEquals("Incorrect initial getName count", 0, getNameCounter.getCalls("getName"));

    bean.getAge();

    assertEquals("Incorrect getAge count on getAge counter", 1, getAgeCounter.getCalls("getAge"));
    assertEquals("Incorrect getAge count on getName counter", 0, getNameCounter.getCalls("getAge"));

    bean.getName();

    assertEquals("Incorrect getName count on getName counter", 1, getNameCounter.getCalls("getName"));
    assertEquals("Incorrect getName count on getAge counter", 0, getAgeCounter.getCalls("getName"));
  }
View Full Code Here

    BeanFactory beanFactory = new ClassPathXmlApplicationContext("org/springframework/aop/framework/autoproxy/optimizedAutoProxyCreator.xml");

    ITestBean testBean = (ITestBean) beanFactory.getBean("optimizedTestBean");
    assertTrue(AopUtils.isAopProxy(testBean));

    CountingBeforeAdvice beforeAdvice = (CountingBeforeAdvice) beanFactory.getBean("countingAdvice");

    testBean.setAge(23);
    testBean.getAge();

    assertEquals("Incorrect number of calls to proxy", 2, beforeAdvice.getCalls());
  }
View Full Code Here

    Messenger bean = (Messenger) context.getBean("messenger");
    assertTrue("Bean is not a proxy", AopUtils.isAopProxy(bean));
    assertTrue("Bean is not an Advised object", bean instanceof Advised);

    CountingBeforeAdvice advice = (CountingBeforeAdvice) context.getBean("advice");
    assertEquals(0, advice.getCalls());
    bean.getMessage();
    assertEquals(1, advice.getCalls());
  }
View Full Code Here

    Messenger bean = (Messenger) context.getBean("messenger");
    assertTrue("Bean is not a proxy", AopUtils.isAopProxy(bean));
    assertTrue("Bean is not an Advised object", bean instanceof Advised);

    CountingBeforeAdvice advice = (CountingBeforeAdvice) context.getBean("advice");
    assertEquals(0, advice.getCalls());
    bean.getMessage();
    assertEquals(1, advice.getCalls());
  }
View Full Code Here

TOP

Related Classes of org.springframework.aop.framework.CountingBeforeAdvice

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.