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
;
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().getUserProperty(
42 SlcAntConfig
.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 " + testRunBeanT
);
51 } catch (BeansException e
) {
52 // silent, will try defaults
56 if (testRun
== null) {
57 testRun
= loadSingleFromContext(WritableTestRun
.class);
58 if (testRun
== null) {
59 testRun
= new SimpleTestRun();
60 log
.warn("Created default simple test run");
62 if (log
.isTraceEnabled())
63 log
.trace("Load test run from scanning Spring context");
67 // set overridden references
68 if (testDataArg
!= null) {
69 testRun
.setTestData(testDataArg
.getBeanInstance());
70 log
.trace("Overrides test data");
73 if (testDefinitionArg
!= null) {
74 testRun
.setTestDefinition(testDefinitionArg
.getBeanInstance());
75 log
.trace("Overrides test definition");
78 if (deployedSystemArg
!= null) {
79 testRun
.setDeployedSystem(deployedSystemArg
.getBeanInstance());
80 log
.trace("Overrides deployed system");
83 if (testResultArg
!= null) {
84 testRun
.setTestResult(testResultArg
.getBeanInstance());
85 log
.trace("Overrides test result");
88 // notify path to test result
89 TestResult result
= testRun
.getTestResult();
91 result
= loadSingleFromContext(TestResult
.class);
93 result
= new SimpleTestResult();
94 log
.warn("Created default simple test result");
96 if (log
.isTraceEnabled())
97 log
.trace("Load test result from scanning Spring context");
99 testRun
.setTestResult(result
);
102 SlcExecution slcExecution
= getSlcExecution();
103 testRun
.notifySlcExecution(slcExecution
);
105 if (result
!= null && result
instanceof StructureAware
) {
106 ((StructureAware
<TreeSPath
>) result
).notifyCurrentPath(
107 getRegistry(), getTreeSPath());
110 ((ExecutableTestRun
) testRun
).execute();
114 * The bean name of the test run to use. If not set the default is used.
118 public void setTestRun(String testRunBean
) {
119 this.testRunBean
= testRunBean
;
122 /** Creates sub tag. */
123 public SpringArg
<TestDefinition
> createTestDefinition() {
124 testDefinitionArg
= new SpringArg
<TestDefinition
>();
125 // only test definitions can add to path
126 addSAwareArg(testDefinitionArg
);
127 return testDefinitionArg
;
130 /** Creates sub tag. */
131 public SpringArg
<TestData
> createTestData() {
132 testDataArg
= new SpringArg
<TestData
>();
136 /** Creates sub tag. */
137 public SpringArg
<DeployedSystem
> createDeployedSystem() {
138 deployedSystemArg
= new SpringArg
<DeployedSystem
>();
139 return deployedSystemArg
;
142 /** Creates sub tag. */
143 public SpringArg
<TestResult
> createTestResult() {
144 testResultArg
= new SpringArg
<TestResult
>();
145 return testResultArg
;
148 protected <T
> T
loadSingleFromContext(Class
<T
> clss
) {
149 return SpringUtils
.loadSingleFromContext(getContext(), clss
);