1 19 package org.netbeans.tests.xml; 20 21 import java.io.PrintStream ; 22 import java.io.PrintWriter ; 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 33 public abstract class XTest extends JellyTestCase { 34 public final String CATALOG_BUNDLE = "org.netbeans.modules.xml.catalog.resources.Bundle"; 35 public final String CORE_BUNDLE = "org.netbeans.modules.xml.core.resources.Bundle"; 36 public final String CSS_BUNDLE = "org.netbeans.modules.css.resources.Bundle"; 37 public final String TAX_BUNDLE = "org.netbeans.tax.resources.Bundle"; 38 public final String TEXT_BUNDLE = "org.netbeans.modules.xml.text.resources.Bundle"; 39 public final String TOOLS_BUNDLE = "org.netbeans.modules.xml.tools.resources.Bundle"; 40 public final String TREE_BUNDLE = "org.netbeans.modules.xml.tree.resources.Bundle"; 41 42 protected String packageName; 43 protected String absolutePath; 44 protected String fsName; 45 46 47 protected PrintWriter dbg = new PrintWriter (new NullOutputStream()); 48 49 50 protected static boolean DEBUG = false; 51 private static boolean LOG_INTO_CONSOLE = false; 52 53 public XTest(String testName) { 54 super(testName); 55 } 56 57 58 protected void deleteData(String path) { 59 try { 60 DataObject dao = TestUtil.THIS.findData(path); 61 if (dao != null) dao.delete(); 62 } catch (Exception ex) {} 63 } 64 65 66 protected String packageName() { 67 return getPackageName(); 68 } 69 70 71 protected String getPackageName() { 72 if (packageName == null) { 73 packageName = this.getClass().getPackage().getName(); 74 } 75 return packageName; 76 } 77 78 79 protected String getPackageName(String separator) { 80 String name = getPackageName(); 81 name = org.openide.util.Utilities.replaceString(name, ".", separator); 82 return name; 83 } 84 85 86 protected String getDataPackageName(String separator) { 87 String name = getPackageName(separator); 88 name += separator + "data"; 89 return name; 90 } 91 92 93 protected String getAbsolutePath() { 94 if (absolutePath == null) { 95 String url = this.getClass().getResource("").toExternalForm(); 96 absolutePath = TestUtil.toAbsolutePath(TestUtil.findFileObject(url)); 97 } 98 return absolutePath; 99 } 100 101 102 protected String 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 110 public PrintStream getLog() { 111 if (LOG_INTO_CONSOLE) { 112 return System.out; 113 } else { 114 return super.getLog(); 115 } 116 } 117 118 121 public void log(String message) { 122 getLog().println(message); 123 } 124 125 128 public void log(String message, Exception ex) { 129 getLog().println(message); 130 ex.printStackTrace(getLog()); 131 } 132 133 134 public static void logIntoConsole(boolean console) { 135 LOG_INTO_CONSOLE = console; 136 } 137 138 141 protected static void sleepTest(long millis) { 142 try { 143 Thread.currentThread().sleep(millis); 144 } catch (Exception e) { } 145 } 146 } | Popular Tags |