|
|
|
@ -53,9 +53,9 @@ import org.springframework.core.io.Resource; |
|
|
|
* @author Chris Beams |
|
|
|
* @author Chris Beams |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class PropertyResourceConfigurerTests { |
|
|
|
public class PropertyResourceConfigurerTests { |
|
|
|
|
|
|
|
|
|
|
|
private DefaultListableBeanFactory factory; |
|
|
|
private DefaultListableBeanFactory factory; |
|
|
|
|
|
|
|
|
|
|
|
@Before |
|
|
|
@Before |
|
|
|
public void setUp() { |
|
|
|
public void setUp() { |
|
|
|
factory = new DefaultListableBeanFactory(); |
|
|
|
factory = new DefaultListableBeanFactory(); |
|
|
|
@ -67,15 +67,15 @@ public class PropertyResourceConfigurerTests { |
|
|
|
.genericBeanDefinition(TestBean.class) |
|
|
|
.genericBeanDefinition(TestBean.class) |
|
|
|
.getBeanDefinition(); |
|
|
|
.getBeanDefinition(); |
|
|
|
factory.registerBeanDefinition("tb1", def1); |
|
|
|
factory.registerBeanDefinition("tb1", def1); |
|
|
|
|
|
|
|
|
|
|
|
BeanDefinition def2 = BeanDefinitionBuilder |
|
|
|
BeanDefinition def2 = BeanDefinitionBuilder |
|
|
|
.genericBeanDefinition(TestBean.class) |
|
|
|
.genericBeanDefinition(TestBean.class) |
|
|
|
.getBeanDefinition(); |
|
|
|
.getBeanDefinition(); |
|
|
|
factory.registerBeanDefinition("tb2", def2); |
|
|
|
factory.registerBeanDefinition("tb2", def2); |
|
|
|
|
|
|
|
|
|
|
|
PropertyOverrideConfigurer poc1; |
|
|
|
PropertyOverrideConfigurer poc1; |
|
|
|
PropertyOverrideConfigurer poc2; |
|
|
|
PropertyOverrideConfigurer poc2; |
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
poc1 = new PropertyOverrideConfigurer(); |
|
|
|
poc1 = new PropertyOverrideConfigurer(); |
|
|
|
Properties props = new Properties(); |
|
|
|
Properties props = new Properties(); |
|
|
|
@ -83,7 +83,7 @@ public class PropertyResourceConfigurerTests { |
|
|
|
props.setProperty("tb2.name", "test"); |
|
|
|
props.setProperty("tb2.name", "test"); |
|
|
|
poc1.setProperties(props); |
|
|
|
poc1.setProperties(props); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
poc2 = new PropertyOverrideConfigurer(); |
|
|
|
poc2 = new PropertyOverrideConfigurer(); |
|
|
|
Properties props = new Properties(); |
|
|
|
Properties props = new Properties(); |
|
|
|
@ -91,14 +91,14 @@ public class PropertyResourceConfigurerTests { |
|
|
|
props.setProperty("tb2.name", "test2"); |
|
|
|
props.setProperty("tb2.name", "test2"); |
|
|
|
poc2.setProperties(props); |
|
|
|
poc2.setProperties(props); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// emulate what happens when BFPPs are added to an application context: It's LIFO-based
|
|
|
|
// emulate what happens when BFPPs are added to an application context: It's LIFO-based
|
|
|
|
poc2.postProcessBeanFactory(factory); |
|
|
|
poc2.postProcessBeanFactory(factory); |
|
|
|
poc1.postProcessBeanFactory(factory); |
|
|
|
poc1.postProcessBeanFactory(factory); |
|
|
|
|
|
|
|
|
|
|
|
TestBean tb1 = (TestBean) factory.getBean("tb1"); |
|
|
|
TestBean tb1 = (TestBean) factory.getBean("tb1"); |
|
|
|
TestBean tb2 = (TestBean) factory.getBean("tb2"); |
|
|
|
TestBean tb2 = (TestBean) factory.getBean("tb2"); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals(99, tb1.getAge()); |
|
|
|
assertEquals(99, tb1.getAge()); |
|
|
|
assertEquals(99, tb2.getAge()); |
|
|
|
assertEquals(99, tb2.getAge()); |
|
|
|
assertEquals(null, tb1.getName()); |
|
|
|
assertEquals(null, tb1.getName()); |
|
|
|
@ -111,7 +111,7 @@ public class PropertyResourceConfigurerTests { |
|
|
|
.genericBeanDefinition(IndexedTestBean.class) |
|
|
|
.genericBeanDefinition(IndexedTestBean.class) |
|
|
|
.getBeanDefinition(); |
|
|
|
.getBeanDefinition(); |
|
|
|
factory.registerBeanDefinition("tb", def); |
|
|
|
factory.registerBeanDefinition("tb", def); |
|
|
|
|
|
|
|
|
|
|
|
PropertyOverrideConfigurer poc; |
|
|
|
PropertyOverrideConfigurer poc; |
|
|
|
poc = new PropertyOverrideConfigurer(); |
|
|
|
poc = new PropertyOverrideConfigurer(); |
|
|
|
Properties props = new Properties(); |
|
|
|
Properties props = new Properties(); |
|
|
|
@ -119,7 +119,7 @@ public class PropertyResourceConfigurerTests { |
|
|
|
props.setProperty("tb.list[1].name", "test"); |
|
|
|
props.setProperty("tb.list[1].name", "test"); |
|
|
|
poc.setProperties(props); |
|
|
|
poc.setProperties(props); |
|
|
|
poc.postProcessBeanFactory(factory); |
|
|
|
poc.postProcessBeanFactory(factory); |
|
|
|
|
|
|
|
|
|
|
|
IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb"); |
|
|
|
IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb"); |
|
|
|
assertEquals(99, tb.getArray()[0].getAge()); |
|
|
|
assertEquals(99, tb.getArray()[0].getAge()); |
|
|
|
assertEquals("test", ((TestBean) tb.getList().get(1)).getName()); |
|
|
|
assertEquals("test", ((TestBean) tb.getList().get(1)).getName()); |
|
|
|
@ -131,7 +131,7 @@ public class PropertyResourceConfigurerTests { |
|
|
|
.genericBeanDefinition(IndexedTestBean.class) |
|
|
|
.genericBeanDefinition(IndexedTestBean.class) |
|
|
|
.getBeanDefinition(); |
|
|
|
.getBeanDefinition(); |
|
|
|
factory.registerBeanDefinition("my.tb", def); |
|
|
|
factory.registerBeanDefinition("my.tb", def); |
|
|
|
|
|
|
|
|
|
|
|
PropertyOverrideConfigurer poc; |
|
|
|
PropertyOverrideConfigurer poc; |
|
|
|
poc = new PropertyOverrideConfigurer(); |
|
|
|
poc = new PropertyOverrideConfigurer(); |
|
|
|
Properties props = new Properties(); |
|
|
|
Properties props = new Properties(); |
|
|
|
@ -140,7 +140,7 @@ public class PropertyResourceConfigurerTests { |
|
|
|
poc.setProperties(props); |
|
|
|
poc.setProperties(props); |
|
|
|
poc.setBeanNameSeparator("_"); |
|
|
|
poc.setBeanNameSeparator("_"); |
|
|
|
poc.postProcessBeanFactory(factory); |
|
|
|
poc.postProcessBeanFactory(factory); |
|
|
|
|
|
|
|
|
|
|
|
IndexedTestBean tb = (IndexedTestBean) factory.getBean("my.tb"); |
|
|
|
IndexedTestBean tb = (IndexedTestBean) factory.getBean("my.tb"); |
|
|
|
assertEquals(99, tb.getArray()[0].getAge()); |
|
|
|
assertEquals(99, tb.getArray()[0].getAge()); |
|
|
|
assertEquals("test", ((TestBean) tb.getList().get(1)).getName()); |
|
|
|
assertEquals("test", ((TestBean) tb.getList().get(1)).getName()); |
|
|
|
@ -152,7 +152,7 @@ public class PropertyResourceConfigurerTests { |
|
|
|
.genericBeanDefinition(IndexedTestBean.class) |
|
|
|
.genericBeanDefinition(IndexedTestBean.class) |
|
|
|
.getBeanDefinition(); |
|
|
|
.getBeanDefinition(); |
|
|
|
factory.registerBeanDefinition("tb", def); |
|
|
|
factory.registerBeanDefinition("tb", def); |
|
|
|
|
|
|
|
|
|
|
|
PropertyOverrideConfigurer poc; |
|
|
|
PropertyOverrideConfigurer poc; |
|
|
|
poc = new PropertyOverrideConfigurer(); |
|
|
|
poc = new PropertyOverrideConfigurer(); |
|
|
|
Properties props = new Properties(); |
|
|
|
Properties props = new Properties(); |
|
|
|
@ -160,40 +160,40 @@ public class PropertyResourceConfigurerTests { |
|
|
|
props.setProperty("tb.map[key2.ext]", "test"); |
|
|
|
props.setProperty("tb.map[key2.ext]", "test"); |
|
|
|
poc.setProperties(props); |
|
|
|
poc.setProperties(props); |
|
|
|
poc.postProcessBeanFactory(factory); |
|
|
|
poc.postProcessBeanFactory(factory); |
|
|
|
|
|
|
|
|
|
|
|
IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb"); |
|
|
|
IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb"); |
|
|
|
assertEquals("99", tb.getMap().get("key1")); |
|
|
|
assertEquals("99", tb.getMap().get("key1")); |
|
|
|
assertEquals("test", tb.getMap().get("key2.ext")); |
|
|
|
assertEquals("test", tb.getMap().get("key2.ext")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testPropertyOverrideConfigurerWithHeldProperties() { |
|
|
|
public void testPropertyOverrideConfigurerWithHeldProperties() { |
|
|
|
BeanDefinition def = BeanDefinitionBuilder |
|
|
|
BeanDefinition def = BeanDefinitionBuilder |
|
|
|
.genericBeanDefinition(PropertiesHolder.class) |
|
|
|
.genericBeanDefinition(PropertiesHolder.class) |
|
|
|
.getBeanDefinition(); |
|
|
|
.getBeanDefinition(); |
|
|
|
factory.registerBeanDefinition("tb", def); |
|
|
|
factory.registerBeanDefinition("tb", def); |
|
|
|
|
|
|
|
|
|
|
|
PropertyOverrideConfigurer poc; |
|
|
|
PropertyOverrideConfigurer poc; |
|
|
|
poc = new PropertyOverrideConfigurer(); |
|
|
|
poc = new PropertyOverrideConfigurer(); |
|
|
|
Properties props = new Properties(); |
|
|
|
Properties props = new Properties(); |
|
|
|
props.setProperty("tb.heldProperties[mail.smtp.auth]", "true"); |
|
|
|
props.setProperty("tb.heldProperties[mail.smtp.auth]", "true"); |
|
|
|
poc.setProperties(props); |
|
|
|
poc.setProperties(props); |
|
|
|
poc.postProcessBeanFactory(factory); |
|
|
|
poc.postProcessBeanFactory(factory); |
|
|
|
|
|
|
|
|
|
|
|
PropertiesHolder tb = (PropertiesHolder) factory.getBean("tb"); |
|
|
|
PropertiesHolder tb = (PropertiesHolder) factory.getBean("tb"); |
|
|
|
assertEquals("true", tb.getHeldProperties().getProperty("mail.smtp.auth")); |
|
|
|
assertEquals("true", tb.getHeldProperties().getProperty("mail.smtp.auth")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static class PropertiesHolder { |
|
|
|
static class PropertiesHolder { |
|
|
|
private Properties props = new Properties(); |
|
|
|
private Properties props = new Properties(); |
|
|
|
|
|
|
|
|
|
|
|
public Properties getHeldProperties() { |
|
|
|
public Properties getHeldProperties() { |
|
|
|
return props; |
|
|
|
return props; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setHeldProperties(Properties props) { |
|
|
|
public void setHeldProperties(Properties props) { |
|
|
|
this.props = props; |
|
|
|
this.props = props; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -202,11 +202,11 @@ public class PropertyResourceConfigurerTests { |
|
|
|
.genericBeanDefinition(IndexedTestBean.class) |
|
|
|
.genericBeanDefinition(IndexedTestBean.class) |
|
|
|
.getBeanDefinition(); |
|
|
|
.getBeanDefinition(); |
|
|
|
factory.registerBeanDefinition("tb", def); |
|
|
|
factory.registerBeanDefinition("tb", def); |
|
|
|
|
|
|
|
|
|
|
|
PropertyOverrideConfigurer poc = new PropertyOverrideConfigurer(); |
|
|
|
PropertyOverrideConfigurer poc = new PropertyOverrideConfigurer(); |
|
|
|
poc.setLocation(new ClassPathResource("org/springframework/beans/factory/config/test.properties")); |
|
|
|
poc.setLocation(new ClassPathResource("org/springframework/beans/factory/config/test.properties")); |
|
|
|
poc.postProcessBeanFactory(factory); |
|
|
|
poc.postProcessBeanFactory(factory); |
|
|
|
|
|
|
|
|
|
|
|
IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb"); |
|
|
|
IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb"); |
|
|
|
assertEquals(99, tb.getArray()[0].getAge()); |
|
|
|
assertEquals(99, tb.getArray()[0].getAge()); |
|
|
|
assertEquals("test", ((TestBean) tb.getList().get(1)).getName()); |
|
|
|
assertEquals("test", ((TestBean) tb.getList().get(1)).getName()); |
|
|
|
@ -218,7 +218,7 @@ public class PropertyResourceConfigurerTests { |
|
|
|
.genericBeanDefinition(IndexedTestBean.class) |
|
|
|
.genericBeanDefinition(IndexedTestBean.class) |
|
|
|
.getBeanDefinition(); |
|
|
|
.getBeanDefinition(); |
|
|
|
factory.registerBeanDefinition("tb", def); |
|
|
|
factory.registerBeanDefinition("tb", def); |
|
|
|
|
|
|
|
|
|
|
|
PropertyOverrideConfigurer poc = new PropertyOverrideConfigurer(); |
|
|
|
PropertyOverrideConfigurer poc = new PropertyOverrideConfigurer(); |
|
|
|
poc.setLocations(new Resource[] { |
|
|
|
poc.setLocations(new Resource[] { |
|
|
|
new ClassPathResource("org/springframework/beans/factory/config/test.properties"), |
|
|
|
new ClassPathResource("org/springframework/beans/factory/config/test.properties"), |
|
|
|
@ -227,7 +227,7 @@ public class PropertyResourceConfigurerTests { |
|
|
|
); |
|
|
|
); |
|
|
|
poc.setIgnoreResourceNotFound(true); |
|
|
|
poc.setIgnoreResourceNotFound(true); |
|
|
|
poc.postProcessBeanFactory(factory); |
|
|
|
poc.postProcessBeanFactory(factory); |
|
|
|
|
|
|
|
|
|
|
|
IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb"); |
|
|
|
IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb"); |
|
|
|
assertEquals(99, tb.getArray()[0].getAge()); |
|
|
|
assertEquals(99, tb.getArray()[0].getAge()); |
|
|
|
assertEquals("test", ((TestBean) tb.getList().get(1)).getName()); |
|
|
|
assertEquals("test", ((TestBean) tb.getList().get(1)).getName()); |
|
|
|
@ -239,11 +239,11 @@ public class PropertyResourceConfigurerTests { |
|
|
|
.genericBeanDefinition(IndexedTestBean.class) |
|
|
|
.genericBeanDefinition(IndexedTestBean.class) |
|
|
|
.getBeanDefinition(); |
|
|
|
.getBeanDefinition(); |
|
|
|
factory.registerBeanDefinition("tb", def); |
|
|
|
factory.registerBeanDefinition("tb", def); |
|
|
|
|
|
|
|
|
|
|
|
PropertyOverrideConfigurer poc = new PropertyOverrideConfigurer(); |
|
|
|
PropertyOverrideConfigurer poc = new PropertyOverrideConfigurer(); |
|
|
|
poc.setLocation(new ClassPathResource("org/springframework/beans/factory/config/test-properties.xml")); |
|
|
|
poc.setLocation(new ClassPathResource("org/springframework/beans/factory/config/test-properties.xml")); |
|
|
|
poc.postProcessBeanFactory(factory); |
|
|
|
poc.postProcessBeanFactory(factory); |
|
|
|
|
|
|
|
|
|
|
|
IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb"); |
|
|
|
IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb"); |
|
|
|
assertEquals(99, tb.getArray()[0].getAge()); |
|
|
|
assertEquals(99, tb.getArray()[0].getAge()); |
|
|
|
assertEquals("test", ((TestBean) tb.getList().get(1)).getName()); |
|
|
|
assertEquals("test", ((TestBean) tb.getList().get(1)).getName()); |
|
|
|
@ -255,14 +255,14 @@ public class PropertyResourceConfigurerTests { |
|
|
|
.genericBeanDefinition(IndexedTestBean.class) |
|
|
|
.genericBeanDefinition(IndexedTestBean.class) |
|
|
|
.getBeanDefinition(); |
|
|
|
.getBeanDefinition(); |
|
|
|
factory.registerBeanDefinition("tb", def); |
|
|
|
factory.registerBeanDefinition("tb", def); |
|
|
|
|
|
|
|
|
|
|
|
ConvertingOverrideConfigurer bfpp = new ConvertingOverrideConfigurer(); |
|
|
|
ConvertingOverrideConfigurer bfpp = new ConvertingOverrideConfigurer(); |
|
|
|
Properties props = new Properties(); |
|
|
|
Properties props = new Properties(); |
|
|
|
props.setProperty("tb.array[0].name", "99"); |
|
|
|
props.setProperty("tb.array[0].name", "99"); |
|
|
|
props.setProperty("tb.list[1].name", "test"); |
|
|
|
props.setProperty("tb.list[1].name", "test"); |
|
|
|
bfpp.setProperties(props); |
|
|
|
bfpp.setProperties(props); |
|
|
|
bfpp.postProcessBeanFactory(factory); |
|
|
|
bfpp.postProcessBeanFactory(factory); |
|
|
|
|
|
|
|
|
|
|
|
IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb"); |
|
|
|
IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb"); |
|
|
|
assertEquals("X99", tb.getArray()[0].getName()); |
|
|
|
assertEquals("X99", tb.getArray()[0].getName()); |
|
|
|
assertEquals("Xtest", ((TestBean) tb.getList().get(1)).getName()); |
|
|
|
assertEquals("Xtest", ((TestBean) tb.getList().get(1)).getName()); |
|
|
|
@ -272,7 +272,7 @@ public class PropertyResourceConfigurerTests { |
|
|
|
public void testPropertyOverrideConfigurerWithInvalidKey() { |
|
|
|
public void testPropertyOverrideConfigurerWithInvalidKey() { |
|
|
|
factory.registerBeanDefinition("tb1", genericBeanDefinition(TestBean.class).getBeanDefinition()); |
|
|
|
factory.registerBeanDefinition("tb1", genericBeanDefinition(TestBean.class).getBeanDefinition()); |
|
|
|
factory.registerBeanDefinition("tb2", genericBeanDefinition(TestBean.class).getBeanDefinition()); |
|
|
|
factory.registerBeanDefinition("tb2", genericBeanDefinition(TestBean.class).getBeanDefinition()); |
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
PropertyOverrideConfigurer poc = new PropertyOverrideConfigurer(); |
|
|
|
PropertyOverrideConfigurer poc = new PropertyOverrideConfigurer(); |
|
|
|
poc.setIgnoreInvalidKeys(true); |
|
|
|
poc.setIgnoreInvalidKeys(true); |
|
|
|
@ -303,7 +303,7 @@ public class PropertyResourceConfigurerTests { |
|
|
|
public void testPropertyOverrideConfigurerWithIgnoreInvalidKeys() { |
|
|
|
public void testPropertyOverrideConfigurerWithIgnoreInvalidKeys() { |
|
|
|
factory.registerBeanDefinition("tb1", genericBeanDefinition(TestBean.class).getBeanDefinition()); |
|
|
|
factory.registerBeanDefinition("tb1", genericBeanDefinition(TestBean.class).getBeanDefinition()); |
|
|
|
factory.registerBeanDefinition("tb2", genericBeanDefinition(TestBean.class).getBeanDefinition()); |
|
|
|
factory.registerBeanDefinition("tb2", genericBeanDefinition(TestBean.class).getBeanDefinition()); |
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
PropertyOverrideConfigurer poc = new PropertyOverrideConfigurer(); |
|
|
|
PropertyOverrideConfigurer poc = new PropertyOverrideConfigurer(); |
|
|
|
Properties props = new Properties(); |
|
|
|
Properties props = new Properties(); |
|
|
|
@ -323,7 +323,7 @@ public class PropertyResourceConfigurerTests { |
|
|
|
poc.setProperties(props); |
|
|
|
poc.setProperties(props); |
|
|
|
poc.postProcessBeanFactory(factory); |
|
|
|
poc.postProcessBeanFactory(factory); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TestBean tb1 = (TestBean) factory.getBean("tb1"); |
|
|
|
TestBean tb1 = (TestBean) factory.getBean("tb1"); |
|
|
|
TestBean tb2 = (TestBean) factory.getBean("tb2"); |
|
|
|
TestBean tb2 = (TestBean) factory.getBean("tb2"); |
|
|
|
assertEquals(99, tb1.getAge()); |
|
|
|
assertEquals(99, tb1.getAge()); |
|
|
|
@ -440,7 +440,7 @@ public class PropertyResourceConfigurerTests { |
|
|
|
factory.registerBeanDefinition("tb", |
|
|
|
factory.registerBeanDefinition("tb", |
|
|
|
genericBeanDefinition(TestBean.class) |
|
|
|
genericBeanDefinition(TestBean.class) |
|
|
|
.addPropertyValue("touchy", "${os.name}").getBeanDefinition()); |
|
|
|
.addPropertyValue("touchy", "${os.name}").getBeanDefinition()); |
|
|
|
|
|
|
|
|
|
|
|
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); |
|
|
|
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); |
|
|
|
ppc.postProcessBeanFactory(factory); |
|
|
|
ppc.postProcessBeanFactory(factory); |
|
|
|
|
|
|
|
|
|
|
|
@ -453,13 +453,13 @@ public class PropertyResourceConfigurerTests { |
|
|
|
factory.registerBeanDefinition("tb", |
|
|
|
factory.registerBeanDefinition("tb", |
|
|
|
genericBeanDefinition(TestBean.class) |
|
|
|
genericBeanDefinition(TestBean.class) |
|
|
|
.addPropertyValue("touchy", "${os.name}").getBeanDefinition()); |
|
|
|
.addPropertyValue("touchy", "${os.name}").getBeanDefinition()); |
|
|
|
|
|
|
|
|
|
|
|
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); |
|
|
|
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); |
|
|
|
Properties props = new Properties(); |
|
|
|
Properties props = new Properties(); |
|
|
|
props.setProperty("os.name", "myos"); |
|
|
|
props.setProperty("os.name", "myos"); |
|
|
|
ppc.setProperties(props); |
|
|
|
ppc.setProperties(props); |
|
|
|
ppc.postProcessBeanFactory(factory); |
|
|
|
ppc.postProcessBeanFactory(factory); |
|
|
|
|
|
|
|
|
|
|
|
TestBean tb = (TestBean) factory.getBean("tb"); |
|
|
|
TestBean tb = (TestBean) factory.getBean("tb"); |
|
|
|
assertEquals("myos", tb.getTouchy()); |
|
|
|
assertEquals("myos", tb.getTouchy()); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -469,14 +469,14 @@ public class PropertyResourceConfigurerTests { |
|
|
|
factory.registerBeanDefinition("tb", |
|
|
|
factory.registerBeanDefinition("tb", |
|
|
|
genericBeanDefinition(TestBean.class) |
|
|
|
genericBeanDefinition(TestBean.class) |
|
|
|
.addPropertyValue("touchy", "${os.name}").getBeanDefinition()); |
|
|
|
.addPropertyValue("touchy", "${os.name}").getBeanDefinition()); |
|
|
|
|
|
|
|
|
|
|
|
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); |
|
|
|
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); |
|
|
|
Properties props = new Properties(); |
|
|
|
Properties props = new Properties(); |
|
|
|
props.put("os.name", "myos"); |
|
|
|
props.put("os.name", "myos"); |
|
|
|
ppc.setProperties(props); |
|
|
|
ppc.setProperties(props); |
|
|
|
ppc.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE); |
|
|
|
ppc.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE); |
|
|
|
ppc.postProcessBeanFactory(factory); |
|
|
|
ppc.postProcessBeanFactory(factory); |
|
|
|
|
|
|
|
|
|
|
|
TestBean tb = (TestBean) factory.getBean("tb"); |
|
|
|
TestBean tb = (TestBean) factory.getBean("tb"); |
|
|
|
assertEquals(System.getProperty("os.name"), tb.getTouchy()); |
|
|
|
assertEquals(System.getProperty("os.name"), tb.getTouchy()); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -486,10 +486,10 @@ public class PropertyResourceConfigurerTests { |
|
|
|
factory.registerBeanDefinition("tb", |
|
|
|
factory.registerBeanDefinition("tb", |
|
|
|
genericBeanDefinition(TestBean.class) |
|
|
|
genericBeanDefinition(TestBean.class) |
|
|
|
.addPropertyValue("touchy", "${user.dir}").getBeanDefinition()); |
|
|
|
.addPropertyValue("touchy", "${user.dir}").getBeanDefinition()); |
|
|
|
|
|
|
|
|
|
|
|
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); |
|
|
|
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); |
|
|
|
ppc.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_NEVER); |
|
|
|
ppc.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_NEVER); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
ppc.postProcessBeanFactory(factory); |
|
|
|
ppc.postProcessBeanFactory(factory); |
|
|
|
fail("Should have thrown BeanDefinitionStoreException"); |
|
|
|
fail("Should have thrown BeanDefinitionStoreException"); |
|
|
|
@ -505,9 +505,9 @@ public class PropertyResourceConfigurerTests { |
|
|
|
factory.registerBeanDefinition("tb", |
|
|
|
factory.registerBeanDefinition("tb", |
|
|
|
genericBeanDefinition(TestBean.class) |
|
|
|
genericBeanDefinition(TestBean.class) |
|
|
|
.addPropertyValue("name", "${ref}").getBeanDefinition()); |
|
|
|
.addPropertyValue("name", "${ref}").getBeanDefinition()); |
|
|
|
|
|
|
|
|
|
|
|
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); |
|
|
|
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
ppc.postProcessBeanFactory(factory); |
|
|
|
ppc.postProcessBeanFactory(factory); |
|
|
|
fail("Should have thrown BeanDefinitionStoreException"); |
|
|
|
fail("Should have thrown BeanDefinitionStoreException"); |
|
|
|
@ -523,11 +523,11 @@ public class PropertyResourceConfigurerTests { |
|
|
|
factory.registerBeanDefinition("tb", |
|
|
|
factory.registerBeanDefinition("tb", |
|
|
|
genericBeanDefinition(TestBean.class) |
|
|
|
genericBeanDefinition(TestBean.class) |
|
|
|
.addPropertyValue("name", "${ref}").getBeanDefinition()); |
|
|
|
.addPropertyValue("name", "${ref}").getBeanDefinition()); |
|
|
|
|
|
|
|
|
|
|
|
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); |
|
|
|
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); |
|
|
|
ppc.setIgnoreUnresolvablePlaceholders(true); |
|
|
|
ppc.setIgnoreUnresolvablePlaceholders(true); |
|
|
|
ppc.postProcessBeanFactory(factory); |
|
|
|
ppc.postProcessBeanFactory(factory); |
|
|
|
|
|
|
|
|
|
|
|
TestBean tb = (TestBean) factory.getBean("tb"); |
|
|
|
TestBean tb = (TestBean) factory.getBean("tb"); |
|
|
|
assertEquals("${ref}", tb.getName()); |
|
|
|
assertEquals("${ref}", tb.getName()); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -537,11 +537,11 @@ public class PropertyResourceConfigurerTests { |
|
|
|
factory.registerBeanDefinition("tb", |
|
|
|
factory.registerBeanDefinition("tb", |
|
|
|
genericBeanDefinition(TestBean.class) |
|
|
|
genericBeanDefinition(TestBean.class) |
|
|
|
.addPropertyValue("name", "").getBeanDefinition()); |
|
|
|
.addPropertyValue("name", "").getBeanDefinition()); |
|
|
|
|
|
|
|
|
|
|
|
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); |
|
|
|
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); |
|
|
|
ppc.setNullValue(""); |
|
|
|
ppc.setNullValue(""); |
|
|
|
ppc.postProcessBeanFactory(factory); |
|
|
|
ppc.postProcessBeanFactory(factory); |
|
|
|
|
|
|
|
|
|
|
|
TestBean tb = (TestBean) factory.getBean("tb"); |
|
|
|
TestBean tb = (TestBean) factory.getBean("tb"); |
|
|
|
assertNull(tb.getName()); |
|
|
|
assertNull(tb.getName()); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -551,14 +551,14 @@ public class PropertyResourceConfigurerTests { |
|
|
|
factory.registerBeanDefinition("tb", |
|
|
|
factory.registerBeanDefinition("tb", |
|
|
|
genericBeanDefinition(TestBean.class) |
|
|
|
genericBeanDefinition(TestBean.class) |
|
|
|
.addPropertyValue("name", "${ref}").getBeanDefinition()); |
|
|
|
.addPropertyValue("name", "${ref}").getBeanDefinition()); |
|
|
|
|
|
|
|
|
|
|
|
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); |
|
|
|
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); |
|
|
|
ppc.setNullValue(""); |
|
|
|
ppc.setNullValue(""); |
|
|
|
Properties props = new Properties(); |
|
|
|
Properties props = new Properties(); |
|
|
|
props.put("ref", ""); |
|
|
|
props.put("ref", ""); |
|
|
|
ppc.setProperties(props); |
|
|
|
ppc.setProperties(props); |
|
|
|
ppc.postProcessBeanFactory(factory); |
|
|
|
ppc.postProcessBeanFactory(factory); |
|
|
|
|
|
|
|
|
|
|
|
TestBean tb = (TestBean) factory.getBean("tb"); |
|
|
|
TestBean tb = (TestBean) factory.getBean("tb"); |
|
|
|
assertNull(tb.getName()); |
|
|
|
assertNull(tb.getName()); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -568,18 +568,18 @@ public class PropertyResourceConfigurerTests { |
|
|
|
factory.registerBeanDefinition("tb", |
|
|
|
factory.registerBeanDefinition("tb", |
|
|
|
genericBeanDefinition(TestBean.class) |
|
|
|
genericBeanDefinition(TestBean.class) |
|
|
|
.addPropertyValue("name", "${my${key}key}").getBeanDefinition()); |
|
|
|
.addPropertyValue("name", "${my${key}key}").getBeanDefinition()); |
|
|
|
|
|
|
|
|
|
|
|
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); |
|
|
|
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); |
|
|
|
Properties props = new Properties(); |
|
|
|
Properties props = new Properties(); |
|
|
|
props.put("key", "new"); |
|
|
|
props.put("key", "new"); |
|
|
|
props.put("mynewkey", "myname"); |
|
|
|
props.put("mynewkey", "myname"); |
|
|
|
ppc.setProperties(props); |
|
|
|
ppc.setProperties(props); |
|
|
|
ppc.postProcessBeanFactory(factory); |
|
|
|
ppc.postProcessBeanFactory(factory); |
|
|
|
|
|
|
|
|
|
|
|
TestBean tb = (TestBean) factory.getBean("tb"); |
|
|
|
TestBean tb = (TestBean) factory.getBean("tb"); |
|
|
|
assertEquals("myname", tb.getName()); |
|
|
|
assertEquals("myname", tb.getName()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testPropertyPlaceholderConfigurerWithCircularReference() { |
|
|
|
public void testPropertyPlaceholderConfigurerWithCircularReference() { |
|
|
|
factory.registerBeanDefinition("tb", |
|
|
|
factory.registerBeanDefinition("tb", |
|
|
|
@ -587,14 +587,14 @@ public class PropertyResourceConfigurerTests { |
|
|
|
.addPropertyValue("age", "${age}") |
|
|
|
.addPropertyValue("age", "${age}") |
|
|
|
.addPropertyValue("name", "name${var}") |
|
|
|
.addPropertyValue("name", "name${var}") |
|
|
|
.getBeanDefinition()); |
|
|
|
.getBeanDefinition()); |
|
|
|
|
|
|
|
|
|
|
|
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); |
|
|
|
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); |
|
|
|
Properties props = new Properties(); |
|
|
|
Properties props = new Properties(); |
|
|
|
props.setProperty("age", "99"); |
|
|
|
props.setProperty("age", "99"); |
|
|
|
props.setProperty("var", "${m}"); |
|
|
|
props.setProperty("var", "${m}"); |
|
|
|
props.setProperty("m", "${var}"); |
|
|
|
props.setProperty("m", "${var}"); |
|
|
|
ppc.setProperties(props); |
|
|
|
ppc.setProperties(props); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
ppc.postProcessBeanFactory(factory); |
|
|
|
ppc.postProcessBeanFactory(factory); |
|
|
|
fail("Should have thrown BeanDefinitionStoreException"); |
|
|
|
fail("Should have thrown BeanDefinitionStoreException"); |
|
|
|
@ -609,13 +609,13 @@ public class PropertyResourceConfigurerTests { |
|
|
|
factory.registerBeanDefinition("tb", |
|
|
|
factory.registerBeanDefinition("tb", |
|
|
|
genericBeanDefinition(TestBean.class) |
|
|
|
genericBeanDefinition(TestBean.class) |
|
|
|
.addPropertyValue("touchy", "${test}").getBeanDefinition()); |
|
|
|
.addPropertyValue("touchy", "${test}").getBeanDefinition()); |
|
|
|
|
|
|
|
|
|
|
|
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); |
|
|
|
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); |
|
|
|
Properties props = new Properties(); |
|
|
|
Properties props = new Properties(); |
|
|
|
props.put("test", "mytest"); |
|
|
|
props.put("test", "mytest"); |
|
|
|
ppc.setProperties(props); |
|
|
|
ppc.setProperties(props); |
|
|
|
ppc.postProcessBeanFactory(factory); |
|
|
|
ppc.postProcessBeanFactory(factory); |
|
|
|
|
|
|
|
|
|
|
|
TestBean tb = (TestBean) factory.getBean("tb"); |
|
|
|
TestBean tb = (TestBean) factory.getBean("tb"); |
|
|
|
assertEquals("mytest", tb.getTouchy()); |
|
|
|
assertEquals("mytest", tb.getTouchy()); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -648,10 +648,10 @@ public class PropertyResourceConfigurerTests { |
|
|
|
factory.registerBeanDefinition("tb", |
|
|
|
factory.registerBeanDefinition("tb", |
|
|
|
genericBeanDefinition(TestBean.class) |
|
|
|
genericBeanDefinition(TestBean.class) |
|
|
|
.addPropertyValue("touchy", "${test}").getBeanDefinition()); |
|
|
|
.addPropertyValue("touchy", "${test}").getBeanDefinition()); |
|
|
|
|
|
|
|
|
|
|
|
factory.registerAlias("tb", "${myAlias}"); |
|
|
|
factory.registerAlias("tb", "${myAlias}"); |
|
|
|
factory.registerAlias("${myTarget}", "alias2"); |
|
|
|
factory.registerAlias("${myTarget}", "alias2"); |
|
|
|
|
|
|
|
|
|
|
|
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); |
|
|
|
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); |
|
|
|
Properties props = new Properties(); |
|
|
|
Properties props = new Properties(); |
|
|
|
props.put("test", "mytest"); |
|
|
|
props.put("test", "mytest"); |
|
|
|
@ -659,7 +659,7 @@ public class PropertyResourceConfigurerTests { |
|
|
|
props.put("myTarget", "tb"); |
|
|
|
props.put("myTarget", "tb"); |
|
|
|
ppc.setProperties(props); |
|
|
|
ppc.setProperties(props); |
|
|
|
ppc.postProcessBeanFactory(factory); |
|
|
|
ppc.postProcessBeanFactory(factory); |
|
|
|
|
|
|
|
|
|
|
|
TestBean tb = (TestBean) factory.getBean("tb"); |
|
|
|
TestBean tb = (TestBean) factory.getBean("tb"); |
|
|
|
assertEquals("mytest", tb.getTouchy()); |
|
|
|
assertEquals("mytest", tb.getTouchy()); |
|
|
|
tb = (TestBean) factory.getBean("alias"); |
|
|
|
tb = (TestBean) factory.getBean("alias"); |
|
|
|
@ -676,7 +676,7 @@ public class PropertyResourceConfigurerTests { |
|
|
|
.addPropertyValue("age", "${myAge}") |
|
|
|
.addPropertyValue("age", "${myAge}") |
|
|
|
.addPropertyValue("touchy", "${myTouchy}") |
|
|
|
.addPropertyValue("touchy", "${myTouchy}") |
|
|
|
.getBeanDefinition()); |
|
|
|
.getBeanDefinition()); |
|
|
|
|
|
|
|
|
|
|
|
PreferencesPlaceholderConfigurer ppc = new PreferencesPlaceholderConfigurer(); |
|
|
|
PreferencesPlaceholderConfigurer ppc = new PreferencesPlaceholderConfigurer(); |
|
|
|
Properties props = new Properties(); |
|
|
|
Properties props = new Properties(); |
|
|
|
props.put("myAge", "99"); |
|
|
|
props.put("myAge", "99"); |
|
|
|
@ -704,7 +704,7 @@ public class PropertyResourceConfigurerTests { |
|
|
|
.addPropertyValue("age", "${myAge}") |
|
|
|
.addPropertyValue("age", "${myAge}") |
|
|
|
.addPropertyValue("touchy", "${myTouchy}") |
|
|
|
.addPropertyValue("touchy", "${myTouchy}") |
|
|
|
.getBeanDefinition()); |
|
|
|
.getBeanDefinition()); |
|
|
|
|
|
|
|
|
|
|
|
PreferencesPlaceholderConfigurer ppc = new PreferencesPlaceholderConfigurer(); |
|
|
|
PreferencesPlaceholderConfigurer ppc = new PreferencesPlaceholderConfigurer(); |
|
|
|
Properties props = new Properties(); |
|
|
|
Properties props = new Properties(); |
|
|
|
props.put("myAge", "99"); |
|
|
|
props.put("myAge", "99"); |
|
|
|
@ -716,7 +716,7 @@ public class PropertyResourceConfigurerTests { |
|
|
|
Preferences.userRoot().node("myUserPath").put("myTouchy", "myOtherTouchyValue"); |
|
|
|
Preferences.userRoot().node("myUserPath").put("myTouchy", "myOtherTouchyValue"); |
|
|
|
ppc.afterPropertiesSet(); |
|
|
|
ppc.afterPropertiesSet(); |
|
|
|
ppc.postProcessBeanFactory(factory); |
|
|
|
ppc.postProcessBeanFactory(factory); |
|
|
|
|
|
|
|
|
|
|
|
TestBean tb = (TestBean) factory.getBean("tb"); |
|
|
|
TestBean tb = (TestBean) factory.getBean("tb"); |
|
|
|
assertEquals("myNameValue", tb.getName()); |
|
|
|
assertEquals("myNameValue", tb.getName()); |
|
|
|
assertEquals(99, tb.getAge()); |
|
|
|
assertEquals(99, tb.getAge()); |
|
|
|
@ -734,7 +734,7 @@ public class PropertyResourceConfigurerTests { |
|
|
|
.addPropertyValue("age", "${myAge}") |
|
|
|
.addPropertyValue("age", "${myAge}") |
|
|
|
.addPropertyValue("touchy", "${myotherpath/myTouchy}") |
|
|
|
.addPropertyValue("touchy", "${myotherpath/myTouchy}") |
|
|
|
.getBeanDefinition()); |
|
|
|
.getBeanDefinition()); |
|
|
|
|
|
|
|
|
|
|
|
PreferencesPlaceholderConfigurer ppc = new PreferencesPlaceholderConfigurer(); |
|
|
|
PreferencesPlaceholderConfigurer ppc = new PreferencesPlaceholderConfigurer(); |
|
|
|
Properties props = new Properties(); |
|
|
|
Properties props = new Properties(); |
|
|
|
props.put("myAge", "99"); |
|
|
|
props.put("myAge", "99"); |
|
|
|
@ -746,7 +746,7 @@ public class PropertyResourceConfigurerTests { |
|
|
|
Preferences.userRoot().node("myUserPath/myotherpath").put("myTouchy", "myOtherTouchyValue"); |
|
|
|
Preferences.userRoot().node("myUserPath/myotherpath").put("myTouchy", "myOtherTouchyValue"); |
|
|
|
ppc.afterPropertiesSet(); |
|
|
|
ppc.afterPropertiesSet(); |
|
|
|
ppc.postProcessBeanFactory(factory); |
|
|
|
ppc.postProcessBeanFactory(factory); |
|
|
|
|
|
|
|
|
|
|
|
TestBean tb = (TestBean) factory.getBean("tb"); |
|
|
|
TestBean tb = (TestBean) factory.getBean("tb"); |
|
|
|
assertEquals("myNameValue", tb.getName()); |
|
|
|
assertEquals("myNameValue", tb.getName()); |
|
|
|
assertEquals(99, tb.getAge()); |
|
|
|
assertEquals(99, tb.getAge()); |
|
|
|
|