KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > compliance > modelmbean > ModelMBeanInfoSupportTEST


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package test.compliance.modelmbean;
9
10 import javax.management.Descriptor;
11 import javax.management.MBeanOperationInfo;
12 import javax.management.modelmbean.ModelMBeanAttributeInfo;
13 import javax.management.modelmbean.ModelMBeanConstructorInfo;
14 import javax.management.modelmbean.ModelMBeanInfo;
15 import javax.management.modelmbean.ModelMBeanInfoSupport;
16 import javax.management.modelmbean.ModelMBeanOperationInfo;
17 import javax.management.modelmbean.RequiredModelMBean;
18
19 import junit.framework.AssertionFailedError;
20 import junit.framework.TestCase;
21
22
23 public class ModelMBeanInfoSupportTEST extends TestCase
24 {
25    public ModelMBeanInfoSupportTEST(String s)
26    {
27       super(s);
28    }
29
30    public void testSetDescriptors() throws Exception
31    {
32       final boolean READABLE = true;
33       final boolean WRITABLE = true;
34       final boolean ISIS = true;
35       
36       RequiredModelMBean mbean = new RequiredModelMBean();
37       
38       ModelMBeanAttributeInfo attr1 = new ModelMBeanAttributeInfo(
39             "Kissa",
40             String.class.getName(),
41             "Some attribute description",
42             !READABLE, !WRITABLE, !ISIS
43       );
44       
45       ModelMBeanAttributeInfo attr2 = new ModelMBeanAttributeInfo(
46             "Koira",
47             String.class.getName(),
48             "Another attribute description",
49             !READABLE, !WRITABLE, !ISIS
50       );
51       
52       ModelMBeanConstructorInfo constr1 = new ModelMBeanConstructorInfo(
53             "FirstConstructor",
54             "Description of the first constructor",
55             null
56       );
57       
58       ModelMBeanConstructorInfo constr2 = new ModelMBeanConstructorInfo(
59             "SecondConstructor",
60             "Description of the second constructor",
61             null
62       );
63       
64       ModelMBeanConstructorInfo constr3 = new ModelMBeanConstructorInfo(
65             "ThirdConstructor",
66             "Description of the 3rd constructor",
67             null
68       );
69       
70       ModelMBeanOperationInfo operation = new ModelMBeanOperationInfo(
71             "AnOperation",
72             "The description",
73             null,
74             "AType",
75             MBeanOperationInfo.ACTION
76       );
77       
78       ModelMBeanInfoSupport info = new ModelMBeanInfoSupport(
79             mbean.getClass().getName(),
80             "some description",
81             new ModelMBeanAttributeInfo[] { attr1, attr2 },
82             new ModelMBeanConstructorInfo[] { constr1, constr2, constr3 },
83             new ModelMBeanOperationInfo[] { operation },
84             null
85       );
86             
87       Descriptor descr1 = info.getDescriptor("SecondConstructor", "constructor");
88       
89       assertTrue(descr1.getFieldValue("name").equals("SecondConstructor"));
90       assertTrue(descr1.getFieldValue("role").equals("constructor"));
91       
92       Descriptor descr2 = null;
93       
94       Descriptor[] descr3 = info.getDescriptors("operation");
95       
96       assertTrue(descr3[0].getFieldValue("descriptorType").equals("operation"));
97       assertTrue(descr3[0].getFieldValue("name").equals("AnOperation"));
98       
99       descr1.setField("someField", "someValue");
100       descr3[0].setField("Yksi", "Kaksi");
101       
102       info.setDescriptors(new Descriptor[] { descr1, descr2, descr3[0] });
103       
104       descr1 = info.getDescriptor("SecondConstructor", "constructor");
105       assertTrue(descr1.getFieldValue("name").equals("SecondConstructor"));
106       assertTrue(descr1.getFieldValue("role").equals("constructor"));
107       assertTrue(descr1.getFieldValue("someField").equals("someValue"));
108       
109       descr1 = info.getDescriptor("AnOperation", "operation");
110       
111       assertTrue(descr1.getFieldValue("name").equals("AnOperation"));
112       assertTrue(descr1.getFieldValue("Yksi").equals("Kaksi"));
113       
114    }
115    
116    public void testGetDescriptor() throws Exception
117    {
118       final boolean READABLE = true;
119       final boolean WRITABLE = true;
120       final boolean ISIS = true;
121       
122       RequiredModelMBean mbean = new RequiredModelMBean();
123       
124       ModelMBeanAttributeInfo attr1 = new ModelMBeanAttributeInfo(
125             "Kissa",
126             String.class.getName(),
127             "Some attribute description",
128             !READABLE, !WRITABLE, !ISIS
129       );
130       
131       ModelMBeanAttributeInfo attr2 = new ModelMBeanAttributeInfo(
132             "Koira",
133             String.class.getName(),
134             "Another attribute description",
135             !READABLE, !WRITABLE, !ISIS
136       );
137       
138       ModelMBeanConstructorInfo constr1 = new ModelMBeanConstructorInfo(
139             "FirstConstructor",
140             "Description of the first constructor",
141             null
142       );
143       
144       ModelMBeanConstructorInfo constr2 = new ModelMBeanConstructorInfo(
145             "SecondConstructor",
146             "Description of the second constructor",
147             null
148       );
149       
150       ModelMBeanConstructorInfo constr3 = new ModelMBeanConstructorInfo(
151             "ThirdConstructor",
152             "Description of the 3rd constructor",
153             null
154       );
155       
156       ModelMBeanOperationInfo operation = new ModelMBeanOperationInfo(
157             "AnOperation",
158             "The description",
159             null,
160             "AType",
161             MBeanOperationInfo.ACTION
162       );
163       
164       ModelMBeanInfoSupport info = new ModelMBeanInfoSupport(
165             mbean.getClass().getName(),
166             "some description",
167             new ModelMBeanAttributeInfo[] { attr1, attr2 },
168             new ModelMBeanConstructorInfo[] { constr1, constr2, constr3 },
169             new ModelMBeanOperationInfo[] { operation },
170             null
171       );
172
173       Descriptor descr = info.getDescriptor("SecondConstructor", "constructor");
174
175       try
176       {
177          assertTrue(descr.getFieldValue("descriptorType").equals("operation"));
178       }
179       catch (AssertionFailedError e)
180       {
181          throw new AssertionFailedError(
182                "FAILS IN JBOSSMX: We incorrectly return descriptor type " +
183                "'constructor' here -- should be 'operation'"
184          );
185       }
186       
187    }
188    
189    
190    public void testClone() throws Exception
191    {
192       final boolean READABLE = true;
193       final boolean WRITABLE = true;
194       final boolean ISIS = true;
195       
196       RequiredModelMBean mbean = new RequiredModelMBean();
197       
198       ModelMBeanAttributeInfo attr1 = new ModelMBeanAttributeInfo(
199             "Kissa",
200             String.class.getName(),
201             "Some attribute description",
202             !READABLE, !WRITABLE, !ISIS
203       );
204       
205       ModelMBeanAttributeInfo attr2 = new ModelMBeanAttributeInfo(
206             "Koira",
207             String.class.getName(),
208             "Another attribute description",
209             !READABLE, !WRITABLE, !ISIS
210       );
211       
212       ModelMBeanConstructorInfo constr1 = new ModelMBeanConstructorInfo(
213             "FirstConstructor",
214             "Description of the first constructor",
215             null
216       );
217       
218       ModelMBeanConstructorInfo constr2 = new ModelMBeanConstructorInfo(
219             "SecondConstructor",
220             "Description of the second constructor",
221             null
222       );
223       
224       ModelMBeanConstructorInfo constr3 = new ModelMBeanConstructorInfo(
225             "ThirdConstructor",
226             "Description of the 3rd constructor",
227             null
228       );
229       
230       ModelMBeanOperationInfo operation = new ModelMBeanOperationInfo(
231             "AnOperation",
232             "The description",
233             null,
234             "AType",
235             MBeanOperationInfo.ACTION
236       );
237       
238       ModelMBeanInfoSupport info = new ModelMBeanInfoSupport(
239             mbean.getClass().getName(),
240             "some description",
241             new ModelMBeanAttributeInfo[] { attr1, attr2 },
242             new ModelMBeanConstructorInfo[] { constr1, constr2, constr3 },
243             new ModelMBeanOperationInfo[] { operation },
244             null
245       );
246
247       ModelMBeanInfo clone = (ModelMBeanInfo)info.clone();
248       
249       assertTrue(clone.getDescriptors(null).length == info.getDescriptors(null).length);
250       
251       // FIXME: equality not implemented to match field, value pairs
252
//assertTrue(clone.getDescriptor("FirstConstructor", "constructor")
253
// .equals(
254
// info.getDescriptor("FirstConstructor", "constructor"))
255
//);
256

257       assertTrue(
258             clone.getDescriptor("AnOperation", "operation")
259             .getFieldValue("descriptorType")
260             .equals(
261             info.getDescriptor("AnOperation", "operation")
262             .getFieldValue("descriptorType"))
263       );
264       
265       assertTrue(
266             clone.getDescriptor("AnOperation", "operation")
267             .getFieldValue("name")
268             .equals(
269             info.getDescriptor("AnOperation", "operation")
270             .getFieldValue("name"))
271       );
272       
273    }
274    
275 }
276
Popular Tags