Search in sources :

Example 36 with TestBean

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

the class DirectFieldAccessorTests method withShadowedField.

@Test
public void withShadowedField() throws Exception {
    final StringBuilder sb = new StringBuilder();
    @SuppressWarnings("serial") TestBean target = new TestBean() {

        @SuppressWarnings("unused")
        StringBuilder name = sb;
    };
    DirectFieldAccessor dfa = createAccessor(target);
    assertEquals(StringBuilder.class, dfa.getPropertyType("name"));
    assertEquals(sb, dfa.getPropertyValue("name"));
}
Also used : TestBean(org.springframework.tests.sample.beans.TestBean) Test(org.junit.Test)

Example 37 with TestBean

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

the class BeanUtilsTests method testCopyPropertiesWithDifferentTypes2.

@Test
public void testCopyPropertiesWithDifferentTypes2() throws Exception {
    TestBean tb = new TestBean();
    tb.setName("rod");
    tb.setAge(32);
    tb.setTouchy("touchy");
    DerivedTestBean tb2 = new DerivedTestBean();
    assertTrue("Name empty", tb2.getName() == null);
    assertTrue("Age empty", tb2.getAge() == 0);
    assertTrue("Touchy empty", tb2.getTouchy() == null);
    BeanUtils.copyProperties(tb, tb2);
    assertTrue("Name copied", tb2.getName().equals(tb.getName()));
    assertTrue("Age copied", tb2.getAge() == tb.getAge());
    assertTrue("Touchy copied", tb2.getTouchy().equals(tb.getTouchy()));
}
Also used : DerivedTestBean(org.springframework.tests.sample.beans.DerivedTestBean) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) DerivedTestBean(org.springframework.tests.sample.beans.DerivedTestBean) Test(org.junit.Test)

Example 38 with TestBean

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

the class PropertyPathFactoryBeanTests method testPropertyPathFactoryBeanAsInnerBean.

@Test
public void testPropertyPathFactoryBeanAsInnerBean() {
    DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONTEXT);
    TestBean spouse = (TestBean) xbf.getBean("otb.spouse");
    TestBean tbWithInner = (TestBean) xbf.getBean("tbWithInner");
    assertSame(spouse, tbWithInner.getSpouse());
    assertTrue(!tbWithInner.getFriends().isEmpty());
    assertSame(spouse, tbWithInner.getFriends().iterator().next());
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Test(org.junit.Test)

Example 39 with TestBean

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

the class PropertyPathFactoryBeanTests method testPropertyPathFactoryBeanWithPrototypeResult.

@Test
public void testPropertyPathFactoryBeanWithPrototypeResult() {
    DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONTEXT);
    assertNull(xbf.getType("tb.spouse"));
    assertEquals(TestBean.class, xbf.getType("propertyPath3"));
    Object result1 = xbf.getBean("tb.spouse");
    Object result2 = xbf.getBean("propertyPath3");
    Object result3 = xbf.getBean("propertyPath3");
    assertTrue(result1 instanceof TestBean);
    assertTrue(result2 instanceof TestBean);
    assertTrue(result3 instanceof TestBean);
    assertEquals(11, ((TestBean) result1).getAge());
    assertEquals(11, ((TestBean) result2).getAge());
    assertEquals(11, ((TestBean) result3).getAge());
    assertTrue(result1 != result2);
    assertTrue(result1 != result3);
    assertTrue(result2 != result3);
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Test(org.junit.Test)

Example 40 with TestBean

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

the class PropertyPlaceholderConfigurerTests method trimValuesIsOffByDefault.

@Test
public void trimValuesIsOffByDefault() {
    PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
    getModifiableSystemEnvironment().put("my.name", " myValue  ");
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    bf.registerBeanDefinition("testBean", rootBeanDefinition(TestBean.class).addPropertyValue("name", "${my.name}").getBeanDefinition());
    ppc.postProcessBeanFactory(bf);
    assertThat(bf.getBean(TestBean.class).getName(), equalTo(" myValue  "));
    getModifiableSystemEnvironment().remove("my.name");
}
Also used : TestBean(org.springframework.tests.sample.beans.TestBean) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) 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