1 4 package org.oddjob.values.types; 5 6 import java.util.Date ; 7 8 import junit.framework.TestCase; 9 10 import org.apache.commons.beanutils.BeanUtils; 11 import org.apache.commons.beanutils.PropertyUtils; 12 import org.oddjob.arooa.reflect.IntrospectionHelper; 13 import org.oddjob.values.types.PropertyType; 14 15 18 public class PropertyTypeTest extends TestCase { 19 20 public void test1() throws Exception { 21 PropertyType p = new PropertyType(); 22 p.add("aaa.bbb.1", null); 23 System.out.println(p); 24 PropertyType p2 = (PropertyType) PropertyUtils.getProperty(p, "aaa.bbb"); 25 System.out.println(p2); 26 assertNotNull(p2.get("1")); 27 } 28 29 public void test2() throws Exception { 30 PropertyType p = new PropertyType(); 31 try { 33 BeanUtils.setProperty(p, "aaa.bbb.1", "foo"); 34 assertEquals(1, p.size()); 35 assertNotNull(PropertyUtils.getProperty(p, "aaa.bbb.1")); 36 } 37 catch (Exception e) { 38 39 } 40 } 41 42 public void test3() throws Exception { 43 PropertyType p = new PropertyType(); 44 p.add("aaa.bbb.1", null); 45 46 BeanUtils.setProperty(p, "aaa.bbb.1", "foo"); 47 BeanUtils.setProperty(p, "aaa.bbb.2", "ba"); 48 49 assertEquals("foo", IntrospectionHelper.valueFor( 50 PropertyUtils.getProperty(p, "aaa.bbb.1"), String .class)); 51 assertEquals("ba", IntrospectionHelper.valueFor( 52 PropertyUtils.getProperty(p, "aaa.bbb.2"), String .class)); 53 } 54 55 public void testValueForDate() { 56 PropertyType p = new PropertyType(); 57 p.set("date", new Date ()); 58 59 assertEquals(Date .class, IntrospectionHelper. 60 valueFor(p.get("date")).getClass()); 61 } 62 63 } 64 | Popular Tags |