KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > windows > awt > ValidateLayerJavaHelpTest


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 2002 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.core.windows.awt;
21
22 import java.io.InputStream JavaDoc;
23 import junit.framework.*;
24 import org.netbeans.junit.*;
25 import org.openide.cookies.InstanceCookie;
26
27 import org.openide.filesystems.*;
28 import org.openide.loaders.*;
29
30 /** Checks the consistence of Services/JavaHelp folder.
31  *
32  * @author Stanislav Aubrecht
33  */

34 public class ValidateLayerJavaHelpTest extends NbTestCase {
35
36     /** Creates a new instance of ValidateLayerJavaHelpTest */
37     public ValidateLayerJavaHelpTest( String JavaDoc name ) {
38         super( name );
39     }
40
41     //
42
// override in subclasses
43
//
44

45     protected String JavaDoc rootName () {
46         return "Services/JavaHelp";
47     }
48     
49     /** Allowes to skip filest that are know to be broken */
50     protected boolean skipFile (FileObject fo) {
51         // ignore these files, there are helpers for Helpset ordering
52
return fo.hasExt ("txt");
53     }
54     
55     protected boolean correctInstance (Object JavaDoc obj) {
56         if (obj instanceof javax.help.HelpSet) {
57             return true;
58         }
59         
60         return false;
61     }
62     
63     
64     //
65
// the test
66
//
67

68     public void testContentCorrect () throws Exception JavaDoc {
69         java.util.ArrayList JavaDoc errors = new java.util.ArrayList JavaDoc ();
70         
71         DataFolder df = DataFolder.findFolder( Repository.getDefault().getDefaultFileSystem().findResource( rootName() ) );
72         verifyHelpSets( df, errors );
73         
74         if (!errors.isEmpty()) {
75             fail ("Some files do not provide valid helpsets " + errors);
76         }
77     }
78     
79     private void verifyHelpSets( DataFolder f, java.util.ArrayList JavaDoc errors ) throws Exception JavaDoc {
80         DataObject[] arr = f.getChildren();
81         for (int i = 0; i < arr.length; i++) {
82             if (arr[i] instanceof DataFolder) {
83                 verifyHelpSets( (DataFolder)arr[i], errors );
84                 continue;
85             }
86             FileObject file = arr[i].getPrimaryFile ();
87             
88             if (skipFile (file)) {
89                 continue;
90             }
91             
92             Object JavaDoc url = file.getURL();
93             
94             InstanceCookie ic = (InstanceCookie)arr[i].getCookie(InstanceCookie.class);
95             if (ic == null) {
96                 errors.add ("\n File " + file + " does not have instance cookie, url: " + url);
97                 continue;
98             }
99             
100             try {
101                 Object JavaDoc obj = ic.instanceCreate();
102                 if (correctInstance (obj)) {
103                     continue;
104                 }
105                 errors.add ("\n File " + arr[i].getPrimaryFile () + " does not provide correct instance: " + obj + " url: " + url);
106             } catch (Exception JavaDoc ex) {
107                 errors.add ("\n File " + arr[i].getPrimaryFile () + " cannot be read " + ex + " url: " + url);
108             }
109         }
110     }
111 }
112
113
Popular Tags