KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > tests > xml > JXTest


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.tests.xml;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.PrintWriter JavaDoc;
25 import java.io.StringWriter JavaDoc;
26 import org.netbeans.jellytools.Bundle;
27 import org.netbeans.jellytools.ExplorerOperator;
28 import org.netbeans.jellytools.nodes.Node;
29 import org.netbeans.jemmy.JemmyProperties;
30 import org.netbeans.jemmy.operators.JTreeOperator;
31 import org.netbeans.jemmy.operators.Operator;
32 import org.netbeans.jemmy.util.Dumper;
33 import org.netbeans.jemmy.util.PNGEncoder;
34
35
36 /**
37  * Provides the basic support for XML Jemmy tests.
38  * @author ms113234
39  */

40 public class JXTest extends XTest {
41     public static final String JavaDoc DELIM = "|";
42     protected static boolean captureScreen = true;
43     protected static boolean dumpScreen = true;
44     
45     
46     /** Creates a new instance of JXMLXtest */
47     public JXTest(String JavaDoc name) {
48         super(name);
49         boolean dbgTimeouts = Boolean.getBoolean(System.getProperty("xmltest.dbgTimeouts", "true"));
50         try {
51             if (dbgTimeouts) {
52                 JemmyProperties.getCurrentTimeouts().loadDebugTimeouts();
53             }
54         } catch (IOException JavaDoc ioe) {
55             log("Load Debug Timeouts fail.", ioe);
56         }
57     }
58
59     protected void fail(String JavaDoc msg, Exception JavaDoc e) {
60         StringWriter JavaDoc sw = new StringWriter JavaDoc();
61         PrintWriter JavaDoc pw = new PrintWriter JavaDoc(sw);
62         e.printStackTrace(pw);
63         if (captureScreen) {
64             try {
65                 PNGEncoder.captureScreen(getWorkDirPath()+File.separator+"screen.png");
66             } catch (Exception JavaDoc e1) {}
67         }
68         if (dumpScreen) {
69             try {
70                 Dumper.dumpAll(getWorkDirPath()+File.separator+"screen.xml");
71             } catch (Exception JavaDoc e2) {}
72         }
73         fail(msg + "\n" + sw);
74     }
75     
76     /**
77      * Finds Node in the 'data' forlder.
78      * @param path relative to the 'data' folder delimited by 'DELIM'
79      */

80     protected Node findDataNode(String JavaDoc path) {
81         Node node = null;
82         try {
83             String JavaDoc treePath = getFilesystemName() + DELIM + getDataPackageName(DELIM) + DELIM + path;
84             JTreeOperator tree = ExplorerOperator.invoke().repositoryTab().tree();
85             tree.setComparator(new Operator.DefaultStringComparator(true, true));
86             node = new Node(tree, treePath);
87         } catch (Exception JavaDoc ex) {
88             log("Cannot find data node: " + path, ex);
89         }
90         return node;
91     }
92     
93     /**
94      * Finds Catalog's node.
95      * @param path relative to the 'XML Entity Catalogs' root delimited by 'DELIM'
96      */

97 // protected Node findCatalogNode(String path) {
98
// Node node = null;
99
// try {
100
// String treePath = Bundle.getStringTrimmed("org.netbeans.modules.xml.catalog.Bundle", "TEXT_catalog_root");
101
// if (path != null && path.length() > 0) treePath += DELIM + path;
102
// JTreeOperator tree = ExplorerOperator.invoke().runtimeTab().tree();
103
// node = new Node(tree, treePath);
104
// } catch (Exception ex) {
105
// log("Cannot find catalog node: " + path, ex);
106
// }
107
// return node;
108
// }
109

110 // /**
111
// * Returns work directory subnode or null
112
// */
113
// protected FolderNode getWorkDirNode(String name) throws IOException {
114
// final String FILESYSTEMS = JelloBundle.getString("org.netbeans.core.Bundle", "dataSystemName");
115
// String path = FILESYSTEMS + ", " + getWorkDirPath() + ", " + name;
116
//
117
// Explorer explorer = new Explorer();
118
// explorer.switchToFilesystemsTab();
119
// //TreePath treePath = explorer.getJTreeOperator().findPath(path, ", ");
120
// //explorer.getJTreeOperator().expandPath(treePath);
121
//
122
// return FolderNode.findFolder(FILESYSTEMS + ", " + getWorkDirPath() + ", " + name);
123
// }
124
}
125
Popular Tags