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
.SlcException
;
11 import org
.argeo
.slc
.core
.deploy
.DeployedSystem
;
12 import org
.argeo
.slc
.core
.process
.SlcExecution
;
13 import org
.argeo
.slc
.core
.process
.SlcExecutionAware
;
14 import org
.argeo
.slc
.core
.structure
.StructureAware
;
15 import org
.argeo
.slc
.core
.structure
.tree
.TreeSPath
;
16 import org
.argeo
.slc
.core
.test
.ExecutableTestRun
;
17 import org
.argeo
.slc
.core
.test
.SimpleTestResult
;
18 import org
.argeo
.slc
.core
.test
.SimpleTestRun
;
19 import org
.argeo
.slc
.core
.test
.TestData
;
20 import org
.argeo
.slc
.core
.test
.TestDefinition
;
21 import org
.argeo
.slc
.core
.test
.TestResult
;
22 import org
.argeo
.slc
.core
.test
.WritableTestRun
;
23 import org
.argeo
.slc
.spring
.SpringUtils
;
25 /** Ant task wrapping a test run. */
26 public class SlcTestTask
extends SAwareTask
{
27 private Log log
= LogFactory
.getLog(SlcTestTask
.class);
29 private String testRunBean
= null;
31 private TestDefinitionArg testDefinitionArg
;
32 private TestDataArg testDataArg
;
33 private DeployedSystemArg deployedSystemArg
;
34 private TestResultArg testResultArg
;
37 public void executeActions(String mode
) throws BuildException
{
39 final String testRunBeanT
;
40 if (testRunBean
!= null) {
41 testRunBeanT
= testRunBean
;
43 testRunBeanT
= getProject().getUserProperty(
44 SlcAntConfig
.DEFAULT_TEST_RUN_PROPERTY
);
46 WritableTestRun testRun
= null;
48 if (testRunBeanT
!= null) {
49 testRun
= (WritableTestRun
) getContext().getBean(testRunBeanT
);
50 if (log
.isTraceEnabled())
51 log
.trace("Load test run bean from bean name " + testRunBeanT
);
54 if (testRun
== null) {
55 testRun
= loadSingleFromContext(WritableTestRun
.class);
56 if (testRun
== null) {
57 testRun
= new SimpleTestRun();
58 log
.warn("Created default 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 log
.warn("Created default simple test result");
94 if (log
.isTraceEnabled())
95 log
.trace("Load test result from scanning Spring context");
97 testRun
.setTestResult(result
);
100 SlcExecution slcExecution
= getSlcExecution();
101 testRun
.notifySlcExecution(slcExecution
);
103 if (result
!= null && result
instanceof StructureAware
) {
104 ((StructureAware
<TreeSPath
>) result
).notifyCurrentPath(
105 getRegistry(), getTreeSPath());
108 ((ExecutableTestRun
) testRun
).execute();
112 * The bean name of the test run to use. If not set the default is used.
116 public void setTestRun(String testRunBean
) {
117 this.testRunBean
= testRunBean
;
120 /** Creates sub tag. */
121 public TestDefinitionArg
createTestDefinition() {
122 testDefinitionArg
= new TestDefinitionArg();
123 // only test definitions can add to path
124 addSAwareArg(testDefinitionArg
);
125 return testDefinitionArg
;
128 /** Creates sub tag. */
129 public TestDataArg
createTestData() {
130 testDataArg
= new TestDataArg();
134 /** Creates sub tag. */
135 public DeployedSystemArg
createDeployedSystem() {
136 deployedSystemArg
= new DeployedSystemArg();
137 return deployedSystemArg
;
140 /** Creates sub tag. */
141 public TestResultArg
createTestResult() {
142 testResultArg
= new TestResultArg();
143 return testResultArg
;
146 protected <T
> T
loadSingleFromContext(Class
<T
> clss
) {
147 return SpringUtils
.loadSingleFromContext(getContext(), clss
);
151 class TestDefinitionArg
extends AbstractSpringArg
{
152 TestDefinition
getTestDefinition() {
153 return (TestDefinition
) getBeanInstance();
157 class TestDataArg
extends AbstractSpringArg
{
158 TestData
getTestData() {
159 return (TestData
) getBeanInstance();
164 class DeployedSystemArg
extends AbstractSpringArg
{
165 DeployedSystem
getDeployedSystem() {
166 return (DeployedSystem
) getBeanInstance();
171 class TestResultArg
extends AbstractSpringArg
{
172 TestResult
getTestResult() {
173 return (TestResult
) getBeanInstance();