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.remote.compliance.serialization.support;
010:
011: import javax.management.Notification;
012: import javax.management.remote.JMXConnectionNotification;
013: import javax.management.remote.JMXProviderException;
014: import javax.management.remote.JMXServerErrorException;
015: import javax.management.remote.NotificationResult;
016: import javax.management.remote.SubjectDelegationPermission;
017: import javax.management.remote.TargetedNotification;
018: import javax.management.remote.rmi.RMIConnector;
019:
020: /**
021: * @version $Revision: 1.6 $
022: */
023: public class RemoteComparator {
024:
025: public void compareJMXConnectionNotification(Object obj1,
026: Object obj2) {
027: JMXConnectionNotification jcn1 = (JMXConnectionNotification) obj1;
028: JMXConnectionNotification jcn2 = (JMXConnectionNotification) obj2;
029: boolean valid = jcn1.getConnectionId().equals(
030: jcn2.getConnectionId());
031: compareNotifications(jcn1, jcn2);
032: if (!valid)
033: throw new RuntimeException();
034: }
035:
036: public void compareJMXProviderException(Object obj1, Object obj2) {
037: JMXProviderException jpe1 = (JMXProviderException) obj1;
038: JMXProviderException jpe2 = (JMXProviderException) obj2;
039: boolean valid = true;
040: /*
041: if (jpe1.getCause() != null)
042: valid = valid && (jpe1.getCause().equals(jpe2.getCause()));
043: */
044: if (jpe1.getLocalizedMessage() != null)
045: valid = valid
046: && (jpe1.getLocalizedMessage().equals(jpe2
047: .getLocalizedMessage()));
048: if (jpe1.getMessage() != null)
049: valid = valid
050: && (jpe1.getMessage().equals(jpe2.getMessage()));
051:
052: valid = valid && (jpe1.toString().equals(jpe2.toString()));
053: if (!valid)
054: throw new RuntimeException();
055: }
056:
057: public void compareJMXServerErrorException(Object obj1, Object obj2) {
058: JMXServerErrorException jse1 = (JMXServerErrorException) obj1;
059: JMXServerErrorException jse2 = (JMXServerErrorException) obj2;
060: boolean valid = true; // jse1.getCause().getClass().equals(jse2.getCause().getClass());
061: valid = valid
062: && (jse1.getLocalizedMessage().equals(jse2
063: .getLocalizedMessage()));
064: valid = valid && (jse1.getMessage().equals(jse2.getMessage()));
065: valid = valid && (jse1.toString().equals(jse2.toString()));
066: if (!valid)
067: throw new RuntimeException();
068: }
069:
070: public void compareNotificationResult(Object obj1, Object obj2) {
071: NotificationResult nr1 = (NotificationResult) obj1;
072: NotificationResult nr2 = (NotificationResult) obj2;
073: boolean valid = nr1.getEarliestSequenceNumber() == nr2
074: .getEarliestSequenceNumber();
075: valid = valid
076: && (nr1.getNextSequenceNumber() == nr2
077: .getNextSequenceNumber());
078: TargetedNotification[] tns1 = nr1.getTargetedNotifications();
079: TargetedNotification[] tns2 = nr2.getTargetedNotifications();
080:
081: if (tns1.length != tns2.length)
082: throw new RuntimeException();
083:
084: for (int i = 0; i < tns1.length; i++) {
085: compareTargetedNotification(tns1[i], tns2[i]);
086: }
087:
088: if (!valid)
089: throw new RuntimeException();
090: }
091:
092: public void compareSubjectDelegationPermission(Object obj1,
093: Object obj2) {
094: SubjectDelegationPermission sdp1 = (SubjectDelegationPermission) obj1;
095: SubjectDelegationPermission sdp2 = (SubjectDelegationPermission) obj2;
096: boolean valid = sdp1.equals(sdp2);
097: valid = valid && (sdp1.getActions().equals(sdp2.getActions()));
098: valid = valid && (sdp1.getName().equals(sdp2.getName()));
099: valid = valid && (sdp1.implies(sdp2));
100:
101: if (!valid)
102: throw new RuntimeException();
103: }
104:
105: public void compareTargetedNotification(Object obj1, Object obj2) {
106: TargetedNotification tn1 = (TargetedNotification) obj1;
107: TargetedNotification tn2 = (TargetedNotification) obj2;
108: boolean valid = tn1.getListenerID().equals(tn2.getListenerID());
109: compareNotifications(tn1.getNotification(), tn2
110: .getNotification());
111:
112: if (!valid)
113: throw new RuntimeException();
114: }
115:
116: private void compareNotifications(Notification not1,
117: Notification not2) {
118: boolean valid = (not1.getMessage().equals(not2.getMessage()));
119: valid = valid
120: && (not1.getSequenceNumber() == not2
121: .getSequenceNumber());
122: valid = valid && (not1.getSource().equals(not2.getSource()));
123: valid = valid && (not1.getType().equals(not2.getType()));
124: valid = valid
125: && (not1.getUserData().equals(not2.getUserData()));
126: if (!valid)
127: throw new RuntimeException();
128: }
129:
130: public void compareRMIConnector(Object obj1, Object obj2) {
131: RMIConnector rc1 = (RMIConnector) obj1;
132: RMIConnector rc2 = (RMIConnector) obj2;
133: boolean valid = true; // rc1.getConnectionId().equals(rc2.getConnectionId());
134:
135: if (!valid)
136: throw new RuntimeException();
137: }
138: }
|