Package org.springframework.beans

Examples of org.springframework.beans.TestBean


      assertTrue("We have rejected age in exception", ex.getPropertyAccessException("age").getPropertyChangeEvent().getNewValue().equals("34x"));
    }
  }

  public void testGrandparentDefinitionFoundInBeanFactory() throws Exception {
    TestBean dad = (TestBean) getBeanFactory().getBean("father");
    assertTrue("Dad has correct name", dad.getName().equals("Albert"));
  }
View Full Code Here


  }

  public void testFactorySingleton() throws Exception {
    assertTrue(getBeanFactory().isSingleton("&singletonFactory"));
    assertTrue(getBeanFactory().isSingleton("singletonFactory"));
    TestBean tb = (TestBean) getBeanFactory().getBean("singletonFactory");
    assertTrue("Singleton from factory has correct name, not " + tb.getName(), tb.getName().equals(DummyFactory.SINGLETON_NAME));
    DummyFactory factory = (DummyFactory) getBeanFactory().getBean("&singletonFactory");
    TestBean tb2 = (TestBean) getBeanFactory().getBean("singletonFactory");
    assertTrue("Singleton references ==", tb == tb2);
    assertTrue("FactoryBean is BeanFactoryAware", factory.getBeanFactory() != null);
  }
View Full Code Here

  }
 
  public void testFactoryPrototype() throws Exception {
    assertTrue(getBeanFactory().isSingleton("&prototypeFactory"));
    assertFalse(getBeanFactory().isSingleton("prototypeFactory"));
    TestBean tb = (TestBean) getBeanFactory().getBean("prototypeFactory");
    assertTrue(!tb.getName().equals(DummyFactory.SINGLETON_NAME));
    TestBean tb2 = (TestBean) getBeanFactory().getBean("prototypeFactory");
    assertTrue("Prototype references !=", tb != tb2);
  }
View Full Code Here

  /**
   * Check that afterPropertiesSet gets called on factory
   * @throws Exception
   */
  public void testFactoryIsInitialized() throws Exception {
    TestBean tb = (TestBean) getBeanFactory().getBean("singletonFactory");
    DummyFactory factory = (DummyFactory) getBeanFactory().getBean("&singletonFactory");
    assertTrue("Factory was initialized because it implemented InitializingBean", factory.wasInitialized());
  }
View Full Code Here


  public static class TestBeanEditor extends PropertyEditorSupport {

    public void setAsText(String text) {
      TestBean tb = new TestBean();
      StringTokenizer st = new StringTokenizer(text, "_");
      tb.setName(st.nextToken());
      tb.setAge(Integer.parseInt(st.nextToken()));
      setValue(tb);
    }
View Full Code Here

    lbf.registerCustomEditor(Float.class, new CustomNumberEditor(Float.class, nf, true));
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("myFloat", new RuntimeBeanReference("myFloat"));
    lbf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class, pvs));
    lbf.registerSingleton("myFloat", "1,1");
    TestBean testBean = (TestBean) lbf.getBean("testBean");
    assertTrue(testBean.getMyFloat().floatValue() == 1.1f);
  }
View Full Code Here

    pvs.addPropertyValue("myFloat", "1,1");
    ConstructorArgumentValues cav = new ConstructorArgumentValues();
    cav.addIndexedArgumentValue(0, "myName");
    cav.addIndexedArgumentValue(1, "myAge");
    lbf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class, cav, pvs));
    TestBean testBean = (TestBean) lbf.getBean("testBean");
    assertEquals("myName", testBean.getName());
    assertEquals(5, testBean.getAge());
    assertTrue(testBean.getMyFloat().floatValue() == 1.1f);
  }
View Full Code Here

    ac.registerSingleton("configurer", PreferencesPlaceholderConfigurer.class, pvs);
    Preferences.systemRoot().node("mySystemPath").node("mypath").put("myName", "myNameValue");
    Preferences.systemRoot().node("mySystemPath/myotherpath").put("myTouchy", "myTouchyValue");
    Preferences.userRoot().node("myUserPath/myotherpath").put("myTouchy", "myOtherTouchyValue");
    ac.refresh();
    TestBean tb = (TestBean) ac.getBean("tb");
    assertEquals("myNameValue", tb.getName());
    assertEquals(99, tb.getAge());
    assertEquals("myOtherTouchyValue", tb.getTouchy());
    Preferences.userRoot().node("myUserPath/myotherpath").remove("myTouchy");
    Preferences.systemRoot().node("mySystemPath/myotherpath").remove("myTouchy");
    Preferences.systemRoot().node("mySystemPath/mypath").remove("myName");
  }
View Full Code Here

    ConstructorArgumentValues cav = new ConstructorArgumentValues();
    cav.addIndexedArgumentValue(0, "myName");
    cav.addIndexedArgumentValue(1, "myAge");
    lbf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class, cav, pvs));
    lbf.registerSingleton("myFloat", "1,1");
    TestBean testBean = (TestBean) lbf.getBean("testBean");
    assertEquals("myName", testBean.getName());
    assertEquals(5, testBean.getAge());
    assertTrue(testBean.getMyFloat().floatValue() == 1.1f);
  }
View Full Code Here

public abstract class OverrideOneMethod extends MethodReplaceCandidate implements OverrideInterface {

  protected abstract TestBean protectedOverrideSingleton();

  public TestBean getPrototypeDependency(Object someParam) {
    return new TestBean();
  }
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.