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;
010:
011: import java.io.File;
012: import java.net.MalformedURLException;
013: import java.net.URL;
014: import java.net.URLClassLoader;
015: import javax.management.MBeanServer;
016: import javax.management.MBeanServerFactory;
017:
018: import junit.framework.TestCase;
019:
020: /**
021: * Base class for MX4J tests
022: *
023: * @version $Revision: 1.11 $
024: */
025: public class MX4JTestCase extends TestCase {
026: public MX4JTestCase(String name) {
027: super (name);
028: }
029:
030: protected MBeanServer newMBeanServer() {
031: return MBeanServerFactory.newMBeanServer();
032: }
033:
034: protected ClassLoader createMX4JClassLoader()
035: throws MalformedURLException {
036: File jmx = new File("dist/test/mx4j-jmx.jar");
037: File impl = new File("dist/test/mx4j-impl.jar");
038: return new URLClassLoader(
039: new URL[] { jmx.toURL(), impl.toURL() }, getClass()
040: .getClassLoader().getParent());
041: }
042:
043: protected ClassLoader createJMXRIClassLoader()
044: throws MalformedURLException {
045: File jmxri = new File("dist/test/jmxri.jar");
046: if (!jmxri.exists())
047: fail("JMXRI jar is not available");
048: return new URLClassLoader(new URL[] { jmxri.toURL() },
049: getClass().getClassLoader().getParent());
050: }
051:
052: protected ClassLoader createJMXRIWithMX4JImplClassLoader()
053: throws MalformedURLException {
054: File jmxri = new File("dist/test/jmxri.jar");
055: if (!jmxri.exists())
056: fail("JMXRI jar is not available");
057: File mx4j = new File("dist/test/mx4j-impl.jar");
058: return new URLClassLoader(new URL[] { jmxri.toURL(),
059: mx4j.toURL() }, getClass().getClassLoader().getParent());
060: }
061:
062: protected ClassLoader createMX4JWithTestsClassLoader()
063: throws MalformedURLException {
064: File jmx = new File("dist/test/mx4j-jmx.jar");
065: File impl = new File("dist/test/mx4j-impl.jar");
066: File tests = new File("dist/test/mx4j-tests.jar");
067: return new URLClassLoader(new URL[] { jmx.toURL(),
068: impl.toURL(), tests.toURL() }, getClass()
069: .getClassLoader().getParent());
070: }
071:
072: protected ClassLoader createRemoteMX4JWithTestsClassLoader()
073: throws MalformedURLException {
074: File jmx = new File("dist/test/mx4j-jmx.jar");
075: File impl = new File("dist/test/mx4j-impl.jar");
076: File rjmx = new File("dist/test/mx4j-rjmx.jar");
077: File rimpl = new File("dist/test/mx4j-rimpl.jar");
078: File tests = new File("dist/test/mx4j-tests.jar");
079: File jaas = new File("dist/test/jaas.jar");
080: return new URLClassLoader(new URL[] { jaas.toURL(),
081: jmx.toURL(), impl.toURL(), rjmx.toURL(), rimpl.toURL(),
082: tests.toURL() }, getClass().getClassLoader()
083: .getParent());
084: }
085:
086: protected ClassLoader createJMXRIWithTestsClassLoader()
087: throws MalformedURLException {
088: File jmxri = new File("dist/test/jmxri.jar");
089: if (!jmxri.exists())
090: fail("JMXRI jar is not available");
091: File tests = new File("dist/test/mx4j-tests.jar");
092: return new URLClassLoader(new URL[] { jmxri.toURL(),
093: tests.toURL() }, getClass().getClassLoader()
094: .getParent());
095: }
096:
097: protected ClassLoader createRemoteJMXRIWithTestsClassLoader()
098: throws MalformedURLException {
099: File jmx = new File("dist/test/jmxri.jar");
100: if (!jmx.exists())
101: fail("JMXRI jar is not available");
102: File rjmx = new File("dist/test/jmxremote.jar");
103: if (!rjmx.exists())
104: fail("JMX Remote jar is not available");
105: File tests = new File("dist/test/mx4j-tests.jar");
106: File jaas = new File("dist/test/jaas.jar");
107: return new URLClassLoader(new URL[] { jaas.toURL(),
108: jmx.toURL(), rjmx.toURL(), tests.toURL() }, getClass()
109: .getClassLoader().getParent());
110: }
111:
112: protected ClassLoader createOptionalRemoteJMXRIWithTestsClassLoader()
113: throws MalformedURLException {
114: File jmx = new File("dist/test/jmxri.jar");
115: if (!jmx.exists())
116: fail("JMXRI jar is not available");
117: File rjmx = new File("dist/test/jmxremote.jar");
118: if (!rjmx.exists())
119: fail("JMX Remote jar is not available");
120: File orjmx = new File("dist/test/jmxremote_optional.jar");
121: if (!orjmx.exists())
122: fail("JMX Optional Remote jar is not available");
123: File tests = new File("dist/test/mx4j-tests.jar");
124: return new URLClassLoader(new URL[] { jmx.toURL(),
125: rjmx.toURL(), orjmx.toURL(), tests.toURL() },
126: getClass().getClassLoader().getParent());
127: }
128:
129: protected void sleep(long time) {
130: try {
131: Thread.sleep(time);
132: } catch (InterruptedException x) {
133: Thread.currentThread().interrupt();
134: }
135: }
136: }
|