1 8 9 package test.javax.management.compliance; 10 11 import java.io.IOException ; 12 import java.net.MalformedURLException ; 13 import java.util.ArrayList ; 14 import java.util.Collections ; 15 import java.util.Enumeration ; 16 import java.util.jar.JarEntry ; 17 import java.util.jar.JarFile ; 18 19 import test.MX4JTestCase; 20 21 24 public abstract class ComplianceTestCase extends MX4JTestCase 25 { 26 public ComplianceTestCase(String s) 27 { 28 super(s); 29 } 30 31 public void testCompliance() throws Exception 32 { 33 ClassLoader loader = createClassLoader(); 34 35 JarFile jar = loadJar(); 36 37 Enumeration entries = jar.entries(); 38 ArrayList nonExistingMethods = new ArrayList (); 39 while (entries.hasMoreElements()) 40 { 41 JarEntry entry = (JarEntry )entries.nextElement(); 42 43 if (entry.isDirectory()) continue; 45 46 String entryName = entry.getName(); 48 if (entryName.startsWith("javax")) 49 { 50 String fullClassName = entryName.replace('/', '.'); 52 fullClassName = fullClassName.substring(0, fullClassName.length() - ".class".length()); 53 54 if (skipClassName(fullClassName)) continue; 55 56 Class cls = loader.loadClass(fullClassName); 57 58 if (skipClass(cls)) continue; 59 60 String name = fullClassName.substring("javax.management".length()); 61 name = name.replace('.', '_'); 62 try 63 { 64 getClass().getMethod("test" + name, new Class [0]); 66 } 67 catch (NoSuchMethodException x) 68 { 69 nonExistingMethods.add(fullClassName); 70 } 71 } 72 } 73 Collections.sort(nonExistingMethods); 74 if (nonExistingMethods.size() > 0) fail("Compliance test incomplete, missing classes are:\n" + nonExistingMethods); 75 } 76 77 protected abstract boolean skipClassName(String className); 78 79 protected abstract boolean skipClass(Class cls); 80 81 protected abstract void checkCompliance(String className) throws Exception ; 82 83 protected abstract ClassLoader createClassLoader() throws MalformedURLException ; 84 85 protected abstract JarFile loadJar() throws IOException ; 86 87 protected void check(String partialClassName) throws Exception 88 { 89 ClassLoader loader = createClassLoader(); 90 String fullName = "javax.management." + partialClassName; 91 if (skipClassName(fullName)) return; 92 if (skipClass(loader.loadClass(fullName))) return; 93 checkCompliance(fullName); 94 } 95 } 96 | Popular Tags |