Examples of CountingBeforeAdvice


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

Examples of org.springframework.aop.framework.CountingBeforeAdvice

    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

Examples of org.springframework.aop.framework.CountingBeforeAdvice

    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

Examples of org.springframework.aop.framework.CountingBeforeAdvice

    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

Examples of org.springframework.aop.framework.CountingBeforeAdvice

    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

Examples of org.springframework.tests.aop.advice.CountingBeforeAdvice

    CountingThrowsAdvice cta = new CountingThrowsAdvice();

    pf.addAdvice(new SerializableNopInterceptor());
    // Try various advice types
    pf.addAdvice(new CountingBeforeAdvice());
    pf.addAdvice(new CountingAfterReturningAdvice());
    pf.addAdvice(cta);
    Person p = (Person) createAopProxy(pf).getProxy();

    p.echo(null);
View Full Code Here

Examples of org.springframework.tests.aop.advice.CountingBeforeAdvice

    t.getAge();
    // Unchanged
    assertEquals(3, di.getCount());
    assertEquals(2, di2.getCount());

    CountingBeforeAdvice cba = new CountingBeforeAdvice();
    assertEquals(0, cba.getCalls());
    advised.addAdvice(cba);
    t.setAge(16);
    assertEquals(16, t.getAge());
    assertEquals(2, cba.getCalls());
  }
View Full Code Here

Examples of org.springframework.tests.aop.advice.CountingBeforeAdvice

  public void testProxyConfigString() {
    TestBean target = new TestBean();
    ProxyFactory pc = new ProxyFactory(target);
    pc.setInterfaces(new Class<?>[] {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();
View Full Code Here

Examples of org.springframework.tests.aop.advice.CountingBeforeAdvice

  public void testCanPreventCastToAdvisedUsingOpaque() {
    TestBean target = new TestBean();
    ProxyFactory pc = new ProxyFactory(target);
    pc.setInterfaces(new Class<?>[] {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);
  }
View Full Code Here

Examples of org.springframework.tests.aop.advice.CountingBeforeAdvice

    BeanFactory beanFactory = new ClassPathXmlApplicationContext(OPTIMIZED_CONTEXT, CLASS);

    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
TOP
Copyright © 2018 www.massapi.com. 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.