1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.nuiton.jrst;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.junit.Assert;
27 import org.junit.BeforeClass;
28 import org.nuiton.util.TimeLog;
29
30 import java.io.File;
31 import java.io.IOException;
32 import java.io.InputStream;
33
34
35
36
37 public class JRSTAbstractTest extends Assert {
38
39
40 protected static Log log = LogFactory.getLog(JRSTAbstractTest.class);
41
42 protected static File testWorkDir;
43 protected static File testResourcesDir;
44
45 @BeforeClass
46 public static void initTest() throws IOException {
47
48 String basedir = System.getenv("basedir");
49 if (basedir == null) {
50
51
52 basedir = new File("").getAbsolutePath();
53 }
54 File basedirFile = new File(basedir);
55 testWorkDir = new File(basedirFile,
56 "target" + File.separator +
57 "surefire-workdir");
58
59 boolean b = testWorkDir.exists() || testWorkDir.mkdirs();
60 if (!b) {
61 throw new IOException(
62 "Could not create workdir directory " + testWorkDir);
63 }
64
65 testResourcesDir = new File(basedirFile,
66 "src" + File.separator +
67 "test" + File.separator +
68 "resources" + File.separator);
69 }
70
71 public static File getOutputTestFile(String fileName) throws IOException {
72 File file = new File(testWorkDir,System.nanoTime()+"_"+ fileName);
73 file.createNewFile();
74
75 return file;
76 }
77
78 public static String getOutputTestPath(String fileName) throws IOException {
79 File file = getOutputTestFile(fileName);
80 return file.getPath();
81 }
82
83 public static File getTestFile(String testName) {
84 return new File(testResourcesDir, testName);
85 }
86
87 public static File getBugTestFile(String testName) {
88 return new File(testResourcesDir, File.separator + "bugs" + File.separator + testName);
89 }
90
91 public static InputStream getTestStream(String testName) {
92 return JRSTAbstractTest.class.getResourceAsStream("/" + testName);
93 }
94
95 public static class JRSTTestGenerator {
96 protected String outputType;
97 protected File in;
98 protected File out;
99 protected JRST.Overwrite overwrite;
100
101 public JRSTTestGenerator(String outputType, File in, File out, JRST.Overwrite overwrite) throws Exception {
102 this.outputType = outputType;
103 this.in = in;
104 this.out = out;
105 this.overwrite = overwrite;
106 generate();
107 }
108
109 public void generate() throws Exception {
110 TimeLog simpleModeTimeLog = new TimeLog("Simple Mode");
111 simpleModeTimeLog.setTimeToLogInfo(100l);
112 Long start = TimeLog.getTime();
113 JRST.generate(outputType, in, out, overwrite, true);
114 simpleModeTimeLog.log(start, "Simple Mode generation");
115 assertJRST(in, out);
116
117 TimeLog docutilsTimeLog = new TimeLog("DocUtils");
118 start = TimeLog.getTime();
119 JRST.generate(outputType, in, out, overwrite, false);
120 docutilsTimeLog.log(start, "DocUtils generation");
121 assertJRST(in, out);
122 }
123
124
125
126
127
128
129
130 public void assertJRST(File in, File out) throws Exception {
131 }
132 }
133
134 public void generate(String outputType, File in, File out, JRST.Overwrite overwrite) throws Exception {
135 new JRSTTestGenerator(outputType, in, out, overwrite);
136 }
137 }