KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.PrintWriter JavaDoc;
25 import java.net.URL JavaDoc;
26 import javax.swing.text.StyledDocument JavaDoc;
27 import org.netbeans.jellytools.EditorWindowOperator;
28 import org.netbeans.jellytools.JellyTestCase;
29 import org.netbeans.jemmy.util.PNGEncoder;
30 //import org.netbeans.modules.java.settings.JavaSynchronizationSettings;
31
import org.openide.cookies.EditorCookie;
32 import org.openide.cookies.SaveCookie;
33 import org.openide.filesystems.Repository;
34 import org.openide.loaders.DataObject;
35 import org.openide.util.SharedClassObject;
36
37
38 /** Runner
39  * @author Jan Becicka
40  */

41 public abstract class XGUIRunner extends JellyTestCase implements Go {
42     
43     protected String JavaDoc name;
44     
45     protected String JavaDoc packageName;
46     
47     public XGUIRunner(java.lang.String JavaDoc testName) {
48         super(testName);
49     }
50     
51     public void waitEditorOpened() {
52         new EditorWindowOperator().getEditor(name);
53     }
54
55     public void testRun() {
56         DataObject DO = null;
57         //JavaSynchronizationSettings ss = (JavaSynchronizationSettings) SharedClassObject.findObject(JavaSynchronizationSettings.class);
58
//ss.setEnabled(false);
59
String JavaDoc fullName = packageName + "." + name;
60         
61         boolean ok = true;
62         
63         try {
64             ok = go(fullName, new PrintWriter JavaDoc(getLog()));
65             if (!ok) {
66                 getLog().println("go() failed");
67             }
68             
69             DO = DataObject.find(Repository.getDefault().findResource(fullName.replace('.','/') + ".java"));
70             ((SaveCookie) DO.getCookie(SaveCookie.class)).save();
71         } catch (Exception JavaDoc e) {
72             ok = false;
73             e.printStackTrace(getLog());
74         }
75
76         ok = writeResult(DO);
77         try {
78             DO.delete();
79         } catch (IOException JavaDoc e){
80             assertTrue(e.toString(), false);
81         }
82
83         assertTrue("See .log file for details", ok);
84     compareReferenceFiles();
85     }
86     
87      public File JavaDoc getGoldenFile(String JavaDoc filename) {
88         String JavaDoc fullClassName = this.getClass().getName();
89         String JavaDoc className = fullClassName;
90         int lastDot = fullClassName.lastIndexOf('.');
91         if (lastDot != -1) {
92             className = fullClassName.substring(lastDot+1);
93         }
94         String JavaDoc goldenFileName = className+".pass";
95         URL JavaDoc url = this.getClass().getResource(goldenFileName);
96         assertNotNull("Golden file "+goldenFileName+" cannot be found",url);
97         String JavaDoc resString = convertNBFSURL(url);
98         File JavaDoc goldenFile = new File JavaDoc(resString);
99         return goldenFile;
100     }
101
102     protected boolean writeResult(DataObject DO) {
103         String JavaDoc result = "";
104         try {
105             EditorCookie ec=(EditorCookie)(DO.getCookie(EditorCookie.class));
106             StyledDocument JavaDoc doc=ec.openDocument();
107             result=doc.getText(0, doc.getLength());
108             result=Common.unify(result);
109         } catch (Exception JavaDoc e){
110             e.printStackTrace(getLog());
111             return false;
112         }
113         
114         getRef().print(result);
115         return true;
116     }
117     
118 }
119
Popular Tags