]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc/src/main/java/org/argeo/slc/ant/test/SlcTestTask.java
Allow overriding of test result and deployed environment in slc test task
[gpl/argeo-slc.git] / org.argeo.slc / src / main / java / org / argeo / slc / ant / test / SlcTestTask.java
index 4dcd31a3bc6677d2f3b9befe27c082753b41048d..93674a01295cee24e8e98f333cbc44c469401dbe 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.SAwareArg;\r
-import org.argeo.slc.ant.SAwareTask;\r
+import org.argeo.slc.ant.SlcAntConfig;\r
 import org.argeo.slc.ant.spring.AbstractSpringArg;\r
-import org.argeo.slc.ant.spring.AbstractSpringTask;\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.TestData;\r
 import org.argeo.slc.core.test.TestDefinition;\r
+import org.argeo.slc.core.test.TestResult;\r
+import org.argeo.slc.core.test.WritableTestRun;\r
 \r
+/** Ant task wrapping a test run. */\r
 public class SlcTestTask extends SAwareTask {\r
+       Log log = LogFactory.getLog(SlcTestTask.class);\r
 \r
        private TestDefinitionArg testDefinitionArg;\r
        private TestDataArg testDataArg;\r
+       private DeployedSystemArg deployedSystemArg;\r
+       private TestResultArg testResultArg;\r
 \r
        @Override\r
-       public void execute() throws BuildException {\r
-               TestDefinition testDefinition = testDefinitionArg.getTestDefinition();\r
-               testDefinition.setTestData(testDataArg.getTestData());\r
-               testDefinition.execute();\r
+       public void executeActions(String mode) throws BuildException {\r
+               WritableTestRun testRun = (WritableTestRun) getContext().getBean(\r
+                               getProject().getUserProperty(\r
+                                               SlcAntConfig.DEFAULT_TEST_RUN_PROPERTY));\r
+\r
+               // set overriden 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
+               testRun.execute();\r
        }\r
 \r
        public TestDefinitionArg createTestDefinition() {\r
                testDefinitionArg = new TestDefinitionArg();\r
-               testDefinitionArg.setParentSAware(sAware);\r
+               // only test definitions can add to path\r
+               addSAwareArg(testDefinitionArg);\r
                return testDefinitionArg;\r
        }\r
 \r
        public TestDataArg createTestData() {\r
                testDataArg = new TestDataArg();\r
-               testDataArg.setParentSAware(sAware);\r
                return testDataArg;\r
        }\r
+\r
+       public DeployedSystemArg createDeployedSystem() {\r
+               deployedSystemArg = new DeployedSystemArg();\r
+               return deployedSystemArg;\r
+       }\r
+\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
+               return (TestDefinition) getBeanInstance();\r
+       }\r
+}\r
+\r
+class TestDataArg extends AbstractSpringArg {\r
+       public TestData getTestData() {\r
+               return (TestData) getBeanInstance();\r
+       }\r
+\r
 }\r
 \r
-class TestDefinitionArg extends SAwareArg {\r
-       public TestDefinition getTestDefinition(){\r
-               return (TestDefinition)getBeanInstance();\r
+class DeployedSystemArg extends AbstractSpringArg {\r
+       public DeployedSystem getDeployedSystem() {\r
+               return (DeployedSystem) getBeanInstance();\r
        }\r
+\r
 }\r
 \r
-class TestDataArg extends SAwareArg {\r
-       public TestData getTestData(){\r
-               return (TestData)getBeanInstance();\r
+class TestResultArg extends AbstractSpringArg {\r
+       public TestResult getTestResult() {\r
+               return (TestResult) getBeanInstance();\r
        }\r
 \r
 }\r