Package net.sourceforge.stripes.test

Examples of net.sourceforge.stripes.test.TestBean


        Assert.assertTrue(root.getNestedBean() == BeanUtil.getPropertyValue("nestedBean", root));
    }

    @Test(groups="fast")
    public void testListProperties() throws Exception {
        TestBean root = new TestBean();

        BeanUtil.setPropertyValue("beanList[3]", root, new TestBean());
        Assert.assertNull( BeanUtil.getPropertyValue("beanList[0]", root) );
        Assert.assertNull( BeanUtil.getPropertyValue("beanList[1]", root) );
        Assert.assertNull( BeanUtil.getPropertyValue("beanList[2]", root) );
        Assert.assertNotNull( BeanUtil.getPropertyValue("beanList[3]", root) );
        Assert.assertNull( BeanUtil.getPropertyValue("beanList[4]", root) );

        BeanUtil.setPropertyValue("beanList[3].stringProperty", root, "testValue");
        Assert.assertEquals("testValue", root.getBeanList().get(3).getStringProperty());

        BeanUtil.setPropertyValue("stringList[1]", root, "testValue");
        BeanUtil.setPropertyValue("stringList[5]", root, "testValue");
        BeanUtil.setPropertyValue("stringList[9]", root, "testValue");
        BeanUtil.setPropertyValue("stringList[7]", root, "testValue");
        BeanUtil.setPropertyValue("stringList[3]", root, "testValue");

        for (int i=0; i<10; ++i) {
            if (i%2 == 0) {
                Assert.assertNull(root.getStringList().get(i),
                                  "String list index " + i + " should be null.");
            }
            else {
                Assert.assertEquals("testValue", root.getStringList().get(i),
                                    "String list index " + i + " should be 'testValue'.");
            }
        }
    }
View Full Code Here


        }
    }

    @Test(groups="fast")
    public void testMapProperties() throws Exception {
        TestBean root = new TestBean();

        Assert.assertNull( BeanUtil.getPropertyValue("stringMap['foo']", root) );
        Assert.assertNull( BeanUtil.getPropertyValue("stringMap['bar']", root) );
        Assert.assertNull( BeanUtil.getPropertyValue("stringMap['testValue']", root) );

        Assert.assertNull( BeanUtil.getPropertyValue("beanMap['foo']", root) );
        Assert.assertNull( BeanUtil.getPropertyValue("beanMap['bar']", root) );
        Assert.assertNull( BeanUtil.getPropertyValue("beanMap['testValue']", root) );

        Assert.assertNull( BeanUtil.getPropertyValue("beanMap['foo'].longProperty", root) );
        Assert.assertNull( BeanUtil.getPropertyValue("beanMap['bar'].stringProperty", root) );
        Assert.assertNull( BeanUtil.getPropertyValue("beanMap['testValue'].enumProperty", root) );

        BeanUtil.setPropertyValue("stringMap['testKey']", root, "testValue");
        Assert.assertEquals("testValue", root.getStringMap().get("testKey"));

        BeanUtil.setPropertyValue("beanMap['testKey'].enumProperty", root, TestEnum.Fifth);
        Assert.assertNotNull(root.getBeanMap());
        Assert.assertNotNull(root.getBeanMap().get("testKey"));
        Assert.assertEquals(TestEnum.Fifth, root.getBeanMap().get("testKey").getEnumProperty());
    }
View Full Code Here

        Assert.assertEquals(TestEnum.Fifth, root.getBeanMap().get("testKey").getEnumProperty());
    }

    @Test(groups="fast")
    public void testSetNull() throws Exception {
        TestBean root = new TestBean();

        // Try setting a null on a null nested property and make sure the nested
        // property doesn't get instantiated
        Assert.assertNull(root.getNestedBean());
        BeanUtil.setPropertyToNull("nestedBean.stringProperty", root);
        Assert.assertNull(root.getNestedBean());

        // Now set the property set the nest bean and do it again
        root.setNestedBean( new TestBean() );
        BeanUtil.setPropertyToNull("nestedBean.stringProperty", root);
        Assert.assertNotNull(root.getNestedBean());
        Assert.assertNull(root.getNestedBean().getStringProperty());

        // Now set the string property and null it out for real
        root.getNestedBean().setStringProperty("Definitely Not Null");
        BeanUtil.setPropertyToNull("nestedBean.stringProperty", root);
        Assert.assertNotNull(root.getNestedBean());
        Assert.assertNull(root.getNestedBean().getStringProperty());

        // Now use setNullValue to trim the nestedBean
        BeanUtil.setPropertyToNull("nestedBean", root);
        Assert.assertNull(root.getNestedBean());

        // Now try some nulling out of indexed properties
        root.setStringList(new ArrayList<String>());
        root.getStringList().add("foo");
        root.getStringList().add("bar");
        Assert.assertNotNull(root.getStringList().get(0));
        Assert.assertNotNull(root.getStringList().get(1));
        BeanUtil.setPropertyToNull("stringList[1]", root);
        Assert.assertNotNull(root.getStringList().get(0));
        Assert.assertNull(root.getStringList().get(1));
    }
View Full Code Here

        Assert.assertNull(root.getStringList().get(1));
    }

    @Test(groups="fast")
    public void testSetNullPrimitives() throws Exception {
        TestBean root = new TestBean();
        root.setBooleanProperty(true);
        root.setIntProperty(77);

        Assert.assertEquals(77, root.getIntProperty());
        Assert.assertEquals(true, root.isBooleanProperty());

        BeanUtil.setPropertyToNull("intProperty", root);
        BeanUtil.setPropertyToNull("booleanProperty", root);

        Assert.assertEquals(0, root.getIntProperty());
        Assert.assertEquals(false, root.isBooleanProperty());
    }
View Full Code Here

     * would not fall back to looking at instance information to figure out the type info.
     */
    @Test(groups="fast")
    public void testFallBackToInstanceInfo() throws Exception {
        Map<String,TestBean> map = new HashMap<String,TestBean>();
        map.put("foo", new TestBean());
        map.get("foo").setStringProperty("bar");
        Map.Entry<String,TestBean> entry = map.entrySet().iterator().next();
        String value = (String) BeanUtil.getPropertyValue("value.stringProperty", entry);
        Assert.assertEquals(value, "bar");
    }
View Full Code Here

TOP

Related Classes of net.sourceforge.stripes.test.TestBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.