Package org.springframework.aop.interceptor

Examples of org.springframework.aop.interceptor.NopInterceptor


  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

    TestBean target1 = new TestBean();
    ProxyFactory pf1 = new ProxyFactory(target1);
    // Permit proxy and invocation checkers to get context from AopContext
    pf1.setExposeProxy(true);
    NopInterceptor di1 = new NopInterceptor();
    pf1.addAdvice(0, di1);
    pf1.addAdvice(1, new ProxyMatcherInterceptor());
    pf1.addAdvice(2, new CheckMethodInvocationIsSameInAndOutInterceptor());
    pf1.addAdvice(1, new CheckMethodInvocationViaThreadLocalIsSameInAndOutInterceptor());
    // Must be first
    pf1.addAdvice(0, ExposeInvocationInterceptor.INSTANCE);
    ITestBean advised1 = (ITestBean) pf1.getProxy();
    advised1.setAge(age1); // = 1 invocation

    TestBean target2 = new TestBean();
    ProxyFactory pf2 = new ProxyFactory(target2);
    pf2.setExposeProxy(true);
    NopInterceptor di2 = new NopInterceptor();
    pf2.addAdvice(0, di2);
    pf2.addAdvice(1, new ProxyMatcherInterceptor());
    pf2.addAdvice(2, new CheckMethodInvocationIsSameInAndOutInterceptor());
    pf2.addAdvice(1, new CheckMethodInvocationViaThreadLocalIsSameInAndOutInterceptor());
    pf2.addAdvice(0, ExposeInvocationInterceptor.INSTANCE);
    //System.err.println(pf2.toProxyConfigString());
    ITestBean advised2 = (ITestBean) createProxy(pf2);
    advised2.setAge(age2);
    advised1.setSpouse(advised2); // = 2 invocations

    assertEquals("Advised one has correct age", age1, advised1.getAge()); // = 3 invocations
    assertEquals("Advised two has correct age", age2, advised2.getAge());
    // Means extra call on advised 2
    assertEquals("Advised one spouse has correct age", age2, advised1.getSpouse().getAge()); // = 4 invocations on 1 and another one on 2

    assertEquals("one was invoked correct number of times", 4, di1.getCount());
    // Got hit by call to advised1.getSpouse().getAge()
    assertEquals("one was invoked correct number of times", 3, di2.getCount());
  }
View Full Code Here

  public void testReentrance() {
    int age1 = 33;

    TestBean target1 = new TestBean();
    ProxyFactory pf1 = new ProxyFactory(target1);
    NopInterceptor di1 = new NopInterceptor();
    pf1.addAdvice(0, di1);
    ITestBean advised1 = (ITestBean) createProxy(pf1);
    advised1.setAge(age1); // = 1 invocation
    advised1.setSpouse(advised1); // = 2 invocations

    assertEquals("one was invoked correct number of times", 2, di1.getCount());

    assertEquals("Advised one has correct age", age1, advised1.getAge()); // = 3 invocations
    assertEquals("one was invoked correct number of times", 3, di1.getCount());

    // = 5 invocations, as reentrant call to spouse is advised also
    assertEquals("Advised spouse has correct age", age1, advised1.getSpouse().getAge());

    assertEquals("one was invoked correct number of times", 5, di1.getCount());
  }
View Full Code Here

    assertEquals("one was invoked correct number of times", 5, di1.getCount());
  }

  public void testTargetCanGetProxy() {
    NopInterceptor di = new NopInterceptor();
    INeedsToSeeProxy target = new TargetChecker();
    ProxyFactory proxyFactory = new ProxyFactory(target);
    proxyFactory.setExposeProxy(true);
    assertTrue(proxyFactory.isExposeProxy());

    proxyFactory.addAdvice(0, di);
    INeedsToSeeProxy proxied = (INeedsToSeeProxy) createProxy(proxyFactory);
    assertEquals(0, di.getCount());
    assertEquals(0, target.getCount());
    proxied.incrementViaThis();
    assertEquals("Increment happened", 1, target.getCount());

    assertEquals("Only one invocation via AOP as use of this wasn't proxied", 1, di.getCount());
    // 1 invocation
    assertEquals("Increment happened", 1, proxied.getCount());
    proxied.incrementViaProxy(); // 2 invoocations
    assertEquals("Increment happened", 2, target.getCount());
    assertEquals("3 more invocations via AOP as the first call was reentrant through the proxy", 4, di.getCount());
  }
View Full Code Here

    BeanFactory bf = new ClassPathXmlApplicationContext("/org/springframework/aop/framework/autoproxy/advisorAutoProxyCreatorWithCommonInterceptors.xml");
    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

  }

  public void testCanCastProxyToProxyConfig() throws Throwable {
    TestBean tb = new TestBean();
    ProxyFactory pc = new ProxyFactory(tb);
    NopInterceptor di = new NopInterceptor();
    pc.addAdvice(0, di);

    ITestBean t = (ITestBean) createProxy(pc);
    assertEquals(0, di.getCount());
    t.setAge(23);
    assertEquals(23, t.getAge());
    assertEquals(2, di.getCount());

    Advised advised = (Advised) t;
    assertEquals("Have 1 advisor", 1, advised.getAdvisors().length);
    assertEquals(di, advised.getAdvisors()[0].getAdvice());
    NopInterceptor di2 = new NopInterceptor();
    advised.addAdvice(1, di2);
    t.getName();
    assertEquals(3, di.getCount());
    assertEquals(1, di2.getCount());
    // will remove di
    advised.removeAdvisor(0);
    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);
View Full Code Here

  public void testAdviceImplementsIntroductionInfo() throws Throwable {
    TestBean tb = new TestBean();
    String name = "tony";
    tb.setName(name);
    ProxyFactory pc = new ProxyFactory(tb);
    NopInterceptor di = new NopInterceptor();
    pc.addAdvice(di);
    final long ts = 37;
    pc.addAdvice(new DelegatingIntroductionInterceptor(new TimeStamped() {
      public long getTimeStamp() {
        return ts;
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.