1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
package nl.toolforge.karma.core.test; |
20 |
|
|
21 |
|
import junit.framework.TestCase; |
22 |
|
import nl.toolforge.core.util.file.MyFileUtils; |
23 |
|
import nl.toolforge.karma.core.boot.WorkingContext; |
24 |
|
import nl.toolforge.karma.core.boot.WorkingContextConfiguration; |
25 |
|
import nl.toolforge.karma.core.boot.WorkingContextException; |
26 |
|
import org.apache.commons.io.FileUtils; |
27 |
|
|
28 |
|
import java.io.File; |
29 |
|
import java.io.IOException; |
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
774 |
public class BaseTest extends TestCase { |
39 |
|
|
40 |
774 |
private File wcBaseDir = null; |
41 |
805 |
private File projectBaseDir = null; |
42 |
805 |
private File localRepo = null; |
43 |
805 |
private WorkingContext ctx = null; |
44 |
62 |
|
45 |
62 |
public void setUp() { |
46 |
62 |
|
47 |
31 |
|
48 |
|
|
49 |
774 |
System.setProperty("TESTMODE", "true"); |
50 |
774 |
System.setProperty("locale", "en"); |
51 |
|
|
52 |
31 |
try { |
53 |
836 |
wcBaseDir = MyFileUtils.createTempDirectory(); |
54 |
805 |
projectBaseDir = MyFileUtils.createTempDirectory(); |
55 |
774 |
localRepo = MyFileUtils.createTempDirectory(); |
56 |
31 |
|
57 |
496 |
String wc = "test"; |
58 |
836 |
ctx = new WorkingContext(wc, wcBaseDir); |
59 |
31 |
|
60 |
465 |
MyFileUtils.writeFile( |
61 |
31 |
ctx.getWorkingContextConfigurationBaseDir(), |
62 |
371 |
new File("test/test-working-context.xml"), |
63 |
31 |
new File("working-context.xml"), |
64 |
31 |
this.getClass().getClassLoader() |
65 |
371 |
); |
66 |
31 |
|
67 |
465 |
WorkingContextConfiguration config = new WorkingContextConfiguration(ctx); |
68 |
|
try { |
69 |
465 |
config.load(); |
70 |
402 |
} catch (WorkingContextException e) { |
71 |
31 |
fail(e.getMessage()); |
72 |
434 |
} |
73 |
774 |
ctx.configure(config); |
74 |
|
|
75 |
774 |
config.setProperty(WorkingContext.PROJECT_BASE_DIRECTORY_PROPERTY, projectBaseDir.getPath()); |
76 |
|
|
77 |
774 |
MyFileUtils.writeFile(WorkingContext.getConfigurationBaseDir(), new File("test/authenticators.xml"), new File("authenticators.xml"), this.getClassLoader()); |
78 |
|
|
79 |
774 |
File mStore = ctx.getConfiguration().getManifestStore().getModule().getBaseDir(); |
80 |
465 |
File lStore = ctx.getConfiguration().getLocationStore().getModule().getBaseDir(); |
81 |
402 |
|
82 |
465 |
MyFileUtils.writeFile(lStore, new File("test/test-locations.xml"), new File("test-locations.xml"), this.getClassLoader()); |
83 |
805 |
MyFileUtils.writeFile(lStore, new File("test/test-locations-2.xml"), new File("test-locations-2.xml"), this.getClassLoader()); |
84 |
402 |
|
85 |
496 |
MyFileUtils.writeFile(mStore, new File("test/test-manifest-1.xml"), new File("test-manifest-1.xml"), this.getClassLoader()); |
86 |
836 |
MyFileUtils.writeFile(mStore, new File("test/test-manifest-2.xml"), new File("test-manifest-2.xml"), this.getClassLoader()); |
87 |
836 |
MyFileUtils.writeFile(mStore, new File("test/test-manifest-3.xml"), new File("test-manifest-3.xml"), this.getClassLoader()); |
88 |
371 |
|
89 |
465 |
MyFileUtils.writeFile(mStore, new File("test/included-test-manifest-1.xml"), new File("included-test-manifest-1.xml"), this.getClassLoader()); |
90 |
836 |
MyFileUtils.writeFile(mStore, new File("test/included-test-manifest-2.xml"), new File("included-test-manifest-2.xml"), this.getClassLoader()); |
91 |
402 |
|
92 |
62 |
|
93 |
62 |
} catch (IOException e) { |
94 |
31 |
e.printStackTrace(); |
95 |
0 |
fail(e.getMessage()); |
96 |
774 |
} |
97 |
774 |
} |
98 |
|
|
99 |
|
public WorkingContext getWorkingContext() { |
100 |
1018 |
return ctx; |
101 |
31 |
} |
102 |
31 |
|
103 |
31 |
public void tearDown() { |
104 |
31 |
try { |
105 |
805 |
MyFileUtils.makeWriteable(wcBaseDir, true); |
106 |
836 |
MyFileUtils.makeWriteable(projectBaseDir, true); |
107 |
805 |
MyFileUtils.makeWriteable(localRepo, true); |
108 |
31 |
|
109 |
836 |
FileUtils.deleteDirectory(wcBaseDir); |
110 |
805 |
FileUtils.deleteDirectory(projectBaseDir); |
111 |
805 |
FileUtils.deleteDirectory(localRepo); |
112 |
62 |
} catch (IOException e) { |
113 |
62 |
fail(e.getMessage()); |
114 |
31 |
} |
115 |
31 |
catch (InterruptedException e) { |
116 |
62 |
fail(e.getMessage()); |
117 |
805 |
} |
118 |
774 |
} |
119 |
|
|
120 |
|
|
121 |
|
|
122 |
31 |
|
123 |
62 |
public ClassLoader getClassLoader() { |
124 |
6223 |
return this.getClass().getClassLoader(); |
125 |
|
} |
126 |
37 |
|
127 |
37 |
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
31 |
|
132 |
62 |
|
133 |
62 |
} |