KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jmx > compliance > modelmbean > ModelMBeanInfoSupportTEST


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

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

271       assertTrue(
272             clone.getDescriptor("AnOperation", "operation")
273             .getFieldValue("descriptorType")
274             .equals(
275             info.getDescriptor("AnOperation", "operation")
276             .getFieldValue("descriptorType"))
277       );
278       
279       assertTrue(
280             clone.getDescriptor("AnOperation", "operation")
281             .getFieldValue("name")
282             .equals(
283             info.getDescriptor("AnOperation", "operation")
284             .getFieldValue("name"))
285       );
286       
287    }
288    
289 }
290
Popular Tags