KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xsl > action > TransformationActionTest


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.modules.xsl.action;
20
21 import java.awt.event.KeyEvent JavaDoc;
22 import junit.framework.Test;
23 import junit.framework.TestSuite;
24 import junit.textui.TestRunner;
25 import org.netbeans.jellytools.EditorOperator;
26 import org.netbeans.jellytools.EditorWindowOperator;
27 import org.netbeans.jellytools.actions.OpenAction;
28 import org.netbeans.jellytools.modules.xml.XSLTransformationDialog;
29 import org.netbeans.jellytools.modules.xsl.actions.TransformAction;
30 import org.netbeans.jellytools.nodes.Node;
31 import org.netbeans.junit.NbTestSuite;
32 import org.netbeans.tests.xml.JXTest;
33 import org.openide.loaders.DataObject;
34
35 /** Checks XSL Transformation action. */
36
37 public class TransformationActionTest extends JXTest {
38     
39     /** Creates new XMLNodeTest */
40     public TransformationActionTest(String JavaDoc testName) {
41         super(testName);
42     }
43     
44     // TESTS ///////////////////////////////////////////////////////////////////
45

46     /** Performs 'XSL Transformation...' action and checks output. */
47     public void testTransformation() throws Exception JavaDoc {
48         
49         final String JavaDoc OUT_FILE = "../out/document.html";
50         //final String OUT_FILE = "output.html"; //!!!
51
final String JavaDoc OUT_NODE = "out" + DELIM + "document";
52         //final String OUT_NODE = "sources" + DELIM + "output"; //!!!
53

54         // clear output and display Transformation Dialog
55
DataObject dao = TestUtil.THIS.findData("out/document.html");
56         if (dao != null) /* then */ dao.delete();
57         XSLTransformationDialog dialog = transformXML("sources" + DELIM + "document");
58         
59         // fill in the TransformationDialog and execute transformation
60
dialog.cboXSLTScript().clearText();
61         dialog.cboXSLTScript().typeText("../styles/doc2html.xsl");
62         dialog.cboXSLTScript().pressKey(KeyEvent.VK_TAB);
63         
64         dialog.cboOutput().clearText();
65         dialog.cboOutput().typeText(OUT_FILE);
66         dialog.cboJComboBox().selectItem(dialog.ITEM_DONOTHING);
67         dialog.oK();
68         
69         // check the transformation's output
70
char[] cbuf = new char[4000];
71         Node htmlNode = findDataNode(OUT_NODE);
72         new OpenAction().perform(htmlNode);
73         // force editor to reload document
74
EditorWindowOperator ewo = new EditorWindowOperator();
75         EditorOperator eo = ewo.getEditor(htmlNode.getText());
76         eo.setCaretPositionToLine(1);
77         eo.insert("\n");
78         eo.waitModified(true);
79         eo.deleteLine(1);
80         eo.save();
81         
82         String JavaDoc substring = "<h1>Testing Document</h1>";
83         boolean result = eo.getText().indexOf(substring) != -1;
84         assertTrue("Cannot find control substring:\n" + substring, (result));
85         //ewo.close(); //!!! on test machines throws JemmyException: Exception in setClosed
86
}
87     
88     /** Displays XSL Transformation Dialog and vrerifies it */
89     public void testTransformationDialog() throws Exception JavaDoc {
90         // display Transformation Dialog
91
XSLTransformationDialog dialog = transformXML("sources" + DELIM + "document");
92         dialog.verify();
93         dialog.close();
94     }
95     
96     // LIB ////////////////////////////////////////////////////////////////////
97

98     /**
99      * Performs 'XSL Transformation...' action on a XML.
100      * @param path relative to the 'data' folder delimited by 'DELIM'
101      */

102     private XSLTransformationDialog transformXML(String JavaDoc path) throws Exception JavaDoc {
103         TransformAction transform = new TransformAction();
104         transform.perform(findDataNode(path));
105         XSLTransformationDialog dialog = new XSLTransformationDialog();
106         dialog.activate();
107         return dialog;
108     }
109     
110     // MAIN ////////////////////////////////////////////////////////////////////
111

112     public static Test suite() {
113         TestSuite suite = new NbTestSuite();
114         suite.addTest(new TransformationActionTest("testTransformationDialog"));
115         suite.addTest(new TransformationActionTest("testTransformation"));
116         return suite;
117     }
118     
119     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
120         System.setProperty("xmltest.dbgTimeouts", "true");
121         //TestRunner.run(TransformationActionTest.class);
122
TestRunner.run(suite());
123     }
124 }
125
Popular Tags