File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\tasks\junit\ClassResult.java.html

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Daniel Dyer, id:cactusman, Tom Huybrechts, Yahoo!, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 package hudson.tasks.junit;
25
26 import hudson.model.AbstractBuild;
27 import hudson.tasks.test.TabulatedResult;
28 import hudson.tasks.test.TestResult;
29 import hudson.tasks.test.TestObject;
30 import org.kohsuke.stapler.StaplerRequest;
31 import org.kohsuke.stapler.StaplerResponse;
32 import org.kohsuke.stapler.export.Exported;
33
34 import java.util.ArrayList;
35 import java.util.Collections;
36 import java.util.List;
37
38 /**
39 * Cumulative test result of a test class.
40 *
41 * @author Kohsuke Kawaguchi
42 */
43 public final class ClassResult extends TabulatedResult implements Comparable<ClassResult> {
44 private final String className; // simple name
45 private transient String safeName;
46
47 private final List<CaseResult> cases = new ArrayList<CaseResult>();
48
49 private int passCount,failCount,skipCount;
50
51 private float duration;
52
53 private final PackageResult parent;
54
55 ClassResult(PackageResult parent, String className) {
56 this.parent = parent;
57 this.className = className;
58 }
59
60 @Override
61 public AbstractBuild<?, ?> getOwner() {
62 return (parent==null ? null: parent.getOwner());
63 }
64
65 public PackageResult getParent() {
66 return parent;
67 }
68
69 @Override
70 public ClassResult getPreviousResult() {
71 if(parent==null) return null;
72 TestResult pr = parent.getPreviousResult();
73 if(pr==null) return null;
74 if(pr instanceof PackageResult) {
75 return ((PackageResult)pr).getClassResult(getName());
76 }
77 return null;
78 }
79
80 @Override
81 public hudson.tasks.test.TestResult findCorrespondingResult(String id) {
82 String myID = safe(getName());
83 int base = id.indexOf(myID);
84 String caseName;
85 if (base > 0) {
86 int caseNameStart = base + myID.length() + 1;
87 caseName = id.substring(caseNameStart);
88 } else {
89 caseName = id;
90 }
91
92 CaseResult child = getCaseResult(caseName);
93 if (child != null) {
94 return child;
95 }
96
97 return null;
98 }
99
100 public String getTitle() {
101 return Messages.ClassResult_getTitle(getName());
102 }
103
104 @Override
105 public String getChildTitle() {
106 return "Class Reults";
107 }
108
109 @Exported(visibility=999)
110 public String getName() {
111 int idx = className.lastIndexOf('.');
112 if(idx<0) return className;
113 else return className.substring(idx+1);
114 }
115
116 public @Override synchronized String getSafeName() {
117 if (safeName != null) {
118 return safeName;
119 }
120 return safeName = uniquifyName(parent.getChildren(), safe(getName()));
121 }
122
123 public CaseResult getCaseResult(String name) {
124 for (CaseResult c : cases) {
125 if(c.getSafeName().equals(name))
126 return c;
127 }
128 return null;
129 }
130
131 @Override
132 public Object getDynamic(String name, StaplerRequest req, StaplerResponse rsp) {
133 CaseResult c = getCaseResult(name);
134 if (c != null) {
135 return c;
136 } else {
137 return super.getDynamic(name, req, rsp);
138 }
139 }
140
141
142 @Exported(name="child")
143 public List<CaseResult> getChildren() {
144 return cases;
145 }
146
147 public boolean hasChildren() {
148 return ((cases != null) && (cases.size() > 0));
149 }
150
151 // TODO: wait for stapler 1.60 @Exported
152 public float getDuration() {
153 return duration;
154 }
155
156 @Exported
157 public int getPassCount() {
158 return passCount;
159 }
160
161 @Exported
162 public int getFailCount() {
163 return failCount;
164 }
165
166 @Exported
167 public int getSkipCount() {
168 return skipCount;
169 }
170
171 public void add(CaseResult r) {
172 cases.add(r);
173 }
174
175 /**
176 * Recount my children.
177 */
178 @Override
179 public void tally() {
180 passCount=failCount=skipCount=0;
181 duration=0;
182 for (CaseResult r : cases) {
183 r.setClass(this);
184 if (r.isSkipped()) {
185 skipCount++;
186 }
187 else if(r.isPassed()) {
188 passCount++;
189 }
190 else {
191 failCount++;
192 }
193 duration += r.getDuration();
194 }
195 }
196
197
198 void freeze() {
199 passCount=failCount=skipCount=0;
200 duration=0;
201 for (CaseResult r : cases) {
202 r.setClass(this);
203 if (r.isSkipped()) {
204 skipCount++;
205 }
206 else if(r.isPassed()) {
207 passCount++;
208 }
209 else {
210 failCount++;
211 }
212 duration += r.getDuration();
213 }
214 Collections.sort(cases);
215 }
216
217 public String getClassName() {
218 return className;
219 }
220
221 public int compareTo(ClassResult that) {
222 return this.className.compareTo(that.className);
223 }
224
225 public String getDisplayName() {
226 return getName();
227 }
228
229 public String getFullName() {
230 return getParent().getDisplayName() + "." + className;
231 }
232
233 /**
234 * Gets the relative path to this test case from the given object.
235 */
236 @Override
237 public String getRelativePathFrom(TestObject it) {
238 if(it instanceof CaseResult) {
239 return "..";
240 } else {
241 return super.getRelativePathFrom(it);
242 }
243 }
244 }
245