KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > junit > output > TestsuiteNode


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.junit.output;
21
22 import org.openide.nodes.AbstractNode;
23 import org.openide.nodes.Children;
24 import org.openide.util.NbBundle;
25
26 /**
27  *
28  * @author Marian Petras
29  */

30 final class TestsuiteNode extends AbstractNode {
31
32     private String JavaDoc suiteName;
33     private Report report;
34     private boolean filtered;
35
36     /**
37      *
38      * @param suiteName name of the test suite, or {@code ANONYMOUS_SUITE}
39      * in the case of anonymous suite
40      * @see ResultDisplayHandler#ANONYMOUS_SUITE
41      */

42     TestsuiteNode(final String JavaDoc suiteName, final boolean filtered) {
43         this(null, suiteName, filtered);
44     }
45     
46     /**
47      * Creates a new instance of TestsuiteNode
48      */

49     TestsuiteNode(final Report report, final boolean filtered) {
50         this(report, null, filtered);
51     }
52     
53     /**
54      *
55      * @param suiteName name of the test suite, or {@code ANONYMOUS_SUITE}
56      * in the case of anonymous suite
57      * @see ResultDisplayHandler#ANONYMOUS_SUITE
58      */

59     private TestsuiteNode(final Report report,
60                           final String JavaDoc suiteName,
61                           final boolean filtered) {
62         super(report != null ? new TestsuiteNodeChildren(report, filtered)
63                              : Children.LEAF);
64         
65         this.report = report;
66         this.suiteName = (report != null) ? report.suiteClassName : suiteName;
67         this.filtered = filtered;
68         
69         assert this.suiteName != null;
70         
71         setDisplayName();
72         setIconBaseWithExtension(
73                 "org/netbeans/modules/junit/output/res/class.gif"); //NOI18N
74
}
75     
76     /**
77      */

78     void displayReport(final Report report) {
79         assert (this.report == null) && (report != null);
80         assert report.suiteClassName.equals(this.suiteName)
81                || (this.suiteName == ResultDisplayHandler.ANONYMOUS_SUITE);
82         
83         this.report = report;
84         suiteName = report.suiteClassName;
85         
86         setDisplayName();
87         setChildren(new TestsuiteNodeChildren(report, filtered));
88     }
89     
90     /**
91      * Returns a report represented by this node.
92      *
93      * @return the report, or <code>null</code> if this node represents
94      * a running test suite (no report available yet)
95      */

96     Report getReport() {
97         return report;
98     }
99     
100     /**
101      */

102     private void setDisplayName() {
103         String JavaDoc displayName;
104         if (report == null) {
105             if (suiteName != ResultDisplayHandler.ANONYMOUS_SUITE) {
106                 displayName = NbBundle.getMessage(
107                                           getClass(),
108                                           "MSG_TestsuiteRunning", //NOI18N
109
suiteName);
110             } else {
111                 displayName = NbBundle.getMessage(
112                                           getClass(),
113                                           "MSG_TestsuiteRunningNoname");//NOI18N
114
}
115         } else {
116             boolean containsFailed = containsFailed();
117             displayName = containsFailed
118                           ? NbBundle.getMessage(
119                                           getClass(),
120                                           "MSG_TestsuiteFailed", //NOI18N
121
suiteName)
122                           : suiteName;
123         }
124         setDisplayName(displayName);
125     }
126     
127     /**
128      */

129     public String JavaDoc getHtmlDisplayName() {
130         
131         assert suiteName != null;
132         
133         StringBuffer JavaDoc buf = new StringBuffer JavaDoc(60);
134         if (suiteName != ResultDisplayHandler.ANONYMOUS_SUITE) {
135             buf.append(suiteName);
136             buf.append("&nbsp;&nbsp;"); //NOI18N
137
} else {
138             buf.append(NbBundle.getMessage(getClass(),
139                                            "MSG_TestsuiteNoname")); //NOI18N
140
buf.append("&nbsp;");
141         }
142         if (report != null) {
143             final boolean containsFailed = containsFailed();
144
145             buf.append("<font color='#"); //NOI18N
146
buf.append(containsFailed ? "FF0000'>" : "00CC00'>"); //NOI18N
147
buf.append(NbBundle.getMessage(
148                                     getClass(),
149                                     containsFailed
150                                     ? "MSG_TestsuiteFailed_HTML" //NOI18N
151
: "MSG_TestsuitePassed_HTML")); //NOI18N
152
buf.append("</font>"); //NOI18N
153
} else {
154             buf.append(NbBundle.getMessage(
155                                     getClass(),
156                                     "MSG_TestsuiteRunning_HTML")); //NOI18N
157
}
158         return buf.toString();
159     }
160     
161     /**
162      */

163     void setFiltered(final boolean filtered) {
164         if (filtered == this.filtered) {
165             return;
166         }
167         this.filtered = filtered;
168         
169         Children children = getChildren();
170         if (children != Children.LEAF) {
171             ((TestsuiteNodeChildren) children).setFiltered(filtered);
172         }
173     }
174     
175     /**
176      */

177     private boolean containsFailed() {
178         return (report != null) && (report.failures + report.errors != 0);
179     }
180     
181 }
182
Popular Tags