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 * This testclass is highly recommended when writing JUnit testclasses for Karma. It initializes some basic stuff. Just
33 * check this implementation to see how it may help.
34 *
35 * @author D.A. Smedes
36 * @version $Id: BaseTest.java,v 1.38 2004/11/03 21:03:13 asmedes Exp $
37 */
38 public class BaseTest extends TestCase {
39
40 private File wcBaseDir = null;
41 private File projectBaseDir = null;
42 private File localRepo = null;
43 private WorkingContext ctx = null;
44
45 public void setUp() {
46
47
48
49 System.setProperty("TESTMODE", "true");
50 System.setProperty("locale", "en");
51
52 try {
53 wcBaseDir = MyFileUtils.createTempDirectory();
54 projectBaseDir = MyFileUtils.createTempDirectory();
55 localRepo = MyFileUtils.createTempDirectory();
56
57 String wc = "test";
58 ctx = new WorkingContext(wc, wcBaseDir);
59
60 MyFileUtils.writeFile(
61 ctx.getWorkingContextConfigurationBaseDir(),
62 new File("test/test-working-context.xml"),
63 new File("working-context.xml"),
64 this.getClass().getClassLoader()
65 );
66
67 WorkingContextConfiguration config = new WorkingContextConfiguration(ctx);
68 try {
69 config.load();
70 } catch (WorkingContextException e) {
71 fail(e.getMessage());
72 }
73 ctx.configure(config);
74
75 config.setProperty(WorkingContext.PROJECT_BASE_DIRECTORY_PROPERTY, projectBaseDir.getPath());
76
77 MyFileUtils.writeFile(WorkingContext.getConfigurationBaseDir(), new File("test/authenticators.xml"), new File("authenticators.xml"), this.getClassLoader());
78
79 File mStore = ctx.getConfiguration().getManifestStore().getModule().getBaseDir();
80 File lStore = ctx.getConfiguration().getLocationStore().getModule().getBaseDir();
81
82 MyFileUtils.writeFile(lStore, new File("test/test-locations.xml"), new File("test-locations.xml"), this.getClassLoader());
83 MyFileUtils.writeFile(lStore, new File("test/test-locations-2.xml"), new File("test-locations-2.xml"), this.getClassLoader());
84
85 MyFileUtils.writeFile(mStore, new File("test/test-manifest-1.xml"), new File("test-manifest-1.xml"), this.getClassLoader());
86 MyFileUtils.writeFile(mStore, new File("test/test-manifest-2.xml"), new File("test-manifest-2.xml"), this.getClassLoader());
87 MyFileUtils.writeFile(mStore, new File("test/test-manifest-3.xml"), new File("test-manifest-3.xml"), this.getClassLoader());
88
89 MyFileUtils.writeFile(mStore, new File("test/included-test-manifest-1.xml"), new File("included-test-manifest-1.xml"), this.getClassLoader());
90 MyFileUtils.writeFile(mStore, new File("test/included-test-manifest-2.xml"), new File("included-test-manifest-2.xml"), this.getClassLoader());
91
92
93 } catch (IOException e) {
94 e.printStackTrace();
95 fail(e.getMessage());
96 }
97 }
98
99 public WorkingContext getWorkingContext() {
100 return ctx;
101 }
102
103 public void tearDown() {
104 try {
105 MyFileUtils.makeWriteable(wcBaseDir, true);
106 MyFileUtils.makeWriteable(projectBaseDir, true);
107 MyFileUtils.makeWriteable(localRepo, true);
108
109 FileUtils.deleteDirectory(wcBaseDir);
110 FileUtils.deleteDirectory(projectBaseDir);
111 FileUtils.deleteDirectory(localRepo);
112 } catch (IOException e) {
113 fail(e.getMessage());
114 }
115 catch (InterruptedException e) {
116 fail(e.getMessage());
117 }
118 }
119
120 /***
121 * Helper method to retrieve the this class' classloader.
122 */
123 public ClassLoader getClassLoader() {
124 return this.getClass().getClassLoader();
125 }
126
127 /***
128 // * When this class is run (it is a test class), it won't bother you with 'no tests found'.
129 // */
130
131
132
133 }