KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > Result


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.tools.verifier;
25
26 import java.util.Vector JavaDoc;
27 import java.util.logging.Level JavaDoc;
28 import java.util.logging.Logger JavaDoc;
29
30 import com.sun.enterprise.logging.LogDomains;
31
32 public class Result {
33
34     public static final int PASSED = 0;
35     public static final int FAILED = 1;
36     public static final int WARNING = 2;
37     public static final int NOT_APPLICABLE = 3;
38     public static final int NOT_RUN = 4;
39     public static final int NOT_IMPLEMENTED = 5;
40     private int status = NOT_RUN;
41
42     public static final String JavaDoc APP = "application"; // NOI18N
43
public static final String JavaDoc EJB = "ejb"; // NOI18N
44
public static final String JavaDoc WEB = "web"; // NOI18N
45
public static final String JavaDoc APPCLIENT = "appclient"; // NOI18N
46
public static final String JavaDoc CONNECTOR = "connector"; // NOI18N
47
public static final String JavaDoc WEBSERVICE = "webservice"; // NOI18N
48
public static final String JavaDoc WEBSERVICE_CLIENT = "webservice_client"; // NOI18N
49

50     private String JavaDoc moduleName;
51
52     private String JavaDoc componentName;
53     private String JavaDoc assertion;
54     private String JavaDoc testName;
55     private Vector JavaDoc<String JavaDoc> errorDetails = new Vector JavaDoc<String JavaDoc>();
56     private Vector JavaDoc<String JavaDoc> goodDetails = new Vector JavaDoc<String JavaDoc>();
57     private Vector JavaDoc<String JavaDoc> warningDetails = new Vector JavaDoc<String JavaDoc>();
58     private Vector JavaDoc<String JavaDoc> naDetails = new Vector JavaDoc<String JavaDoc>();
59     boolean debug = Verifier.isDebug();
60
61     private Logger JavaDoc logger = LogDomains.getLogger(
62             LogDomains.AVK_VERIFIER_LOGGER);
63
64     /**
65      * Result Constructor
66      */

67     public Result() {
68     }
69
70
71     /**
72      * Initialize the Result object
73      *
74      * @param c Class of the current test/assertion
75      * @param compName
76      */

77     public void init(Class JavaDoc c, String JavaDoc version, String JavaDoc compName) {
78         setComponentName(compName);
79         StringBuffer JavaDoc assertion = new StringBuffer JavaDoc(
80                 StringManagerHelper.getLocalStringsManager().getLocalString(
81                         (c.getName() + ".assertion"), "")); // NOI18N
82
String JavaDoc key = ".specMappingInfo_"+version; // NOI18N
83
StringBuffer JavaDoc specMappingInfo = new StringBuffer JavaDoc(
84                 StringManagerHelper.getLocalStringsManager().getLocalString(
85                         (c.getName() + key), ""));
86         // if specMappingInfo_<version> is unavailable then try just specMappingInfo
87
if(specMappingInfo == null || specMappingInfo.length() == 0) {
88             key = c.getName() + ".specMappingInfo";
89             specMappingInfo = new StringBuffer JavaDoc(StringManagerHelper.getLocalStringsManager().getLocalString(key, ""));
90         }
91         String JavaDoc prefix = StringManagerHelper.getLocalStringsManager().getLocalString(
92                 (getClass().getName() + ".prefix"), ""); // NOI18N
93
String JavaDoc suffix = StringManagerHelper.getLocalStringsManager().getLocalString(
94                 (getClass().getName() + ".suffix"), ""); // NOI18N
95

96         if (specMappingInfo.length()!=0 && specMappingInfo!=null)
97             setAssertion(assertion.append(" ").append(prefix+" ").append(specMappingInfo).append(" "+suffix).toString()); // NOI18N
98
else
99             setAssertion(assertion.toString());
100         String JavaDoc this_package = "com.sun.enterprise.tools.verifier."; // NOI18N
101
setTestName(c.getName().substring(this_package.length()));
102     }
103
104     /**
105      * Store passed info
106      *
107      * @param detail Details of passed test
108      */

109     public void passed(String JavaDoc detail) {
110         setStatus(PASSED);
111         addGoodDetails(detail);
112     }
113
114     /**
115      * Store warning info
116      *
117      * @param detail Details of warning test
118      */

119     public void warning(String JavaDoc detail) {
120         setStatus(WARNING);
121         addWarningDetails(detail);
122     }
123
124     /**
125      * Store Not Applicable info
126      *
127      * @param detail Details of not applicable test
128      */

129     public void notApplicable(String JavaDoc detail) {
130         setStatus(NOT_APPLICABLE);
131         addNaDetails(detail);
132     }
133
134     /**
135      * Store Failed info
136      *
137      * @param detail Details of failed test
138      */

139     public void failed(String JavaDoc detail) {
140         setStatus(FAILED);
141         addErrorDetails(detail);
142     }
143
144     /**
145      * Retrieve Not Applicable details
146      *
147      * @return <code>Vector</code> not applicable details
148      */

149     public Vector JavaDoc getNaDetails() {
150         if(naDetails.isEmpty()){
151             Vector JavaDoc<String JavaDoc> result = new Vector JavaDoc<String JavaDoc>();
152             result.add(StringManagerHelper.getLocalStringsManager()
153                     .getLocalString("tests.componentNameConstructor", // NOI18N
154
"For [ {0} ]", // NOI18N
155
new Object JavaDoc[]{getComponentName()}));
156             result.add(StringManagerHelper.getLocalStringsManager()
157                     .getLocalString(getClass().getName() + ".defaultNADetails", //NOI18N
158
"Test is not applicable.")); // NOI18N
159
logger.fine("Returning default NADetails."); // NOI18N
160
return result;
161         }
162         return naDetails;
163     }
164
165     /**
166      * Retrieve Warning details
167      *
168      * @return <code>Vector</code> warning details
169      */

170     public Vector JavaDoc getWarningDetails() {
171         return warningDetails;
172     }
173
174     /**
175      * Retrieve Not Applicable details
176      *
177      * @param s not applicable details
178      */

179     public void addNaDetails(String JavaDoc s) {
180         naDetails.addElement(s);
181         logger.log(Level.FINE, s);
182     }
183
184     /**
185      * Retrieve Good details
186      *
187      * @return <code>Vector</code> good details
188      */

189     public Vector JavaDoc getGoodDetails() {
190         if(goodDetails.isEmpty()){
191             Vector JavaDoc<String JavaDoc> result = new Vector JavaDoc<String JavaDoc>();
192             result.add(StringManagerHelper.getLocalStringsManager()
193                     .getLocalString("tests.componentNameConstructor", // NOI18N
194
"For [ {0} ]", // NOI18N
195
new Object JavaDoc[]{getComponentName()}));
196             result.add(StringManagerHelper.getLocalStringsManager()
197                     .getLocalString(getClass().getName() + ".defaultGoodDetails", //NOI18N
198
"There were no errors reported.")); // NOI18N
199
logger.fine("Returning default GoodDetails."); // NOI18N
200
return result;
201         }
202         return goodDetails;
203     }
204
205     /**
206      * Fill in Good details
207      *
208      * @param s good detail string
209      */

210     public void addGoodDetails(String JavaDoc s) {
211         goodDetails.addElement(s);
212         logger.log(Level.FINE, s);
213     }
214
215     /**
216      * Fill in Warning details
217      *
218      * @param s warning detail string
219      */

220     public void addWarningDetails(String JavaDoc s) {
221         warningDetails.addElement(s);
222         logger.log(Level.FINE, s);
223     }
224
225     /**
226      * Retrieve Error details
227      *
228      * @return <code>Vector</code> error details
229      */

230     public Vector JavaDoc getErrorDetails() {
231         return errorDetails;
232     }
233
234     /**
235      * Fill in Error details
236      *
237      * @param s error detail string
238      */

239     public void addErrorDetails(String JavaDoc s) {
240         errorDetails.addElement(s);
241         logger.log(Level.FINE, s);
242     }
243
244     /**
245      * Retrieve test result status
246      *
247      * @return <code>int</code> test result status
248      */

249     public int getStatus() {
250         return status;
251     }
252
253     /**
254      * Set test result status
255      *
256      * @param s test result status
257      */

258     public void setStatus(int s) {
259         status = s;
260     }
261
262     /**
263      * Retrieve assertion
264      *
265      * @return <code>String</code> assertion string
266      */

267     public String JavaDoc getAssertion() {
268         return assertion;
269     }
270
271     /**
272      * Set assertion
273      *
274      * @param s assertion string
275      */

276     public void setAssertion(String JavaDoc s) {
277         assertion = s;
278     }
279
280     /**
281      * Retrieve component/module name
282      *
283      * @return <code>String</code> component/module name
284      */

285     public String JavaDoc getComponentName() {
286         return componentName;
287     }
288
289     /**
290      * Set component/module name
291      *
292      * @param s component/module name
293      */

294     public void setComponentName(String JavaDoc s) {
295         componentName = s;
296     }
297
298     /**
299      * Retrieve test name
300      *
301      * @return <code>String</code> test name
302      */

303     public String JavaDoc getTestName() {
304         return testName;
305     }
306
307     /**
308      * Set test name
309      *
310      * @param s test name
311      */

312     public void setTestName(String JavaDoc s) {
313         testName = s;
314     }
315
316     public void setModuleName(String JavaDoc name) {
317         moduleName = name;
318     }
319
320     public String JavaDoc getModuleName() {
321         return moduleName;
322     }
323
324 } // Result class
325
Popular Tags