From c228c125b7f40d1716911dd66971c720dc9478b5 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Sat, 17 Nov 2007 20:01:06 +0000 Subject: [PATCH] Improve unit tests git-svn-id: https://svn.argeo.org/slc/trunk@713 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../include/ant/slc-factory-targets.xml | 18 ++--- .../org/argeo/slc/ant/AntRegistryUtil.java | 7 +- .../argeo/slc/example/junit/TestAntBuild.java | 66 ++++++++++++++++++- org.argeo.slc/src/test/slc/conf/data.xml | 6 +- org.argeo.slc/src/test/slc/conf/slc.xml | 23 ++++--- 5 files changed, 99 insertions(+), 21 deletions(-) diff --git a/org.argeo.slc/src/main/config/include/ant/slc-factory-targets.xml b/org.argeo.slc/src/main/config/include/ant/slc-factory-targets.xml index 6df84da2d..baa1ef763 100644 --- a/org.argeo.slc/src/main/config/include/ant/slc-factory-targets.xml +++ b/org.argeo.slc/src/main/config/include/ant/slc-factory-targets.xml @@ -39,7 +39,7 @@ $LastChangedDate$ - + @@ -117,21 +117,21 @@ $LastChangedDate$ - + + + + + - - - - - + @@ -149,6 +149,8 @@ $LastChangedDate$ + + @@ -162,7 +164,7 @@ $LastChangedDate$ + depends="dist.unittest,jar.sources,dist.api,dist.apiWithSlc,dist.dependencies,dist.appli"> diff --git a/org.argeo.slc/src/main/java/org/argeo/slc/ant/AntRegistryUtil.java b/org.argeo.slc/src/main/java/org/argeo/slc/ant/AntRegistryUtil.java index 872dd9cc1..c73b59015 100644 --- a/org.argeo.slc/src/main/java/org/argeo/slc/ant/AntRegistryUtil.java +++ b/org.argeo.slc/src/main/java/org/argeo/slc/ant/AntRegistryUtil.java @@ -36,7 +36,8 @@ public class AntRegistryUtil { } /** Executes only the active paths of the Ant file. */ - public static void runActive(File antFile, List activePaths) { + public static Project runActive(File antFile, + List activePaths) { if (log.isDebugEnabled()) log.debug("Runs the " + activePaths.size() + " provided active paths of Ant file " + antFile); @@ -53,10 +54,11 @@ public class AntRegistryUtil { registry.setMode(StructureRegistry.ACTIVE); registry.setActivePaths(activePaths); p.executeTarget(p.getDefaultTarget()); + return p; } /** Executes all paths of the default target of the Ant file. */ - public static void runAll(File antFile) { + public static Project runAll(File antFile) { if (log.isDebugEnabled()) log.debug("Runs all paths of Ant file " + antFile); Project p = new Project(); @@ -67,5 +69,6 @@ public class AntRegistryUtil { p.addReference("ant.projectHelper", helper); helper.parse(p, antFile); p.executeTarget(p.getDefaultTarget()); + return p; } } diff --git a/org.argeo.slc/src/test/java/org/argeo/slc/example/junit/TestAntBuild.java b/org.argeo.slc/src/test/java/org/argeo/slc/example/junit/TestAntBuild.java index 70bad1191..ad88b3b6c 100644 --- a/org.argeo.slc/src/test/java/org/argeo/slc/example/junit/TestAntBuild.java +++ b/org.argeo.slc/src/test/java/org/argeo/slc/example/junit/TestAntBuild.java @@ -2,17 +2,81 @@ package org.argeo.slc.example.junit; import java.io.File; +import org.springframework.context.ApplicationContext; + +import org.apache.tools.ant.Project; + import junit.framework.TestCase; import org.argeo.slc.ant.AntRegistryUtil; +import org.argeo.slc.ant.SlcProjectHelper; +import org.argeo.slc.core.structure.tree.TreeSPath; +import org.argeo.slc.core.test.NumericTRId; +import org.argeo.slc.core.test.SimpleResultPart; +import org.argeo.slc.core.test.TestStatus; +import org.argeo.slc.core.test.tree.PartSubList; +import org.argeo.slc.core.test.tree.TreeTestResult; +import org.argeo.slc.dao.test.TestResultDao; public class TestAntBuild extends TestCase { public void testAllRunSimple() { + File[] reportFiles = new File("src/test/slc/work/results/report/").listFiles(); + for(File file: reportFiles){ + file.delete(); + } + File slcBaseDir = new File("./src/test/slc").getAbsoluteFile(); File antFile = new File(slcBaseDir.getPath() + "/root/Category1/SubCategory2/build.xml"); - AntRegistryUtil.runAll(antFile); + Project p = AntRegistryUtil.runAll(antFile); + + ApplicationContext context = (ApplicationContext) p + .getReference(SlcProjectHelper.REF_ROOT_CONTEXT); + + TestResultDao testResultDao = (TestResultDao) context + .getBean("testResultDao"); + + NumericTRId numericTRId = new NumericTRId(); + numericTRId.setValue(1l); + TreeTestResult testResult1 = (TreeTestResult) testResultDao + .getTestResult(numericTRId); + // assertPart(testResult1, "", 0, TestStatus.PASSED, ""); + assertPart( + testResult1, + "#root#Category1#SubCategory2#testComplex#slc.test0#0", + 0, + TestStatus.PASSED, + "Sub task with path #root#Category1#SubCategory2#testComplex#slc.test0#0 executed"); + assertPart(testResult1, + "#root#Category1#SubCategory2#testSimple#slc.test0", 1, + TestStatus.FAILED, + "Compare nato-expected.txt with nato-reached.txt"); + + numericTRId.setValue(2l); + TreeTestResult testResult2 = (TreeTestResult) testResultDao + .getTestResult(numericTRId); + assertPart(testResult2, + "#root#Category1#SubCategory2#testSimple#slc.test2", 1, + TestStatus.PASSED, + "Compare eu-reform-expected.txt with eu-reform-reached.txt"); + assertPart(testResult2, + "#root#Category1#SubCategory2#testSimple#slc.test3", 1, + TestStatus.FAILED, + "Compare eu-reform-expected.txt with eu-reform-reached.txt"); + + assertTrue(new File("src/test/slc/work/results/report/index.html") + .exists()); + assertTrue(new File("src/test/slc/work/results/report/1.html").exists()); + assertTrue(new File("src/test/slc/work/results/report/2.html").exists()); + } + private void assertPart(TreeTestResult testResult, String pathStr, + int index, Integer status, String message) { + TreeSPath path = TreeSPath.parseToCreatePath(pathStr, '#'); + PartSubList list = testResult.getResultParts().get(path); + SimpleResultPart part = (SimpleResultPart) list.getParts().get(index); + assertEquals(status, part.getStatus()); + assertEquals(message, part.getMessage()); } } diff --git a/org.argeo.slc/src/test/slc/conf/data.xml b/org.argeo.slc/src/test/slc/conf/data.xml index 6e4ce5cde..4ab0629fc 100644 --- a/org.argeo.slc/src/test/slc/conf/data.xml +++ b/org.argeo.slc/src/test/slc/conf/data.xml @@ -8,8 +8,10 @@ class="org.springframework.jdbc.datasource.SingleConnectionDataSource" destroy-method="destroy"> + + value="jdbc:hsqldb:mem:results" /> @@ -51,7 +53,7 @@ cache.use_minimal_puts=false max_fetch_depth=3 current_session_context_class=thread - hibernate.hbm2ddl.auto=update + hibernate.hbm2ddl.auto=create diff --git a/org.argeo.slc/src/test/slc/conf/slc.xml b/org.argeo.slc/src/test/slc/conf/slc.xml index 9ec452b68..ab92fe8b1 100644 --- a/org.argeo.slc/src/test/slc/conf/slc.xml +++ b/org.argeo.slc/src/test/slc/conf/slc.xml @@ -17,7 +17,11 @@ - + + + + + @@ -27,9 +31,12 @@ - + class="org.argeo.slc.core.test.tree.TreeTestResult"> + + + + + @@ -37,11 +44,11 @@ - + @@ -68,7 +75,7 @@ - + @@ -84,7 +91,7 @@ - + -- 2.39.2