1 19 20 package org.netbeans.test.java; 21 22 import org.openide.cookies.SaveCookie; 23 import org.openide.cookies.EditorCookie; 24 import org.openide.filesystems.FileObject; 25 import org.openide.filesystems.FileUtil; 26 import org.openide.loaders.*; 27 28 30 33 public abstract class XRunner extends LogTestCase implements Go { 34 35 protected String packageName; 36 protected String name; 37 38 40 43 44 private static boolean disabled = false; 45 46 public XRunner(java.lang.String testName) { 47 super(testName); 48 } 49 50 52 public void testRun() throws DataObjectNotFoundException { 53 boolean ok = true; 54 55 String result=""; 56 57 FileObject artefact=null; 58 try { 59 artefact=FileUtil.toFileObject(classPathWorkDir); 60 } catch (Exception ex) { 61 ex.printStackTrace(log); 62 assertTrue(ex.toString(), false); 63 } 64 FileObject fo = artefact.getFileObject((packageName + "." + name).replace(".","/")); 65 66 if (fo == null) { 67 try { 68 fo = Common.createClass(artefact, packageName, name); 69 } catch (Exception e) { 70 e.printStackTrace(log); 71 assertTrue(e.toString(), false); 72 } 73 } 74 DataObject DO = DataObject.find(fo); 76 try { 77 ok&= go(fo, log ); 78 if (!ok) { 79 System.out.println("go() failed"); 80 } 81 } catch (Exception e) { 82 ok = false; 83 e.printStackTrace(log); 84 } 85 ok&= writeResult(DO); 86 try { 87 if (DO.getCookie(SaveCookie.class) != null) { 88 ((SaveCookie) DO.getCookie(SaveCookie.class)).save(); 89 } 90 DO.delete(); 91 } catch (Exception e){ 92 assertTrue(e.toString(), false); 93 } 94 assertTrue("See .log file for details", ok); 95 } 96 97 private static void disable() { 98 if (!disabled) { 99 disabled = true; 100 103 111 } 112 } 113 114 protected boolean writeResult(DataObject DO) { 115 String result=""; 116 try { 117 EditorCookie ec=(EditorCookie)(DO.getCookie(EditorCookie.class)); 118 javax.swing.text.StyledDocument doc=ec.openDocument(); 119 result=doc.getText(0, doc.getLength()); 120 result=Common.unify(result); 121 } catch (Exception e){ 122 e.printStackTrace(log); 123 return false; 124 } 125 ref(result); 126 return true; 127 } 128 } 129 | Popular Tags |