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 org.netbeans.tests.xml;
043:
044: import java.io.File;
045: import java.io.IOException;
046: import java.io.PrintWriter;
047: import java.io.StringWriter;
048: import org.netbeans.jellytools.Bundle;
049: import org.netbeans.jellytools.ExplorerOperator;
050: import org.netbeans.jellytools.nodes.Node;
051: import org.netbeans.jemmy.JemmyProperties;
052: import org.netbeans.jemmy.operators.JTreeOperator;
053: import org.netbeans.jemmy.operators.Operator;
054: import org.netbeans.jemmy.util.Dumper;
055: import org.netbeans.jemmy.util.PNGEncoder;
056:
057: /**
058: * Provides the basic support for XML Jemmy tests.
059: * @author ms113234
060: */
061: public class JXTest extends XTest {
062: public static final String DELIM = "|";
063: protected static boolean captureScreen = true;
064: protected static boolean dumpScreen = true;
065:
066: /** Creates a new instance of JXMLXtest */
067: public JXTest(String name) {
068: super (name);
069: boolean dbgTimeouts = Boolean.getBoolean(System.getProperty(
070: "xmltest.dbgTimeouts", "true"));
071: try {
072: if (dbgTimeouts) {
073: JemmyProperties.getCurrentTimeouts()
074: .loadDebugTimeouts();
075: }
076: } catch (IOException ioe) {
077: log("Load Debug Timeouts fail.", ioe);
078: }
079: }
080:
081: protected void fail(String msg, Exception e) {
082: StringWriter sw = new StringWriter();
083: PrintWriter pw = new PrintWriter(sw);
084: e.printStackTrace(pw);
085: if (captureScreen) {
086: try {
087: PNGEncoder.captureScreen(getWorkDirPath()
088: + File.separator + "screen.png");
089: } catch (Exception e1) {
090: }
091: }
092: if (dumpScreen) {
093: try {
094: Dumper.dumpAll(getWorkDirPath() + File.separator
095: + "screen.xml");
096: } catch (Exception e2) {
097: }
098: }
099: fail(msg + "\n" + sw);
100: }
101:
102: /**
103: * Finds Node in the 'data' forlder.
104: * @param path relative to the 'data' folder delimited by 'DELIM'
105: */
106: protected Node findDataNode(String path) {
107: Node node = null;
108: try {
109: String treePath = getFilesystemName() + DELIM
110: + getDataPackageName(DELIM) + DELIM + path;
111: JTreeOperator tree = ExplorerOperator.invoke()
112: .repositoryTab().tree();
113: tree.setComparator(new Operator.DefaultStringComparator(
114: true, true));
115: node = new Node(tree, treePath);
116: } catch (Exception ex) {
117: log("Cannot find data node: " + path, ex);
118: }
119: return node;
120: }
121:
122: /**
123: * Finds Catalog's node.
124: * @param path relative to the 'XML Entity Catalogs' root delimited by 'DELIM'
125: */
126: // protected Node findCatalogNode(String path) {
127: // Node node = null;
128: // try {
129: // String treePath = Bundle.getStringTrimmed("org.netbeans.modules.xml.catalog.Bundle", "TEXT_catalog_root");
130: // if (path != null && path.length() > 0) treePath += DELIM + path;
131: // JTreeOperator tree = ExplorerOperator.invoke().runtimeTab().tree();
132: // node = new Node(tree, treePath);
133: // } catch (Exception ex) {
134: // log("Cannot find catalog node: " + path, ex);
135: // }
136: // return node;
137: // }
138: // /**
139: // * Returns work directory subnode or null
140: // */
141: // protected FolderNode getWorkDirNode(String name) throws IOException {
142: // final String FILESYSTEMS = JelloBundle.getString("org.netbeans.core.Bundle", "dataSystemName");
143: // String path = FILESYSTEMS + ", " + getWorkDirPath() + ", " + name;
144: //
145: // Explorer explorer = new Explorer();
146: // explorer.switchToFilesystemsTab();
147: // //TreePath treePath = explorer.getJTreeOperator().findPath(path, ", ");
148: // //explorer.getJTreeOperator().expandPath(treePath);
149: //
150: // return FolderNode.findFolder(FILESYSTEMS + ", " + getWorkDirPath() + ", " + name);
151: // }
152: }
|