KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > tests > xml > XTest


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 package org.netbeans.tests.xml;
20
21 import java.io.PrintStream JavaDoc;
22 import java.io.PrintWriter JavaDoc;
23 import org.netbeans.jellytools.JellyTestCase;
24 import org.openide.filesystems.FileStateInvalidException;
25 import org.openide.loaders.DataObject;
26 import org.openide.util.Utilities;
27 import org.openide.util.io.NullOutputStream;
28
29 /**
30  * Provides the basic support for XML API tests.
31  * @author mschovanek
32  */

33 public abstract class XTest extends JellyTestCase {
34     public final String JavaDoc CATALOG_BUNDLE = "org.netbeans.modules.xml.catalog.resources.Bundle";
35     public final String JavaDoc CORE_BUNDLE = "org.netbeans.modules.xml.core.resources.Bundle";
36     public final String JavaDoc CSS_BUNDLE = "org.netbeans.modules.css.resources.Bundle";
37     public final String JavaDoc TAX_BUNDLE = "org.netbeans.tax.resources.Bundle";
38     public final String JavaDoc TEXT_BUNDLE = "org.netbeans.modules.xml.text.resources.Bundle";
39     public final String JavaDoc TOOLS_BUNDLE = "org.netbeans.modules.xml.tools.resources.Bundle";
40     public final String JavaDoc TREE_BUNDLE = "org.netbeans.modules.xml.tree.resources.Bundle";
41     
42     protected String JavaDoc packageName;
43     protected String JavaDoc absolutePath;
44     protected String JavaDoc fsName;
45     
46     /** debug test output */
47     protected PrintWriter JavaDoc dbg = new PrintWriter JavaDoc(new NullOutputStream());
48     
49     /** debug switch */
50     protected static boolean DEBUG = false;
51     private static boolean LOG_INTO_CONSOLE = false;
52     
53     public XTest(String JavaDoc testName) {
54         super(testName);
55     }
56     
57     
58     protected void deleteData(String JavaDoc path) {
59         try {
60         DataObject dao = TestUtil.THIS.findData(path);
61         if (dao != null) dao.delete();
62         } catch (Exception JavaDoc ex) {}
63     }
64
65     /** @depricated use getPackegeName() */
66     protected String JavaDoc packageName() {
67         return getPackageName();
68     }
69
70     /** Returns test's package name. */
71     protected String JavaDoc getPackageName() {
72         if (packageName == null) {
73             packageName = this.getClass().getPackage().getName();
74         }
75         return packageName;
76     }
77
78     /** Returns test's package name delimited by 'separator'. */
79     protected String JavaDoc getPackageName(String JavaDoc separator) {
80         String JavaDoc name = getPackageName();
81         name = org.openide.util.Utilities.replaceString(name, ".", separator);
82         return name;
83     }
84
85     /** Returns data package name delimited by 'separator'. */
86     protected String JavaDoc getDataPackageName(String JavaDoc separator) {
87         String JavaDoc name = getPackageName(separator);
88         name += separator + "data";
89         return name;
90     }
91
92     /** Returns absolute test folder path. **/
93     protected String JavaDoc getAbsolutePath() {
94         if (absolutePath == null) {
95             String JavaDoc url = this.getClass().getResource("").toExternalForm();
96             absolutePath = TestUtil.toAbsolutePath(TestUtil.findFileObject(url));
97         }
98         return absolutePath;
99     }
100
101     /** Returns test's filesystem display name */
102     protected String JavaDoc getFilesystemName() throws FileStateInvalidException {
103         if (fsName == null) {
104             fsName = TestUtil.findFileObject(packageName(), Utilities.getShortClassName(this.getClass()), "class").getFileSystem().getDisplayName();
105         }
106         return fsName;
107     }
108     
109     /** Returns default log. @see super#getLog() , @see #logIntoConsole(boolean) */
110     public PrintStream JavaDoc getLog() {
111         if (LOG_INTO_CONSOLE) {
112             return System.out;
113         } else {
114             return super.getLog();
115         }
116     }
117     
118     /** Simple and easy to use method for printing a message to a default log
119      * @param message meesage to log
120      */

121     public void log(String JavaDoc message) {
122         getLog().println(message);
123     }
124     
125     /** Simple and easy to use method for printing a message to a default log
126      * @param message meesage to log
127      */

128     public void log(String JavaDoc message, Exception JavaDoc ex) {
129         getLog().println(message);
130         ex.printStackTrace(getLog());
131     }
132     
133     /** Redirects log into console. @see #getLog() */
134     public static void logIntoConsole(boolean console) {
135         LOG_INTO_CONSOLE = console;
136     }
137     
138     /** Causes the test to sleep for the specified nmuber of milliseconds.
139      * Does not throw any exception.
140      */

141     protected static void sleepTest(long millis) {
142         try {
143             Thread.currentThread().sleep(millis);
144         } catch (Exception JavaDoc e) { /* do nothig */}
145     }
146 }
Popular Tags