Package org.springframework.beans

Examples of org.springframework.beans.TestBean


    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, new MutablePropertyValues());
    lbf.registerBeanDefinition("spouse", bd);
    DependenciesBean existingBean = new DependenciesBean();
    lbf.autowireBeanProperties(existingBean, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, true);
    TestBean spouse = (TestBean) lbf.getBean("spouse");
    assertEquals(existingBean.getSpouse(), spouse);
    assertSame(spouse, BeanFactoryUtils.beanOfType(lbf, TestBean.class));
  }
View Full Code Here


    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, new MutablePropertyValues());
    lbf.registerBeanDefinition("test", bd);
    DependenciesBean existingBean = new DependenciesBean();
    lbf.autowireBeanProperties(existingBean, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
    TestBean test = (TestBean) lbf.getBean("test");
    assertEquals(existingBean.getSpouse(), test);
  }
View Full Code Here

  }

  public void testInvalidAutowireMode() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    try {
      lbf.autowireBeanProperties(new TestBean(), AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false);
      fail("Should have thrown IllegalArgumentException");
    }
    catch (IllegalArgumentException expected) {
    }
  }
View Full Code Here

  public void testApplyBeanPropertyValues() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("age", "99");
    lbf.registerBeanDefinition("test", new RootBeanDefinition(TestBean.class, pvs));
    TestBean tb = new TestBean();
    assertEquals(0, tb.getAge());
    lbf.applyBeanPropertyValues(tb, "test");
    assertEquals(99, tb.getAge());
  }
View Full Code Here

  public void testApplyBeanPropertyValuesWithIncompleteDefinition() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("age", "99");
    lbf.registerBeanDefinition("test", new RootBeanDefinition(null, pvs));
    TestBean tb = new TestBean();
    assertEquals(0, tb.getAge());
    lbf.applyBeanPropertyValues(tb, "test");
    assertEquals(99, tb.getAge());
    assertNull(tb.getBeanFactory());
    assertNull(tb.getSpouse());
  }
View Full Code Here

    this.reader = new PropertiesBeanDefinitionReader(beanFactory);
  }

  public void testWithSimpleConstructorArg() {
    this.reader.loadBeanDefinitions(new ClassPathResource("simpleConstructorArg.properties", getClass()));
    TestBean bean = (TestBean)this.beanFactory.getBean("testBean");
    assertEquals("Rob Harrop", bean.getName());
  }
View Full Code Here

    assertEquals("Rob Harrop", bean.getName());
  }

  public void testWithConstructorArgRef() throws Exception {
    this.reader.loadBeanDefinitions(new ClassPathResource("refConstructorArg.properties", getClass()));
    TestBean rob = (TestBean)this.beanFactory.getBean("rob");
    TestBean sally = (TestBean)this.beanFactory.getBean("sally");
    assertEquals(sally, rob.getSpouse());
  }
View Full Code Here

    assertEquals(sally, rob.getSpouse());
  }

  public void testWithMultipleConstructorsArgs() throws Exception {
    this.reader.loadBeanDefinitions(new ClassPathResource("multiConstructorArgs.properties", getClass()));
    TestBean bean = (TestBean)this.beanFactory.getBean("testBean");
    assertEquals("Rob Harrop", bean.getName());
    assertEquals(23, bean.getAge());
  }
View Full Code Here

  public void testConfigureBean() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("age", "99");
    lbf.registerBeanDefinition("test", new RootBeanDefinition(TestBean.class, pvs));
    TestBean tb = new TestBean();
    assertEquals(0, tb.getAge());
    lbf.configureBean(tb, "test");
    assertEquals(99, tb.getAge());
    assertSame(lbf, tb.getBeanFactory());
    assertNull(tb.getSpouse());
  }
View Full Code Here

    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, new MutablePropertyValues());
    lbf.registerBeanDefinition("spouse", bd);
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("age", "99");
    lbf.registerBeanDefinition("test", new RootBeanDefinition(TestBean.class, RootBeanDefinition.AUTOWIRE_BY_NAME));
    TestBean tb = new TestBean();
    lbf.configureBean(tb, "test");
    assertSame(lbf, tb.getBeanFactory());
    TestBean spouse = (TestBean) lbf.getBean("spouse");
    assertEquals(spouse, tb.getSpouse());
  }
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.