001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package gui.propertyeditors.utilities;
043:
044: import java.io.PrintStream;
045: import java.io.IOException;
046: import java.awt.Component;
047: import javax.swing.JDialog;
048: import org.netbeans.jellytools.JellyTestCase;
049:
050: import org.netbeans.jemmy.ComponentSearcher;
051: import org.netbeans.jemmy.JemmyException;
052: import org.netbeans.jemmy.operators.JDialogOperator;
053:
054: import org.netbeans.junit.NbTestCase;
055:
056: // ide imports
057: import org.openide.filesystems.FileObject;
058: import org.openide.filesystems.FileStateInvalidException;
059: import org.openide.filesystems.Repository;
060:
061: /** Utilities for core tests. From this class extends supports for each testsuite.
062: *
063: * @author Marian.Mirilovic@Sun.Com
064: * @version
065: */
066:
067: public class CoreSupport {
068:
069: /** Creates new utilities */
070: public CoreSupport() {
071: }
072:
073: /**
074: * Find path to the Sample Project.
075: *
076: * @return path to the Sample Project
077: * @param testCase
078: */
079: public static String getSampleProjectPath(JellyTestCase testCase) {
080: return new java.io.File(testCase.getDataDir(), "SampleProject")
081: .getPath();
082: }
083:
084: /**
085: * Find file system name.
086: *
087: * @param exc
088: * @param err
089: */
090: /* public static String getFS(String _package, String fileName, String fileExtension){
091: FileObject f = findFileObject(_package, fileName, fileExtension);
092:
093: if(f==null)
094: throw new JemmyException("Unable find file " + fileName + "." + fileExtension + " in package " + _package);
095:
096: String fs;
097: try{
098: fs = f.getFileSystem().getSystemName();
099: }catch(FileStateInvalidException exc){
100: throw new JemmyException("FileStateInvalidException during attempt get filesystem name for " + fileName + "." + fileExtension + " in package " + _package);
101: }
102:
103: // hack for Win NT/2K , where in FileObject is bad file separator !!!
104: char fileSeparator = System.getProperty("file.separator").charAt(0);
105: String fsName = fs.replace('/',fileSeparator).replace('\\',fileSeparator);
106: //String path = fsName+ ", " + _package + ", " + fileName;
107:
108: return fsName;
109: }
110:
111:
112: public static String getPath(String packageName, String fileName, String fileExtension, String delim){
113: String FS_Name = getFS(packageName, fileName, fileExtension);
114: return FS_Name + delim + packageName.replace('.',delim.charAt(0)) + delim + fileName;
115: }
116:
117: public static String getSystemPath(String packageName, String fileName, String fileExtension){
118: String fileSeparator = System.getProperty("file.separator");
119: return getPath(packageName, fileName, fileExtension, fileSeparator)+ "." + fileExtension;
120: }
121: */
122: public static void writeExc(Exception exc, PrintStream err) {
123: err.println("Test ERROR: ");
124: exc.printStackTrace(err);
125: }
126:
127: /**
128: *
129: * @param testCase
130: */
131: public static void makeIDEScreenshot(NbTestCase testCase) {
132: try {
133: testCase.getWorkDir();
134: org.netbeans.jemmy.util.PNGEncoder.captureScreen(testCase
135: .getWorkDirPath()
136: + System.getProperty("file.separator")
137: + "IDEscreenshot.png");
138: } catch (Exception ioexc) {
139: testCase.log("Impossible make IDE screenshot!!! \n"
140: + ioexc.toString());
141: }
142: }
143:
144: /**
145: *
146: * @param testCase
147: * @param component
148: */
149: public static void makeWindowScreenshot(NbTestCase testCase,
150: Component component) {
151: try {
152: testCase.getWorkDir();
153: if (component != null)
154: org.netbeans.jemmy.util.PNGEncoder.captureScreen(
155: component, testCase.getWorkDirPath()
156: + System.getProperty("file.separator")
157: + "ComponentScreenshot.png");
158: else
159: makeIDEScreenshot(testCase);
160: } catch (Exception ioexc) {
161: testCase
162: .log("Impossible make component screenshot!!! \n ========="
163: + component.toString()
164: + "\n ======== \n "
165: + ioexc.toString());
166: }
167: }
168:
169: public static void closeAllModal() {
170: JDialogOperator oper = null;
171: // find some JDialog
172: JDialog jDialog = JDialogOperator.findJDialog(ComponentSearcher
173: .getTrueChooser(""));
174: // number of opened non-modal
175: int nonModal = 0;
176: // until any modal dialog is opened
177: while (jDialog != null) {
178: oper = new JDialogOperator(jDialog);
179: if (oper.isModal()) {
180: // close if modal
181: oper.close();
182: } else {
183: // increment nonModal
184: nonModal++;
185: }
186: // use nonModal variable as index to skip opened non-modal dialogs
187: jDialog = JDialogOperator.findJDialog(ComponentSearcher
188: .getTrueChooser(""), nonModal);
189: }
190: }
191:
192: }
|