01: package com.mockrunner.test.consistency;
02:
03: import junit.framework.TestCase;
04:
05: import com.mockrunner.gen.jar.TestConfigurationClassLoader;
06: import com.mockrunner.test.consistency.MockrunnerJarTestConfiguration.Mapping;
07: import com.mockrunner.util.common.MethodUtil;
08:
09: public class JarReferenceTest extends TestCase {
10: public void testReferenceTests() throws Exception {
11: MockrunnerJarTestConfiguration configuration = new MockrunnerJarTestConfiguration();
12: Mapping[] mappings = configuration.createMappings();
13: int numberErrors = 0;
14: for (int ii = 0; ii < mappings.length; ii++) {
15: LauncherThread thread = new LauncherThread(mappings[ii]);
16: thread.start();
17: thread.join();
18: if (thread.hasError()) {
19: numberErrors++;
20: }
21: }
22: assertTrue("There are errors.", numberErrors == 0);
23: }
24:
25: private class LauncherThread extends Thread {
26: private Mapping mapping;
27: private boolean hasError;
28:
29: public LauncherThread(Mapping mapping) {
30: this .mapping = mapping;
31: hasError = false;
32: }
33:
34: public synchronized boolean hasError() {
35: return hasError;
36: }
37:
38: private synchronized void setHasError() {
39: hasError = true;
40: }
41:
42: public void run() {
43: try {
44: TestConfigurationClassLoader classLoader = new TestConfigurationClassLoader(
45: mapping.getUrls(), this .getClass()
46: .getClassLoader());
47: Object launcher = classLoader.loadClass(
48: "com.mockrunner.test.consistency.Launcher")
49: .newInstance();
50: setContextClassLoader(classLoader);
51: System.out.println("Executing reference test for "
52: + mapping.getUrls()[0] + ": "
53: + mapping.getTestClass());
54: MethodUtil.invoke(launcher, "run", mapping
55: .getTestClass());
56: } catch (Exception exc) {
57: setHasError();
58: }
59: }
60: }
61: }
|