1 8 9 package test; 10 11 import java.io.File ; 12 import java.net.MalformedURLException ; 13 import java.net.URL ; 14 import java.net.URLClassLoader ; 15 import javax.management.MBeanServer ; 16 import javax.management.MBeanServerFactory ; 17 18 import junit.framework.TestCase; 19 20 25 public class MX4JTestCase extends TestCase 26 { 27 public MX4JTestCase(String name) 28 { 29 super(name); 30 } 31 32 protected MBeanServer newMBeanServer() 33 { 34 return MBeanServerFactory.newMBeanServer(); 35 } 36 37 protected ClassLoader createMX4JClassLoader() throws MalformedURLException 38 { 39 File jmx = new File ("dist/test/mx4j-jmx.jar"); 40 File impl = new File ("dist/test/mx4j-impl.jar"); 41 return new URLClassLoader (new URL []{jmx.toURL(), impl.toURL()}, getClass().getClassLoader().getParent()); 42 } 43 44 protected ClassLoader createJMXRIClassLoader() throws MalformedURLException 45 { 46 File jmxri = new File ("dist/test/jmxri.jar"); 47 if (!jmxri.exists()) fail("JMXRI jar is not available"); 48 return new URLClassLoader (new URL []{jmxri.toURL()}, getClass().getClassLoader().getParent()); 49 } 50 51 protected ClassLoader createJMXRIWithMX4JImplClassLoader() throws MalformedURLException 52 { 53 File jmxri = new File ("dist/test/jmxri.jar"); 54 if (!jmxri.exists()) fail("JMXRI jar is not available"); 55 File mx4j = new File ("dist/test/mx4j-impl.jar"); 56 return new URLClassLoader (new URL []{jmxri.toURL(), mx4j.toURL()}, getClass().getClassLoader().getParent()); 57 } 58 59 protected ClassLoader createMX4JWithTestsClassLoader() throws MalformedURLException 60 { 61 File jmx = new File ("dist/test/mx4j-jmx.jar"); 62 File impl = new File ("dist/test/mx4j-impl.jar"); 63 File tests = new File ("dist/test/mx4j-tests.jar"); 64 return new URLClassLoader (new URL []{jmx.toURL(), impl.toURL(), tests.toURL()}, getClass().getClassLoader().getParent()); 65 } 66 67 protected ClassLoader createRemoteMX4JWithTestsClassLoader() throws MalformedURLException 68 { 69 File jmx = new File ("dist/test/mx4j-jmx.jar"); 70 File impl = new File ("dist/test/mx4j-impl.jar"); 71 File rjmx = new File ("dist/test/mx4j-rjmx.jar"); 72 File rimpl = new File ("dist/test/mx4j-rimpl.jar"); 73 File tests = new File ("dist/test/mx4j-tests.jar"); 74 File jaas = new File ("dist/test/jaas.jar"); 75 return new URLClassLoader (new URL []{jaas.toURL(), jmx.toURL(), impl.toURL(), rjmx.toURL(), rimpl.toURL(), tests.toURL()}, getClass().getClassLoader().getParent()); 76 } 77 78 protected ClassLoader createJMXRIWithTestsClassLoader() throws MalformedURLException 79 { 80 File jmxri = new File ("dist/test/jmxri.jar"); 81 if (!jmxri.exists()) fail("JMXRI jar is not available"); 82 File tests = new File ("dist/test/mx4j-tests.jar"); 83 return new URLClassLoader (new URL []{jmxri.toURL(), tests.toURL()}, getClass().getClassLoader().getParent()); 84 } 85 86 protected ClassLoader createRemoteJMXRIWithTestsClassLoader() throws MalformedURLException 87 { 88 File jmx = new File ("dist/test/jmxri.jar"); 89 if (!jmx.exists()) fail("JMXRI jar is not available"); 90 File rjmx = new File ("dist/test/jmxremote.jar"); 91 if (!rjmx.exists()) fail("JMX Remote jar is not available"); 92 File tests = new File ("dist/test/mx4j-tests.jar"); 93 File jaas = new File ("dist/test/jaas.jar"); 94 return new URLClassLoader (new URL []{jaas.toURL(), jmx.toURL(), rjmx.toURL(), tests.toURL()}, getClass().getClassLoader().getParent()); 95 } 96 97 protected ClassLoader createOptionalRemoteJMXRIWithTestsClassLoader() throws MalformedURLException 98 { 99 File jmx = new File ("dist/test/jmxri.jar"); 100 if (!jmx.exists()) fail("JMXRI jar is not available"); 101 File rjmx = new File ("dist/test/jmxremote.jar"); 102 if (!rjmx.exists()) fail("JMX Remote jar is not available"); 103 File orjmx = new File ("dist/test/jmxremote_optional.jar"); 104 if (!orjmx.exists()) fail("JMX Optional Remote jar is not available"); 105 File tests = new File ("dist/test/mx4j-tests.jar"); 106 return new URLClassLoader (new URL []{jmx.toURL(), rjmx.toURL(), orjmx.toURL(), tests.toURL()}, getClass().getClassLoader().getParent()); 107 } 108 109 protected void sleep(long time) 110 { 111 try 112 { 113 Thread.sleep(time); 114 } 115 catch (InterruptedException x) 116 { 117 Thread.currentThread().interrupt(); 118 } 119 } 120 } 121 | Popular Tags |