001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package test.compliance.modelmbean;
023:
024: import javax.management.Descriptor;
025: import javax.management.MBeanOperationInfo;
026: import javax.management.modelmbean.ModelMBeanAttributeInfo;
027: import javax.management.modelmbean.ModelMBeanConstructorInfo;
028: import javax.management.modelmbean.ModelMBeanInfo;
029: import javax.management.modelmbean.ModelMBeanInfoSupport;
030: import javax.management.modelmbean.ModelMBeanOperationInfo;
031: import javax.management.modelmbean.RequiredModelMBean;
032:
033: import junit.framework.AssertionFailedError;
034: import junit.framework.TestCase;
035:
036: public class ModelMBeanInfoSupportTEST extends TestCase {
037: public ModelMBeanInfoSupportTEST(String s) {
038: super (s);
039: }
040:
041: public void testSetDescriptors() throws Exception {
042: final boolean READABLE = true;
043: final boolean WRITABLE = true;
044: final boolean ISIS = true;
045:
046: RequiredModelMBean mbean = new RequiredModelMBean();
047:
048: ModelMBeanAttributeInfo attr1 = new ModelMBeanAttributeInfo(
049: "Kissa", String.class.getName(),
050: "Some attribute description", !READABLE, !WRITABLE,
051: !ISIS);
052:
053: ModelMBeanAttributeInfo attr2 = new ModelMBeanAttributeInfo(
054: "Koira", String.class.getName(),
055: "Another attribute description", !READABLE, !WRITABLE,
056: !ISIS);
057:
058: ModelMBeanConstructorInfo constr1 = new ModelMBeanConstructorInfo(
059: "FirstConstructor",
060: "Description of the first constructor", null);
061:
062: ModelMBeanConstructorInfo constr2 = new ModelMBeanConstructorInfo(
063: "SecondConstructor",
064: "Description of the second constructor", null);
065:
066: ModelMBeanConstructorInfo constr3 = new ModelMBeanConstructorInfo(
067: "ThirdConstructor",
068: "Description of the 3rd constructor", null);
069:
070: ModelMBeanOperationInfo operation = new ModelMBeanOperationInfo(
071: "AnOperation", "The description", null, "AType",
072: MBeanOperationInfo.ACTION);
073:
074: ModelMBeanInfoSupport info = new ModelMBeanInfoSupport(mbean
075: .getClass().getName(), "some description",
076: new ModelMBeanAttributeInfo[] { attr1, attr2 },
077: new ModelMBeanConstructorInfo[] { constr1, constr2,
078: constr3 },
079: new ModelMBeanOperationInfo[] { operation }, null);
080:
081: Descriptor descr1 = info.getDescriptor("SecondConstructor",
082: "constructor");
083:
084: assertTrue(descr1.getFieldValue("name").equals(
085: "SecondConstructor"));
086: assertTrue(descr1.getFieldValue("role").equals("constructor"));
087:
088: Descriptor descr2 = null;
089:
090: Descriptor[] descr3 = info.getDescriptors("operation");
091:
092: assertTrue(descr3[0].getFieldValue("descriptorType").equals(
093: "operation"));
094: assertTrue(descr3[0].getFieldValue("name")
095: .equals("AnOperation"));
096:
097: descr1.setField("someField", "someValue");
098: descr3[0].setField("Yksi", "Kaksi");
099:
100: info.setDescriptors(new Descriptor[] { descr1, descr2,
101: descr3[0] });
102:
103: descr1 = info.getDescriptor("SecondConstructor", "constructor");
104: assertTrue(descr1.getFieldValue("name").equals(
105: "SecondConstructor"));
106: assertTrue(descr1.getFieldValue("role").equals("constructor"));
107: assertTrue(descr1.getFieldValue("someField")
108: .equals("someValue"));
109:
110: descr1 = info.getDescriptor("AnOperation", "operation");
111:
112: assertTrue(descr1.getFieldValue("name").equals("AnOperation"));
113: assertTrue(descr1.getFieldValue("Yksi").equals("Kaksi"));
114:
115: }
116:
117: public void testGetDescriptor() throws Exception {
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", String.class.getName(),
126: "Some attribute description", !READABLE, !WRITABLE,
127: !ISIS);
128:
129: ModelMBeanAttributeInfo attr2 = new ModelMBeanAttributeInfo(
130: "Koira", String.class.getName(),
131: "Another attribute description", !READABLE, !WRITABLE,
132: !ISIS);
133:
134: ModelMBeanConstructorInfo constr1 = new ModelMBeanConstructorInfo(
135: "FirstConstructor",
136: "Description of the first constructor", null);
137:
138: ModelMBeanConstructorInfo constr2 = new ModelMBeanConstructorInfo(
139: "SecondConstructor",
140: "Description of the second constructor", null);
141:
142: ModelMBeanConstructorInfo constr3 = new ModelMBeanConstructorInfo(
143: "ThirdConstructor",
144: "Description of the 3rd constructor", null);
145:
146: ModelMBeanOperationInfo operation = new ModelMBeanOperationInfo(
147: "AnOperation", "The description", null, "AType",
148: MBeanOperationInfo.ACTION);
149:
150: ModelMBeanInfoSupport info = new ModelMBeanInfoSupport(mbean
151: .getClass().getName(), "some description",
152: new ModelMBeanAttributeInfo[] { attr1, attr2 },
153: new ModelMBeanConstructorInfo[] { constr1, constr2,
154: constr3 },
155: new ModelMBeanOperationInfo[] { operation }, null);
156:
157: Descriptor descr = info.getDescriptor("SecondConstructor",
158: "constructor");
159:
160: try {
161: assertTrue(descr.getFieldValue("descriptorType").equals(
162: "operation"));
163: } catch (AssertionFailedError e) {
164: throw new AssertionFailedError(
165: "FAILS IN JBOSSMX: We incorrectly return descriptor type "
166: + "'constructor' here -- should be 'operation'");
167: }
168:
169: }
170:
171: public void testClone() throws Exception {
172: final boolean READABLE = true;
173: final boolean WRITABLE = true;
174: final boolean ISIS = true;
175:
176: RequiredModelMBean mbean = new RequiredModelMBean();
177:
178: ModelMBeanAttributeInfo attr1 = new ModelMBeanAttributeInfo(
179: "Kissa", String.class.getName(),
180: "Some attribute description", !READABLE, !WRITABLE,
181: !ISIS);
182:
183: ModelMBeanAttributeInfo attr2 = new ModelMBeanAttributeInfo(
184: "Koira", String.class.getName(),
185: "Another attribute description", !READABLE, !WRITABLE,
186: !ISIS);
187:
188: ModelMBeanConstructorInfo constr1 = new ModelMBeanConstructorInfo(
189: "FirstConstructor",
190: "Description of the first constructor", null);
191:
192: ModelMBeanConstructorInfo constr2 = new ModelMBeanConstructorInfo(
193: "SecondConstructor",
194: "Description of the second constructor", null);
195:
196: ModelMBeanConstructorInfo constr3 = new ModelMBeanConstructorInfo(
197: "ThirdConstructor",
198: "Description of the 3rd constructor", null);
199:
200: ModelMBeanOperationInfo operation = new ModelMBeanOperationInfo(
201: "AnOperation", "The description", null, "AType",
202: MBeanOperationInfo.ACTION);
203:
204: ModelMBeanInfoSupport info = new ModelMBeanInfoSupport(mbean
205: .getClass().getName(), "some description",
206: new ModelMBeanAttributeInfo[] { attr1, attr2 },
207: new ModelMBeanConstructorInfo[] { constr1, constr2,
208: constr3 },
209: new ModelMBeanOperationInfo[] { operation }, null);
210:
211: ModelMBeanInfo clone = (ModelMBeanInfo) info.clone();
212:
213: assertTrue(clone.getDescriptors(null).length == info
214: .getDescriptors(null).length);
215:
216: // FIXME: equality not implemented to match field, value pairs
217: //assertTrue(clone.getDescriptor("FirstConstructor", "constructor")
218: // .equals(
219: // info.getDescriptor("FirstConstructor", "constructor"))
220: //);
221:
222: assertTrue(clone.getDescriptor("AnOperation", "operation")
223: .getFieldValue("descriptorType").equals(
224: info.getDescriptor("AnOperation", "operation")
225: .getFieldValue("descriptorType")));
226:
227: assertTrue(clone.getDescriptor("AnOperation", "operation")
228: .getFieldValue("name").equals(
229: info.getDescriptor("AnOperation", "operation")
230: .getFieldValue("name")));
231:
232: }
233:
234: }
|