]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.core/src/main/java/org/argeo/slc/ant/test/SlcTestTask.java
Introduce context at ant level
[gpl/argeo-slc.git] / org.argeo.slc.core / src / main / java / org / argeo / slc / ant / test / SlcTestTask.java
1 package org.argeo.slc.ant.test;
2
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
5 import org.apache.tools.ant.BuildException;
6
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.test.ExecutableTestRun;
13 import org.argeo.slc.core.test.TestData;
14 import org.argeo.slc.core.test.TestDefinition;
15 import org.argeo.slc.core.test.TestResult;
16 import org.argeo.slc.core.test.WritableTestRun;
17
18 /** Ant task wrapping a test run. */
19 public class SlcTestTask extends SAwareTask {
20 private Log log = LogFactory.getLog(SlcTestTask.class);
21
22 private String testRunBean = null;
23
24 private TestDefinitionArg testDefinitionArg;
25 private TestDataArg testDataArg;
26 private DeployedSystemArg deployedSystemArg;
27 private TestResultArg testResultArg;
28
29 @Override
30 public void executeActions(String mode) throws BuildException {
31 final String testRunBeanT;
32 if (testRunBean != null) {
33 testRunBeanT = testRunBean;
34 } else {
35 testRunBeanT = getProject().getUserProperty(
36 SlcAntConfig.DEFAULT_TEST_RUN_PROPERTY);
37 }
38 WritableTestRun testRun = (WritableTestRun) getContext().getBean(
39 testRunBeanT);
40
41 // set overridden references
42 if (testDataArg != null) {
43 testRun.setTestData(testDataArg.getTestData());
44 log.trace("Overrides test data");
45 }
46
47 if (testDefinitionArg != null) {
48 testRun.setTestDefinition(testDefinitionArg.getTestDefinition());
49 log.trace("Overrides test definition");
50 }
51
52 if (deployedSystemArg != null) {
53 testRun.setDeployedSystem(deployedSystemArg.getDeployedSystem());
54 log.trace("Overrides deployed system");
55 }
56
57 if (testResultArg != null) {
58 testRun.setTestResult(testResultArg.getTestResult());
59 log.trace("Overrides test result");
60 }
61
62 // notify path to test result
63 TestResult result = testRun.getTestResult();
64 if (result != null && result instanceof StructureAware) {
65 ((StructureAware) result).notifyCurrentPath(getRegistry(),
66 getPath());
67 }
68
69 ((ExecutableTestRun) testRun).execute();
70 }
71
72 /**
73 * The bean name of the test run to use. If not set the default is used.
74 *
75 * @see SlcAntConfig
76 */
77 public void setTestRun(String testRunBean) {
78 this.testRunBean = testRunBean;
79 }
80
81 /** Creates sub tag. */
82 public TestDefinitionArg createTestDefinition() {
83 testDefinitionArg = new TestDefinitionArg();
84 // only test definitions can add to path
85 addSAwareArg(testDefinitionArg);
86 return testDefinitionArg;
87 }
88
89 /** Creates sub tag. */
90 public TestDataArg createTestData() {
91 testDataArg = new TestDataArg();
92 return testDataArg;
93 }
94
95 /** Creates sub tag. */
96 public DeployedSystemArg createDeployedSystem() {
97 deployedSystemArg = new DeployedSystemArg();
98 return deployedSystemArg;
99 }
100
101 /** Creates sub tag. */
102 public TestResultArg createTestResult() {
103 testResultArg = new TestResultArg();
104 return testResultArg;
105 }
106
107 }
108
109 class TestDefinitionArg extends AbstractSpringArg {
110 TestDefinition getTestDefinition() {
111 return (TestDefinition) getBeanInstance();
112 }
113 }
114
115 class TestDataArg extends AbstractSpringArg {
116 TestData getTestData() {
117 return (TestData) getBeanInstance();
118 }
119
120 }
121
122 class DeployedSystemArg extends AbstractSpringArg {
123 DeployedSystem getDeployedSystem() {
124 return (DeployedSystem) getBeanInstance();
125 }
126
127 }
128
129 class TestResultArg extends AbstractSpringArg {
130 TestResult getTestResult() {
131 return (TestResult) getBeanInstance();
132 }
133
134 }