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
;
6 import org
.argeo
.slc
.ant
.AntConstants
;
7 import org
.argeo
.slc
.ant
.spring
.SpringArg
;
8 import org
.argeo
.slc
.ant
.structure
.SAwareTask
;
9 import org
.argeo
.slc
.core
.deploy
.DeployedSystem
;
10 import org
.argeo
.slc
.core
.process
.SlcExecution
;
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
;
21 import org
.springframework
.beans
.BeansException
;
23 /** Ant task wrapping a test run. */
24 public class SlcTestTask
extends SAwareTask
{
25 private Log log
= LogFactory
.getLog(SlcTestTask
.class);
27 private String testRunBean
= null;
29 private SpringArg
<TestDefinition
> testDefinitionArg
;
30 private SpringArg
<TestData
> testDataArg
;
31 private SpringArg
<DeployedSystem
> deployedSystemArg
;
32 private SpringArg
<TestResult
> testResultArg
;
35 public void executeActions(String mode
) throws BuildException
{
37 final String testRunBeanT
;
38 if (testRunBean
!= null) {
39 testRunBeanT
= testRunBean
;
41 testRunBeanT
= getProject().getProperty(
42 AntConstants
.DEFAULT_TEST_RUN_PROPERTY
);
44 WritableTestRun testRun
= null;
46 if (testRunBeanT
!= null) {
48 testRun
= (WritableTestRun
) getContext().getBean(testRunBeanT
);
49 if (log
.isTraceEnabled())
50 log
.trace("Load test run bean from bean name "
52 } catch (BeansException e
) {
53 // silent, will try defaults
57 if (testRun
== null) {
58 testRun
= loadSingleFromContext(WritableTestRun
.class);
59 if (testRun
== null) {
60 testRun
= new SimpleTestRun();
61 log
.trace("Created default simple test run");
63 if (log
.isTraceEnabled())
64 log
.trace("Load test run from scanning Spring context");
68 // set overridden references
69 if (testDataArg
!= null) {
70 testRun
.setTestData(testDataArg
.getBeanInstance());
71 log
.trace("Overrides test data");
74 if (testDefinitionArg
!= null) {
75 testRun
.setTestDefinition(testDefinitionArg
.getBeanInstance());
76 log
.trace("Overrides test definition");
79 if (deployedSystemArg
!= null) {
80 testRun
.setDeployedSystem(deployedSystemArg
.getBeanInstance());
81 log
.trace("Overrides deployed system");
84 if (testResultArg
!= null) {
85 testRun
.setTestResult(testResultArg
.getBeanInstance());
86 log
.trace("Overrides test result");
89 // notify path to test result
90 TestResult result
= testRun
.getTestResult();
92 result
= loadSingleFromContext(TestResult
.class);
94 result
= new SimpleTestResult();
95 log
.warn("Created default simple test result");
97 if (log
.isTraceEnabled())
98 log
.trace("Load test result from scanning Spring context");
100 testRun
.setTestResult(result
);
103 SlcExecution slcExecution
= getSlcExecution();
104 testRun
.notifySlcExecution(slcExecution
);
106 if (result
!= null && result
instanceof StructureAware
) {
107 ((StructureAware
<TreeSPath
>) result
).notifyCurrentPath(
108 getRegistry(), getTreeSPath());
111 ((ExecutableTestRun
) testRun
).execute();
115 * The bean name of the test run to use. If not set the default is used.
119 public void setTestRun(String testRunBean
) {
120 this.testRunBean
= testRunBean
;
123 /** Creates sub tag. */
124 public SpringArg
<TestDefinition
> createTestDefinition() {
125 testDefinitionArg
= new SpringArg
<TestDefinition
>();
126 // only test definitions can add to path
127 addSAwareArg(testDefinitionArg
);
128 return testDefinitionArg
;
131 /** Creates sub tag. */
132 public SpringArg
<TestData
> createTestData() {
133 testDataArg
= new SpringArg
<TestData
>();
137 /** Creates sub tag. */
138 public SpringArg
<DeployedSystem
> createDeployedSystem() {
139 deployedSystemArg
= new SpringArg
<DeployedSystem
>();
140 return deployedSystemArg
;
143 /** Creates sub tag. */
144 public SpringArg
<TestResult
> createTestResult() {
145 testResultArg
= new SpringArg
<TestResult
>();
146 return testResultArg
;
149 protected <T
> T
loadSingleFromContext(Class
<T
> clss
) {
150 return SpringUtils
.loadSingleFromContext(getContext(), clss
);