commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@apache.org
Subject cvs commit: jakarta-commons/beanutils/src/test/org/apache/commons/beanutils BeanUtilsTestCase.java DynaBeanUtilsTestCase.java PropertyUtilsTestCase.java TestBean.java
Date Sat, 20 Jul 2002 22:36:36 GMT
craigmcc    2002/07/20 15:36:36

  Modified:    beanutils/src/test/org/apache/commons/beanutils
                        BeanUtilsTestCase.java DynaBeanUtilsTestCase.java
                        PropertyUtilsTestCase.java TestBean.java
  Log:
  Add test cases to demonstrate that a property ("dupProperty") with both
  subscript-based and array-based getters and setters can be utilized, including
  via BeanUtils.copyProperties().
  
  BeanUtils.populate() will not be modified to deal with this, because it is
  designed to convert an array of Strings into a single String if that is the
  destination data type (which is what JavaBeans introspection will report in
  this case).  For general purpose copying of bean properties with conversion,
  BeanUtils.copyProperties() should be used instead.
  
  PR: Bugzilla #9868
  Submitted by:	Jerome Jacobsen <jerome.jacobsen at gentootech.com>
  
  Revision  Changes    Path
  1.13      +20 -4     jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/BeanUtilsTestCase.java
  
  Index: BeanUtilsTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/BeanUtilsTestCase.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- BeanUtilsTestCase.java	13 Jul 2002 02:22:09 -0000	1.12
  +++ BeanUtilsTestCase.java	20 Jul 2002 22:36:36 -0000	1.13
  @@ -116,6 +116,7 @@
       { "booleanProperty",
         "booleanSecond",
         "doubleProperty",
  +      "dupProperty",
         "floatProperty",
         "intArray",
         //      "intIndexed",
  @@ -190,6 +191,8 @@
           }
           orig.set("booleanProperty", Boolean.FALSE);
           orig.set("doubleProperty", new Double(333.33));
  +        orig.set("dupProperty",
  +                 new String[] { "New 0", "New 1", "New 2" });
           orig.set("intArray", new int[] { 100, 200, 300 });
           orig.set("intProperty", new Integer(333));
           orig.set("longProperty", new Long(3333));
  @@ -226,6 +229,12 @@
                        bean.getStringProperty());
   
           // Validate the results for array properties
  +        String dupProperty[] = bean.getDupProperty();
  +        assertNotNull("dupProperty present", dupProperty);
  +        assertEquals("dupProperty length", 3, dupProperty.length);
  +        assertEquals("dupProperty[0]", "New 0", dupProperty[0]);
  +        assertEquals("dupProperty[1]", "New 1", dupProperty[1]);
  +        assertEquals("dupProperty[2]", "New 2", dupProperty[2]);
           int intArray[] = bean.getIntArray();
           assertNotNull("intArray present", intArray);
           assertEquals("intArray length", 3, intArray.length);
  @@ -250,6 +259,7 @@
           TestBean orig = new TestBean();
           orig.setBooleanProperty(false);
           orig.setDoubleProperty(333.33);
  +        orig.setDupProperty(new String[] { "New 0", "New 1", "New 2" });
           orig.setIntArray(new int[] { 100, 200, 300 });
           orig.setIntProperty(333);
           orig.setLongProperty(3333);
  @@ -286,6 +296,12 @@
                        bean.getStringProperty());
   
           // Validate the results for array properties
  +        String dupProperty[] = bean.getDupProperty();
  +        assertNotNull("dupProperty present", dupProperty);
  +        assertEquals("dupProperty length", 3, dupProperty.length);
  +        assertEquals("dupProperty[0]", "New 0", dupProperty[0]);
  +        assertEquals("dupProperty[1]", "New 1", dupProperty[1]);
  +        assertEquals("dupProperty[2]", "New 2", dupProperty[2]);
           int intArray[] = bean.getIntArray();
           assertNotNull("intArray present", intArray);
           assertEquals("intArray length", 3, intArray.length);
  
  
  
  1.11      +22 -4     jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/DynaBeanUtilsTestCase.java
  
  Index: DynaBeanUtilsTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/DynaBeanUtilsTestCase.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- DynaBeanUtilsTestCase.java	13 Jul 2002 02:22:09 -0000	1.10
  +++ DynaBeanUtilsTestCase.java	20 Jul 2002 22:36:36 -0000	1.11
  @@ -105,6 +105,7 @@
       { "booleanProperty",
         "booleanSecond",
         "doubleProperty",
  +      "dupProperty",
         "floatProperty",
         "intArray",
         "intIndexed",
  @@ -155,6 +156,8 @@
           bean.set("booleanSecond", new Boolean(true));
           bean.set("doubleProperty", new Double(321.0));
           bean.set("floatProperty", new Float((float) 123.0));
  +        String dupProperty[] = { "Dup 0", "Dup 1", "Dup 2", "Dup 3", "Dup 4"};
  +        bean.set("dupProperty", dupProperty);
           int intArray[] = { 0, 10, 20, 30, 40 };
           bean.set("intArray", intArray);
           int intIndexed[] = { 0, 10, 20, 30, 40 };
  @@ -231,6 +234,7 @@
           }
           orig.set("booleanProperty", Boolean.FALSE);
           orig.set("doubleProperty", new Double(333.33));
  +        orig.set("dupProperty", new String[] { "New 0", "New 1", "New 2" });
           orig.set("intArray", new int[] { 100, 200, 300 });
           orig.set("intProperty", new Integer(333));
           orig.set("longProperty", new Long(3333));
  @@ -267,6 +271,12 @@
                        (String) bean.get("stringProperty"));
   
           // Validate the results for array properties
  +        String dupProperty[] = (String[]) bean.get("dupProperty");
  +        assertNotNull("dupProperty present", dupProperty);
  +        assertEquals("dupProperty length", 3, dupProperty.length);
  +        assertEquals("dupProperty[0]", "New 0", dupProperty[0]);
  +        assertEquals("dupProperty[1]", "New 1", dupProperty[1]);
  +        assertEquals("dupProperty[2]", "New 2", dupProperty[2]);
           int intArray[] = (int[]) bean.get("intArray");
           assertNotNull("intArray present", intArray);
           assertEquals("intArray length", 3, intArray.length);
  @@ -291,6 +301,7 @@
           TestBean orig = new TestBean();
           orig.setBooleanProperty(false);
           orig.setDoubleProperty(333.33);
  +        orig.setDupProperty(new String[] { "New 0", "New 1", "New 2" });
           orig.setIntArray(new int[] { 100, 200, 300 });
           orig.setIntProperty(333);
           orig.setLongProperty(3333);
  @@ -327,6 +338,12 @@
                        (String) bean.get("stringProperty"));
   
           // Validate the results for array properties
  +        String dupProperty[] = (String[]) bean.get("dupProperty");
  +        assertNotNull("dupProperty present", dupProperty);
  +        assertEquals("dupProperty length", 3, dupProperty.length);
  +        assertEquals("dupProperty[0]", "New 0", dupProperty[0]);
  +        assertEquals("dupProperty[1]", "New 1", dupProperty[1]);
  +        assertEquals("dupProperty[2]", "New 2", dupProperty[2]);
           int intArray[] = (int[]) bean.get("intArray");
           assertNotNull("intArray present", intArray);
           assertEquals("intArray length", 3, intArray.length);
  @@ -776,6 +793,7 @@
                               new DynaProperty("booleanProperty", Boolean.TYPE),
                               new DynaProperty("booleanSecond", Boolean.TYPE),
                               new DynaProperty("doubleProperty", Double.TYPE),
  +                            new DynaProperty("dupProperty", stringArray.getClass()),
                               new DynaProperty("floatProperty", Float.TYPE),
                               new DynaProperty("intArray", intArray.getClass()),
                               new DynaProperty("intIndexed", intArray.getClass()),
  
  
  
  1.20      +109 -75   jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/PropertyUtilsTestCase.java
  
  Index: PropertyUtilsTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/PropertyUtilsTestCase.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- PropertyUtilsTestCase.java	20 Jul 2002 19:12:45 -0000	1.19
  +++ PropertyUtilsTestCase.java	20 Jul 2002 22:36:36 -0000	1.20
  @@ -174,31 +174,6 @@
   
   
       /**
  -     * The set of properties that should be described.
  -     */
  -    protected String describes[] =
  -    { "booleanProperty",
  -      "booleanSecond",
  -      "doubleProperty",
  -      "floatProperty",
  -      "intArray",
  -      //      "intIndexed",
  -      "intProperty",
  -      "listIndexed",
  -      "longProperty",
  -      //      "mappedProperty",
  -      //      "mappedIntProperty",
  -      "nested",
  -      "nullProperty",
  -      "readOnlyProperty",
  -      "shortProperty",
  -      "stringArray",
  -      //      "stringIndexed",
  -      "stringProperty"
  -    };
  -
  -
  -    /**
        * The set of property names we expect to have returned when calling
        * <code>getPropertyDescriptors()</code>.  You should update this list
        * when new properties are added to TestBean.
  @@ -207,6 +182,7 @@
           "booleanProperty",
           "booleanSecond",
           "doubleProperty",
  +        "dupProperty",
           "floatProperty",
           "intArray",
           "intIndexed",
  @@ -285,52 +261,6 @@
   
   
       /**
  -     * Test the describe() method.
  -     */
  -    public void testDescribe() {
  -
  -        Map map = null;
  -        try {
  -            map = BeanUtils.describe(bean);
  -        } catch (Exception e) {
  -            fail("Threw exception " + e);
  -        }
  -
  -        // Verify existence of all the properties that should be present
  -        for (int i = 0; i < describes.length; i++) {
  -            assertTrue("Property '" + describes[i] + "' is present",
  -                       map.containsKey(describes[i]));
  -        }
  -        assertTrue("Property 'writeOnlyProperty' is not present",
  -                   !map.containsKey("writeOnlyProperty"));
  -
  -        // Verify the values of scalar properties
  -        assertEquals("Value of 'booleanProperty'",
  -                     "true",
  -                     (String) map.get("booleanProperty"));
  -        assertEquals("Value of 'doubleProperty'",
  -                     "321.0",
  -                     (String) map.get("doubleProperty"));
  -        assertEquals("Value of 'floatProperty'",
  -                     "123.0",
  -                     (String) map.get("floatProperty"));
  -        assertEquals("Value of 'intProperty'",
  -                     "123",
  -                     (String) map.get("intProperty"));
  -        assertEquals("Value of 'longProperty'",
  -                     "321",
  -                     (String) map.get("longProperty"));
  -        assertEquals("Value of 'shortProperty'",
  -                     "987",
  -                     (String) map.get("shortProperty"));
  -        assertEquals("Value of 'stringProperty'",
  -                     "This is a string",
  -                     (String) map.get("stringProperty"));
  -
  -    }
  -
  -
  -    /**
        * Corner cases on getPropertyDescriptor invalid arguments.
        */
       public void testGetDescriptorArguments() {
  @@ -643,6 +573,19 @@
           for (int i = 0; i < 5; i++) {
   
               try {
  +                value = PropertyUtils.getIndexedProperty
  +                    (bean, "dupProperty", i);
  +                assertNotNull("dupProperty returned value " + i, value);
  +                assertTrue("dupProperty returned String " + i,
  +                        value instanceof String);
  +                assertEquals("dupProperty returned correct " + i,
  +                             "Dup " + i,
  +                             (String) value);
  +            } catch (Throwable t) {
  +                fail("dupProperty " + i + " threw " + t);
  +            }
  +
  +            try {
                   value =
                           PropertyUtils.getIndexedProperty(bean, "intArray", i);
                   assertNotNull("intArray returned value " + i, value);
  @@ -709,6 +652,19 @@
           for (int i = 0; i < 5; i++) {
   
               try {
  +                value = PropertyUtils.getIndexedProperty
  +                    (bean, "dupProperty[" + i + "]");
  +                assertNotNull("dupProperty returned value " + i, value);
  +                assertTrue("dupProperty returned String " + i,
  +                        value instanceof String);
  +                assertEquals("dupProperty returned correct " + i,
  +                             "Dup " + i,
  +                             (String) value);
  +            } catch (Throwable t) {
  +                fail("dupProperty " + i + " threw " + t);
  +            }
  +
  +            try {
                   value =
                           PropertyUtils.getIndexedProperty(bean,
                                   "intArray[" + i + "]");
  @@ -780,6 +736,28 @@
           try {
               value =
                       PropertyUtils.getIndexedProperty(bean,
  +                            "dupProperty", -1);
  +            fail("Should have thrown ArrayIndexOutOfBoundsException");
  +        } catch (ArrayIndexOutOfBoundsException t) {
  +            ; // Expected results
  +        } catch (Throwable t) {
  +            fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException");
  +        }
  +
  +        try {
  +            value =
  +                    PropertyUtils.getIndexedProperty(bean,
  +                            "dupProperty", 5);
  +            fail("Should have thrown ArrayIndexOutOfBoundsException");
  +        } catch (ArrayIndexOutOfBoundsException t) {
  +            ; // Expected results
  +        } catch (Throwable t) {
  +            fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException");
  +        }
  +
  +        try {
  +            value =
  +                    PropertyUtils.getIndexedProperty(bean,
                               "intArray", -1);
               fail("Should have thrown ArrayIndexOutOfBoundsException");
           } catch (ArrayIndexOutOfBoundsException t) {
  @@ -1443,6 +1421,8 @@
               assertEquals("booleanSecond type", Boolean.TYPE, clazz);
               clazz = PropertyUtils.getPropertyType(bean, "doubleProperty");
               assertEquals("doubleProperty type", Double.TYPE, clazz);
  +            clazz = PropertyUtils.getPropertyType(bean, "dupProperty");
  +            assertEquals("dupProperty type", String.class, clazz);
               clazz = PropertyUtils.getPropertyType(bean, "floatProperty");
               assertEquals("floatProperty type", Float.TYPE, clazz);
               clazz = PropertyUtils.getPropertyType(bean, "intArray");
  @@ -2086,6 +2066,22 @@
   
           try {
               PropertyUtils.setIndexedProperty(bean,
  +                    "dupProperty", 0,
  +                    "New 0");
  +            value =
  +                    PropertyUtils.getIndexedProperty(bean,
  +                            "dupProperty", 0);
  +            assertNotNull("Returned new value 0", value);
  +            assertTrue("Returned String new value 0",
  +                    value instanceof String);
  +            assertEquals("Returned correct new value 0", "New 0",
  +                    (String) value);
  +        } catch (Throwable t) {
  +            fail("Threw " + t);
  +        }
  +
  +        try {
  +            PropertyUtils.setIndexedProperty(bean,
                       "intArray", 0,
                       new Integer(1));
               value =
  @@ -2168,6 +2164,22 @@
   
           try {
               PropertyUtils.setIndexedProperty(bean,
  +                    "dupProperty[4]",
  +                    "New 4");
  +            value =
  +                    PropertyUtils.getIndexedProperty(bean,
  +                            "dupProperty[4]");
  +            assertNotNull("Returned new value 4", value);
  +            assertTrue("Returned String new value 4",
  +                    value instanceof String);
  +            assertEquals("Returned correct new value 4", "New 4",
  +                         (String) value);
  +        } catch (Throwable t) {
  +            fail("Threw " + t);
  +        }
  +
  +        try {
  +            PropertyUtils.setIndexedProperty(bean,
                       "intArray[4]",
                       new Integer(1));
               value =
  @@ -2247,6 +2259,28 @@
           }
   
           // Index out of bounds tests
  +
  +        try {
  +            PropertyUtils.setIndexedProperty(bean,
  +                    "dupProperty", -1,
  +                    "New -1");
  +            fail("Should have thrown ArrayIndexOutOfBoundsException");
  +        } catch (ArrayIndexOutOfBoundsException t) {
  +            ; // Expected results
  +        } catch (Throwable t) {
  +            fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException");
  +        }
  +
  +        try {
  +            PropertyUtils.setIndexedProperty(bean,
  +                    "dupProperty", 5,
  +                    "New 5");
  +            fail("Should have thrown ArrayIndexOutOfBoundsException");
  +        } catch (ArrayIndexOutOfBoundsException t) {
  +            ; // Expected results
  +        } catch (Throwable t) {
  +            fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException");
  +        }
   
           try {
               PropertyUtils.setIndexedProperty(bean,
  
  
  
  1.11      +28 -4     jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/TestBean.java
  
  Index: TestBean.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/TestBean.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- TestBean.java	20 Jul 2002 19:12:45 -0000	1.10
  +++ TestBean.java	20 Jul 2002 22:36:36 -0000	1.11
  @@ -125,6 +125,30 @@
   
   
       /**
  +     * An "indexed property" accessible via both array and subscript
  +     * based getters and setters.
  +     */
  +    private String dupProperty[] =
  +    { "Dup 0", "Dup 1", "Dup 2", "Dup 3", "Dup 4" };
  +
  +    public String[] getDupProperty() {
  +        return (this.dupProperty);
  +    }
  +
  +    public String getDupProperty(int index) {
  +        return (this.dupProperty[index]);
  +    }
  +
  +    public void setDupProperty(int index, String value) {
  +        this.dupProperty[index] = value;
  +    }
  +
  +    public void setDupProperty(String dupProperty[]) {
  +        this.dupProperty = dupProperty;
  +    }
  +
  +
  +    /**
        * A float property.
        */
       private float floatProperty = (float) 123.0;
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message