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.xml.test.core;
042:
043: import java.awt.event.KeyEvent;
044: import java.io.IOException;
045: import junit.framework.Test;
046: import junit.framework.TestSuite;
047: import junit.textui.TestRunner;
048: import org.netbeans.jellytools.Bundle;
049: import org.netbeans.jellytools.EditorOperator;
050: import org.netbeans.jellytools.NewFileWizardOperator;
051: import org.netbeans.junit.NbTestSuite;
052: import org.netbeans.xml.test.core.wizardoperator.DTDOptionsWizardOperator;
053: import org.netbeans.xml.test.core.wizardoperator.NewXMLFileTestTypeWizardOperator;
054: import org.netbeans.xml.test.core.wizardoperator.NewXMLFileWizardOperator;
055: import org.netbeans.xml.test.core.wizardoperator.XSDOptionsWizardOperator;
056:
057: /**
058: * <P>
059: * <P>
060: * <FONT COLOR="#CC3333" FACE="Courier New, Monospaced" SIZE="+1">
061: * <B>
062: * <BR> XML Module Jemmy Test: NewFromTemplate
063: * </B>
064: * </FONT>
065: * <BR><BR><B>What it tests:</B><BR>
066: *
067: * This test tests New From Template action on all XML's templates.
068: *
069: * <BR><BR><B>How it works:</B><BR>
070: *
071: * 1) create new documents from template<BR>
072: * 2) write the created documents to output<BR>
073: * 3) close source editor<BR>
074: *
075: * <BR><BR><B>Settings:</B><BR>
076: * none<BR>
077: *
078: * <BR><BR><B>Output (Golden file):</B><BR>
079: * Set XML documents.<BR>
080: *
081: * <BR><B>To Do:</B><BR>
082: * none<BR>
083: *
084: * <P>Created on Januar 09, 2001, 12:33 PM
085: * <P>
086: */
087:
088: /**
089: *
090: * @author jindra
091: */
092: public class CoreTemplatesTest extends XMLTest {
093:
094: protected static boolean DEBUG = false;
095: private static final String packageName = "pack";
096: private static final String folder = "web";
097: private static final String projectName = "CoreTemplatesTestProject";
098: private static final String category = Bundle.getString(
099: CORE_BUNDLE, "OpenIDE-Module-Display-Category");
100: private static final String wizardTitle = Bundle.getString(
101: UI_BUNDLE, "LBL_NewFileWizard_Title");
102: private static final int WELL_FORMED = 0;
103: private static final int DTD_FORMED = 1;
104: private static final int XSD_FORMED = 2;
105: private boolean generateGoldenFiles = false;
106:
107: /** Creates new CoreTemplatesTest */
108: public CoreTemplatesTest(String testName) {
109: super (testName);
110: }
111:
112: //----------------- TESTS ------------------//
113:
114: public void testNewXML() throws Exception {
115: create(WELL_FORMED);
116: }
117:
118: public void testNewXMLDTDFormed() throws Exception {
119: create(DTD_FORMED);
120: }
121:
122: public void testNewXMLXSDFormed() throws Exception {
123: create(XSD_FORMED);
124: }
125:
126: public void testNewDTD() throws Exception {
127: NewFileWizard(Bundle.getString(CORE_BUNDLE,
128: "Templates/XML/emptyDTD.dtd"), false);
129: }
130:
131: public void testNewXMLSchema() throws Exception {
132: NewFileWizard(Bundle.getString(XMLSchema_BUNDLE,
133: "Templates/XML/XMLSchema.xsd"), false);
134: }
135:
136: public void testNewCSS() throws Exception {
137: NewFileWizard(Bundle.getString(CSS_BUNDLE,
138: "Templates/XML/CascadeStyleSheet.css"), false);
139: }
140:
141: public void testNewXSLStyleSheet() throws Exception {
142: NewFileWizard(Bundle.getString(CORE_BUNDLE,
143: "Templates/XML/StyleSheet.xsl"), false);
144: }
145:
146: public void testNewXMLEntity() throws Exception {
147: NewFileWizard(Bundle.getString(CORE_BUNDLE,
148: "Templates/XML/xml_entity.ent"), false);
149: }
150:
151: // ------------- LIB --------------------------//
152:
153: private void NewFileWizard(String fileType, boolean next)
154: throws IOException {
155: String fileName = this .getName();
156: NewFileWizardOperator nfwo = NewFileWizardOperator
157: .invoke(wizardTitle);
158: nfwo.selectProject(projectName);
159: nfwo.selectCategory(category);
160: nfwo.selectFileType(fileType);
161: nfwo.next();
162: NewXMLFileWizardOperator op = new NewXMLFileWizardOperator(
163: "New " + fileType);
164: op.folder().setText(folder);
165: op.fileName().setText(fileName);
166: if (next)
167: op.next();
168: else {
169: op.finish();
170: removeComment();
171: ending();
172: }
173: }
174:
175: private void create(int formed) throws IOException {
176: // select file type, category, folder and name
177: String fileType = Bundle.getString(CORE_BUNDLE,
178: "Templates/XML/XMLDocument.xml");
179: NewFileWizard(fileType, true);
180: NewXMLFileTestTypeWizardOperator ttOp = new NewXMLFileTestTypeWizardOperator();
181: switch (formed) {
182: case WELL_FORMED:
183: ttOp.wellFormed().clickMouse();
184: ttOp.finish();
185: break;
186: case XSD_FORMED:
187: ttOp.xsdFormed().clickMouse();
188: ttOp.next();
189: XSDOptionsWizardOperator opXSD = new XSDOptionsWizardOperator();
190: opXSD.rootElement().typeText("basic");
191: opXSD.namespace().typeText("namespace");
192: opXSD.namespace().pushKey(KeyEvent.VK_TAB);
193: opXSD.uri().setText("soubor.xsd");
194: opXSD.finish();
195: break;
196: case DTD_FORMED:
197: ttOp.dtdFormed().clickMouse();
198: ttOp.next();
199: DTDOptionsWizardOperator opDTD = new DTDOptionsWizardOperator();
200: opDTD.publicID().selectItem(
201: "-//NetBeans//DTD Mode Properties 2.2//EN");
202: opDTD.systemID().typeText("systemID");
203: opDTD.documentRoot().selectItem(1);
204: opDTD.finish();
205: break;
206: }
207: removeComment();
208: ending();
209: }
210:
211: private void removeComment() {
212: String author = "Author.*";
213: String created = "Created.*";
214: EditorOperator eo = new EditorOperator(this .getName());
215: String text = eo.getText();
216:
217: // int begin = text.indexOf(author);
218: // int end = text.indexOf("\n", begin);
219: text = text.replaceFirst(author, author);
220: // eo.replace(eo.getText().substring(begin, end), "");// remove author because of different names
221: // begin = text.indexOf(created);
222: // end = text.indexOf("\n", begin);
223: text = text.replaceFirst(created, created);
224: // eo.replace(eo.getText().substring(begin, end), "");// remove cretated because of date
225: ref(text);
226: }
227:
228: public boolean generateGoldenFiles() {
229: return generateGoldenFiles;
230: }
231:
232: // ----------------------- MAIN ---------------------------//
233:
234: public static Test suite() {
235: TestSuite suite = new NbTestSuite();
236: initialization(projectName);
237: suite.addTest(new CoreTemplatesTest("testNewXML"));
238: suite.addTest(new CoreTemplatesTest("testNewXMLDTDFormed"));
239: suite.addTest(new CoreTemplatesTest("testNewXMLXSDFormed"));
240: suite.addTest(new CoreTemplatesTest("testNewDTD"));
241: suite.addTest(new CoreTemplatesTest("testNewXMLSchema"));
242: suite.addTest(new CoreTemplatesTest("testNewXSLStyleSheet"));
243: suite.addTest(new CoreTemplatesTest("testNewXMLEntity"));
244: suite.addTest(new CoreTemplatesTest("testNewCSS"));
245: return suite;
246: }
247:
248: public static void main(String[] args) throws Exception {
249: //DEBUG = true;
250: //JemmyProperties.getCurrentTimeouts().loadDebugTimeouts();
251: TestRunner.run(suite());
252: }
253:
254: }
|