]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc/src/main/java/org/argeo/slc/ant/test/SlcTestTask.java
Improve comments
[gpl/argeo-slc.git] / org.argeo.slc / src / main / java / org / argeo / slc / ant / test / SlcTestTask.java
index 69d08eee50727654ba534005592fe964effcff1b..96b5176e9b70a8dfad1005212e73dd9b1867dd0b 100644 (file)
 package org.argeo.slc.ant.test;\r
 \r
+import org.apache.commons.logging.Log;\r
+import org.apache.commons.logging.LogFactory;\r
 import org.apache.tools.ant.BuildException;\r
 \r
+import org.argeo.slc.ant.SlcAntConfig;\r
 import org.argeo.slc.ant.spring.AbstractSpringArg;\r
 import org.argeo.slc.ant.structure.SAwareTask;\r
 import org.argeo.slc.core.deploy.DeployedSystem;\r
+import org.argeo.slc.core.structure.StructureAware;\r
+import org.argeo.slc.core.test.ExecutableTestRun;\r
 import org.argeo.slc.core.test.TestData;\r
 import org.argeo.slc.core.test.TestDefinition;\r
 import org.argeo.slc.core.test.TestResult;\r
-import org.argeo.slc.core.test.TestRun;\r
+import org.argeo.slc.core.test.WritableTestRun;\r
 \r
 /** Ant task wrapping a test run. */\r
-public class SlcTestTask extends SAwareTask implements TestRun {\r
+public class SlcTestTask extends SAwareTask {\r
+       private Log log = LogFactory.getLog(SlcTestTask.class);\r
+\r
+       private String testRunBean = null;\r
 \r
        private TestDefinitionArg testDefinitionArg;\r
        private TestDataArg testDataArg;\r
+       private DeployedSystemArg deployedSystemArg;\r
+       private TestResultArg testResultArg;\r
 \r
        @Override\r
        public void executeActions(String mode) throws BuildException {\r
-               TestDefinition testDefinition = testDefinitionArg.getTestDefinition();\r
-               testDefinition.execute(this);\r
+               final String testRunBeanT;\r
+               if (testRunBean != null) {\r
+                       testRunBeanT = testRunBean;\r
+               } else {\r
+                       testRunBeanT = getProject().getUserProperty(\r
+                                       SlcAntConfig.DEFAULT_TEST_RUN_PROPERTY);\r
+               }\r
+               WritableTestRun testRun = (WritableTestRun) getContext().getBean(\r
+                               testRunBeanT);\r
+\r
+               // set overridden references\r
+               if (testDataArg != null) {\r
+                       testRun.setTestData(testDataArg.getTestData());\r
+                       log.trace("Overrides test data");\r
+               }\r
+\r
+               if (testDefinitionArg != null) {\r
+                       testRun.setTestDefinition(testDefinitionArg.getTestDefinition());\r
+                       log.trace("Overrides test definition");\r
+               }\r
+\r
+               if (deployedSystemArg != null) {\r
+                       testRun.setDeployedSystem(deployedSystemArg.getDeployedSystem());\r
+                       log.trace("Overrides deployed system");\r
+               }\r
+\r
+               if (testResultArg != null) {\r
+                       testRun.setTestResult(testResultArg.getTestResult());\r
+                       log.trace("Overrides test result");\r
+               }\r
+\r
+               // notify path to test result\r
+               TestResult result = testRun.getTestResult();\r
+               if (result != null && result instanceof StructureAware) {\r
+                       ((StructureAware) result).notifyCurrentPath(getRegistry(),\r
+                                       getPath());\r
+               }\r
+\r
+               ((ExecutableTestRun) testRun).execute();\r
+       }\r
+\r
+       /**\r
+        * The bean name of the test run to use. If not set the default is used.\r
+        * \r
+        * @see SlcAntConfig\r
+        */\r
+       public void setTestRun(String testRunBean) {\r
+               this.testRunBean = testRunBean;\r
        }\r
 \r
+       /** Creates sub tag. */\r
        public TestDefinitionArg createTestDefinition() {\r
                testDefinitionArg = new TestDefinitionArg();\r
+               // only test definitions can add to path\r
                addSAwareArg(testDefinitionArg);\r
                return testDefinitionArg;\r
        }\r
 \r
+       /** Creates sub tag. */\r
        public TestDataArg createTestData() {\r
                testDataArg = new TestDataArg();\r
-               addSAwareArg(testDataArg);\r
                return testDataArg;\r
        }\r
 \r
-       public DeployedSystem getDeployedSystem() {\r
-               throw new RuntimeException("Not yet implemented.");\r
-       }\r
-\r
-       public TestDefinition getTestDefinition() {\r
-               return testDefinitionArg.getTestDefinition();\r
+       /** Creates sub tag. */\r
+       public DeployedSystemArg createDeployedSystem() {\r
+               deployedSystemArg = new DeployedSystemArg();\r
+               return deployedSystemArg;\r
        }\r
 \r
-       public TestData getTestData() {\r
-               return testDataArg.getTestData();\r
-       }\r
-\r
-       public TestResult getTestResult() {\r
-               throw new RuntimeException("Not yet implemented.");\r
+       /** Creates sub tag. */\r
+       public TestResultArg createTestResult() {\r
+               testResultArg = new TestResultArg();\r
+               return testResultArg;\r
        }\r
 \r
 }\r
 \r
 class TestDefinitionArg extends AbstractSpringArg {\r
-       public TestDefinition getTestDefinition() {\r
+       TestDefinition getTestDefinition() {\r
                return (TestDefinition) getBeanInstance();\r
        }\r
 }\r
 \r
 class TestDataArg extends AbstractSpringArg {\r
-       public TestData getTestData() {\r
+       TestData getTestData() {\r
                return (TestData) getBeanInstance();\r
        }\r
 \r
 }\r
+\r
+class DeployedSystemArg extends AbstractSpringArg {\r
+       DeployedSystem getDeployedSystem() {\r
+               return (DeployedSystem) getBeanInstance();\r
+       }\r
+\r
+}\r
+\r
+class TestResultArg extends AbstractSpringArg {\r
+       TestResult getTestResult() {\r
+               return (TestResult) getBeanInstance();\r
+       }\r
+\r
+}\r