Package org.springframework.tests.sample.beans

Examples of org.springframework.tests.sample.beans.TestBean


      return TestBean.class.isAssignableFrom(clazz);
    }

    @Override
    public void validate(Object obj, Errors errors) {
      TestBean tb = (TestBean) obj;
      if (tb == null || "XXX".equals(tb.getName())) {
        errors.rejectValue("", "SPOUSE_NOT_AVAILABLE");
        return;
      }
      if (tb.getAge() < 32) {
        errors.rejectValue("age", "TOO_YOUNG", "simply too young");
      }
    }
View Full Code Here


  @Test
  public void innerBeanConfigured() throws Exception {
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(
        new ClassPathResource("simplePropertyNamespaceHandlerTests.xml", getClass()));
    TestBean sally = (TestBean) beanFactory.getBean("sally2");
    ITestBean rob = sally.getSpouse();
    assertEquals("Rob Harrop", rob.getName());
    assertEquals(24, rob.getAge());
    assertEquals(rob.getSpouse(), sally);
  }
View Full Code Here

  public String getFactoryBeanProperty() {
    return this.factoryBeanProperty;
  }

  public FactoryMethods defaultInstance() {
    TestBean tb = new TestBean();
    tb.setName(this.factoryBeanProperty);
    return FactoryMethods.newInstance(tb);
  }
View Full Code Here

      .addPropertyValue("name", "${"+P1+"}")
      .addPropertyValue("sex", "${otherKey}")
      .getBeanDefinition();
    registerWithGeneratedName(p1BeanDef, bf);
    ppc.postProcessBeanFactory(bf);
    TestBean bean = bf.getBean(TestBean.class);
    assertThat(bean.getName(), equalTo(P1_LOCAL_PROPS_VAL));
    assertThat(bean.getSex(), equalTo("systemValue"));
    getModifiableSystemEnvironment().remove("otherKey");
  }
View Full Code Here

  @Test
  public void resolveFromLocalProperties() {
    tearDown(); // eliminate entries from system props/environment
    registerWithGeneratedName(p1BeanDef, bf);
    ppc.postProcessBeanFactory(bf);
    TestBean bean = bf.getBean(TestBean.class);
    assertThat(bean.getName(), equalTo(P1_LOCAL_PROPS_VAL));
  }
View Full Code Here

  @Test
  public void setSystemPropertiesMode_defaultIsFallback() {
    registerWithGeneratedName(p1BeanDef, bf);
    ppc.postProcessBeanFactory(bf);
    TestBean bean = bf.getBean(TestBean.class);
    assertThat(bean.getName(), equalTo(P1_LOCAL_PROPS_VAL));
  }
View Full Code Here

  @Test
  public void setSystemSystemPropertiesMode_toOverride_andResolveFromSystemProperties() {
    registerWithGeneratedName(p1BeanDef, bf);
    ppc.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE);
    ppc.postProcessBeanFactory(bf);
    TestBean bean = bf.getBean(TestBean.class);
    assertThat(bean.getName(), equalTo(P1_SYSTEM_PROPS_VAL));
  }
View Full Code Here

  public void setSystemSystemPropertiesMode_toOverride_andResolveFromSystemEnvironment() {
    registerWithGeneratedName(p1BeanDef, bf);
    System.clearProperty(P1); // will now fall all the way back to system environment
    ppc.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE);
    ppc.postProcessBeanFactory(bf);
    TestBean bean = bf.getBean(TestBean.class);
    assertThat(bean.getName(), equalTo(P1_SYSTEM_ENV_VAL));
  }
View Full Code Here

    registerWithGeneratedName(p1BeanDef, bf);
    System.clearProperty(P1); // will now fall all the way back to system environment
    ppc.setSearchSystemEnvironment(false);
    ppc.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE);
    ppc.postProcessBeanFactory(bf);
    TestBean bean = bf.getBean(TestBean.class);
    assertThat(bean.getName(), equalTo(P1_LOCAL_PROPS_VAL)); // has to resort to local props
  }
View Full Code Here

    DataBinder binder = new DataBinder(rod, "person");
    binder.initDirectFieldAccess();
    binder.registerCustomEditor(TestBean.class, "spouse", new PropertyEditorSupport() {
      @Override
      public void setAsText(String text) throws IllegalArgumentException {
        setValue(new TestBean(text, 0));
      }
      @Override
      public String getAsText() {
        return ((TestBean) getValue()).getName();
      }
View Full Code Here

TOP

Related Classes of org.springframework.tests.sample.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.