Package org.springframework.tests.aop.interceptor

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


  @Test
  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);
View Full Code Here


    assertEquals(1, acf.refreshes);
    assertEquals(1, l.activates);
    assertTrue(pc.isActive());
    assertEquals(target.getAge(), proxied.getAge());
    assertEquals(0, l.adviceChanges);
    NopInterceptor di = new NopInterceptor();
    pc.addAdvice(0, di);
    assertEquals(1, l.adviceChanges);
    assertEquals(2, acf.refreshes);
    assertEquals(target.getAge(), proxied.getAge());
    pc.removeAdvice(di);
    assertEquals(2, l.adviceChanges);
    assertEquals(3, acf.refreshes);
    assertEquals(target.getAge(), proxied.getAge());
    pc.getProxy();
    assertEquals(1, l.activates);

    pc.removeListener(l);
    assertEquals(2, l.adviceChanges);
    pc.addAdvisor(new DefaultPointcutAdvisor(new NopInterceptor()));
    // No longer counting
    assertEquals(2, l.adviceChanges);
  }
View Full Code Here

    tb2.setAge(26);
    tb2.setName("Juergen");
    TestBean tb3 = new TestBean();
    tb3.setAge(37);
    ProxyFactory pc = new ProxyFactory(tb1);
    NopInterceptor nop = new NopInterceptor();
    pc.addAdvice(nop);
    ITestBean proxy = (ITestBean) createProxy(pc);
    assertEquals(nop.getCount(), 0);
    assertEquals(tb1.getAge(), proxy.getAge());
    assertEquals(nop.getCount(), 1);
    // Change to a new static target
    pc.setTarget(tb2);
    assertEquals(tb2.getAge(), proxy.getAge());
    assertEquals(nop.getCount(), 2);

    // Change to a new dynamic target
    HotSwappableTargetSource hts = new HotSwappableTargetSource(tb3);
    pc.setTargetSource(hts);
    assertEquals(tb3.getAge(), proxy.getAge());
    assertEquals(nop.getCount(), 3);
    hts.swap(tb1);
    assertEquals(tb1.getAge(), proxy.getAge());
    tb1.setName("Colin");
    assertEquals(tb1.getName(), proxy.getName());
    assertEquals(nop.getCount(), 5);

    // Change back, relying on casting to Advised
    Advised advised = (Advised) proxy;
    assertSame(hts, advised.getTargetSource());
    SingletonTargetSource sts = new SingletonTargetSource(tb2);
View Full Code Here

  @Test
  public void testDynamicMethodPointcutThatAlwaysAppliesStatically() throws Throwable {
    TestBean tb = new TestBean();
    ProxyFactory pc = new ProxyFactory(new Class<?>[] {ITestBean.class});
    TestDynamicPointcutAdvice dp = new TestDynamicPointcutAdvice(new NopInterceptor(), "getAge");
    pc.addAdvisor(dp);
    pc.setTarget(tb);
    ITestBean it = (ITestBean) createProxy(pc);
    assertEquals(dp.count, 0);
    it.getAge();
View Full Code Here

  @Test
  public void testDynamicMethodPointcutThatAppliesStaticallyOnlyToSetters() throws Throwable {
    TestBean tb = new TestBean();
    ProxyFactory pc = new ProxyFactory(new Class<?>[] {ITestBean.class});
    // Could apply dynamically to getAge/setAge but not to getName
    TestDynamicPointcutForSettersOnly dp = new TestDynamicPointcutForSettersOnly(new NopInterceptor(), "Age");
    pc.addAdvisor(dp);
    this.mockTargetSource.setTarget(tb);
    pc.setTargetSource(mockTargetSource);
    ITestBean it = (ITestBean) createProxy(pc);
    assertEquals(dp.count, 0);
View Full Code Here

  @Test
  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);
    it.getAge();
    assertEquals(di.getCount(), 1);
    it.setAge(11);
    assertEquals(it.getAge(), 11);
    assertEquals(di.getCount(), 2);
  }
View Full Code Here

  @SuppressWarnings("serial")
  @Test
  public void testOverloadedMethodsWithDifferentAdvice() throws Throwable {
    Overloads target = new Overloads();
    ProxyFactory pc = new ProxyFactory(target);
    NopInterceptor overLoadVoids = new NopInterceptor();
    pc.addAdvisor(new StaticMethodMatcherPointcutAdvisor(overLoadVoids) {
      @Override
      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) {
      @Override
      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

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

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.