Package org.springframework.tests.aop.interceptor

Examples of org.springframework.tests.aop.interceptor.NopInterceptor


    BeanFactory bf = new ClassPathXmlApplicationContext(COMMON_INTERCEPTORS_CONTEXT, CLASS);
    ITestBean test1 = (ITestBean) bf.getBean("test1");
    assertTrue(AopUtils.isAopProxy(test1));

    Lockable lockable1 = (Lockable) test1;
    NopInterceptor nop = (NopInterceptor) bf.getBean("nopInterceptor");
    assertEquals(0, nop.getCount());

    ITestBean test2 = (ITestBean) bf.getBean("test2");
    Lockable lockable2 = (Lockable) test2;

    // Locking should be independent; nop is shared
    assertFalse(lockable1.locked());
    assertFalse(lockable2.locked());
    // equals 2 calls on shared nop, because it's first
    // and sees calls against the Lockable interface introduced
    // by the specific advisor
    assertEquals(2, nop.getCount());
    lockable1.lock();
    assertTrue(lockable1.locked());
    assertFalse(lockable2.locked());
    assertEquals(5, nop.getCount());
  }
View Full Code Here


  }

  @Test
  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

  }

  @Test
  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

    String name = "tony";

    TestBean target1 = new TestBean();
    target1.setAge(age1);
    ProxyFactory pf1 = new ProxyFactory(target1);
    pf1.addAdvisor(new DefaultPointcutAdvisor(new NopInterceptor()));
    pf1.addAdvisor(new DefaultPointcutAdvisor(new TimestampIntroductionInterceptor()));
    ITestBean tb = (ITestBean) pf1.getProxy();

    assertEquals(age1, tb.getAge());
    tb.setAge(age2);
View Full Code Here

  private void testManyProxies(int howMany) {
    int age1 = 33;
    TestBean target1 = new TestBean();
    target1.setAge(age1);
    ProxyFactory pf1 = new ProxyFactory(target1);
    pf1.addAdvice(new NopInterceptor());
    pf1.addAdvice(new NopInterceptor());
    ITestBean proxies[] = new ITestBean[howMany];
    for (int i = 0; i < howMany; i++) {
      proxies[i] = (ITestBean) createAopProxy(pf1).getProxy();
      assertEquals(age1, proxies[i].getAge());
    }
View Full Code Here

    TestBean tb = new TestBean();
    assertFalse(SerializationTestUtils.isSerializable(tb));

    ProxyFactory pf = new ProxyFactory(tb);

    pf.addAdvice(new NopInterceptor());
    ITestBean proxy = (ITestBean) createAopProxy(pf).getProxy();

    assertFalse(SerializationTestUtils.isSerializable(proxy));
  }
View Full Code Here

    assertTrue(SerializationTestUtils.isSerializable(sp));

    ProxyFactory pf = new ProxyFactory(sp);

    // This isn't serializable
    Advice i = new NopInterceptor();
    pf.addAdvice(i);
    assertFalse(SerializationTestUtils.isSerializable(i));
    Object proxy = createAopProxy(pf).getProxy();

    assertFalse(SerializationTestUtils.isSerializable(proxy));
View Full Code Here

    // This should work as SerializablePerson is equal
    assertEquals("Proxies should be equal, even after one was serialized", p, p2);
    assertEquals("Proxies should be equal, even after one was serialized", p2, p);

    // Check we can add a new advisor to the target
    NopInterceptor ni = new NopInterceptor();
    p2.getAge();
    assertEquals(0, ni.getCount());
    a2.addAdvice(ni);
    p2.getAge();
    assertEquals(1, ni.getCount());

    cta = (CountingThrowsAdvice) a2.getAdvisors()[3].getAdvice();
    p2.echo(null);
    assertEquals(1, cta.getCalls());
    try {
View Full Code Here

TOP

Related Classes of org.springframework.tests.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.