Package org.springframework.tests.aop.interceptor

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


      }
    };

    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

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

    };

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

    MyThrowsHandler th = new MyThrowsHandler();

    Echo target = new Echo();
    target.setA(16);
    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvice(new NopInterceptor());
    pf.addAdvice(th);
    IEcho proxied = (IEcho) createProxy(pf);
    assertEquals(0, th.getCalls());
    assertEquals(target.getA(), proxied.getA());
    assertEquals(0, th.getCalls());
View Full Code Here

@SuppressWarnings("serial")
class NeverMatchAdvisor extends StaticMethodMatcherPointcutAdvisor {

  public NeverMatchAdvisor() {
    super(new NopInterceptor());
  }
View Full Code Here

  }

  @Test
  public void testNoTarget() {
    AdvisedSupport pc = new AdvisedSupport(new Class<?>[]{ITestBean.class});
    pc.addAdvice(new NopInterceptor());
    try {
      AopProxy aop = createAopProxy(pc);
      aop.getProxy();
      fail("Shouldn't allow no target with CGLIB proxy");
    }
View Full Code Here

    bean.value = "foo";
    mockTargetSource.setTarget(bean);

    AdvisedSupport as = new AdvisedSupport(new Class<?>[]{});
    as.setTargetSource(mockTargetSource);
    as.addAdvice(new NopInterceptor());
    AopProxy aop = new CglibAopProxy(as);

    ProtectedMethodTestBean proxy = (ProtectedMethodTestBean) aop.getProxy();
    assertTrue(AopUtils.isCglibProxy(proxy));
    assertEquals(proxy.getClass().getClassLoader(), bean.getClass().getClassLoader());
View Full Code Here

    bean.value = "foo";
    mockTargetSource.setTarget(bean);

    AdvisedSupport as = new AdvisedSupport(new Class<?>[]{});
    as.setTargetSource(mockTargetSource);
    as.addAdvice(new NopInterceptor());
    AopProxy aop = new CglibAopProxy(as);

    PackageMethodTestBean proxy = (PackageMethodTestBean) aop.getProxy();
    assertTrue(AopUtils.isCglibProxy(proxy));
    assertEquals(proxy.getClass().getClassLoader(), bean.getClass().getClassLoader());
View Full Code Here

    bean.value = "foo";
    mockTargetSource.setTarget(bean);

    AdvisedSupport as = new AdvisedSupport(new Class<?>[]{});
    as.setTargetSource(mockTargetSource);
    as.addAdvice(new NopInterceptor());
    AopProxy aop = new CglibAopProxy(as);

    PackageMethodTestBean proxy = (PackageMethodTestBean) aop.getProxy(child);
    assertTrue(AopUtils.isCglibProxy(proxy));
    assertNotEquals(proxy.getClass().getClassLoader(), bean.getClass().getClassLoader());
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.