001: /*
002: * Copyright (C) The MX4J Contributors.
003: * All rights reserved.
004: *
005: * This software is distributed under the terms of the MX4J License version 1.0.
006: * See the terms of the MX4J License in the documentation provided with this software.
007: */
008:
009: package test.javax.management.compliance.serialization.support;
010:
011: import java.lang.reflect.Field;
012: import java.lang.reflect.Method;
013: import java.util.ArrayList;
014: import java.util.Arrays;
015: import java.util.List;
016: import java.util.Vector;
017: import javax.management.AttributeChangeNotification;
018: import javax.management.AttributeChangeNotificationFilter;
019: import javax.management.AttributeList;
020: import javax.management.AttributeValueExp;
021: import javax.management.BadBinaryOpValueExpException;
022: import javax.management.JMRuntimeException;
023: import javax.management.MBeanAttributeInfo;
024: import javax.management.MBeanConstructorInfo;
025: import javax.management.MBeanException;
026: import javax.management.MBeanFeatureInfo;
027: import javax.management.MBeanInfo;
028: import javax.management.MBeanNotificationInfo;
029: import javax.management.MBeanOperationInfo;
030: import javax.management.MBeanParameterInfo;
031: import javax.management.MBeanServerNotification;
032: import javax.management.MBeanTrustPermission;
033: import javax.management.Notification;
034: import javax.management.NotificationFilterSupport;
035: import javax.management.ObjectName;
036: import javax.management.QueryExp;
037: import javax.management.ReflectionException;
038: import javax.management.RuntimeErrorException;
039: import javax.management.RuntimeMBeanException;
040: import javax.management.RuntimeOperationsException;
041: import javax.management.StringValueExp;
042: import javax.management.ValueExp;
043: import javax.management.modelmbean.DescriptorSupport;
044: import javax.management.modelmbean.ModelMBeanAttributeInfo;
045: import javax.management.modelmbean.ModelMBeanConstructorInfo;
046: import javax.management.modelmbean.ModelMBeanInfoSupport;
047: import javax.management.modelmbean.ModelMBeanNotificationInfo;
048: import javax.management.modelmbean.ModelMBeanOperationInfo;
049: import javax.management.monitor.MonitorNotification;
050: import javax.management.relation.MBeanServerNotificationFilter;
051: import javax.management.relation.RelationNotification;
052: import javax.management.relation.RelationTypeSupport;
053: import javax.management.relation.Role;
054: import javax.management.relation.RoleInfo;
055: import javax.management.relation.RoleList;
056: import javax.management.relation.RoleResult;
057: import javax.management.relation.RoleUnresolved;
058: import javax.management.relation.RoleUnresolvedList;
059: import javax.management.timer.TimerNotification;
060:
061: /**
062: * @version $Revision: 1.7 $
063: */
064: public class Comparator {
065: public void compareAndQueryExp(Object o1, Object o2)
066: throws Exception {
067: compareQueryExp(o1, o2);
068: }
069:
070: public void compareAttributeChangeNotification(Object o1, Object o2) {
071: compareNotification(o1, o2);
072:
073: AttributeChangeNotification n1 = (AttributeChangeNotification) o1;
074: AttributeChangeNotification n2 = (AttributeChangeNotification) o2;
075:
076: if (!n1.getAttributeName().equals(n2.getAttributeName()))
077: throw new RuntimeException();
078: if (!n1.getAttributeType().equals(n2.getAttributeType()))
079: throw new RuntimeException();
080: if (!n1.getNewValue().equals(n2.getNewValue()))
081: throw new RuntimeException();
082: if (!n1.getOldValue().equals(n2.getOldValue()))
083: throw new RuntimeException();
084: }
085:
086: public void compareAttributeChangeNotificationFilter(Object o1,
087: Object o2) {
088: AttributeChangeNotificationFilter f1 = (AttributeChangeNotificationFilter) o1;
089: AttributeChangeNotificationFilter f2 = (AttributeChangeNotificationFilter) o2;
090:
091: if (!f1.getEnabledAttributes()
092: .equals(f2.getEnabledAttributes()))
093: throw new RuntimeException();
094: }
095:
096: public void compareAttributeList(Object o1, Object o2) {
097: AttributeList a1 = (AttributeList) o1;
098: AttributeList a2 = (AttributeList) o2;
099: // It's enough AttributeList.equals()
100: if (!a1.equals(a2))
101: throw new RuntimeException();
102: }
103:
104: public void compareAttributeNotFoundException(Object o1, Object o2) {
105: compareOperationsException(o1, o2);
106: }
107:
108: public void compareAttributeValueExp(Object o1, Object o2) {
109: AttributeValueExp val1 = (AttributeValueExp) o1;
110: AttributeValueExp val2 = (AttributeValueExp) o2;
111:
112: if (!val1.getAttributeName().equals(val2.getAttributeName()))
113: throw new RuntimeException();
114: }
115:
116: public void compareBadAttributeValueExpException(Object o1,
117: Object o2) {
118: // No way to compare them
119: }
120:
121: public void compareBadBinaryOpValueExpException(Object o1, Object o2) {
122: BadBinaryOpValueExpException b1 = (BadBinaryOpValueExpException) o1;
123: BadBinaryOpValueExpException b2 = (BadBinaryOpValueExpException) o2;
124: compareStringValueExp(b1.getExp(), b2.getExp());
125: }
126:
127: public void compareBadStringOperationException(Object o1, Object o2) {
128: // No way to compare them
129: }
130:
131: public void compareBetweenQueryExp(Object o1, Object o2)
132: throws Exception {
133: compareQueryExp(o1, o2);
134: }
135:
136: public void compareBinaryOpValueExp(Object o1, Object o2)
137: throws Exception {
138: ValueExp val1 = (ValueExp) o1;
139: ValueExp val2 = (ValueExp) o2;
140:
141: compareNumericValueExp(val1.apply(null), val2.apply(null));
142: }
143:
144: public void compareBinaryRelQueryExp(Object o1, Object o2)
145: throws Exception {
146: compareQueryExp(o1, o2);
147: }
148:
149: public void compareBooleanValueExp(Object o1, Object o2)
150: throws Exception {
151: Field field = o1.getClass().getDeclaredField("val");
152: field.setAccessible(true);
153: boolean res1 = field.getBoolean(o1);
154: boolean res2 = field.getBoolean(o2);
155: if (!res1 || !res2)
156: throw new RuntimeException();
157: }
158:
159: public void compareClassAttributeValueExp(Object o1, Object o2) {
160: // Nothing to compare
161: }
162:
163: public void compareInQueryExp(Object o1, Object o2)
164: throws Exception {
165: compareQueryExp(o1, o2);
166: }
167:
168: public void compareInstanceAlreadyExistsException(Object o1,
169: Object o2) {
170: compareOperationsException(o1, o2);
171: }
172:
173: public void compareInstanceNotFoundException(Object o1, Object o2) {
174: compareOperationsException(o1, o2);
175: }
176:
177: public void compareIntrospectionException(Object o1, Object o2) {
178: compareOperationsException(o1, o2);
179: }
180:
181: public void compareInvalidApplicationException(Object o1, Object o2) {
182: // No way to compare them
183: }
184:
185: public void compareInvalidAttributeValueException(Object o1,
186: Object o2) {
187: compareOperationsException(o1, o2);
188: }
189:
190: public void compareJMException(Object o1, Object o2) {
191: compareException(o1, o2);
192: }
193:
194: public void compareError(Object o1, Object o2) {
195: Error x1 = (Error) o1;
196: Error x2 = (Error) o2;
197: if (!x1.getMessage().equals(x2.getMessage()))
198: throw new RuntimeException();
199: }
200:
201: public void compareException(Object o1, Object o2) {
202: Exception x1 = (Exception) o1;
203: Exception x2 = (Exception) o2;
204: if (!x1.getMessage().equals(x2.getMessage()))
205: throw new RuntimeException();
206: }
207:
208: public void compareJMRuntimeException(Object o1, Object o2) {
209: JMRuntimeException x1 = (JMRuntimeException) o1;
210: JMRuntimeException x2 = (JMRuntimeException) o2;
211: if (!x1.getMessage().equals(x2.getMessage()))
212: throw new RuntimeException();
213: }
214:
215: public void compareListenerNotFoundException(Object o1, Object o2) {
216: compareOperationsException(o1, o2);
217: }
218:
219: public void compareMalformedObjectNameException(Object o1, Object o2) {
220: compareOperationsException(o1, o2);
221: }
222:
223: public void compareMatchQueryExp(Object o1, Object o2)
224: throws Exception {
225: // Cannot be compared, require MBeanServer
226: }
227:
228: public void compareMBeanAttributeInfo(Object o1, Object o2) {
229: compareMBeanFeatureInfo(o1, o2);
230:
231: MBeanAttributeInfo a1 = (MBeanAttributeInfo) o1;
232: MBeanAttributeInfo a2 = (MBeanAttributeInfo) o2;
233:
234: if (!a1.getType().equals(a2.getType()))
235: throw new RuntimeException();
236: if (a1.isReadable() != a2.isReadable())
237: throw new RuntimeException();
238: if (a1.isWritable() != a2.isWritable())
239: throw new RuntimeException();
240: if (a1.isIs() != a2.isIs())
241: throw new RuntimeException();
242: }
243:
244: public void compareMBeanConstructorInfo(Object o1, Object o2) {
245: compareMBeanFeatureInfo(o1, o2);
246:
247: MBeanConstructorInfo c1 = (MBeanConstructorInfo) o1;
248: MBeanConstructorInfo c2 = (MBeanConstructorInfo) o2;
249:
250: MBeanParameterInfo[] p1 = c1.getSignature();
251: MBeanParameterInfo[] p2 = c2.getSignature();
252:
253: if (p1.length != p2.length)
254: throw new RuntimeException();
255: for (int i = 0; i < p1.length; ++i) {
256: compareMBeanParameterInfo(p1[i], p2[i]);
257: }
258: }
259:
260: public void compareMBeanException(Object o1, Object o2) {
261: compareJMException(o1, o2);
262:
263: MBeanException x1 = (MBeanException) o1;
264: MBeanException x2 = (MBeanException) o2;
265:
266: Exception xx1 = x1.getTargetException();
267: Exception xx2 = x2.getTargetException();
268: compareException(xx1, xx2);
269: }
270:
271: public void compareMBeanFeatureInfo(Object o1, Object o2) {
272: MBeanFeatureInfo f1 = (MBeanFeatureInfo) o1;
273: MBeanFeatureInfo f2 = (MBeanFeatureInfo) o2;
274:
275: if (!f1.getName().equals(f2.getName()))
276: throw new RuntimeException();
277: if (!f1.getDescription().equals(f2.getDescription()))
278: throw new RuntimeException();
279: }
280:
281: public void compareMBeanInfo(Object o1, Object o2) {
282: MBeanInfo i1 = (MBeanInfo) o1;
283: MBeanInfo i2 = (MBeanInfo) o2;
284:
285: if (!i1.getClassName().equals(i2.getClassName()))
286: throw new RuntimeException();
287: if (!i1.getDescription().equals(i2.getDescription()))
288: throw new RuntimeException();
289:
290: MBeanAttributeInfo[] a1 = i1.getAttributes();
291: MBeanAttributeInfo[] a2 = i2.getAttributes();
292: if (a1.length != a2.length)
293: throw new RuntimeException();
294: for (int i = 0; i < a1.length; ++i) {
295: compareMBeanAttributeInfo(a1[i], a2[i]);
296: }
297:
298: MBeanConstructorInfo[] c1 = i1.getConstructors();
299: MBeanConstructorInfo[] c2 = i2.getConstructors();
300: if (c1.length != c2.length)
301: throw new RuntimeException();
302: for (int i = 0; i < c1.length; ++i) {
303: compareMBeanConstructorInfo(c1[i], c2[i]);
304: }
305:
306: MBeanNotificationInfo[] n1 = i1.getNotifications();
307: MBeanNotificationInfo[] n2 = i2.getNotifications();
308: if (n1.length != n2.length)
309: throw new RuntimeException();
310: for (int i = 0; i < n1.length; ++i) {
311: compareMBeanNotificationInfo(n1[i], n2[i]);
312: }
313:
314: MBeanOperationInfo[] op1 = i1.getOperations();
315: MBeanOperationInfo[] op2 = i2.getOperations();
316: if (op1.length != op2.length)
317: throw new RuntimeException();
318: for (int i = 0; i < op1.length; ++i) {
319: compareMBeanOperationInfo(op1[i], op2[i]);
320: }
321: }
322:
323: public void compareMBeanNotificationInfo(Object o1, Object o2) {
324: compareMBeanFeatureInfo(o1, o2);
325:
326: MBeanNotificationInfo n1 = (MBeanNotificationInfo) o1;
327: MBeanNotificationInfo n2 = (MBeanNotificationInfo) o2;
328:
329: String[] t1 = n1.getNotifTypes();
330: String[] t2 = n2.getNotifTypes();
331:
332: if (t1.length != t2.length)
333: throw new RuntimeException();
334: for (int i = 0; i < t1.length; ++i) {
335: if (!t1[i].equals(t2[i]))
336: throw new RuntimeException();
337: }
338: }
339:
340: public void compareMBeanOperationInfo(Object o1, Object o2) {
341: compareMBeanFeatureInfo(o1, o2);
342:
343: MBeanOperationInfo op1 = (MBeanOperationInfo) o1;
344: MBeanOperationInfo op2 = (MBeanOperationInfo) o2;
345:
346: if (op1.getImpact() != op2.getImpact())
347: throw new RuntimeException();
348: if (!op1.getReturnType().equals(op2.getReturnType()))
349: throw new RuntimeException();
350:
351: MBeanParameterInfo[] p1 = op1.getSignature();
352: MBeanParameterInfo[] p2 = op2.getSignature();
353:
354: if (p1.length != p2.length)
355: throw new RuntimeException();
356: for (int i = 0; i < p1.length; ++i) {
357: compareMBeanParameterInfo(p1[i], p2[i]);
358: }
359: }
360:
361: public void compareMBeanParameterInfo(Object o1, Object o2) {
362: compareMBeanFeatureInfo(o1, o2);
363:
364: MBeanParameterInfo p1 = (MBeanParameterInfo) o1;
365: MBeanParameterInfo p2 = (MBeanParameterInfo) o2;
366:
367: if (!p1.getType().equals(p2.getType()))
368: throw new RuntimeException();
369: }
370:
371: public void compareMBeanRegistrationException(Object o1, Object o2) {
372: compareMBeanException(o1, o2);
373: }
374:
375: public void compareMBeanServerNotification(Object o1, Object o2) {
376: compareNotification(o1, o2);
377: ObjectName obj1 = ((MBeanServerNotification) o1).getMBeanName();
378: ObjectName obj2 = ((MBeanServerNotification) o2).getMBeanName();
379: if (!obj1.equals(obj2))
380: throw new RuntimeException();
381: }
382:
383: public void compareMBeanTrustPermission(Object o1, Object o2) {
384: MBeanTrustPermission p1 = (MBeanTrustPermission) o1;
385: MBeanTrustPermission p2 = (MBeanTrustPermission) o2;
386: if (!p1.getName().equals(p2.getName()))
387: throw new RuntimeException();
388: }
389:
390: public void compareNotCompliantMBeanException(Object o1, Object o2) {
391: compareOperationsException(o1, o2);
392: }
393:
394: public void compareNotification(Object o1, Object o2) {
395: Notification n1 = (Notification) o1;
396: Notification n2 = (Notification) o2;
397:
398: if (!n1.getSource().equals(n2.getSource()))
399: throw new RuntimeException();
400: if (!n1.getType().equals(n2.getType()))
401: throw new RuntimeException();
402: if (n1.getSequenceNumber() != n2.getSequenceNumber())
403: throw new RuntimeException();
404: if (!n1.getUserData().equals(n2.getUserData()))
405: throw new RuntimeException();
406: if (!n1.getMessage().equals(n2.getMessage()))
407: throw new RuntimeException();
408: }
409:
410: public void compareNotificationFilterSupport(Object o1, Object o2) {
411: NotificationFilterSupport f1 = (NotificationFilterSupport) o1;
412: NotificationFilterSupport f2 = (NotificationFilterSupport) o2;
413:
414: Vector types1 = f1.getEnabledTypes();
415: Vector types2 = f2.getEnabledTypes();
416: if (!types1.containsAll(types2) || !types2.containsAll(types1))
417: throw new RuntimeException();
418: }
419:
420: public void compareNotQueryExp(Object o1, Object o2)
421: throws Exception {
422: compareQueryExp(o1, o2);
423: }
424:
425: public void compareNumericValueExp(Object o1, Object o2)
426: throws Exception {
427: Method method = o1.getClass().getDeclaredMethod("longValue",
428: new Class[0]);
429: method.setAccessible(true);
430: Object res1 = method.invoke(o1, new Object[0]);
431: Object res2 = method.invoke(o2, new Object[0]);
432: if (!res1.equals(res2))
433: throw new RuntimeException();
434: }
435:
436: public void compareOperationsException(Object o1, Object o2) {
437: compareJMException(o1, o2);
438: }
439:
440: public void compareOrQueryExp(Object o1, Object o2)
441: throws Exception {
442: compareQueryExp(o1, o2);
443: }
444:
445: public void compareQualifiedAttributeValueExp(Object o1, Object o2) {
446: compareAttributeValueExp(o1, o2);
447: }
448:
449: public void compareQueryExp(Object o1, Object o2) throws Exception {
450: QueryExp exp1 = (QueryExp) o1;
451: QueryExp exp2 = (QueryExp) o2;
452:
453: if (!exp1.apply(null))
454: throw new RuntimeException();
455: if (!exp2.apply(null))
456: throw new RuntimeException();
457: }
458:
459: public void compareReflectionException(Object o1, Object o2) {
460: compareJMException(o1, o2);
461:
462: ReflectionException x1 = (ReflectionException) o1;
463: ReflectionException x2 = (ReflectionException) o2;
464:
465: Exception xx1 = x1.getTargetException();
466: Exception xx2 = x2.getTargetException();
467: compareException(xx1, xx2);
468: }
469:
470: public void compareRuntimeErrorException(Object o1, Object o2) {
471: compareJMRuntimeException(o1, o2);
472:
473: RuntimeErrorException x1 = (RuntimeErrorException) o1;
474: RuntimeErrorException x2 = (RuntimeErrorException) o2;
475:
476: Error e1 = x1.getTargetError();
477: Error e2 = x2.getTargetError();
478: compareError(e1, e2);
479: }
480:
481: public void compareRuntimeMBeanException(Object o1, Object o2) {
482: compareJMRuntimeException(o1, o2);
483:
484: RuntimeMBeanException x1 = (RuntimeMBeanException) o1;
485: RuntimeMBeanException x2 = (RuntimeMBeanException) o2;
486:
487: RuntimeException e1 = x1.getTargetException();
488: RuntimeException e2 = x2.getTargetException();
489: compareException(e1, e2);
490: }
491:
492: public void compareRuntimeOperationsException(Object o1, Object o2) {
493: compareJMRuntimeException(o1, o2);
494:
495: RuntimeOperationsException x1 = (RuntimeOperationsException) o1;
496: RuntimeOperationsException x2 = (RuntimeOperationsException) o2;
497:
498: RuntimeException e1 = x1.getTargetException();
499: RuntimeException e2 = x2.getTargetException();
500: compareException(e1, e2);
501: }
502:
503: public void compareServiceNotFoundException(Object o1, Object o2) {
504: compareOperationsException(o1, o2);
505: }
506:
507: public void compareStringValueExp(Object o1, Object o2) {
508: StringValueExp s1 = (StringValueExp) o1;
509: StringValueExp s2 = (StringValueExp) o2;
510: if (!s1.getValue().equals(s2.getValue()))
511: throw new RuntimeException();
512: }
513:
514: //
515: // MODELMBEAN package
516: //
517: public void compareDescriptorSupport(Object o1, Object o2) {
518: DescriptorSupport s1 = (DescriptorSupport) o1;
519: DescriptorSupport s2 = (DescriptorSupport) o2;
520:
521: String[] names1 = s1.getFieldNames();
522: String[] names2 = s2.getFieldNames();
523: Object[] values1 = s1.getFieldValues(names1);
524: Object[] values2 = s2.getFieldValues(names2);
525:
526: ArrayList list1 = new ArrayList(Arrays.asList(names1));
527: ArrayList list2 = new ArrayList(Arrays.asList(names2));
528: if (!list1.containsAll(list2) || !list2.containsAll(list1))
529: throw new RuntimeException();
530:
531: list1 = new ArrayList(Arrays.asList(values1));
532: list2 = new ArrayList(Arrays.asList(values2));
533: if (!list1.containsAll(list2) || !list2.containsAll(list1))
534: throw new RuntimeException();
535: }
536:
537: public void compareInvalidTargetObjectTypeException(Object o1,
538: Object o2) {
539: // No way to compare them
540: }
541:
542: public void compareModelMBeanAttributeInfo(Object o1, Object o2) {
543: compareMBeanAttributeInfo(o1, o2);
544: ModelMBeanAttributeInfo a1 = (ModelMBeanAttributeInfo) o1;
545: ModelMBeanAttributeInfo a2 = (ModelMBeanAttributeInfo) o2;
546: compareDescriptorSupport(a1.getDescriptor(), a2.getDescriptor());
547: }
548:
549: public void compareModelMBeanConstructorInfo(Object o1, Object o2) {
550: compareMBeanConstructorInfo(o1, o2);
551:
552: ModelMBeanConstructorInfo a1 = (ModelMBeanConstructorInfo) o1;
553: ModelMBeanConstructorInfo a2 = (ModelMBeanConstructorInfo) o2;
554: compareDescriptorSupport(a1.getDescriptor(), a2.getDescriptor());
555: }
556:
557: public void compareModelMBeanInfoSupport(Object o1, Object o2)
558: throws MBeanException {
559: compareMBeanInfo(o1, o2);
560:
561: ModelMBeanInfoSupport i1 = (ModelMBeanInfoSupport) o1;
562: ModelMBeanInfoSupport i2 = (ModelMBeanInfoSupport) o2;
563: compareDescriptorSupport(i1.getMBeanDescriptor(), i2
564: .getMBeanDescriptor());
565: }
566:
567: public void compareModelMBeanNotificationInfo(Object o1, Object o2) {
568: compareMBeanNotificationInfo(o1, o2);
569:
570: ModelMBeanNotificationInfo n1 = (ModelMBeanNotificationInfo) o1;
571: ModelMBeanNotificationInfo n2 = (ModelMBeanNotificationInfo) o2;
572: compareDescriptorSupport(n1.getDescriptor(), n2.getDescriptor());
573: }
574:
575: public void compareModelMBeanOperationInfo(Object o1, Object o2) {
576: compareMBeanOperationInfo(o1, o2);
577:
578: ModelMBeanOperationInfo op1 = (ModelMBeanOperationInfo) o1;
579: ModelMBeanOperationInfo op2 = (ModelMBeanOperationInfo) o2;
580: compareDescriptorSupport(op1.getDescriptor(), op2
581: .getDescriptor());
582: }
583:
584: public void compareXMLParseException(Object o1, Object o2) {
585: // Cannot be compared: JMXRI adds a custom message in addition to the one
586: // provided to the XMLParseException constructor.
587: // compareException(o1, o2);
588: }
589:
590: //
591: // MONITOR package
592: //
593: public void compareMonitorNotification(Object o1, Object o2) {
594: compareNotification(o1, o2);
595:
596: MonitorNotification n1 = (MonitorNotification) o1;
597: MonitorNotification n2 = (MonitorNotification) o2;
598:
599: if (!n1.getDerivedGauge().equals(n2.getDerivedGauge()))
600: throw new RuntimeException();
601: if (!n1.getObservedAttribute()
602: .equals(n2.getObservedAttribute()))
603: throw new RuntimeException();
604: if (!n1.getObservedObject().equals(n2.getObservedObject()))
605: throw new RuntimeException();
606: if (!n1.getTrigger().equals(n2.getTrigger()))
607: throw new RuntimeException();
608: }
609:
610: public void compareMonitorSettingException(Object o1, Object o2) {
611: compareJMRuntimeException(o1, o2);
612: }
613:
614: //
615: // OPENMBEANS package
616: //
617: public void compareInvalidKeyException(Object o1, Object o2) {
618: compareException(o1, o2);
619: }
620:
621: public void compareInvalidOpenTypeException(Object o1, Object o2) {
622: compareException(o1, o2);
623: }
624:
625: public void compareKeyAlreadyExistsException(Object o1, Object o2) {
626: compareException(o1, o2);
627: }
628:
629: public void compareOpenDataException(Object o1, Object o2) {
630: compareJMException(o1, o2);
631: }
632:
633: //
634: // RELATION package
635: //
636: public void compareInvalidRelationIdException(Object o1, Object o2) {
637: compareRelationException(o1, o2);
638: }
639:
640: public void compareInvalidRelationServiceException(Object o1,
641: Object o2) {
642: compareRelationException(o1, o2);
643: }
644:
645: public void compareInvalidRelationTypeException(Object o1, Object o2) {
646: compareRelationException(o1, o2);
647: }
648:
649: public void compareInvalidRoleInfoException(Object o1, Object o2) {
650: compareRelationException(o1, o2);
651: }
652:
653: public void compareInvalidRoleValueException(Object o1, Object o2) {
654: compareRelationException(o1, o2);
655: }
656:
657: public void compareMBeanServerNotificationFilter(Object o1,
658: Object o2) {
659: compareNotificationFilterSupport(o1, o2);
660:
661: MBeanServerNotificationFilter f1 = (MBeanServerNotificationFilter) o1;
662: MBeanServerNotificationFilter f2 = (MBeanServerNotificationFilter) o2;
663: Vector names1 = null;
664: try {
665: names1 = f1.getEnabledObjectNames();
666: } catch (NullPointerException ignored) {
667: // JMX RI throws this
668: }
669: Vector names2 = null;
670: try {
671: names2 = f2.getEnabledObjectNames();
672: } catch (NullPointerException ignored) {
673: // JMX RI throws this
674: }
675: if (names1 != null
676: && (!names1.containsAll(names2) || !names2
677: .containsAll(names1)))
678: throw new RuntimeException();
679: if (names1 == null && names2 != null)
680: throw new RuntimeException();
681:
682: Vector names3 = null;
683: try {
684: names3 = f1.getDisabledObjectNames();
685: } catch (NullPointerException ignored) {
686: // JMX RI throws this
687: }
688: Vector names4 = null;
689: try {
690: names4 = f1.getDisabledObjectNames();
691: } catch (NullPointerException ignored) {
692: // JMX RI throws this
693: }
694: if (names3 != null
695: && (!names3.containsAll(names4) || !names4
696: .containsAll(names3)))
697: throw new RuntimeException();
698: if (names3 == null && names4 != null)
699: throw new RuntimeException();
700: }
701:
702: public void compareRelationException(Object o1, Object o2) {
703: compareJMException(o1, o2);
704: }
705:
706: public void compareRelationNotFoundException(Object o1, Object o2) {
707: compareRelationException(o1, o2);
708: }
709:
710: public void compareRelationNotification(Object o1, Object o2) {
711: compareNotification(o1, o2);
712:
713: RelationNotification n1 = (RelationNotification) o1;
714: RelationNotification n2 = (RelationNotification) o2;
715:
716: if (!n1.getMBeansToUnregister().equals(
717: n2.getMBeansToUnregister()))
718: throw new RuntimeException();
719: List news1 = n1.getNewRoleValue();
720: List news2 = n2.getNewRoleValue();
721: if (news1.size() != news2.size())
722: throw new RuntimeException();
723: if (!n1.getObjectName().equals(n2.getObjectName()))
724: throw new RuntimeException();
725: List olds1 = n1.getOldRoleValue();
726: List olds2 = n2.getOldRoleValue();
727: if (olds1.size() != olds2.size())
728: throw new RuntimeException();
729: if (!n1.getRelationId().equals(n2.getRelationId()))
730: throw new RuntimeException();
731: if (!n1.getRelationTypeName().equals(n2.getRelationTypeName()))
732: throw new RuntimeException();
733: if (!n1.getRoleName().equals(n2.getRoleName()))
734: throw new RuntimeException();
735: }
736:
737: public void compareRelationServiceNotRegisteredException(Object o1,
738: Object o2) {
739: compareRelationException(o1, o2);
740: }
741:
742: public void compareRelationTypeNotFoundException(Object o1,
743: Object o2) {
744: compareRelationException(o1, o2);
745: }
746:
747: public void compareRelationTypeSupport(Object o1, Object o2) {
748: RelationTypeSupport r1 = (RelationTypeSupport) o1;
749: RelationTypeSupport r2 = (RelationTypeSupport) o2;
750:
751: if (!r1.getRelationTypeName().equals(r2.getRelationTypeName()))
752: throw new RuntimeException();
753: List infos1 = r1.getRoleInfos();
754: List infos2 = r2.getRoleInfos();
755: // RoleInfo does not override equals() so List.equals() fails; just use size() here
756: if (infos1.size() != infos2.size())
757: throw new RuntimeException();
758: }
759:
760: public void compareRole(Object o1, Object o2) {
761: Role r1 = (Role) o1;
762: Role r2 = (Role) o2;
763:
764: if (!r1.getRoleName().equals(r2.getRoleName()))
765: throw new RuntimeException();
766: if (!r1.getRoleValue().equals(r2.getRoleValue()))
767: throw new RuntimeException();
768: }
769:
770: public void compareRoleInfo(Object o1, Object o2) {
771: RoleInfo r1 = (RoleInfo) o1;
772: RoleInfo r2 = (RoleInfo) o2;
773:
774: if (!r1.getDescription().equals(r2.getDescription()))
775: throw new RuntimeException();
776: if (r1.getMaxDegree() != r2.getMaxDegree())
777: throw new RuntimeException();
778: if (r1.getMinDegree() != r2.getMinDegree())
779: throw new RuntimeException();
780: if (!r1.getName().equals(r2.getName()))
781: throw new RuntimeException();
782: if (!r1.getRefMBeanClassName()
783: .equals(r2.getRefMBeanClassName()))
784: throw new RuntimeException();
785: if (!r1.isReadable() || !r2.isReadable())
786: throw new RuntimeException();
787: if (!r1.isWritable() || !r2.isWritable())
788: throw new RuntimeException();
789: }
790:
791: public void compareRoleInfoNotFoundException(Object o1, Object o2) {
792: compareRelationException(o1, o2);
793: }
794:
795: public void compareRoleList(Object o1, Object o2) {
796: RoleList l1 = (RoleList) o1;
797: RoleList l2 = (RoleList) o2;
798:
799: // Role does not override equals() so List.equals() fails; just use size() here
800: if (l1.size() != l2.size())
801: throw new RuntimeException();
802: }
803:
804: public void compareRoleNotFoundException(Object o1, Object o2) {
805: compareRelationException(o1, o2);
806: }
807:
808: public void compareRoleResult(Object o1, Object o2) {
809: RoleResult r1 = (RoleResult) o1;
810: RoleResult r2 = (RoleResult) o2;
811:
812: compareRoleList(r1.getRoles(), r2.getRoles());
813: compareRoleUnresolvedList(r1.getRolesUnresolved(), r2
814: .getRolesUnresolved());
815: }
816:
817: public void compareRoleUnresolved(Object o1, Object o2) {
818: RoleUnresolved r1 = (RoleUnresolved) o1;
819: RoleUnresolved r2 = (RoleUnresolved) o2;
820:
821: if (r1.getProblemType() != r2.getProblemType())
822: throw new RuntimeException();
823: if (!r1.getRoleName().equals(r2.getRoleName()))
824: throw new RuntimeException();
825: if (!r1.getRoleValue().equals(r2.getRoleValue()))
826: throw new RuntimeException();
827: }
828:
829: public void compareRoleUnresolvedList(Object o1, Object o2) {
830: RoleUnresolvedList l1 = (RoleUnresolvedList) o1;
831: RoleUnresolvedList l2 = (RoleUnresolvedList) o2;
832:
833: // RoleUnresolved does not override equals() so List.equals() fails; just use size() here
834: if (l1.size() != l2.size())
835: throw new RuntimeException();
836: }
837:
838: //
839: // TIMER package
840: //
841: public void compareTimerNotification(Object o1, Object o2) {
842: compareNotification(o1, o2);
843:
844: TimerNotification n1 = (TimerNotification) o1;
845: TimerNotification n2 = (TimerNotification) o2;
846:
847: if (!n1.getNotificationID().equals(n2.getNotificationID()))
848: throw new RuntimeException();
849: }
850: }
|