]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc/src/main/java/org/argeo/slc/ant/test/SlcTestTask.java
1d9132003faec620c03ff87988cef98da3257062
[gpl/argeo-slc.git] / org.argeo.slc / 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 public TestDefinitionArg createTestDefinition() {
82 testDefinitionArg = new TestDefinitionArg();
83 // only test definitions can add to path
84 addSAwareArg(testDefinitionArg);
85 return testDefinitionArg;
86 }
87
88 public TestDataArg createTestData() {
89 testDataArg = new TestDataArg();
90 return testDataArg;
91 }
92
93 public DeployedSystemArg createDeployedSystem() {
94 deployedSystemArg = new DeployedSystemArg();
95 return deployedSystemArg;
96 }
97
98 public TestResultArg createTestResult() {
99 testResultArg = new TestResultArg();
100 return testResultArg;
101 }
102
103 }
104
105 class TestDefinitionArg extends AbstractSpringArg {
106 public TestDefinition getTestDefinition() {
107 return (TestDefinition) getBeanInstance();
108 }
109 }
110
111 class TestDataArg extends AbstractSpringArg {
112 public TestData getTestData() {
113 return (TestData) getBeanInstance();
114 }
115
116 }
117
118 class DeployedSystemArg extends AbstractSpringArg {
119 public DeployedSystem getDeployedSystem() {
120 return (DeployedSystem) getBeanInstance();
121 }
122
123 }
124
125 class TestResultArg extends AbstractSpringArg {
126 public TestResult getTestResult() {
127 return (TestResult) getBeanInstance();
128 }
129
130 }