1 package org
.argeo
.slc
.ant
.test
;
3 import org
.apache
.commons
.logging
.Log
;
4 import org
.apache
.commons
.logging
.LogFactory
;
5 import org
.apache
.tools
.ant
.BuildException
;
7 import org
.argeo
.slc
.ant
.SlcAntConfig
;
8 import org
.argeo
.slc
.ant
.spring
.AbstractSpringArg
;
9 import org
.argeo
.slc
.ant
.structure
.SAwareTask
;
10 import org
.argeo
.slc
.core
.deploy
.DeployedSystem
;
11 import org
.argeo
.slc
.core
.structure
.StructureAware
;
12 import org
.argeo
.slc
.core
.test
.ExecutableTestRun
;
13 import org
.argeo
.slc
.core
.test
.TestData
;
14 import org
.argeo
.slc
.core
.test
.TestDefinition
;
15 import org
.argeo
.slc
.core
.test
.TestResult
;
16 import org
.argeo
.slc
.core
.test
.WritableTestRun
;
18 /** Ant task wrapping a test run. */
19 public class SlcTestTask
extends SAwareTask
{
20 private Log log
= LogFactory
.getLog(SlcTestTask
.class);
22 private String testRunBean
= null;
24 private TestDefinitionArg testDefinitionArg
;
25 private TestDataArg testDataArg
;
26 private DeployedSystemArg deployedSystemArg
;
27 private TestResultArg testResultArg
;
30 public void executeActions(String mode
) throws BuildException
{
31 final String testRunBeanT
;
32 if (testRunBean
!= null) {
33 testRunBeanT
= testRunBean
;
35 testRunBeanT
= getProject().getUserProperty(
36 SlcAntConfig
.DEFAULT_TEST_RUN_PROPERTY
);
38 WritableTestRun testRun
= (WritableTestRun
) getContext().getBean(
41 // set overridden references
42 if (testDataArg
!= null) {
43 testRun
.setTestData(testDataArg
.getTestData());
44 log
.trace("Overrides test data");
47 if (testDefinitionArg
!= null) {
48 testRun
.setTestDefinition(testDefinitionArg
.getTestDefinition());
49 log
.trace("Overrides test definition");
52 if (deployedSystemArg
!= null) {
53 testRun
.setDeployedSystem(deployedSystemArg
.getDeployedSystem());
54 log
.trace("Overrides deployed system");
57 if (testResultArg
!= null) {
58 testRun
.setTestResult(testResultArg
.getTestResult());
59 log
.trace("Overrides test result");
62 // notify path to test result
63 TestResult result
= testRun
.getTestResult();
64 if (result
!= null && result
instanceof StructureAware
) {
65 ((StructureAware
) result
).notifyCurrentPath(getRegistry(),
69 ((ExecutableTestRun
) testRun
).execute();
73 * The bean name of the test run to use. If not set the default is used.
77 public void setTestRun(String testRunBean
) {
78 this.testRunBean
= testRunBean
;
81 /** Creates sub tag. */
82 public TestDefinitionArg
createTestDefinition() {
83 testDefinitionArg
= new TestDefinitionArg();
84 // only test definitions can add to path
85 addSAwareArg(testDefinitionArg
);
86 return testDefinitionArg
;
89 /** Creates sub tag. */
90 public TestDataArg
createTestData() {
91 testDataArg
= new TestDataArg();
95 /** Creates sub tag. */
96 public DeployedSystemArg
createDeployedSystem() {
97 deployedSystemArg
= new DeployedSystemArg();
98 return deployedSystemArg
;
101 /** Creates sub tag. */
102 public TestResultArg
createTestResult() {
103 testResultArg
= new TestResultArg();
104 return testResultArg
;
109 class TestDefinitionArg
extends AbstractSpringArg
{
110 TestDefinition
getTestDefinition() {
111 return (TestDefinition
) getBeanInstance();
115 class TestDataArg
extends AbstractSpringArg
{
116 TestData
getTestData() {
117 return (TestData
) getBeanInstance();
122 class DeployedSystemArg
extends AbstractSpringArg
{
123 DeployedSystem
getDeployedSystem() {
124 return (DeployedSystem
) getBeanInstance();
129 class TestResultArg
extends AbstractSpringArg
{
130 TestResult
getTestResult() {
131 return (TestResult
) getBeanInstance();