Search in sources :

Example 46 with TestBean

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

the class PropertyPlaceholderConfigurerTests method setSystemSystemPropertiesMode_toOverride_andResolveFromSystemProperties.

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

Example 47 with TestBean

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

the class PropertyPlaceholderConfigurerTests method setSystemSystemPropertiesMode_toOverride_andResolveFromSystemEnvironment.

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

Example 48 with TestBean

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

the class InjectAnnotationBeanPostProcessorTests method testOptionalListMethodInjectionWithBeanAvailable.

@Test
public void testOptionalListMethodInjectionWithBeanAvailable() {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
    bpp.setBeanFactory(bf);
    bf.addBeanPostProcessor(bpp);
    bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(OptionalListMethodInjectionBean.class));
    bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
    OptionalListMethodInjectionBean bean = (OptionalListMethodInjectionBean) bf.getBean("annotatedBean");
    assertTrue(bean.getTestBean().isPresent());
    assertSame(bf.getBean("testBean"), bean.getTestBean().get().get(0));
    bf.destroySingletons();
}
Also used : IndexedTestBean(org.springframework.tests.sample.beans.IndexedTestBean) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) NestedTestBean(org.springframework.tests.sample.beans.NestedTestBean) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Example 49 with TestBean

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

the class InjectAnnotationBeanPostProcessorTests method testObjectFactoryWithTypedListField.

@Test
public void testObjectFactoryWithTypedListField() throws Exception {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
    bpp.setBeanFactory(bf);
    bf.addBeanPostProcessor(bpp);
    bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ObjectFactoryListFieldInjectionBean.class));
    bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
    bf.setSerializationId("test");
    ObjectFactoryListFieldInjectionBean bean = (ObjectFactoryListFieldInjectionBean) bf.getBean("annotatedBean");
    assertSame(bf.getBean("testBean"), bean.getTestBean());
    bean = (ObjectFactoryListFieldInjectionBean) SerializationTestUtils.serializeAndDeserialize(bean);
    assertSame(bf.getBean("testBean"), bean.getTestBean());
    bf.destroySingletons();
}
Also used : IndexedTestBean(org.springframework.tests.sample.beans.IndexedTestBean) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) NestedTestBean(org.springframework.tests.sample.beans.NestedTestBean) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Example 50 with TestBean

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

the class InjectAnnotationBeanPostProcessorTests method testObjectFactoryWithTypedMapMethod.

@Test
public void testObjectFactoryWithTypedMapMethod() throws Exception {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
    bpp.setBeanFactory(bf);
    bf.addBeanPostProcessor(bpp);
    bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ObjectFactoryMapMethodInjectionBean.class));
    bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
    bf.setSerializationId("test");
    ObjectFactoryMapMethodInjectionBean bean = (ObjectFactoryMapMethodInjectionBean) bf.getBean("annotatedBean");
    assertSame(bf.getBean("testBean"), bean.getTestBean());
    bean = (ObjectFactoryMapMethodInjectionBean) SerializationTestUtils.serializeAndDeserialize(bean);
    assertSame(bf.getBean("testBean"), bean.getTestBean());
    bf.destroySingletons();
}
Also used : IndexedTestBean(org.springframework.tests.sample.beans.IndexedTestBean) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) NestedTestBean(org.springframework.tests.sample.beans.NestedTestBean) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) 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