Search in sources :

Example 41 with TestBean

use of org.springframework.tests.sample.beans.TestBean in project spring-framework by spring-projects.

the class PropertyPlaceholderConfigurerTests method localPropertiesViaResource.

@Test
public void localPropertiesViaResource() {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    bf.registerBeanDefinition("testBean", genericBeanDefinition(TestBean.class).addPropertyValue("name", "${my.name}").getBeanDefinition());
    PropertyPlaceholderConfigurer pc = new PropertyPlaceholderConfigurer();
    Resource resource = new ClassPathResource("PropertyPlaceholderConfigurerTests.properties", this.getClass());
    pc.setLocation(resource);
    pc.postProcessBeanFactory(bf);
}
Also used : TestBean(org.springframework.tests.sample.beans.TestBean) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 42 with TestBean

use of org.springframework.tests.sample.beans.TestBean in project spring-framework by spring-projects.

the class PropertyPlaceholderConfigurerTests method nullValueIsPreserved.

@Test
public void nullValueIsPreserved() {
    PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
    ppc.setNullValue("customNull");
    getModifiableSystemEnvironment().put("my.name", "customNull");
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    bf.registerBeanDefinition("testBean", rootBeanDefinition(TestBean.class).addPropertyValue("name", "${my.name}").getBeanDefinition());
    ppc.postProcessBeanFactory(bf);
    assertThat(bf.getBean(TestBean.class).getName(), nullValue());
    getModifiableSystemEnvironment().remove("my.name");
}
Also used : TestBean(org.springframework.tests.sample.beans.TestBean) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Test(org.junit.Test)

Example 43 with TestBean

use of org.springframework.tests.sample.beans.TestBean in project spring-framework by spring-projects.

the class PropertyPlaceholderConfigurerTests method setSystemSystemPropertiesMode_toOverride_andSetSearchSystemEnvironment_toFalse.

@Test
public void setSystemSystemPropertiesMode_toOverride_andSetSearchSystemEnvironment_toFalse() {
    registerWithGeneratedName(p1BeanDef, bf);
    // will now fall all the way back to system environment
    System.clearProperty(P1);
    ppc.setSearchSystemEnvironment(false);
    ppc.setSystemPropertiesMode(PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE);
    ppc.postProcessBeanFactory(bf);
    TestBean bean = bf.getBean(TestBean.class);
    // has to resort to local props
    assertThat(bean.getName(), equalTo(P1_LOCAL_PROPS_VAL));
}
Also used : TestBean(org.springframework.tests.sample.beans.TestBean) Test(org.junit.Test)

Example 44 with TestBean

use of org.springframework.tests.sample.beans.TestBean in project spring-framework by spring-projects.

the class PropertyPlaceholderConfigurerTests method setSystemPropertiesMode_defaultIsFallback.

@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));
}
Also used : TestBean(org.springframework.tests.sample.beans.TestBean) Test(org.junit.Test)

Example 45 with TestBean

use of org.springframework.tests.sample.beans.TestBean in project spring-framework by spring-projects.

the class PropertyPlaceholderConfigurerTests method resolveFromLocalProperties.

@Test
public void resolveFromLocalProperties() {
    // eliminate entries from system props/environment
    tearDown();
    registerWithGeneratedName(p1BeanDef, bf);
    ppc.postProcessBeanFactory(bf);
    TestBean bean = bf.getBean(TestBean.class);
    assertThat(bean.getName(), equalTo(P1_LOCAL_PROPS_VAL));
}
Also used : TestBean(org.springframework.tests.sample.beans.TestBean) Test(org.junit.Test)

Aggregations

TestBean (org.springframework.tests.sample.beans.TestBean)788 Test (org.junit.Test)740 ITestBean (org.springframework.tests.sample.beans.ITestBean)456 IndexedTestBean (org.springframework.tests.sample.beans.IndexedTestBean)248 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)225 NestedTestBean (org.springframework.tests.sample.beans.NestedTestBean)164 DerivedTestBean (org.springframework.tests.sample.beans.DerivedTestBean)160 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)144 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)86 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)44 BooleanTestBean (org.springframework.tests.sample.beans.BooleanTestBean)40 NumberTestBean (org.springframework.tests.sample.beans.NumberTestBean)40 Properties (java.util.Properties)35 Errors (org.springframework.validation.Errors)34 NopInterceptor (org.springframework.tests.aop.interceptor.NopInterceptor)33 PropertyEditorSupport (java.beans.PropertyEditorSupport)31 HashMap (java.util.HashMap)30 List (java.util.List)27 Map (java.util.Map)27 PageContext (javax.servlet.jsp.PageContext)27