KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > values > types > PropertyTypeTest


1 /*
2  * (c) Rob Gordon 2005
3  */

4 package org.oddjob.values.types;
5
6 import java.util.Date JavaDoc;
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 /**
16  *
17  */

18 public class PropertyTypeTest extends TestCase {
19
20     public void test1() throws Exception JavaDoc {
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 JavaDoc {
30         PropertyType p = new PropertyType();
31         // can't do this yet!!!
32
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 JavaDoc e) {
38             
39         }
40     }
41     
42     public void test3() throws Exception JavaDoc {
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 JavaDoc.class));
51         assertEquals("ba", IntrospectionHelper.valueFor(
52                 PropertyUtils.getProperty(p, "aaa.bbb.2"), String JavaDoc.class));
53     }
54     
55     public void testValueForDate() {
56         PropertyType p = new PropertyType();
57         p.set("date", new Date JavaDoc());
58         
59         assertEquals(Date JavaDoc.class, IntrospectionHelper.
60                 valueFor(p.get("date")).getClass());
61     }
62     
63 }
64
Popular Tags