Search in sources :

Example 1 with BeanDefinitionBuilder.genericBeanDefinition

use of cn.taketoday.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition in project today-infrastructure by TAKETODAY.

the class PropertyResourceConfigurerTests method testPropertyOverrideConfigurerWithConvertProperties.

@Test
public void testPropertyOverrideConfigurerWithConvertProperties() {
    BeanDefinition def = BeanDefinitionBuilder.genericBeanDefinition(IndexedTestBean.class).getBeanDefinition();
    factory.registerBeanDefinition("tb", def);
    ConvertingOverrideConfigurer bfpp = new ConvertingOverrideConfigurer();
    Properties props = new Properties();
    props.setProperty("tb.array[0].name", "99");
    props.setProperty("tb.list[1].name", "test");
    bfpp.setProperties(props);
    bfpp.postProcessBeanFactory(factory);
    IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb");
    assertThat(tb.getArray()[0].getName()).isEqualTo("X99");
    assertThat(((TestBean) tb.getList().get(1)).getName()).isEqualTo("Xtest");
}
Also used : IndexedTestBean(cn.taketoday.beans.testfixture.beans.IndexedTestBean) IndexedTestBean(cn.taketoday.beans.testfixture.beans.IndexedTestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) ChildBeanDefinition(cn.taketoday.beans.factory.support.ChildBeanDefinition) BeanDefinitionBuilder.genericBeanDefinition(cn.taketoday.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition) Properties(java.util.Properties) Test(org.junit.jupiter.api.Test)

Example 2 with BeanDefinitionBuilder.genericBeanDefinition

use of cn.taketoday.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition in project today-infrastructure by TAKETODAY.

the class PropertyResourceConfigurerTests method testPropertyOverrideConfigurerWithPropertiesFile.

@Test
public void testPropertyOverrideConfigurerWithPropertiesFile() {
    BeanDefinition def = BeanDefinitionBuilder.genericBeanDefinition(IndexedTestBean.class).getBeanDefinition();
    factory.registerBeanDefinition("tb", def);
    PropertyOverrideConfigurer poc = new PropertyOverrideConfigurer();
    poc.setLocation(TEST_PROPS);
    poc.postProcessBeanFactory(factory);
    IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb");
    assertThat(tb.getArray()[0].getAge()).isEqualTo(99);
    assertThat(((TestBean) tb.getList().get(1)).getName()).isEqualTo("test");
}
Also used : IndexedTestBean(cn.taketoday.beans.testfixture.beans.IndexedTestBean) IndexedTestBean(cn.taketoday.beans.testfixture.beans.IndexedTestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) ChildBeanDefinition(cn.taketoday.beans.factory.support.ChildBeanDefinition) BeanDefinitionBuilder.genericBeanDefinition(cn.taketoday.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition) Test(org.junit.jupiter.api.Test)

Example 3 with BeanDefinitionBuilder.genericBeanDefinition

use of cn.taketoday.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition in project today-infrastructure by TAKETODAY.

the class PropertyResourceConfigurerTests method testPropertyOverrideConfigurerWithNestedPropertyAndDotInBeanName.

@Test
public void testPropertyOverrideConfigurerWithNestedPropertyAndDotInBeanName() {
    BeanDefinition def = BeanDefinitionBuilder.genericBeanDefinition(IndexedTestBean.class).getBeanDefinition();
    factory.registerBeanDefinition("my.tb", def);
    PropertyOverrideConfigurer poc;
    poc = new PropertyOverrideConfigurer();
    Properties props = new Properties();
    props.setProperty("my.tb_array[0].age", "99");
    props.setProperty("my.tb_list[1].name", "test");
    poc.setProperties(props);
    poc.setBeanNameSeparator("_");
    poc.postProcessBeanFactory(factory);
    IndexedTestBean tb = (IndexedTestBean) factory.getBean("my.tb");
    assertThat(tb.getArray()[0].getAge()).isEqualTo(99);
    assertThat(((TestBean) tb.getList().get(1)).getName()).isEqualTo("test");
}
Also used : IndexedTestBean(cn.taketoday.beans.testfixture.beans.IndexedTestBean) IndexedTestBean(cn.taketoday.beans.testfixture.beans.IndexedTestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) ChildBeanDefinition(cn.taketoday.beans.factory.support.ChildBeanDefinition) BeanDefinitionBuilder.genericBeanDefinition(cn.taketoday.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition) Properties(java.util.Properties) Test(org.junit.jupiter.api.Test)

Example 4 with BeanDefinitionBuilder.genericBeanDefinition

use of cn.taketoday.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition in project today-infrastructure by TAKETODAY.

the class PropertyResourceConfigurerTests method testPropertyOverrideConfigurerWithInvalidPropertiesFile.

@Test
public void testPropertyOverrideConfigurerWithInvalidPropertiesFile() {
    BeanDefinition def = BeanDefinitionBuilder.genericBeanDefinition(IndexedTestBean.class).getBeanDefinition();
    factory.registerBeanDefinition("tb", def);
    PropertyOverrideConfigurer poc = new PropertyOverrideConfigurer();
    poc.setLocations(TEST_PROPS, XTEST_PROPS);
    poc.setIgnoreResourceNotFound(true);
    poc.postProcessBeanFactory(factory);
    IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb");
    assertThat(tb.getArray()[0].getAge()).isEqualTo(99);
    assertThat(((TestBean) tb.getList().get(1)).getName()).isEqualTo("test");
}
Also used : IndexedTestBean(cn.taketoday.beans.testfixture.beans.IndexedTestBean) IndexedTestBean(cn.taketoday.beans.testfixture.beans.IndexedTestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) ChildBeanDefinition(cn.taketoday.beans.factory.support.ChildBeanDefinition) BeanDefinitionBuilder.genericBeanDefinition(cn.taketoday.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition) Test(org.junit.jupiter.api.Test)

Example 5 with BeanDefinitionBuilder.genericBeanDefinition

use of cn.taketoday.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition in project today-infrastructure by TAKETODAY.

the class PropertyResourceConfigurerTests method testPropertyOverrideConfigurerWithPropertiesXmlFile.

@Test
public void testPropertyOverrideConfigurerWithPropertiesXmlFile() {
    BeanDefinition def = BeanDefinitionBuilder.genericBeanDefinition(IndexedTestBean.class).getBeanDefinition();
    factory.registerBeanDefinition("tb", def);
    PropertyOverrideConfigurer poc = new PropertyOverrideConfigurer();
    poc.setLocation(TEST_PROPS_XML);
    poc.postProcessBeanFactory(factory);
    IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb");
    assertThat(tb.getArray()[0].getAge()).isEqualTo(99);
    assertThat(((TestBean) tb.getList().get(1)).getName()).isEqualTo("test");
}
Also used : IndexedTestBean(cn.taketoday.beans.testfixture.beans.IndexedTestBean) IndexedTestBean(cn.taketoday.beans.testfixture.beans.IndexedTestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) ChildBeanDefinition(cn.taketoday.beans.factory.support.ChildBeanDefinition) BeanDefinitionBuilder.genericBeanDefinition(cn.taketoday.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

BeanDefinitionBuilder.genericBeanDefinition (cn.taketoday.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition)27 ChildBeanDefinition (cn.taketoday.beans.factory.support.ChildBeanDefinition)27 RootBeanDefinition (cn.taketoday.beans.factory.support.RootBeanDefinition)27 Test (org.junit.jupiter.api.Test)27 IndexedTestBean (cn.taketoday.beans.testfixture.beans.IndexedTestBean)24 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)21 Properties (java.util.Properties)18 BeanDefinition (cn.taketoday.beans.factory.config.BeanDefinition)9 PropertyOverrideConfigurer (cn.taketoday.beans.factory.config.PropertyOverrideConfigurer)8