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
.SlcAntConfig
;
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
;
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 SpringArg
<TestDefinition
> testDefinitionArg
;
29 private SpringArg
<TestData
> testDataArg
;
30 private SpringArg
<DeployedSystem
> deployedSystemArg
;
31 private SpringArg
<TestResult
> 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 log
.warn("Created default simple test run");
57 if (log
.isTraceEnabled())
58 log
.trace("Load test run from scanning Spring context");
62 // set overridden references
63 if (testDataArg
!= null) {
64 testRun
.setTestData(testDataArg
.getBeanInstance());
65 log
.trace("Overrides test data");
68 if (testDefinitionArg
!= null) {
69 testRun
.setTestDefinition(testDefinitionArg
.getBeanInstance());
70 log
.trace("Overrides test definition");
73 if (deployedSystemArg
!= null) {
74 testRun
.setDeployedSystem(deployedSystemArg
.getBeanInstance());
75 log
.trace("Overrides deployed system");
78 if (testResultArg
!= null) {
79 testRun
.setTestResult(testResultArg
.getBeanInstance());
80 log
.trace("Overrides test result");
83 // notify path to test result
84 TestResult result
= testRun
.getTestResult();
86 result
= loadSingleFromContext(TestResult
.class);
88 result
= new SimpleTestResult();
89 log
.warn("Created default simple test result");
91 if (log
.isTraceEnabled())
92 log
.trace("Load test result from scanning Spring context");
94 testRun
.setTestResult(result
);
97 SlcExecution slcExecution
= getSlcExecution();
98 testRun
.notifySlcExecution(slcExecution
);
100 if (result
!= null && result
instanceof StructureAware
) {
101 ((StructureAware
<TreeSPath
>) result
).notifyCurrentPath(
102 getRegistry(), getTreeSPath());
105 ((ExecutableTestRun
) testRun
).execute();
109 * The bean name of the test run to use. If not set the default is used.
113 public void setTestRun(String testRunBean
) {
114 this.testRunBean
= testRunBean
;
117 /** Creates sub tag. */
118 public SpringArg
<TestDefinition
> createTestDefinition() {
119 testDefinitionArg
= new SpringArg
<TestDefinition
>();
120 // only test definitions can add to path
121 addSAwareArg(testDefinitionArg
);
122 return testDefinitionArg
;
125 /** Creates sub tag. */
126 public SpringArg
<TestData
> createTestData() {
127 testDataArg
= new SpringArg
<TestData
>();
131 /** Creates sub tag. */
132 public SpringArg
<DeployedSystem
> createDeployedSystem() {
133 deployedSystemArg
= new SpringArg
<DeployedSystem
>();
134 return deployedSystemArg
;
137 /** Creates sub tag. */
138 public SpringArg
<TestResult
> createTestResult() {
139 testResultArg
= new SpringArg
<TestResult
>();
140 return testResultArg
;
143 protected <T
> T
loadSingleFromContext(Class
<T
> clss
) {
144 return SpringUtils
.loadSingleFromContext(getContext(), clss
);