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
.process
.SlcExecution
;
12 import org
.argeo
.slc
.core
.process
.SlcExecutionAware
;
13 import org
.argeo
.slc
.core
.structure
.StructureAware
;
14 import org
.argeo
.slc
.core
.structure
.tree
.TreeSPath
;
15 import org
.argeo
.slc
.core
.test
.ExecutableTestRun
;
16 import org
.argeo
.slc
.core
.test
.SimpleTestResult
;
17 import org
.argeo
.slc
.core
.test
.SimpleTestRun
;
18 import org
.argeo
.slc
.core
.test
.TestData
;
19 import org
.argeo
.slc
.core
.test
.TestDefinition
;
20 import org
.argeo
.slc
.core
.test
.TestResult
;
21 import org
.argeo
.slc
.core
.test
.WritableTestRun
;
22 import org
.argeo
.slc
.spring
.SpringUtils
;
24 /** Ant task wrapping a test run. */
25 public class SlcTestTask
extends SAwareTask
{
26 private Log log
= LogFactory
.getLog(SlcTestTask
.class);
28 private String testRunBean
= null;
30 private TestDefinitionArg testDefinitionArg
;
31 private TestDataArg testDataArg
;
32 private DeployedSystemArg deployedSystemArg
;
33 private TestResultArg testResultArg
;
36 public void executeActions(String mode
) throws BuildException
{
38 final String testRunBeanT
;
39 if (testRunBean
!= null) {
40 testRunBeanT
= testRunBean
;
42 testRunBeanT
= getProject().getUserProperty(
43 SlcAntConfig
.DEFAULT_TEST_RUN_PROPERTY
);
45 WritableTestRun testRun
= null;
47 if (testRunBeanT
!= null) {
48 testRun
= (WritableTestRun
) getContext().getBean(testRunBeanT
);
49 if (log
.isTraceEnabled())
50 log
.trace("Load test run bean from bean name " + testRunBeanT
);
53 if (testRun
== null) {
54 testRun
= loadSingleFromContext(WritableTestRun
.class);
55 if (testRun
== null) {
56 testRun
= new SimpleTestRun();
57 if (log
.isTraceEnabled())
58 log
.trace("Created simple test run");
60 if (log
.isTraceEnabled())
61 log
.trace("Load test run from scanning Spring context");
65 // set overridden references
66 if (testDataArg
!= null) {
67 testRun
.setTestData(testDataArg
.getTestData());
68 log
.trace("Overrides test data");
71 if (testDefinitionArg
!= null) {
72 testRun
.setTestDefinition(testDefinitionArg
.getTestDefinition());
73 log
.trace("Overrides test definition");
76 if (deployedSystemArg
!= null) {
77 testRun
.setDeployedSystem(deployedSystemArg
.getDeployedSystem());
78 log
.trace("Overrides deployed system");
81 if (testResultArg
!= null) {
82 testRun
.setTestResult(testResultArg
.getTestResult());
83 log
.trace("Overrides test result");
86 // notify path to test result
87 TestResult result
= testRun
.getTestResult();
89 result
= loadSingleFromContext(TestResult
.class);
91 result
= new SimpleTestResult();
92 if (log
.isTraceEnabled())
93 log
.trace("Created simple test result");
95 if (log
.isTraceEnabled())
96 log
.trace("Load test result from scanning Spring context");
98 testRun
.setTestResult(result
);
101 SlcExecution slcExecution
= getSlcExecution();
102 testRun
.notifySlcExecution(slcExecution
);
104 if (result
!= null && result
instanceof StructureAware
) {
105 ((StructureAware
<TreeSPath
>) result
).notifyCurrentPath(
106 getRegistry(), getTreeSPath());
109 ((ExecutableTestRun
) testRun
).execute();
113 * The bean name of the test run to use. If not set the default is used.
117 public void setTestRun(String testRunBean
) {
118 this.testRunBean
= testRunBean
;
121 /** Creates sub tag. */
122 public TestDefinitionArg
createTestDefinition() {
123 testDefinitionArg
= new TestDefinitionArg();
124 // only test definitions can add to path
125 addSAwareArg(testDefinitionArg
);
126 return testDefinitionArg
;
129 /** Creates sub tag. */
130 public TestDataArg
createTestData() {
131 testDataArg
= new TestDataArg();
135 /** Creates sub tag. */
136 public DeployedSystemArg
createDeployedSystem() {
137 deployedSystemArg
= new DeployedSystemArg();
138 return deployedSystemArg
;
141 /** Creates sub tag. */
142 public TestResultArg
createTestResult() {
143 testResultArg
= new TestResultArg();
144 return testResultArg
;
147 protected <T
> T
loadSingleFromContext(Class
<T
> clss
) {
148 return SpringUtils
.loadSingleFromContext(getContext(), clss
);
152 class TestDefinitionArg
extends AbstractSpringArg
{
153 TestDefinition
getTestDefinition() {
154 return (TestDefinition
) getBeanInstance();
158 class TestDataArg
extends AbstractSpringArg
{
159 TestData
getTestData() {
160 return (TestData
) getBeanInstance();
165 class DeployedSystemArg
extends AbstractSpringArg
{
166 DeployedSystem
getDeployedSystem() {
167 return (DeployedSystem
) getBeanInstance();
172 class TestResultArg
extends AbstractSpringArg
{
173 TestResult
getTestResult() {
174 return (TestResult
) getBeanInstance();