1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.cubby.plugins.s2.beans;
17
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertFalse;
20 import static org.junit.Assert.assertTrue;
21
22 import org.junit.Test;
23 import org.seasar.cubby.plugins.s2.spi.S2BeanDescProvider;
24 import org.seasar.cubby.spi.BeanDescProvider;
25 import org.seasar.cubby.spi.beans.Attribute;
26 import org.seasar.cubby.spi.beans.BeanDesc;
27
28 public class S2BeanDescProviderTest {
29
30 BeanDescProvider beanDescProvider = new S2BeanDescProvider();
31
32 @Test
33 public void propertyDesc() throws Exception {
34 final BeanDesc beanDesc = beanDescProvider.getBeanDesc(MyBean.class);
35 assertEquals(5, beanDesc.findtPropertyAttributes().size());
36 Attribute propDesc = beanDesc.getPropertyAttribute("aaa");
37 assertEquals("aaa", propDesc.getName());
38 assertEquals(String.class, propDesc.getType());
39 assertTrue(propDesc.isReadable());
40 assertFalse(propDesc.isWritable());
41
42 propDesc = beanDesc.getPropertyAttribute("CCC");
43 assertEquals("CCC", propDesc.getName());
44 assertEquals(boolean.class, propDesc.getType());
45 assertTrue(propDesc.isReadable());
46 assertFalse(propDesc.isWritable());
47
48 propDesc = beanDesc.getPropertyAttribute("eee");
49 assertEquals("eee", propDesc.getName());
50 assertEquals(String.class, propDesc.getType());
51 assertTrue(propDesc.isReadable());
52 assertTrue(propDesc.isWritable());
53
54 propDesc = beanDesc.getPropertyAttribute("fff");
55 assertEquals("fff", propDesc.getName());
56 assertEquals(Boolean.class, propDesc.getType());
57
58 assertFalse(beanDesc.hasPropertyAttribute("hhh"));
59 assertFalse(beanDesc.hasPropertyAttribute("iii"));
60 }
61
62 @Test
63 public void invalidProperty() throws Exception {
64 final BeanDesc beanDesc = beanDescProvider.getBeanDesc(MyBean2.class);
65 assertEquals("1", false, beanDesc.hasPropertyAttribute("aaa"));
66 }
67
68
69
70
71 public static interface MyInterface {
72
73
74
75 String HOGE = "hoge";
76 }
77
78
79
80
81 public static interface MyInterface2 extends MyInterface {
82
83
84
85 String HOGE = "hoge2";
86 }
87
88
89
90
91 public static class MyBean implements MyInterface2 {
92
93 private String aaa;
94
95 private String eee;
96
97 private Boolean fff;
98
99
100
101
102 public String ggg;
103
104
105
106
107 public String getAaa() {
108 return aaa;
109 }
110
111
112
113
114
115 public String getBbb(final Object a) {
116 return null;
117 }
118
119
120
121
122 public boolean isCCC() {
123 return true;
124 }
125
126
127
128
129 public Object isDdd() {
130 return null;
131 }
132
133
134
135
136 public String getEee() {
137 return eee;
138 }
139
140
141
142
143 public void setEee(final String eee) {
144 this.eee = eee;
145 }
146
147
148
149
150 public Boolean isFff() {
151 return fff;
152 }
153
154
155
156
157
158 public MyBean setHhh(final String hhh) {
159 return this;
160 }
161
162
163
164
165 public void getIii() {
166 }
167
168
169
170
171
172
173 public Number add(final Number arg1, final Number arg2) {
174 return Integer.valueOf(3);
175 }
176
177
178
179
180
181
182 public int add2(final int arg1, final int arg2) {
183 return arg1 + arg2;
184 }
185
186
187
188
189
190 public Integer echo(final Integer arg) {
191 return arg;
192 }
193
194
195
196
197 public void throwException() {
198 throw new IllegalStateException("hoge");
199 }
200 }
201
202
203
204
205 public class MyBean2 {
206
207
208
209 public MyBean2() {
210 }
211
212
213
214
215
216
217
218 public MyBean2(final int num, final String text, final MyBean bean1,
219 final MyBean2 bean2) {
220 }
221
222
223
224
225 public void setAaa(final int i) {
226 }
227
228
229
230
231 public void setAaa(final String s) {
232 }
233 }
234
235 }