KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > jellytools > modules > xml > actions > ActionsTest


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 package org.netbeans.jellytools.modules.xml.actions;
20
21 import junit.textui.TestRunner;
22 import org.netbeans.jellytools.NbDialogOperator;
23 import org.netbeans.jellytools.actions.Action;
24 import org.netbeans.jellytools.modules.css.actions.CheckCSSAction;
25 import org.netbeans.jellytools.modules.css.actions.CopyHTMLStyleAction;
26 import org.netbeans.jellytools.modules.css.actions.CopyXMLStyleAction;
27 import org.netbeans.jellytools.modules.xml.catalog.nodes.XMLEntityCatalogsNode;
28 import org.netbeans.jellytools.nodes.Node;
29 import org.netbeans.jemmy.EventDispatcher;
30 import org.netbeans.tests.xml.JXTest;
31
32 /** Checks XSL Transformation action. */
33
34 public class ActionsTest extends JXTest {
35     private static final int CLASS = 0;
36     private static final int TPATH = 1;
37     private static final int ATTRS = 2;
38     
39     /** Creates new XMLNodeTest */
40     public ActionsTest(String JavaDoc testName) {
41         super(testName);
42     }
43     
44     // TESTS ///////////////////////////////////////////////////////////////////
45

46     public void test() {
47         //documentActionTest(new CheckDTDAction(), "PA", "states");
48
//documentActionTest(new CheckXMLAction(), "PAS", "XMLDocument");
49
////documentActionTest(new EditScenariosAction(), "PASc", "stylesheet"); //!!! #26559
50
//documentActionTest(new GenerateCSSAction(), "PAc", "states");
51
//documentActionTest(new GenerateDOMTreeScannerAction(), "PAc", "states");
52
//documentActionTest(new GenerateDTDAction(), "PAc", "XMLDocument");
53
//documentActionTest(new GenerateDocumentationAction(), "PAc", "states");
54
//documentActionTest(new NewAttributeAction(), "Pc", "XMLDocument" + DELIM + "root");
55
//documentActionTest(new NewCDATAction(), "Pc", "XMLDocument" + DELIM + "root");
56
//documentActionTest(new NewCharRefAction(), "Pc", "XMLDocument" + DELIM + "root");
57
//documentActionTest(new NewCommentAction(), "Pc", "XMLDocument");
58
//documentActionTest(new NewDoctypeAction(), "Pc", "XMLDocument");
59
//documentActionTest(new NewElementAction(), "Pc", "XMLDocument");
60
//documentActionTest(new NewEntityReferenceAction(), "Pc", "XMLwithDTD" + DELIM + "root");
61
//documentActionTest(new NewPIAction(), "Pc", "XMLDocument");
62
//documentActionTest(new NewTextAction(), "Pc", "XMLDocument" + DELIM + "root");
63
//documentActionTest(new NormalizeElementAction(), "P", "XMLDocument" + DELIM + "root");
64
//documentActionTest(new ReloadDocumentAction(), "PA", "XMLDocument");
65
//documentActionTest(new SAXDocumentHandlerWizardAction(), "PAc", "states");
66
//documentActionTest(new TransformAction(), "PASc", "XMLDocument");
67
//documentActionTest(new ValidateXMLAction(), "PA", "XMLDocument");
68

69         //documentActionTest(new CheckCSSAction(), "PA", "CascadeStyleSheet");
70
//documentActionTest(new CopyXMLStyleAction(), "PA", "CascadeStyleSheet");
71
//documentActionTest(new CopyHTMLStyleAction(), "PA", "CascadeStyleSheet");
72

73         //catalogActionTest(new MountCatalogAction(), "PAc", "");
74

75         //!!! should be a stand-alone tests:
76
//!!! a) needs mounted NB Catalog; b) unmount test have to mount unmounted catalog
77

78         //catalogActionTest(new RefreshCatalogAction(), "PA", "NetBeans Catalog");
79
//catalogActionTest(new UnmountCatalogAction(), "PA", "NetBeans Catalog");
80
}
81     
82     // LIB /////////////////////////////////////////////////////////////////////
83

84     /** @see actionTest(Action, String, Node) */
85     private boolean catalogActionTest(Action action, String JavaDoc attrs, String JavaDoc treePath) {
86         return actionTest(action, attrs, XMLEntityCatalogsNode.getInstance().getCatalog(treePath));
87     }
88     
89     /** @see actionTest(Action, String, Node) */
90     private boolean documentActionTest(Action action, String JavaDoc attrs, String JavaDoc treePath) {
91         return actionTest(action, attrs, findDataNode(treePath));
92     }
93     
94     /** Tests org.netbeans.jellytools.actions.Action's subclases.
95      * @param action tested action
96      * @param attrs can consist from
97      * <li> P - test performPopup()
98      * <li> A - test performAPI()
99      * <li> S - test performShortcut()
100      * <li> c - close dialog after each perform method
101      * @param treePath relative path to 'data' folder delimited by DELIM
102      * @return true if test passes esle false
103      */

104     private boolean actionTest(Action action, String JavaDoc attrs, Node node) {
105         boolean pass = true;
106         log("<test class=\"" + action.getClass().getName() + "\">");
107         try {
108             boolean close = (attrs.indexOf('c') != -1);
109             
110             // if (attrs.indexOf('S') != -1) {
111
// log(" <shortcut-test-start\\>");
112
// action.performShortcut(node);
113
// if (close) cancelDialog();
114
// log(" <shortcut-test-finished\\>");
115
// }
116
if (attrs.indexOf('P') != -1) {
117                 log(" <popup-test-start\\>");
118                 action.performPopup(node);
119                 if (close) cancelDialog();
120                 else sleepTest(1000);
121                 log(" <popup-test-finished\\>");
122             }
123             if (attrs.indexOf('A') != -1) {
124                 log(" <API-test-start\\>");
125                 action.performAPI(node);
126                 if (close) cancelDialog();
127                 else sleepTest(1000);
128                 log(" <API-test-finished\\>");
129             }
130         } catch (Exception JavaDoc ex) {
131             pass = false;
132             log("Failed:", ex);
133         } finally {
134             log("<\\test>");
135         }
136         return pass;
137     }
138     
139     /** Waits for 3 secs and close the first dialog. */
140     private void cancelDialog() {
141         try {
142             EventDispatcher.waitQueueEmpty();
143         } catch (Exception JavaDoc e) { /* do nothing */ }
144         sleepTest(1000);
145         
146         new NbDialogOperator("").cancel();
147     }
148     
149     // MAIN ////////////////////////////////////////////////////////////////////
150

151     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
152         System.setProperty("xmltest.dbgTimeouts", "true");
153         logIntoConsole(true);
154         TestRunner.run(ActionsTest.class);
155     }
156 }
157
Popular Tags