1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.trinidad.bean;
20
21 import org.apache.myfaces.trinidad.bean.FacesBean;
22 import org.apache.myfaces.trinidad.bean.PropertyKey;
23
24 import junit.framework.Test;
25 import junit.framework.TestCase;
26 import junit.framework.TestSuite;
27
28 public class TypeTest extends TestCase
29 {
30 public static final Test suite()
31 {
32 return new TestSuite(TypeTest.class);
33 }
34
35 public static void main(String[] args) throws Throwable
36 {
37 junit.textui.TestRunner.run(suite());
38 }
39
40 public TypeTest(
41 String testName)
42 {
43 super(testName);
44 }
45
46 @Override
47 public void setUp()
48 {
49 _type = new FacesBean.Type();
50 _fooKey = _type.registerKey("foo",
51 PropertyKey.CAP_TRANSIENT);
52 _barKey = _type.registerKey("bar",
53 PropertyKey.CAP_LIST);
54
55 _fooAliasKey = _type.registerAlias(_fooKey, "fooAlias");
56
57 _subtype = new FacesBean.Type(_type);
58 _bazKey = _subtype.registerKey("baz");
59 }
60
61 @Override
62 public void tearDown()
63 {
64 _type = null;
65 }
66
67 public void testKeyEquality()
68 {
69 assertTrue(_fooKey.equals(_fooKey));
70 assertTrue(_barKey.equals(_barKey));
71 assertTrue(!_fooKey.equals(_barKey));
72 assertTrue(!_barKey.equals(_fooKey));
73 assertTrue(!_fooKey.equals(null));
74 assertTrue(!_fooKey.equals("foo"));
75 assertTrue(!"foo".equals(_fooKey));
76 }
77
78 public void testKeyCapabilities()
79 {
80 assertTrue(_fooKey.isTransient());
81 assertTrue(_fooKey.getSupportsBinding());
82 assertTrue(!_fooKey.isList());
83
84 assertTrue(!_barKey.isTransient());
85 assertTrue(!_barKey.getSupportsBinding());
86 assertTrue(_barKey.isList());
87 }
88
89 public void testFindKeyByName()
90 {
91 PropertyKey foo = _type.findKey("foo");
92 assertSame(foo, _fooKey);
93 assertEquals("foo", foo.getName());
94
95 PropertyKey bar = _type.findKey("bar");
96 assertSame(bar, _barKey);
97 assertEquals("bar", bar.getName());
98
99 PropertyKey baz = _type.findKey("baz");
100 assertNull(baz);
101
102 baz = _subtype.findKey("baz");
103 assertSame(baz, _bazKey);
104 }
105
106 public void testFindKeyByIndex()
107 {
108 PropertyKey foo = _type.findKey(0);
109 assertSame(foo, _fooKey);
110 assertEquals(0, foo.getIndex());
111
112 PropertyKey bar = _type.findKey(1);
113 assertSame(bar, _barKey);
114 assertEquals(1, bar.getIndex());
115
116 PropertyKey baz = _type.findKey(2);
117 assertNull(baz);
118
119 baz = _type.findKey(-1);
120 assertNull(baz);
121 }
122
123 public void testTypeModifications()
124 {
125 PropertyKey newKey = _subtype.registerKey("new");
126 assertNotNull(newKey);
127
128 assertEquals(3, newKey.getIndex());
129 assertEquals("new", newKey.getName());
130
131
132 try
133 {
134 _subtype.registerKey("new");
135 fail();
136 }
137 catch (IllegalStateException ise)
138 {
139 }
140
141
142
143 assertSame(newKey, _subtype.findKey("new"));
144 assertSame(newKey, _subtype.findKey(3));
145
146
147 _subtype.lock();
148
149
150 try
151 {
152 _subtype.registerKey("reallyNew");
153 fail();
154 }
155 catch (IllegalStateException ise)
156 {
157 }
158
159
160 assertNull(_subtype.findKey("reallyNew"));
161 assertNull(_subtype.findKey(4));
162 }
163
164 public void testAlias()
165 {
166 assertSame(_fooKey, _fooAliasKey);
167 assertSame(_fooKey, _type.findKey("fooAlias"));
168 }
169
170 private FacesBean.Type _type;
171 private FacesBean.Type _subtype;
172 private PropertyKey _fooKey;
173 private PropertyKey _barKey;
174 private PropertyKey _bazKey;
175 private PropertyKey _fooAliasKey;
176 }