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
.structure
.tree
.TreeSPath
;
13 import org
.argeo
.slc
.core
.test
.ExecutableTestRun
;
14 import org
.argeo
.slc
.core
.test
.SimpleTestResult
;
15 import org
.argeo
.slc
.core
.test
.SimpleTestRun
;
16 import org
.argeo
.slc
.core
.test
.TestData
;
17 import org
.argeo
.slc
.core
.test
.TestDefinition
;
18 import org
.argeo
.slc
.core
.test
.TestResult
;
19 import org
.argeo
.slc
.core
.test
.WritableTestRun
;
20 import org
.argeo
.slc
.spring
.SpringUtils
;
22 /** Ant task wrapping a test run. */
23 public class SlcTestTask
extends SAwareTask
{
24 private Log log
= LogFactory
.getLog(SlcTestTask
.class);
26 private String testRunBean
= null;
28 private TestDefinitionArg testDefinitionArg
;
29 private TestDataArg testDataArg
;
30 private DeployedSystemArg deployedSystemArg
;
31 private TestResultArg testResultArg
;
34 public void executeActions(String mode
) throws BuildException
{
36 final String testRunBeanT
;
37 if (testRunBean
!= null) {
38 testRunBeanT
= testRunBean
;
40 testRunBeanT
= getProject().getUserProperty(
41 SlcAntConfig
.DEFAULT_TEST_RUN_PROPERTY
);
43 WritableTestRun testRun
= null;
45 if (testRunBeanT
!= null) {
46 testRun
= (WritableTestRun
) getContext().getBean(testRunBeanT
);
47 if (log
.isTraceEnabled())
48 log
.trace("Load test run bean from bean name " + testRunBeanT
);
51 if (testRun
== null) {
52 testRun
= loadSingleFromContext(WritableTestRun
.class);
53 if (testRun
== null) {
54 testRun
= new SimpleTestRun();
55 if (log
.isTraceEnabled())
56 log
.trace("Created simple test run");
58 if (log
.isTraceEnabled())
59 log
.trace("Load test run from scanning Spring context");
63 // set overridden references
64 if (testDataArg
!= null) {
65 testRun
.setTestData(testDataArg
.getTestData());
66 log
.trace("Overrides test data");
69 if (testDefinitionArg
!= null) {
70 testRun
.setTestDefinition(testDefinitionArg
.getTestDefinition());
71 log
.trace("Overrides test definition");
74 if (deployedSystemArg
!= null) {
75 testRun
.setDeployedSystem(deployedSystemArg
.getDeployedSystem());
76 log
.trace("Overrides deployed system");
79 if (testResultArg
!= null) {
80 testRun
.setTestResult(testResultArg
.getTestResult());
81 log
.trace("Overrides test result");
84 // notify path to test result
85 TestResult result
= testRun
.getTestResult();
87 result
= loadSingleFromContext(TestResult
.class);
89 result
= new SimpleTestResult();
90 if (log
.isTraceEnabled())
91 log
.trace("Created simple test result");
93 if (log
.isTraceEnabled())
94 log
.trace("Load test result from scanning Spring context");
96 testRun
.setTestResult(result
);
99 if (result
!= null && result
instanceof StructureAware
) {
100 ((StructureAware
<TreeSPath
>) result
).notifyCurrentPath(
101 getRegistry(), getTreeSPath());
104 ((ExecutableTestRun
) testRun
).execute();
108 * The bean name of the test run to use. If not set the default is used.
112 public void setTestRun(String testRunBean
) {
113 this.testRunBean
= testRunBean
;
116 /** Creates sub tag. */
117 public TestDefinitionArg
createTestDefinition() {
118 testDefinitionArg
= new TestDefinitionArg();
119 // only test definitions can add to path
120 addSAwareArg(testDefinitionArg
);
121 return testDefinitionArg
;
124 /** Creates sub tag. */
125 public TestDataArg
createTestData() {
126 testDataArg
= new TestDataArg();
130 /** Creates sub tag. */
131 public DeployedSystemArg
createDeployedSystem() {
132 deployedSystemArg
= new DeployedSystemArg();
133 return deployedSystemArg
;
136 /** Creates sub tag. */
137 public TestResultArg
createTestResult() {
138 testResultArg
= new TestResultArg();
139 return testResultArg
;
142 protected <T
> T
loadSingleFromContext(Class
<T
> clss
) {
143 return SpringUtils
.loadSingleFromContext(getContext(), clss
);
147 class TestDefinitionArg
extends AbstractSpringArg
{
148 TestDefinition
getTestDefinition() {
149 return (TestDefinition
) getBeanInstance();
153 class TestDataArg
extends AbstractSpringArg
{
154 TestData
getTestData() {
155 return (TestData
) getBeanInstance();
160 class DeployedSystemArg
extends AbstractSpringArg
{
161 DeployedSystem
getDeployedSystem() {
162 return (DeployedSystem
) getBeanInstance();
167 class TestResultArg
extends AbstractSpringArg
{
168 TestResult
getTestResult() {
169 return (TestResult
) getBeanInstance();