]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.example/src/test/java/org/argeo/slc/example/junit/ExampleIntegrationTest.java
Introduce unit tests
[gpl/argeo-slc.git] / org.argeo.slc.example / src / test / java / org / argeo / slc / example / junit / ExampleIntegrationTest.java
1 package org.argeo.slc.example.junit;
2
3 import java.io.File;
4
5 import junit.framework.TestCase;
6
7 import org.springframework.context.ApplicationContext;
8
9 import org.apache.commons.logging.Log;
10 import org.apache.commons.logging.LogFactory;
11 import org.apache.tools.ant.Project;
12
13 import org.argeo.slc.ant.AntRegistryUtil;
14 import org.argeo.slc.ant.SlcProjectHelper;
15 import org.argeo.slc.core.test.NumericTRId;
16 import org.argeo.slc.core.test.TestStatus;
17 import org.argeo.slc.core.test.tree.TreeTestResult;
18 import org.argeo.slc.dao.test.TestResultDao;
19 import org.argeo.slc.unit.test.tree.UnitTestTreeUtil;
20
21 /** High level tests for SLC Ant. */
22 public class ExampleIntegrationTest extends TestCase {
23 private static Log log = LogFactory.getLog(ExampleIntegrationTest.class);
24
25 /** Tests an end-to-end Ant run. */
26 public void testAllRunSimple() throws Exception {
27 String slcBase = System.getProperty("it.slc.base", "exampleSlcAppli");
28 File slcBaseDir = new File(slcBase).getCanonicalFile();
29 log.info("SLC base: " + slcBaseDir);
30
31 String reportDirPath = slcBaseDir.getPath() + "/work/results/report/";
32 File[] reportFiles = new File(reportDirPath).listFiles();
33 for (File file : reportFiles) {
34 file.delete();
35 }
36
37 File antFile = new File(slcBaseDir.getPath()
38 + "/root/Category1/SubCategory2/build.xml");
39 Project p = AntRegistryUtil.runAll(antFile);
40
41 ApplicationContext context = (ApplicationContext) p
42 .getReference(SlcProjectHelper.REF_ROOT_CONTEXT);
43
44 TestResultDao testResultDao = (TestResultDao) context
45 .getBean("testResultDao");
46
47 NumericTRId numericTRId = new NumericTRId();
48 numericTRId.setValue(1l);
49 TreeTestResult testResult1 = (TreeTestResult) testResultDao
50 .getTestResult(numericTRId);
51 // assertPart(testResult1, "", 0, TestStatus.PASSED, "");
52 UnitTestTreeUtil
53 .assertPart(
54 testResult1,
55 "/root/Category1/SubCategory2/testComplex/slc.test0/0",
56 0,
57 TestStatus.PASSED,
58 "Sub task with path /root/Category1/SubCategory2/testComplex/slc.test0/0 executed");
59 UnitTestTreeUtil.assertPart(testResult1,
60 "/root/Category1/SubCategory2/testSimple/slc.test0", 1,
61 TestStatus.FAILED,
62 "Compare nato-expected.txt with nato-reached.txt");
63 UnitTestTreeUtil.assertPart(testResult1,
64 "/root/Category1/SubCategory2/testError/slc.test0", 0,
65 TestStatus.ERROR, "Execute example appli");
66
67 numericTRId.setValue(2l);
68 TreeTestResult testResult2 = (TreeTestResult) testResultDao
69 .getTestResult(numericTRId);
70 UnitTestTreeUtil.assertPart(testResult2,
71 "/root/Category1/SubCategory2/testSimple/slc.test2", 1,
72 TestStatus.PASSED,
73 "Compare eu-reform-expected.txt with eu-reform-reached.txt");
74 UnitTestTreeUtil.assertPart(testResult2,
75 "/root/Category1/SubCategory2/testSimple/slc.test3", 1,
76 TestStatus.FAILED,
77 "Compare eu-reform-expected.txt with eu-reform-reached.txt");
78
79 assertTrue(new File(reportDirPath + "index.html").exists());
80 assertTrue(new File(reportDirPath + "slc-resultsList.html").exists());
81 assertTrue(new File(reportDirPath + "slc-result-1.html").exists());
82 assertTrue(new File(reportDirPath + "slc-result-2.html").exists());
83 }
84
85 }