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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Daniel Dyer, Red Hat, Inc., 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.test;
25
26 import hudson.model.AbstractBuild;
27 import hudson.tasks.junit.CaseResult;
28 import hudson.tasks.junit.TestResult;
29 import org.kohsuke.stapler.export.Exported;
30 import org.kohsuke.stapler.export.ExportedBean;
31
32 import java.util.AbstractList;
33 import java.util.ArrayList;
34 import java.util.List;
35
36 /**
37 * {@link AbstractTestResultAction} that aggregates all the test results
38 * from the corresponding {@link AbstractBuild}s.
39 *
40 * <p>
41 * (This has nothing to do with {@link AggregatedTestResultPublisher}, unfortunately)
42 *
43 * @author Kohsuke Kawaguchi
44 */
45 @ExportedBean
46 public abstract class AggregatedTestResultAction extends AbstractTestResultAction {
47 private int failCount,skipCount,totalCount;
48
49 public static final class Child {
50 /**
51 * Name of the module. Could be relative to something.
52 * The interpretation of this is done by
53 * {@link AggregatedTestResultAction#getChildName(AbstractTestResultAction)} and
54 * {@link AggregatedTestResultAction#resolveChild(Child)} and
55 */
56 public final String name;
57 public final int build;
58
59 public Child(String name, int build) {
60 this.name = name;
61 this.build = build;
62 }
63 }
64
65 /**
66 * child builds whose test results are used for aggregation.
67 */
68 public final List<Child> children = new ArrayList<Child>();
69
70 public AggregatedTestResultAction(AbstractBuild owner) {
71 super(owner);
72 }
73
74 protected void update(List<? extends AbstractTestResultAction> children) {
75 failCount = skipCount = totalCount = 0;
76 this.children.clear();
77 for (AbstractTestResultAction tr : children)
78 add(tr);
79 }
80
81 protected void add(AbstractTestResultAction child) {
82 failCount += child.getFailCount();
83 skipCount += child.getSkipCount();
84 totalCount += child.getTotalCount();
85 this.children.add(new Child(getChildName(child),child.owner.number));
86 }
87
88 public int getFailCount() {
89 return failCount;
90 }
91
92 @Override
93 public int getSkipCount() {
94 return skipCount;
95 }
96
97 public int getTotalCount() {
98 return totalCount;
99 }
100
101 public List<ChildReport> getResult() {
102 // I think this is a reasonable default.
103 return getChildReports();
104 }
105
106 @Override
107 public List<CaseResult> getFailedTests() {
108 List<CaseResult> failedTests = new ArrayList<CaseResult>(failCount);
109 for (ChildReport childReport : getChildReports()) {
110 if (childReport.result instanceof TestResult) {
111 failedTests.addAll(((TestResult) childReport.result).getFailedTests());
112 }
113 }
114 return failedTests;
115 }
116
117 /**
118 * Data-binding bean for the remote API.
119 */
120 @ExportedBean(defaultVisibility=2)
121 public static final class ChildReport {
122 @Exported
123 public final AbstractBuild<?,?> child;
124 @Exported
125 public final Object result;
126
127 public ChildReport(AbstractBuild<?, ?> child, AbstractTestResultAction result) {
128 this.child = child;
129 this.result = result!=null ? result.getResult() : null;
130 }
131 }
132
133 /**
134 * Mainly for the remote API. Expose results from children.
135 */
136 @Exported(inline=true)
137 public List<ChildReport> getChildReports() {
138 return new AbstractList<ChildReport>() {
139 public ChildReport get(int index) {
140 return new ChildReport(
141 resolveChild(children.get(index)),
142 getChildReport(children.get(index)));
143 }
144
145 public int size() {
146 return children.size();
147 }
148 };
149 }
150
151 protected abstract String getChildName(AbstractTestResultAction tr);
152 public abstract AbstractBuild<?,?> resolveChild(Child child);
153
154 /**
155 * Uses {@link #resolveChild(Child)} and obtain the
156 * {@link AbstractTestResultAction} object for the given child.
157 */
158 protected AbstractTestResultAction getChildReport(Child child) {
159 AbstractBuild<?,?> b = resolveChild(child);
160 if(b==null) return null;
161 return b.getAction(AbstractTestResultAction.class);
162 }
163
164 /**
165 * Since there's no TestObject that points this action as the owner
166 * (aggregated {@link TestObject}s point to their respective real owners, not 'this'),
167 * so this method should be never invoked.
168 *
169 * @deprecated
170 * so that IDE warns you if you accidentally try to call it.
171 */
172 @Override
173 protected final String getDescription(TestObject object) {
174 throw new AssertionError();
175 }
176
177 /**
178 * See {@link #getDescription(TestObject)}
179 *
180 * @deprecated
181 * so that IDE warns you if you accidentally try to call it.
182 */
183 @Override
184 protected final void setDescription(TestObject object, String description) {
185 throw new AssertionError();
186 }
187 }
188