1 | 0 | |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
package pt.digitalis.dif.sanitycheck.manager; |
7 | |
|
8 | |
import java.lang.reflect.InvocationTargetException; |
9 | |
import java.lang.reflect.Method; |
10 | |
import java.util.ArrayList; |
11 | |
import java.util.Arrays; |
12 | |
import java.util.List; |
13 | |
|
14 | |
import pt.digitalis.dif.sanitycheck.ISanityCheckTestSuite; |
15 | |
import pt.digitalis.dif.sanitycheck.SanityCheckResult; |
16 | |
import pt.digitalis.dif.sanitycheck.annotations.SanityCheckDependency; |
17 | |
import pt.digitalis.dif.sanitycheck.annotations.SanityCheckFinalize; |
18 | |
import pt.digitalis.dif.sanitycheck.annotations.SanityCheckSetup; |
19 | |
import pt.digitalis.dif.sanitycheck.annotations.SanityCheckTest; |
20 | |
import pt.digitalis.dif.sanitycheck.exceptions.WrongTestMethodSignature; |
21 | |
import pt.digitalis.utils.common.StringUtils; |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
public class SanityCheckTestSuiteDefinition { |
30 | |
|
31 | |
|
32 | |
private List<String> dependencies; |
33 | |
|
34 | |
|
35 | |
private SanityCheckResult executionResult; |
36 | |
|
37 | |
|
38 | |
private Method finalizeMethod; |
39 | |
|
40 | |
|
41 | |
private String id; |
42 | |
|
43 | |
|
44 | |
private String name; |
45 | |
|
46 | |
|
47 | |
private Method setupMethod; |
48 | |
|
49 | |
|
50 | |
private List<TestMethodDefinition> testMethods; |
51 | |
|
52 | |
|
53 | |
private ISanityCheckTestSuite testSuiteInstance; |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
public SanityCheckTestSuiteDefinition(String id, ISanityCheckTestSuite testSuiteInstance) |
60 | |
{ |
61 | 0 | super(); |
62 | 0 | this.id = id; |
63 | 0 | this.name = StringUtils.camelCaseToString(testSuiteInstance.getClass().getSimpleName()); |
64 | 0 | this.testSuiteInstance = testSuiteInstance; |
65 | |
|
66 | |
|
67 | 0 | this.dependencies = null; |
68 | |
|
69 | |
|
70 | 0 | this.testMethods = new ArrayList<TestMethodDefinition>(); |
71 | |
|
72 | |
|
73 | 0 | for (Method method: testSuiteInstance.getClass().getMethods()) |
74 | |
{ |
75 | 0 | if (method.isAnnotationPresent(SanityCheckSetup.class)) |
76 | 0 | setupMethod = method; |
77 | |
|
78 | 0 | else if (method.isAnnotationPresent(SanityCheckFinalize.class)) |
79 | 0 | finalizeMethod = method; |
80 | |
|
81 | 0 | else if (method.isAnnotationPresent(SanityCheckTest.class)) |
82 | |
try |
83 | |
{ |
84 | 0 | testMethods.add(new TestMethodDefinition(testSuiteInstance, method)); |
85 | |
} |
86 | 0 | catch (WrongTestMethodSignature e) |
87 | |
{ |
88 | 0 | e.printStackTrace(); |
89 | |
} |
90 | |
} |
91 | 0 | } |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
public List<SanityCheckTestSuiteDefinition> getDependencies() |
97 | |
{ |
98 | 0 | if (dependencies == null) |
99 | |
{ |
100 | |
|
101 | 0 | dependencies = new ArrayList<String>(); |
102 | 0 | SanityCheckDependency dependenciesAnnotation = testSuiteInstance.getClass().getAnnotation( |
103 | 0 | SanityCheckDependency.class); |
104 | |
|
105 | 0 | if (dependenciesAnnotation != null) |
106 | |
{ |
107 | 0 | String[] depencencyList = dependenciesAnnotation.value().split(","); |
108 | 0 | dependencies = Arrays.asList(depencencyList); |
109 | |
} |
110 | |
} |
111 | |
|
112 | 0 | List<SanityCheckTestSuiteDefinition> result = new ArrayList<SanityCheckTestSuiteDefinition>(); |
113 | |
|
114 | 0 | for (String dependencyID: dependencies) |
115 | 0 | result.add(SanityCheckManager.getTestSuites().get(dependencyID)); |
116 | |
|
117 | 0 | return result; |
118 | |
} |
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
public SanityCheckResult getExecutionResult() |
126 | |
{ |
127 | 0 | return executionResult; |
128 | |
} |
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
public Method getFinalizeMethod() |
136 | |
{ |
137 | 0 | return finalizeMethod; |
138 | |
} |
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
public String getId() |
146 | |
{ |
147 | 0 | return id; |
148 | |
} |
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
public String getName() |
156 | |
{ |
157 | 0 | return name; |
158 | |
} |
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
public Method getSetupMethod() |
166 | |
{ |
167 | 0 | return setupMethod; |
168 | |
} |
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
public List<TestMethodDefinition> getTestMethods() |
176 | |
{ |
177 | 0 | return testMethods; |
178 | |
} |
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
public ISanityCheckTestSuite getTestSuiteInstance() |
186 | |
{ |
187 | 0 | return testSuiteInstance; |
188 | |
} |
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
public void runTestsFinalize() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException |
198 | |
{ |
199 | 0 | if (finalizeMethod != null) |
200 | 0 | finalizeMethod.invoke(testSuiteInstance); |
201 | 0 | } |
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
public void runTestsSetup() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException |
211 | |
{ |
212 | 0 | if (setupMethod != null) |
213 | 0 | setupMethod.invoke(testSuiteInstance); |
214 | 0 | } |
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
public void setExecutionResult(SanityCheckResult executionResult) |
223 | |
{ |
224 | 0 | this.executionResult = executionResult; |
225 | 0 | } |
226 | |
} |