Package org.springframework.beans

Examples of org.springframework.beans.ITestBean


    new XmlBeanDefinitionReader(ctx).loadBeanDefinitions(new ClassPathResource("scopedOverride.xml", getClass()));
    SimpleMapScope scope = new SimpleMapScope();
    ctx.getBeanFactory().registerScope("request", scope);
    ctx.refresh();

    ITestBean bean = (ITestBean) ctx.getBean("testBean");
    assertEquals("male", bean.getName());
    assertEquals(99, bean.getAge());

    assertTrue(scope.getMap().containsKey("scopedTarget.testBean"));
    assertEquals(TestBean.class, scope.getMap().get("scopedTarget.testBean").getClass());
  }
View Full Code Here


  public void testJdkScopedProxy() throws Exception {
    XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("scopedTestBean.xml", getClass()));
    SimpleMapScope scope = new SimpleMapScope();
    bf.registerScope("request", scope);

    ITestBean bean = (ITestBean) bf.getBean("testBean");
    assertNotNull(bean);
    assertTrue(AopUtils.isJdkDynamicProxy(bean));
    assertTrue(bean instanceof ScopedObject);
    ScopedObject scoped = (ScopedObject) bean;
    assertEquals(TestBean.class, scoped.getTargetObject().getClass());
View Full Code Here

    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

*/
public class ExposeInvocationInterceptorTests extends TestCase {

  public void testXmlConfig() {
    ClassPathXmlApplicationContext xac = new ClassPathXmlApplicationContext("org/springframework/aop/interceptor/exposeInvocation.xml");
    ITestBean tb = (ITestBean) xac.getBean("proxy");
    String name= "tony";
    tb.setName(name);
    // Fires context checks
    assertEquals(name, tb.getName());
  }
View Full Code Here

    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;
    int i2 = 13;

    // Won't be advised
    proxied.setAge(i1);
    assertEquals(i1, proxied.getAge());
    assertEquals(i1, aa.sum);
    proxied.setAge(i2);
    assertEquals(i2, proxied.getAge());
    assertEquals(i1 + i2, aa.sum);
    assertEquals(i2, proxied.getAge());
  }
View Full Code Here

    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;
    proxied.setAge(age);
    assertEquals(age, proxied.getAge());
    assertEquals(2, car.getCalls());
    Exception exc = new Exception();
    // On exception it won't be invoked
    try {
      proxied.exceptional(exc);
      fail();
    }
    catch (Throwable t) {
      assertSame(exc, t);
    }
View Full Code Here

    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setInterfaces(new Class[] {ITestBean.class});
    ConcurrencyThrottleInterceptor cti = new ConcurrencyThrottleInterceptor();
    proxyFactory.addAdvice(cti);
    proxyFactory.setTarget(tb);
    ITestBean proxy = (ITestBean) proxyFactory.getProxy();
    proxy.getAge();

    ITestBean serializedProxy = (ITestBean) SerializationTestUtils.serializeAndDeserialize(proxy);
    Advised advised = (Advised) serializedProxy;
    ConcurrencyThrottleInterceptor serializedCti =
        (ConcurrencyThrottleInterceptor) advised.getAdvisors()[0].getAdvice();
    assertEquals(cti.getConcurrencyLimit(), serializedCti.getConcurrencyLimit());
    serializedProxy.getAge();
  }
View Full Code Here

  public void testLazyInitSingletonTargetSource() {
    XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("lazyInitSingletonTests.xml", getClass()));
    bf.preInstantiateSingletons();

    ITestBean tb = (ITestBean) bf.getBean("proxy");
    assertFalse(bf.containsSingleton("target"));
    assertEquals(10, tb.getAge());
    assertTrue(bf.containsSingleton("target"));
  }
View Full Code Here

    proxyFactory.setInterfaces(new Class[] {ITestBean.class});
    ConcurrencyThrottleInterceptor cti = new ConcurrencyThrottleInterceptor();
    cti.setConcurrencyLimit(concurrencyLimit);
    proxyFactory.addAdvice(cti);
    proxyFactory.setTarget(tb);
    ITestBean proxy = (ITestBean) proxyFactory.getProxy();

    Thread[] threads = new Thread[NR_OF_THREADS];
    for (int i = 0; i < NR_OF_THREADS; i++) {
      threads[i] = new ConcurrencyTest(proxy, null);
      threads[i].start();
View Full Code Here

  public void testCustomLazyInitSingletonTargetSource() {
    XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("customLazyInitTarget.xml", getClass()));
    bf.preInstantiateSingletons();

    ITestBean tb = (ITestBean) bf.getBean("proxy");
    assertFalse(bf.containsSingleton("target"));
    assertEquals("Rob Harrop", tb.getName());
    assertTrue(bf.containsSingleton("target"));
  }
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.