001 /* 002 * Copyright 2007 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 * @author Arne Limburg 026 */ 027 public class ObjectPropertyAccessStrategyTests extends AbstractPropertyAccessStrategyTests { 028 029 protected AbstractPropertyAccessStrategy createPropertyAccessStrategy(Object target) { 030 return new ObjectPropertyAccessStrategy(target); 031 } 032 033 /** 034 * Test the metadata on type/readability/writeability. 035 */ 036 public void testMetaData() { 037 PropertyMetadataAccessStrategy mas = pas.getMetadataAccessStrategy(); 038 039 assertPropertyMetadata(mas, "simpleProperty", String.class, true, true); 040 assertPropertyMetadata(mas, "mapProperty", Map.class, true, true); 041 assertPropertyMetadata(mas, "listProperty", List.class, true, true); 042 assertPropertyMetadata(mas, "readOnly", Object.class, true, false); 043 assertPropertyMetadata(mas, "writeOnly", Object.class, false, true); 044 045 // type/readable/writeable depend not on the property being not null 046 assertPropertyMetadata(mas, "nestedProperty.simpleProperty", String.class, true, true); 047 048 // test access to map 049 final Map map = new HashMap(); 050 testBean.setMapProperty(map); 051 map.put("key", new Integer(1)); 052 assertPropertyMetadata(mas, "mapProperty[key]", Object.class, true, true); 053 } 054 }