X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.slc%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fant%2Ftest%2FSlcTestTask.java;h=96b5176e9b70a8dfad1005212e73dd9b1867dd0b;hb=5469796ed10ab0ddb8f7bf1cb7ba663676b7d73d;hp=69d08eee50727654ba534005592fe964effcff1b;hpb=d62a44995fa4bc758ab3b3e6e7ffe7b79c8684ef;p=gpl%2Fargeo-slc.git diff --git a/org.argeo.slc/src/main/java/org/argeo/slc/ant/test/SlcTestTask.java b/org.argeo.slc/src/main/java/org/argeo/slc/ant/test/SlcTestTask.java index 69d08eee5..96b5176e9 100644 --- a/org.argeo.slc/src/main/java/org/argeo/slc/ant/test/SlcTestTask.java +++ b/org.argeo.slc/src/main/java/org/argeo/slc/ant/test/SlcTestTask.java @@ -1,66 +1,134 @@ package org.argeo.slc.ant.test; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.tools.ant.BuildException; +import org.argeo.slc.ant.SlcAntConfig; import org.argeo.slc.ant.spring.AbstractSpringArg; import org.argeo.slc.ant.structure.SAwareTask; import org.argeo.slc.core.deploy.DeployedSystem; +import org.argeo.slc.core.structure.StructureAware; +import org.argeo.slc.core.test.ExecutableTestRun; import org.argeo.slc.core.test.TestData; import org.argeo.slc.core.test.TestDefinition; import org.argeo.slc.core.test.TestResult; -import org.argeo.slc.core.test.TestRun; +import org.argeo.slc.core.test.WritableTestRun; /** Ant task wrapping a test run. */ -public class SlcTestTask extends SAwareTask implements TestRun { +public class SlcTestTask extends SAwareTask { + private Log log = LogFactory.getLog(SlcTestTask.class); + + private String testRunBean = null; private TestDefinitionArg testDefinitionArg; private TestDataArg testDataArg; + private DeployedSystemArg deployedSystemArg; + private TestResultArg testResultArg; @Override public void executeActions(String mode) throws BuildException { - TestDefinition testDefinition = testDefinitionArg.getTestDefinition(); - testDefinition.execute(this); + final String testRunBeanT; + if (testRunBean != null) { + testRunBeanT = testRunBean; + } else { + testRunBeanT = getProject().getUserProperty( + SlcAntConfig.DEFAULT_TEST_RUN_PROPERTY); + } + WritableTestRun testRun = (WritableTestRun) getContext().getBean( + testRunBeanT); + + // set overridden references + if (testDataArg != null) { + testRun.setTestData(testDataArg.getTestData()); + log.trace("Overrides test data"); + } + + if (testDefinitionArg != null) { + testRun.setTestDefinition(testDefinitionArg.getTestDefinition()); + log.trace("Overrides test definition"); + } + + if (deployedSystemArg != null) { + testRun.setDeployedSystem(deployedSystemArg.getDeployedSystem()); + log.trace("Overrides deployed system"); + } + + if (testResultArg != null) { + testRun.setTestResult(testResultArg.getTestResult()); + log.trace("Overrides test result"); + } + + // notify path to test result + TestResult result = testRun.getTestResult(); + if (result != null && result instanceof StructureAware) { + ((StructureAware) result).notifyCurrentPath(getRegistry(), + getPath()); + } + + ((ExecutableTestRun) testRun).execute(); + } + + /** + * The bean name of the test run to use. If not set the default is used. + * + * @see SlcAntConfig + */ + public void setTestRun(String testRunBean) { + this.testRunBean = testRunBean; } + /** Creates sub tag. */ public TestDefinitionArg createTestDefinition() { testDefinitionArg = new TestDefinitionArg(); + // only test definitions can add to path addSAwareArg(testDefinitionArg); return testDefinitionArg; } + /** Creates sub tag. */ public TestDataArg createTestData() { testDataArg = new TestDataArg(); - addSAwareArg(testDataArg); return testDataArg; } - public DeployedSystem getDeployedSystem() { - throw new RuntimeException("Not yet implemented."); - } - - public TestDefinition getTestDefinition() { - return testDefinitionArg.getTestDefinition(); + /** Creates sub tag. */ + public DeployedSystemArg createDeployedSystem() { + deployedSystemArg = new DeployedSystemArg(); + return deployedSystemArg; } - public TestData getTestData() { - return testDataArg.getTestData(); - } - - public TestResult getTestResult() { - throw new RuntimeException("Not yet implemented."); + /** Creates sub tag. */ + public TestResultArg createTestResult() { + testResultArg = new TestResultArg(); + return testResultArg; } } class TestDefinitionArg extends AbstractSpringArg { - public TestDefinition getTestDefinition() { + TestDefinition getTestDefinition() { return (TestDefinition) getBeanInstance(); } } class TestDataArg extends AbstractSpringArg { - public TestData getTestData() { + TestData getTestData() { return (TestData) getBeanInstance(); } } + +class DeployedSystemArg extends AbstractSpringArg { + DeployedSystem getDeployedSystem() { + return (DeployedSystem) getBeanInstance(); + } + +} + +class TestResultArg extends AbstractSpringArg { + TestResult getTestResult() { + return (TestResult) getBeanInstance(); + } + +}