Package org.springframework.aop.interceptor

Examples of org.springframework.aop.interceptor.NopInterceptor


  }

  public void testStaticMethodPointcut() throws Throwable {
    TestBean tb = new TestBean();
    ProxyFactory pc = new ProxyFactory(new Class[] {ITestBean.class});
    NopInterceptor di = new NopInterceptor();
    TestStaticPointcutAdvice sp = new TestStaticPointcutAdvice(di, "getAge");
    pc.addAdvisor(sp);
    pc.setTarget(tb);
    ITestBean it = (ITestBean) createProxy(pc);
    assertEquals(di.getCount(), 0);
    int age = it.getAge();
    assertEquals(di.getCount(), 1);
    it.setAge(11);
    assertEquals(it.getAge(), 11);
    assertEquals(di.getCount(), 2);
  }
View Full Code Here


  }

  public void testOverloadedMethodsWithDifferentAdvice() throws Throwable {
    Overloads target = new Overloads();
    ProxyFactory pc = new ProxyFactory(target);
    NopInterceptor overLoadVoids = new NopInterceptor();
    pc.addAdvisor(new StaticMethodMatcherPointcutAdvisor(overLoadVoids) {
      public boolean matches(Method m, Class targetClass) {
        return m.getName().equals("overload") && m.getParameterTypes().length == 0;
      }
    });
    NopInterceptor overLoadInts = new NopInterceptor();
    pc.addAdvisor(new StaticMethodMatcherPointcutAdvisor(overLoadInts) {
      public boolean matches(Method m, Class targetClass) {
        return m.getName().equals("overload") && m.getParameterTypes().length == 1 &&
          m.getParameterTypes()[0].equals(int.class);
      }
    });

    IOverloads proxy = (IOverloads) createProxy(pc);
    assertEquals(0, overLoadInts.getCount());
    assertEquals(0, overLoadVoids.getCount());
    proxy.overload();
    assertEquals(0, overLoadInts.getCount());
    assertEquals(1, overLoadVoids.getCount());
    assertEquals(25, proxy.overload(25));
    assertEquals(1, overLoadInts.getCount());
    assertEquals(1, overLoadVoids.getCount());
    proxy.noAdvice();
    assertEquals(1, overLoadInts.getCount());
    assertEquals(1, overLoadVoids.getCount());
  }
View Full Code Here

  }
 
  public void testEquals() {
    IOther a = new AllInstancesAreEqual();
    IOther b = new AllInstancesAreEqual();
    NopInterceptor i1 = new NopInterceptor();
    NopInterceptor i2 = new NopInterceptor();
    ProxyFactory pfa = new ProxyFactory(a);
    pfa.addAdvice(i1);
    ProxyFactory pfb = new ProxyFactory(b);
    pfb.addAdvice(i2);
    IOther proxyA = (IOther) createProxy(pfa);
View Full Code Here

      }
    };
    TestBean target = new TestBean();
    target.setAge(80);
    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvice(new NopInterceptor());
    pf.addAdvisor(matchesNoArgs);
    assertEquals("Advisor was added", matchesNoArgs, pf.getAdvisors()[1]);
    ITestBean proxied = (ITestBean) createProxy(pf);
    assertEquals(0, cba.getCalls());
    assertEquals(0, cba.getCalls("getAge"));
View Full Code Here

      }
    };
    TestBean target = new TestBean();
    target.setAge(80);
    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvice(new NopInterceptor());
    pf.addAdvisor(matchesNoArgs);
    assertEquals("Advisor was added", matchesNoArgs, pf.getAdvisors()[1]);
    ITestBean proxied = (ITestBean) createProxy(pf);

    assertEquals(0, cca.getCalls());
View Full Code Here

      }
    };

    TestBean target = new TestBean();
    target.setAge(80);
    NopInterceptor nop1 = new NopInterceptor();
    NopInterceptor nop2 = new NopInterceptor();
    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvice(nop1);
    pf.addAdvice(ba);
    pf.addAdvice(nop2);
    ITestBean proxied = (ITestBean) createProxy(pf);
    // Won't throw an exception
    assertEquals(target.getAge(), proxied.getAge());
    assertEquals(1, ba.getCalls());
    assertEquals(1, ba.getCalls("getAge"));
    assertEquals(1, nop1.getCount());
    assertEquals(1, nop2.getCount());
    // Will fail, after invoking Nop1
    try {
      proxied.setAge(26);
      fail("before advice should have ended chain");
    }
    catch (RuntimeException ex) {
      assertEquals(rex, ex);
    }
    assertEquals(2, ba.getCalls());
    assertEquals(2, nop1.getCount());
    // Nop2 didn't get invoked when the exception was thrown
    assertEquals(1, nop2.getCount());
    // Shouldn't have changed value in joinpoint
    assertEquals(target.getAge(), proxied.getAge());
  }
View Full Code Here

        return m.getReturnType() == int.class;
      }
    };
    TestBean target = new TestBean();
    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvice(new NopInterceptor());
    pf.addAdvisor(matchesInt);
    assertEquals("Advisor was added", matchesInt, pf.getAdvisors()[1]);
    ITestBean proxied = (ITestBean) createProxy(pf);
    assertEquals(0, aa.sum);
    int i1 = 12;
View Full Code Here

  public void testAfterReturningAdvisorIsNotInvokedOnException() {
    CountingAfterReturningAdvice car = new CountingAfterReturningAdvice();
    TestBean target = new TestBean();
    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvice(new NopInterceptor());
    pf.addAdvice(car);
    assertEquals("Advice was wrapped in Advisor and added", car, pf.getAdvisors()[1].getAdvice());
    ITestBean proxied = (ITestBean) createProxy(pf);
    assertEquals(0, car.getCalls());
    int age = 10;
View Full Code Here

    };

    ThrowsAdviceInterceptorTests.Echo target = new ThrowsAdviceInterceptorTests.Echo();
    target.setA(16);
    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvice(new NopInterceptor());
    pf.addAdvisor(matchesEchoInvocations);
    assertEquals("Advisor was added", matchesEchoInvocations, pf.getAdvisors()[1]);
    ThrowsAdviceInterceptorTests.IEcho proxied = (ThrowsAdviceInterceptorTests.IEcho) createProxy(pf);
    assertEquals(0, th.getCalls());
    assertEquals(target.getA(), proxied.getA());
View Full Code Here

    ThrowsAdviceInterceptorTests.MyThrowsHandler th = new ThrowsAdviceInterceptorTests.MyThrowsHandler();

    ThrowsAdviceInterceptorTests.Echo target = new ThrowsAdviceInterceptorTests.Echo();
    target.setA(16);
    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvice(new NopInterceptor());
    pf.addAdvice(th);
    ThrowsAdviceInterceptorTests.IEcho proxied = (ThrowsAdviceInterceptorTests.IEcho) createProxy(pf);
    assertEquals(0, th.getCalls());
    assertEquals(target.getA(), proxied.getA());
    assertEquals(0, th.getCalls());
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.