KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > java > XRunner


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
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 //import org.netbeans.modules.java.settings.JavaSynchronizationSettings;
29

30 /** Runner
31  * @author Jan Becicka
32  */

33 public abstract class XRunner extends LogTestCase implements Go {
34     
35     protected String JavaDoc packageName;
36     protected String JavaDoc name;
37     
38     /** golden file
39      */

40     /*protected File passFile;
41      
42     private String result="";*/

43     
44     private static boolean disabled = false;
45     
46     public XRunner(java.lang.String JavaDoc testName) {
47         super(testName);
48     }
49     
50     /** "main" of the TestCase
51      */

52     public void testRun() throws DataObjectNotFoundException {
53         boolean ok = true;
54         
55         String JavaDoc result="";
56         
57         FileObject artefact=null;
58         try {
59             artefact=FileUtil.toFileObject(classPathWorkDir);
60         } catch (Exception JavaDoc 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 JavaDoc e) {
70                 e.printStackTrace(log);
71                 assertTrue(e.toString(), false);
72             }
73         }
74         //clazz.getSource().prepare().waitFinished();
75
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 JavaDoc 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 JavaDoc 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 // JavaSynchronizationSettings jss = (JavaSynchronizationSettings) JavaSynchronizationSettings.findObject(JavaSynchronizationSettings.class, true);
101
//jss.setEnabled(false);
102

103 /* try {
104                 org.netbeans.test.oo.gui.jello.JelloOKOnlyDialog ok = new org.netbeans.test.oo.gui.jello.JelloOKOnlyDialog("Warning");
105                 ok.ok();
106             } catch (Exception texc) {
107                 // it's OK no error
108                 // texc.printStackTrace();
109             }
110  */

111         }
112     }
113     
114     protected boolean writeResult(DataObject DO) {
115         String JavaDoc result="";
116         try {
117             EditorCookie ec=(EditorCookie)(DO.getCookie(EditorCookie.class));
118             javax.swing.text.StyledDocument JavaDoc doc=ec.openDocument();
119             result=doc.getText(0, doc.getLength());
120             result=Common.unify(result);
121         } catch (Exception JavaDoc e){
122             e.printStackTrace(log);
123             return false;
124         }
125         ref(result);
126         return true;
127     }
128 }
129
Popular Tags