01: package org.uispec4j.extension;
02:
03: import org.uispec4j.utils.UnitTestCase;
04:
05: import java.io.File;
06: import java.io.IOException;
07:
08: public class ExtensionGeneratorTest extends UnitTestCase {
09: private File output;
10:
11: protected void setUp() throws Exception {
12: super .setUp();
13: output = new File("tmp/extension.jar");
14: output.getParentFile().mkdirs();
15: output.delete();
16: }
17:
18: public void testStandardGenerationUsageWithCustomClass()
19: throws Exception {
20: checkStandardGenerationUsage(CustomCountingButton.class);
21: }
22:
23: public void testStandardGenerationUsageWithDerivedClass()
24: throws Exception {
25: checkStandardGenerationUsage(DerivedCountingButton.class);
26: }
27:
28: public void testRunningTheGenerationOverAnExistingJarReplacesThePanelClass()
29: throws Exception {
30: checkRunningTheGenerationOverAnExistingJarReplacesThePanelClass(CustomCountingButton.class);
31: checkRunningTheGenerationOverAnExistingJarReplacesThePanelClass(DerivedCountingButton.class);
32: }
33:
34: public void checkStandardGenerationUsage(Class componentClass)
35: throws Exception {
36: ExtensionGenerator.main(new String[] {
37: "tmp/extension.jar",
38: "CountingButton:" + componentClass.getName() + ":"
39: + JCountingButton.class.getName() });
40: runCheckerClass(componentClass);
41: }
42:
43: private void checkRunningTheGenerationOverAnExistingJarReplacesThePanelClass(
44: Class componentClass) throws Exception {
45: ExtensionGenerator.main(new String[] {
46: "tmp/extension.jar",
47: "MyButton:" + componentClass.getName() + ":"
48: + JCountingButton.class.getName() });
49: ExtensionGenerator.main(new String[] {
50: "tmp/extension.jar",
51: "CountingButton:" + componentClass.getName() + ":"
52: + JCountingButton.class.getName() });
53: runCheckerClass(componentClass);
54: }
55:
56: private void runCheckerClass(Class componentClass)
57: throws IOException, InterruptedException {
58: String classpath = output.getAbsolutePath()
59: + System.getProperty("path.separator")
60: + System.getProperty("java.class.path");
61: Process process = Runtime.getRuntime().exec(
62: new String[] { "java", "-Xmx512m", "-classpath",
63: classpath, GeneratedJarChecker.class.getName(),
64: componentClass.getName() });
65: StreamRecorder output = StreamRecorder.run(process
66: .getInputStream());
67: StreamRecorder error = StreamRecorder.run(process
68: .getErrorStream());
69: process.waitFor();
70:
71: // Workaround for Apple bug
72: // http://developer.apple.com/releasenotes/Java/Java50Release4RN/OutstandingIssues/chapter_4_section_3.html
73: if ("Mac OS X".equals(System.getProperty("os.name"))) {
74: if (error.getResult().length() != 0) {
75: assertEquals(
76: "_-_-_ _:_:_._ java[_] CFLog (_): CFMessagePort: bootstrap_register(): failed _ (_), port = _, name = 'java.ServiceProvider'\n"
77: + "See /usr/include/servers/bootstrap_defs.h for the error codes.\n"
78: + "_-_-_ _:_:_._ java[_] CFLog (_): CFMessagePortCreateLocal(): failed to name Mach port (java.ServiceProvider)",
79: error.getResult()
80: .replaceAll("[0-9][\\w]*", "_"));
81: }
82: } else {
83: assertEquals("", error.getResult());
84: }
85: assertEquals("OK", output.getResult());
86: }
87: }
|