Package org.springframework.tests.aop.interceptor

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


    CglibTestBean bean = new CglibTestBean();
    bean.setName("Rob Harrop");

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

    CglibTestBean proxy = (CglibTestBean) aop.getProxy();
    assertEquals("The name property has been overwritten by the constructor", "Rob Harrop", proxy.getName());
  }
View Full Code Here


  private ITestBean getAdvisedProxy(TestBean target) {
    ProxyFactory pf = new ProxyFactory(new Class<?>[]{ITestBean.class});
    pf.setProxyTargetClass(true);

    MethodInterceptor advice = new NopInterceptor();
    Pointcut pointcut = new Pointcut() {
      @Override
      public ClassFilter getClassFilter() {
        return ClassFilter.TRUE;
      }
View Full Code Here

    ITestBean target = new TestBean();

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

    ITestBean proxy1 = (ITestBean) cglib.getProxy();

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

    assertThat(cglib.getProxy(), instanceOf(ITestBean.class));
  }
View Full Code Here

    ITestBean target = new TestBean();
    mockTargetSource.setTarget(target);

    AdvisedSupport as = new AdvisedSupport(new Class<?>[]{});
    as.setTargetSource(mockTargetSource);
    as.addAdvice(new NopInterceptor());
    as.addInterface(Serializable.class);
    CglibAopProxy cglib = new CglibAopProxy(as);

    ITestBean proxy1 = (ITestBean) cglib.getProxy();

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

    ITestBean proxy2 = (ITestBean) cglib.getProxy();
    assertTrue(proxy2 instanceof Serializable);
  }
View Full Code Here

    ExceptionThrower bean = new ExceptionThrower();
    mockTargetSource.setTarget(bean);

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

    ExceptionThrower proxy = (ExceptionThrower) aop.getProxy();

    try {
View Full Code Here

    JmxTestBean bean = new JmxTestBean();
    bean.setName("Rob Harrop");

    ProxyFactory factory = new ProxyFactory();
    factory.setTarget(bean);
    factory.addAdvice(new NopInterceptor());
    factory.setInterfaces(IJmxTestBean.class);

    IJmxTestBean proxy = (IJmxTestBean) factory.getProxy();
    String name = "bean:mmm=whatever";
View Full Code Here

    assertEquals(test1.getAge(), test1_1.getAge());
    Advised pc1 = (Advised) test1;
    Advised pc2 = (Advised) test1_1;
    assertArrayEquals(pc1.getAdvisors(), pc2.getAdvisors());
    int oldLength = pc1.getAdvisors().length;
    NopInterceptor di = new NopInterceptor();
    pc1.addAdvice(1, di);
    assertArrayEquals(pc1.getAdvisors(), pc2.getAdvisors());
    assertEquals("Now have one more advisor", oldLength + 1, pc2.getAdvisors().length);
    assertEquals(di.getCount(), 0);
    test1.setAge(5);
    assertEquals(test1_1.getAge(), test1.getAge());
    assertEquals(di.getCount(), 3);
  }
View Full Code Here

  @Test
  public void testCanAddAndRemoveAdvicesOnSingleton() {
    ITestBean it = (ITestBean) factory.getBean("test1");
    Advised pc = (Advised) it;
    it.getAge();
    NopInterceptor di = new NopInterceptor();
    pc.addAdvice(0, di);
    assertEquals(0, di.getCount());
    it.setAge(25);
    assertEquals(25, it.getAge());
    assertEquals(2, di.getCount());
  }
View Full Code Here

    assertEquals(p, p2);
    assertNotSame(p, p2);
    assertEquals("serializableSingleton", p2.getName());

    // Add unserializable advice
    Advice nop = new NopInterceptor();
    ((Advised) p).addAdvice(nop);
    // Check it still works
    assertEquals(p2.getName(), p2.getName());
    assertFalse("Not serializable because an interceptor isn't serializable", SerializationTestUtils.isSerializable(p));
View Full Code Here

  @Test
  public void testWithCglibProxy() throws Exception {
    IJmxTestBean tb = createJmxTestBean();
    ProxyFactory pf = new ProxyFactory();
    pf.setTarget(tb);
    pf.addAdvice(new NopInterceptor());
    Object proxy = pf.getProxy();

    MetadataMBeanInfoAssembler assembler = (MetadataMBeanInfoAssembler) getAssembler();

    MBeanExporter exporter = new MBeanExporter();
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.