]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.example/src/test/java/org/argeo/slc/example/junit/ExampleIntegrationTest.java
cdc8fd59654cb83a17d613ae1b8d7c44bf02cca7
[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.structure.tree.TreeSPath;
16 import org.argeo.slc.core.test.NumericTRId;
17 import org.argeo.slc.core.test.SimpleResultPart;
18 import org.argeo.slc.core.test.TestStatus;
19 import org.argeo.slc.core.test.tree.PartSubList;
20 import org.argeo.slc.core.test.tree.TreeTestResult;
21 import org.argeo.slc.dao.test.TestResultDao;
22
23 /** High level tests for SLC Ant. */
24 public class ExampleIntegrationTest extends TestCase {
25 private static Log log = LogFactory.getLog(ExampleIntegrationTest.class);
26
27 /** Tests an end-to-end Ant run. */
28 public void testAllRunSimple() throws Exception {
29 String slcBase = System.getProperty("it.slc.base", "exampleSlcAppli");
30 File slcBaseDir = new File(slcBase).getCanonicalFile();
31 log.info("SLC base: " + slcBaseDir);
32
33 String reportDirPath = slcBaseDir.getPath() + "/work/results/report/";
34 File[] reportFiles = new File(reportDirPath).listFiles();
35 for (File file : reportFiles) {
36 file.delete();
37 }
38
39 File antFile = new File(slcBaseDir.getPath()
40 + "/root/Category1/SubCategory2/build.xml");
41 Project p = AntRegistryUtil.runAll(antFile);
42
43 ApplicationContext context = (ApplicationContext) p
44 .getReference(SlcProjectHelper.REF_ROOT_CONTEXT);
45
46 TestResultDao testResultDao = (TestResultDao) context
47 .getBean("testResultDao");
48
49 NumericTRId numericTRId = new NumericTRId();
50 numericTRId.setValue(1l);
51 TreeTestResult testResult1 = (TreeTestResult) testResultDao
52 .getTestResult(numericTRId);
53 // assertPart(testResult1, "", 0, TestStatus.PASSED, "");
54 assertPart(
55 testResult1,
56 "/root/Category1/SubCategory2/testComplex/slc.test0/0",
57 0,
58 TestStatus.PASSED,
59 "Sub task with path /root/Category1/SubCategory2/testComplex/slc.test0/0 executed");
60 assertPart(testResult1,
61 "/root/Category1/SubCategory2/testSimple/slc.test0", 1,
62 TestStatus.FAILED,
63 "Compare nato-expected.txt with nato-reached.txt");
64 assertPart(testResult1,
65 "/root/Category1/SubCategory2/testError/slc.test0", 0,
66 TestStatus.ERROR, "Execute example appli");
67
68 // Context
69 assertPart(testResult1,
70 "/root/Category1/SubCategory2/testContext/slc.test1/reference",
71 0, TestStatus.PASSED, "Values matched for key 'reference'");
72 assertPart(testResult1,
73 "/root/Category1/SubCategory2/testContext/slc.test1/varIntern",
74 0, TestStatus.PASSED, "Values matched for key 'varIntern'");
75 assertPart(testResult1,
76 "/root/Category1/SubCategory2/testContext/slc.test1/varExtern",
77 0, TestStatus.PASSED, "Values matched for key 'varExtern'");
78
79 numericTRId.setValue(2l);
80 TreeTestResult testResult2 = (TreeTestResult) testResultDao
81 .getTestResult(numericTRId);
82 assertPart(testResult2,
83 "/root/Category1/SubCategory2/testSimple/slc.test2", 1,
84 TestStatus.PASSED,
85 "Compare eu-reform-expected.txt with eu-reform-reached.txt");
86 assertPart(testResult2,
87 "/root/Category1/SubCategory2/testSimple/slc.test3", 1,
88 TestStatus.FAILED,
89 "Compare eu-reform-expected.txt with eu-reform-reached.txt");
90
91 assertTrue(new File(reportDirPath + "index.html").exists());
92 assertTrue(new File(reportDirPath + "slc-resultsList.html").exists());
93 assertTrue(new File(reportDirPath + "slc-result-1.html").exists());
94 assertTrue(new File(reportDirPath + "slc-result-2.html").exists());
95 }
96
97 private void assertPart(TreeTestResult testResult, String pathStr,
98 int index, Integer status, String message) {
99 TreeSPath path = TreeSPath.parseToCreatePath(pathStr);
100 PartSubList list = testResult.getResultParts().get(path);
101 SimpleResultPart part = (SimpleResultPart) list.getParts().get(index);
102 assertEquals(status, part.getStatus());
103 assertEquals(message, part.getMessage());
104 }
105 }