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