01: /*
02: * Copyright (C) The MX4J Contributors.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the MX4J License version 1.0.
06: * See the terms of the MX4J License in the documentation provided with this software.
07: */
08:
09: package test.javax.management.compliance.signature;
10:
11: import java.io.Serializable;
12: import java.lang.reflect.Modifier;
13:
14: import test.javax.management.compliance.JMXComplianceTestCase;
15: import test.javax.management.compliance.signature.support.NotCompliantException;
16: import test.javax.management.compliance.signature.support.NotCompliantWarningException;
17: import test.javax.management.compliance.signature.support.SignatureVerifier;
18:
19: /**
20: * Test that verifies that the signature of the classes in JMXRI are equal to MX4J classes.
21: * It resembles a small TCK, for signatures of the JMX classes only.
22: *
23: * @version $Revision: 1.3 $
24: */
25: public class JMXSignatureTest extends JMXComplianceTestCase {
26: public JMXSignatureTest(String s) {
27: super (s);
28: }
29:
30: protected boolean skipClassName(String className) {
31: return "javax.management.MBeanServerPermissionCollection"
32: .equals(className);
33: }
34:
35: protected boolean skipClass(Class cls) {
36: // Exclude implementation classes in javax.management package
37: // Do not exclude classes that are package private but serializable
38: // like for example the QueryExp and ValueExp implementations (unless some exception)
39:
40: int modifiers = cls.getModifiers();
41: boolean isPublic = Modifier.isPublic(modifiers);
42: boolean isProtected = Modifier.isProtected(modifiers);
43: boolean isPackage = !Modifier.isPrivate(modifiers)
44: && !isProtected && !isPublic;
45: boolean isSerializable = Serializable.class
46: .isAssignableFrom(cls);
47:
48: if (isPublic || isProtected || (isPackage && isSerializable))
49: return false;
50: return true;
51: }
52:
53: protected void checkCompliance(String className) throws Exception {
54: ClassLoader jmxriLoader = createJMXRIWithTestsClassLoader();
55: ClassLoader mx4jLoader = createMX4JWithTestsClassLoader();
56:
57: SignatureVerifier verifier = new SignatureVerifier();
58:
59: try {
60: verifier
61: .verifySignature(className, jmxriLoader, mx4jLoader);
62: } catch (NotCompliantException x) {
63: fail(x.getMessage());
64: } catch (NotCompliantWarningException x) {
65: System.out.println("WARNING: " + x.getMessage());
66: }
67: }
68: }
|