]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/SimpleTestRun.java
Improve demo
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / test / SimpleTestRun.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.argeo.slc.core.test;
18
19 import java.util.UUID;
20
21 import org.argeo.slc.core.structure.tree.TreeSPath;
22 import org.argeo.slc.deploy.DeployedSystem;
23 import org.argeo.slc.process.SlcExecution;
24 import org.argeo.slc.process.SlcExecutionRelated;
25 import org.argeo.slc.process.SlcExecutionStep;
26 import org.argeo.slc.structure.StructureAware;
27 import org.argeo.slc.structure.StructureRegistry;
28 import org.argeo.slc.test.ExecutableTestRun;
29 import org.argeo.slc.test.TestData;
30 import org.argeo.slc.test.TestDefinition;
31 import org.argeo.slc.test.TestResult;
32 import org.argeo.slc.test.WritableTestRun;
33
34 /**
35 * A basic bean implementation of a <code>WritableTestRun</code>, holding
36 * references to the various parts of a test run.
37 */
38 @SuppressWarnings("deprecation")
39 public class SimpleTestRun implements WritableTestRun, ExecutableTestRun,
40 SlcExecutionRelated, StructureAware<TreeSPath> {
41 private String uuid;
42
43 private String slcExecutionUuid;
44 private String slcExecutionStepUuid;
45
46 private TreeSPath path;
47 private StructureRegistry<TreeSPath> registry;
48
49 private DeployedSystem deployedSystem;
50 private TestData testData;
51 private TestDefinition testDefinition;
52 private TestResult testResult;
53
54 /** Executes the underlying test definition. */
55 @SuppressWarnings("unchecked")
56 public void run() {
57 uuid = UUID.randomUUID().toString();
58 if (testResult != null)
59 testResult.notifyTestRun(this);
60
61 // Structure
62 if (testResult != null && path != null
63 && testResult instanceof StructureAware)
64 ((StructureAware<TreeSPath>) testResult).notifyCurrentPath(
65 registry, path);
66
67 if (path != null && testDefinition instanceof StructureAware)
68 ((StructureAware<TreeSPath>) testDefinition).notifyCurrentPath(
69 registry, path);
70
71 testDefinition.execute(this);
72 }
73
74 @SuppressWarnings("unchecked")
75 public <T extends DeployedSystem> T getDeployedSystem() {
76 return (T) deployedSystem;
77 }
78
79 public void setDeployedSystem(DeployedSystem deployedSystem) {
80 this.deployedSystem = deployedSystem;
81 }
82
83 @SuppressWarnings("unchecked")
84 public <T extends TestData> T getTestData() {
85 return (T) testData;
86 }
87
88 public void setTestData(TestData testData) {
89 this.testData = testData;
90 }
91
92 @SuppressWarnings("unchecked")
93 public <T extends TestDefinition> T getTestDefinition() {
94 return (T) testDefinition;
95 }
96
97 public void setTestDefinition(TestDefinition testDefinition) {
98 this.testDefinition = testDefinition;
99 }
100
101 @SuppressWarnings("unchecked")
102 public <T extends TestResult> T getTestResult() {
103 return (T) testResult;
104 }
105
106 public void setTestResult(TestResult testResult) {
107 this.testResult = testResult;
108 }
109
110 public String getUuid() {
111 return uuid;
112 }
113
114 public void setUuid(String uuid) {
115 this.uuid = uuid;
116 }
117
118 public String getSlcExecutionUuid() {
119 return slcExecutionUuid;
120 }
121
122 public void setSlcExecutionUuid(String slcExecutionUuid) {
123 this.slcExecutionUuid = slcExecutionUuid;
124 }
125
126 public String getSlcExecutionStepUuid() {
127 return slcExecutionStepUuid;
128 }
129
130 public void setSlcExecutionStepUuid(String slcExecutionStepUuid) {
131 this.slcExecutionStepUuid = slcExecutionStepUuid;
132 }
133
134 @Deprecated
135 public void notifySlcExecution(SlcExecution slcExecution) {
136 if (slcExecution != null) {
137 slcExecutionUuid = slcExecution.getUuid();
138 SlcExecutionStep step = slcExecution.currentStep();
139 if (step != null) {
140 slcExecutionStepUuid = step.getUuid();
141 }
142 }
143 }
144
145 public void notifyCurrentPath(StructureRegistry<TreeSPath> registry,
146 TreeSPath path) {
147 this.registry = registry;
148 this.path = path;
149 }
150
151 }