Package org.springframework.beans

Examples of org.springframework.beans.TestBean


      RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, pvs);
      lbf.registerBeanDefinition("bean" + i, bd);
    }
    lbf.preInstantiateSingletons();
    for (int i = 0; i < 1000; i++) {
      TestBean bean = (TestBean) lbf.getBean("bean" + i);
      TestBean otherBean = (TestBean) lbf.getBean("bean" + (i < 99 ? i + 1 : 0));
      assertTrue(bean.getSpouse() == otherBean);
    }
  }
View Full Code Here


    rbd.getConstructorArgumentValues().addGenericArgumentValue("99");
    lbf.registerBeanDefinition("test", rbd);
    StopWatch sw = new StopWatch();
    sw.start("prototype");
    for (int i = 0; i < 100000; i++) {
      TestBean tb = (TestBean) lbf.getBean("test");
      assertEquals("juergen", tb.getName());
      assertEquals(99, tb.getAge());
    }
    sw.stop();
    // System.out.println(sw.getTotalTimeMillis());
    assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 3000);
  }
View Full Code Here

    RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class);
    rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
    rbd.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference("spouse"));
    lbf.registerBeanDefinition("test", rbd);
    lbf.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class));
    TestBean spouse = (TestBean) lbf.getBean("spouse");
    StopWatch sw = new StopWatch();
    sw.start("prototype");
    for (int i = 0; i < 100000; i++) {
      TestBean tb = (TestBean) lbf.getBean("test");
      assertSame(spouse, tb.getSpouse());
    }
    sw.stop();
    // System.out.println(sw.getTotalTimeMillis());
    assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
  }
View Full Code Here

    rbd.getPropertyValues().addPropertyValue("age", "99");
    lbf.registerBeanDefinition("test", rbd);
    StopWatch sw = new StopWatch();
    sw.start("prototype");
    for (int i = 0; i < 100000; i++) {
      TestBean tb = (TestBean) lbf.getBean("test");
      assertEquals("juergen", tb.getName());
      assertEquals(99, tb.getAge());
    }
    sw.stop();
    // System.out.println(sw.getTotalTimeMillis());
    assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 3000);
  }
View Full Code Here

    RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class);
    rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
    rbd.getPropertyValues().addPropertyValue("spouse", new RuntimeBeanReference("spouse"));
    lbf.registerBeanDefinition("test", rbd);
    lbf.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class));
    TestBean spouse = (TestBean) lbf.getBean("spouse");
    StopWatch sw = new StopWatch();
    sw.start("prototype");
    for (int i = 0; i < 100000; i++) {
      TestBean tb = (TestBean) lbf.getBean("test");
      assertSame(spouse, tb.getSpouse());
    }
    sw.stop();
    // System.out.println(sw.getTotalTimeMillis());
    assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
  }
View Full Code Here

    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    RootBeanDefinition bd = new RootBeanDefinition(BeanWithDisposableBean.class);
    lbf.registerBeanDefinition("test", bd);
    lbf.addBeanPostProcessor(new BeanPostProcessor() {
      public Object postProcessBeforeInitialization(Object bean, String beanName) {
        return new TestBean();
      }

      public Object postProcessAfterInitialization(Object bean, String beanName) {
        return bean;
      }
View Full Code Here

    RootBeanDefinition bd = new RootBeanDefinition(BeanWithDestroyMethod.class);
    bd.setDestroyMethodName("close");
    lbf.registerBeanDefinition("test", bd);
    lbf.addBeanPostProcessor(new BeanPostProcessor() {
      public Object postProcessBeforeInitialization(Object bean, String beanName) {
        return new TestBean();
      }

      public Object postProcessAfterInitialization(Object bean, String beanName) {
        return bean;
      }
View Full Code Here

    List tbNames = Arrays.asList(lbf.getBeanNamesForType(TestBean.class));
    assertTrue(tbNames.contains("fmWithProperties"));
    assertTrue(tbNames.contains("fmWithArgs"));
    assertEquals(2, tbNames.size());

    TestBean tb = (TestBean) lbf.getBean("fmWithProperties");
    TestBean second = (TestBean) lbf.getBean("fmWithProperties");
    if (singleton) {
      assertSame(tb, second);
    }
    else {
      assertNotSame(tb, second);
    }
    assertEquals(expectedNameFromProperties, tb.getName());

    tb = (TestBean) lbf.getBean("fmGeneric");
    second = (TestBean) lbf.getBean("fmGeneric");
    if (singleton) {
      assertSame(tb, second);
    }
    else {
      assertNotSame(tb, second);
    }
    assertEquals(expectedNameFromProperties, tb.getName());

    TestBean tb2 = (TestBean) lbf.getBean("fmWithArgs");
    second = (TestBean) lbf.getBean("fmWithArgs");
    if (singleton) {
      assertSame(tb2, second);
    }
    else {
      assertNotSame(tb2, second);
    }
    assertEquals(expectedNameFromArgs, tb2.getName());
  }
View Full Code Here

    bd.getPropertyValues().addPropertyValue(new PropertyValue("age", new Integer(ageSetByPropertyValue)));
    lbf.registerBeanDefinition("test", bd);
    final String nameSetOnField = "nameSetOnField";
    lbf.addBeanPostProcessor(new InstantiationAwareBeanPostProcessorAdapter() {
      public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
        TestBean tb = (TestBean) bean;
        try {
          Field f = TestBean.class.getDeclaredField("name");
          f.setAccessible(true);
          f.set(tb, nameSetOnField);
          return !skipPropertyPopulation;
        }
        catch (Exception ex) {
          fail("Unexpected exception: " + ex);
          // Keep compiler happy about return
          throw new IllegalStateException();
        }
      }
    });
    lbf.preInstantiateSingletons();
    TestBean tb = (TestBean) lbf.getBean("test");
    assertEquals("Name was set on field by IAPP", nameSetOnField, tb.getName());
    if (!skipPropertyPopulation) {
      assertEquals("Property value still set", ageSetByPropertyValue, tb.getAge());
    }
    else {
      assertEquals("Property value was NOT set and still has default value", 0, tb.getAge());
    }
  }
View Full Code Here

* @since 10.06.2003
*/
public class CustomEditorTests extends TestCase {

  public void testComplexObject() {
    TestBean tb = new TestBean();
    String newName = "Rod";
    String tbString = "Kerry_34";

    BeanWrapper bw = new BeanWrapperImpl(tb);
    bw.registerCustomEditor(ITestBean.class, new TestBeanEditor());
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue(new PropertyValue("age", new Integer(55)));
    pvs.addPropertyValue(new PropertyValue("name", newName));
    pvs.addPropertyValue(new PropertyValue("touchy", "valid"));
    pvs.addPropertyValue(new PropertyValue("spouse", tbString));
    bw.setPropertyValues(pvs);
    assertTrue("spouse is non-null", tb.getSpouse() != null);
    assertTrue("spouse name is Kerry and age is 34",
        tb.getSpouse().getName().equals("Kerry") && tb.getSpouse().getAge() == 34);
  }
View Full Code Here

TOP

Related Classes of org.springframework.beans.TestBean

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.