Package org.springframework.beans

Examples of org.springframework.beans.ITestBean


    TestBean target1 = new TestBean();
    target1.setAge(age1);
    ProxyFactory pf1 = new ProxyFactory(target1);
    pf1.addAdvisor(new DefaultPointcutAdvisor(new NopInterceptor()));
    pf1.addAdvisor(new DefaultPointcutAdvisor(new TimestampIntroductionInterceptor()));
    ITestBean tb = (ITestBean) pf1.getProxy();

    assertEquals(age1, tb.getAge());
    tb.setAge(age2);
    assertEquals(age2, tb.getAge());
    assertNull(tb.getName());
    tb.setName(name);
    assertEquals(name, tb.getName());
  }
View Full Code Here


    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

    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

    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()
View Full Code Here

    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

      pc.setTarget(new TestBean());
    }
    AopProxy aop = createAopProxy(pc);

    assertNoInvocationContext();
    ITestBean tb = (ITestBean) aop.getProxy();
    assertNoInvocationContext();
    assertTrue("correct return value", tb.getName() == s);
  }
View Full Code Here

    ProxyCreatorSupport pc = new ProxyCreatorSupport();
    pc.setInterfaces(new Class[] {ITestBean.class});
    pc.setTarget(raw);

    ITestBean tb = (ITestBean) createProxy(pc);
    assertTrue("this return is wrapped in proxy", tb.getSpouse() == tb);
  }
View Full Code Here

    mockTargetSource.setTarget(new Object());
    pc.setTargetSource(mockTargetSource);
    AopProxy aop = createAopProxy(pc);

    try {
      ITestBean tb = (ITestBean) aop.getProxy();
      // Note: exception param below isn't used
      tb.exceptional(expectedException);
      fail("Should have thrown exception raised by interceptor");
    }
    catch (Exception thrown) {
      assertEquals("exception matches", expectedException, thrown);
    }
View Full Code Here

    pc.addAdvice(mi);

    // We don't care about the object
    pc.setTarget(new TestBean());
    AopProxy aop = createAopProxy(pc);
    ITestBean tb = (ITestBean) aop.getProxy();

    try {
      // Note: exception param below isn't used
      tb.getAge();
      fail("Should have wrapped exception raised by interceptor");
    }
    catch (UndeclaredThrowableException thrown) {
      assertEquals("exception matches", unexpectedException, thrown.getUndeclaredThrowable());
    }
View Full Code Here

    pc.addAdvice(mi);

    // We don't care about the object
    pc.setTarget(new TestBean());
    AopProxy aop = createAopProxy(pc);
    ITestBean tb = (ITestBean) aop.getProxy();

    try {
      // Note: exception param below isn't used
      tb.getAge();
      fail("Should have wrapped exception raised by interceptor");
    }
    catch (RuntimeException thrown) {
      assertEquals("exception matches", unexpectedException, thrown);
    }
View Full Code Here

TOP

Related Classes of org.springframework.beans.ITestBean

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.