001    /*
002     * Copyright 2002-2004 the original author or authors.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005     * use this file except in compliance with the License. You may obtain a copy of
006     * the License at
007     *
008     * http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012     * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013     * License for the specific language governing permissions and limitations under
014     * the License.
015     */
016    package org.springframework.binding.support;
017    
018    import java.util.HashMap;
019    import java.util.List;
020    import java.util.Map;
021    
022    import org.springframework.binding.PropertyMetadataAccessStrategy;
023    
024    /**
025     * Tests class {@link BeanPropertyAccessStrategy}.
026     *
027     * @author Oliver Hutchison
028     */
029    public class BeanPropertyAccessStrategyTests extends AbstractPropertyAccessStrategyTests {
030    
031            protected AbstractPropertyAccessStrategy createPropertyAccessStrategy(Object target) {
032                    return new BeanPropertyAccessStrategy(target);
033            }
034    
035        /**
036         * Test the metadata on type/readability/writeability.
037         */
038        public void testMetaData() {
039            PropertyMetadataAccessStrategy mas = pas.getMetadataAccessStrategy();
040    
041            assertPropertyMetadata(mas, "simpleProperty", String.class, true, true);
042            assertPropertyMetadata(mas, "mapProperty", Map.class, true, true);
043            assertPropertyMetadata(mas, "listProperty", List.class, true, true);
044            assertPropertyMetadata(mas, "readOnly", Object.class, true, false);
045            assertPropertyMetadata(mas, "writeOnly", Object.class, false, true);
046    
047            // test nested property
048            // when null, no type, not readable, not writeable
049            assertPropertyMetadata(mas, "nestedProperty.simpleProperty", null, false, false);
050            final TestBean nestedProperty = new TestBean();
051            testBean.setNestedProperty(nestedProperty);
052            // when provided, type/readable/writeable deducted from nested object
053            assertPropertyMetadata(mas, "nestedProperty.simpleProperty", String.class, true, true);
054    
055            // test access to map
056            final Map map = new HashMap();
057            testBean.setMapProperty(map);
058            map.put("key", new Integer(1));
059            assertPropertyMetadata(mas, "mapProperty[key]", Integer.class, true, true);
060        }
061    
062    }