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: package org.netbeans.modules.xsl.action;
042:
043: import java.awt.event.KeyEvent;
044: import junit.framework.Test;
045: import junit.framework.TestSuite;
046: import junit.textui.TestRunner;
047: import org.netbeans.jellytools.EditorOperator;
048: import org.netbeans.jellytools.EditorWindowOperator;
049: import org.netbeans.jellytools.actions.OpenAction;
050: import org.netbeans.jellytools.modules.xml.XSLTransformationDialog;
051: import org.netbeans.jellytools.modules.xsl.actions.TransformAction;
052: import org.netbeans.jellytools.nodes.Node;
053: import org.netbeans.junit.NbTestSuite;
054: import org.netbeans.tests.xml.JXTest;
055: import org.openide.loaders.DataObject;
056:
057: /** Checks XSL Transformation action. */
058:
059: public class TransformationActionTest extends JXTest {
060:
061: /** Creates new XMLNodeTest */
062: public TransformationActionTest(String testName) {
063: super (testName);
064: }
065:
066: // TESTS ///////////////////////////////////////////////////////////////////
067:
068: /** Performs 'XSL Transformation...' action and checks output. */
069: public void testTransformation() throws Exception {
070:
071: final String OUT_FILE = "../out/document.html";
072: //final String OUT_FILE = "output.html"; //!!!
073: final String OUT_NODE = "out" + DELIM + "document";
074: //final String OUT_NODE = "sources" + DELIM + "output"; //!!!
075:
076: // clear output and display Transformation Dialog
077: DataObject dao = TestUtil.THIS.findData("out/document.html");
078: if (dao != null) /* then */
079: dao.delete();
080: XSLTransformationDialog dialog = transformXML("sources" + DELIM
081: + "document");
082:
083: // fill in the TransformationDialog and execute transformation
084: dialog.cboXSLTScript().clearText();
085: dialog.cboXSLTScript().typeText("../styles/doc2html.xsl");
086: dialog.cboXSLTScript().pressKey(KeyEvent.VK_TAB);
087:
088: dialog.cboOutput().clearText();
089: dialog.cboOutput().typeText(OUT_FILE);
090: dialog.cboJComboBox().selectItem(dialog.ITEM_DONOTHING);
091: dialog.oK();
092:
093: // check the transformation's output
094: char[] cbuf = new char[4000];
095: Node htmlNode = findDataNode(OUT_NODE);
096: new OpenAction().perform(htmlNode);
097: // force editor to reload document
098: EditorWindowOperator ewo = new EditorWindowOperator();
099: EditorOperator eo = ewo.getEditor(htmlNode.getText());
100: eo.setCaretPositionToLine(1);
101: eo.insert("\n");
102: eo.waitModified(true);
103: eo.deleteLine(1);
104: eo.save();
105:
106: String substring = "<h1>Testing Document</h1>";
107: boolean result = eo.getText().indexOf(substring) != -1;
108: assertTrue("Cannot find control substring:\n" + substring,
109: (result));
110: //ewo.close(); //!!! on test machines throws JemmyException: Exception in setClosed
111: }
112:
113: /** Displays XSL Transformation Dialog and vrerifies it */
114: public void testTransformationDialog() throws Exception {
115: // display Transformation Dialog
116: XSLTransformationDialog dialog = transformXML("sources" + DELIM
117: + "document");
118: dialog.verify();
119: dialog.close();
120: }
121:
122: // LIB ////////////////////////////////////////////////////////////////////
123:
124: /**
125: * Performs 'XSL Transformation...' action on a XML.
126: * @param path relative to the 'data' folder delimited by 'DELIM'
127: */
128: private XSLTransformationDialog transformXML(String path)
129: throws Exception {
130: TransformAction transform = new TransformAction();
131: transform.perform(findDataNode(path));
132: XSLTransformationDialog dialog = new XSLTransformationDialog();
133: dialog.activate();
134: return dialog;
135: }
136:
137: // MAIN ////////////////////////////////////////////////////////////////////
138:
139: public static Test suite() {
140: TestSuite suite = new NbTestSuite();
141: suite.addTest(new TransformationActionTest(
142: "testTransformationDialog"));
143: suite
144: .addTest(new TransformationActionTest(
145: "testTransformation"));
146: return suite;
147: }
148:
149: public static void main(String[] args) throws Exception {
150: System.setProperty("xmltest.dbgTimeouts", "true");
151: //TestRunner.run(TransformationActionTest.class);
152: TestRunner.run(suite());
153: }
154: }
|