NotificationInfoTest.java revision 0
/*
* Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 5012634
* @summary Test that JMX classes use fully-qualified class names
* in MBeanNotificationInfo
* @author Eamonn McManus
* @run clean NotificationInfoTest
* @run build NotificationInfoTest
* @run main NotificationInfoTest
*/
import javax.management.*;
/*
* This test finds all classes in the same code-base as the JMX
* classes that look like Standard MBeans, and checks that if they are
* NotificationBroadcasters they declare existent notification types.
* A class looks like a Standard MBean if both Thing and ThingMBean
* classes exist. So for example javax.management.timer.Timer looks
* like a Standard MBean because javax.management.timer.TimerMBean
* exists. Timer is instanceof NotificationBroadcaster, so we expect
* that ((NotificationBroadcaster) timer).getNotificationInfo() will
* return an array of MBeanNotificationInfo where each entry has a
* getName() that names an existent Java class that is a Notification.
*
* An MBean is "suspicious" if it is a NotificationBroadcaster but its
* MBeanNotificationInfo[] is empty. This is legal, but surprising.
*
* In order to call getNotificationInfo(), we need an instance of the
* class. We attempt to make one by calling a public no-arg
* constructor. But the "construct" method below can be extended to
* construct specific MBean classes for which the no-arg constructor
* doesn't exist.
*
* The test is obviously not exhaustive, but does catch the cases that
* failed in 5012634.
*/
public class NotificationInfoTest {
// class or object names where the test failed
// class or object names where there were no MBeanNotificationInfo entries
"NotificationBroadcasters have sane " +
"MBeanInfo.getNotifications()");
CodeSource cs =
.getCodeSource();
} else
Class c;
try {
} catch (Throwable e) {
continue;
}
if (!NotificationBroadcaster.class.isAssignableFrom(c)) {
continue;
}
try {
} catch (Exception e) {
+ e);
continue;
}
try {
} catch (Exception e) {
continue;
}
}
check(new RelationService(false));
/*
We can't do this:
check(new RequiredModelMBean());
because the Model MBean spec more or less forces us to use the
names GENERIC and ATTRIBUTE_CHANGE for its standard notifs.
*/
if (!suspicious.isEmpty())
else {
}
}
throws Exception {
}
private static void checkPlatformMBeans() throws Exception {
try {
} catch (Exception e) {
+ e);
return;
}
NotificationBroadcaster.class.getName())) {
} else {
}
}
}
private static void checkRMIConnectorServer() throws Exception {
try {
} catch (Exception e) {
return;
}
"service:jmx:rmi://"
});
jmxServiceURL, Map.class
});
});
}
return;
}
// Each MBeanNotificationInfo.getName() should be an existent
// Java class that is Notification or a subclass of it
try {
} catch (Exception e) {
") ");
continue;
}
": not a Notification) ");
continue;
}
}
}
throws Exception {
else
}
}
}
throws Exception {
continue;
}
return names;
}
throws Exception {
return names;
}
throws Exception {
return;
if (f.isDirectory())
}
}
}
}