Package net.sourceforge.stripes.test

Examples of net.sourceforge.stripes.test.TestBean


    }

    @Test(groups="fast")
    public void testGetPropertyTypeWithBackToBackMapIndexing() {
        PropertyExpression expr = PropertyExpression.getExpression("nestedMap['foo']['bar']");
        PropertyExpressionEvaluation eval = new PropertyExpressionEvaluation(expr, new TestBean());
        Class<?> type = eval.getType();
        Assert.assertEquals(type, Boolean.class);
    }
View Full Code Here


    }

    @Test(groups="fast")
    public void testGetPropertyTypeWithBackToBackListArrayIndexing() {
        PropertyExpression expr = PropertyExpression.getExpression("genericArray[1][0]");
        PropertyExpressionEvaluation eval = new PropertyExpressionEvaluation(expr, new TestBean());
        Class<?> type = eval.getType();
        Assert.assertEquals(type, Float.class);
    }
View Full Code Here

    //////////////////////////////////////////////////////////////////////////////////////

    @Test(groups="fast")
    public void testGetSimpleProperties() throws Exception {
        TestBean root = new TestBean();
        root.setStringProperty("testValue");
        root.setIntProperty(77);
        root.setLongProperty(777l);
        root.setEnumProperty(TestEnum.Seventh);

        Assert.assertEquals("testValue", BeanUtil.getPropertyValue("stringProperty", root));
        Assert.assertEquals(77, BeanUtil.getPropertyValue("intProperty", root));
        Assert.assertEquals(777l, BeanUtil.getPropertyValue("longProperty", root));
        Assert.assertEquals(TestEnum.Seventh, BeanUtil.getPropertyValue("enumProperty", root));
View Full Code Here

        Assert.assertEquals(TestEnum.Seventh, BeanUtil.getPropertyValue("enumProperty", root));
    }

    @Test(groups="fast")
    public void testGetNestedProperties() throws Exception {
        TestBean root = new TestBean();
        TestBean nested = new TestBean();
        root.setNestedBean(nested);
        nested.setStringProperty("testValue");
        nested.setIntProperty(77);
        nested.setLongProperty(777l);
        nested.setEnumProperty(TestEnum.Seventh);

        Assert.assertEquals("testValue", BeanUtil.getPropertyValue("nestedBean.stringProperty", root));
        Assert.assertEquals(77, BeanUtil.getPropertyValue("nestedBean.intProperty", root));
        Assert.assertEquals(777l, BeanUtil.getPropertyValue("nestedBean.longProperty", root));
        Assert.assertEquals(TestEnum.Seventh, BeanUtil.getPropertyValue("nestedBean.enumProperty", root));
View Full Code Here

        Assert.assertEquals(TestEnum.Seventh, BeanUtil.getPropertyValue("nestedBean.enumProperty", root));
    }

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

        // Test simple and nested props, leaving out primitives
        Assert.assertNull( BeanUtil.getPropertyValue("stringProperty" , root) );
        Assert.assertNull( BeanUtil.getPropertyValue("longProperty" , root) );
        Assert.assertNull( BeanUtil.getPropertyValue("enumProperty" , root) );
View Full Code Here

        Assert.assertNull( BeanUtil.getPropertyValue("stringMap", root));
    }

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

        BeanUtil.setPropertyValue("stringProperty", root, "testValue");
        BeanUtil.setPropertyValue("intProperty",    root, 77);
        BeanUtil.setPropertyValue("longProperty",   root, 777l);
        BeanUtil.setPropertyValue("enumProperty",   root, TestEnum.Seventh);

        Assert.assertEquals("testValue", root.getStringProperty());
        Assert.assertEquals("testValue", BeanUtil.getPropertyValue("stringProperty", root));

        Assert.assertEquals(77, root.getIntProperty());
        Assert.assertEquals(77, BeanUtil.getPropertyValue("intProperty", root));

        Assert.assertEquals(new Long(777l), root.getLongProperty());
        Assert.assertEquals(777l, BeanUtil.getPropertyValue("longProperty", root));

        Assert.assertEquals(TestEnum.Seventh, root.getEnumProperty());
        Assert.assertEquals(TestEnum.Seventh, BeanUtil.getPropertyValue("enumProperty", root));

    }
View Full Code Here

    }

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

        BeanUtil.setPropertyValue("nestedBean.stringProperty", root, "testValue");
        BeanUtil.setPropertyValue("nestedBean.intProperty",    root, 77);
        BeanUtil.setPropertyValue("nestedBean.longProperty",   root, 777l);
        BeanUtil.setPropertyValue("nestedBean.enumProperty",   root, TestEnum.Seventh);

        Assert.assertEquals("testValue", root.getNestedBean().getStringProperty());
        Assert.assertEquals("testValue", BeanUtil.getPropertyValue("nestedBean.stringProperty", root));

        Assert.assertEquals(77, root.getNestedBean().getIntProperty());
        Assert.assertEquals(77, BeanUtil.getPropertyValue("nestedBean.intProperty", root));

        Assert.assertEquals(new Long(777l), root.getNestedBean().getLongProperty());
        Assert.assertEquals(777l, BeanUtil.getPropertyValue("nestedBean.longProperty", root));

        Assert.assertEquals(TestEnum.Seventh, root.getNestedBean().getEnumProperty());
        Assert.assertEquals(TestEnum.Seventh, BeanUtil.getPropertyValue("nestedBean.enumProperty", root));

        Assert.assertTrue(root.getNestedBean() == BeanUtil.getPropertyValue("nestedBean", root));
    }
View Full Code Here

        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

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.