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.io.File;
044: import java.io.IOException;
045: import java.util.ArrayList;
046: import javax.swing.text.StyledDocument;
047: import org.netbeans.api.project.Project;
048: import org.netbeans.jellytools.Bundle;
049: import org.netbeans.jellytools.EditorOperator;
050: import org.netbeans.jellytools.OutputOperator;
051: import org.netbeans.jellytools.OutputTabOperator;
052: import org.netbeans.junit.NbTestCase;
053: import org.netbeans.junit.ide.ProjectSupport;
054: import org.openide.cookies.EditorCookie;
055: import org.openide.filesystems.FileObject;
056: import org.openide.filesystems.FileUtil;
057: import org.openide.loaders.DataObject;
058:
059: /**
060: *
061: * @author jindra
062: */
063: public class XMLTest extends NbTestCase {
064: public static final String ACTIONS_BUNDLE = "org.netbeans.modules.xml.core.actions.Bundle";
065: public static final String OPTIONS_GENERAL_BUNDLE = "org.netbeans.modules.options.general.Bundle";
066: public static final String TOOLS_ACTIONS_BUNDLE = "org.netbeans.modules.xml.tools.actions.Bundle";
067: public static final String TOOLS_DOCLET_BUNDLE = "org.netbeans.modules.xml.tools.doclet.Bundle";
068: public static final String TOOLS_GENERATOR_BUNDLE = "org.netbeans.modules.xml.tools.generator.Bundle";
069: public static final String CORE_BUNDLE = "org.netbeans.modules.xml.core.resources.Bundle";
070: public static final String CSS_BUNDLE = "org.netbeans.modules.css.resources.Bundle";
071: public static final String CSS_ACTIONS_BUNDLE = "org.netbeans.modules.css.actions.Bundle";
072: public static final String XSL_ACTIONS_BUNDLE = "org.netbeans.modules.xsl.actions.Bundle";
073: public static final String XSL_TRANSFORM_BUNDLE = "org.netbeans.modules.xsl.transform.Bundle";
074:
075: // public static final String CATALOG_BUNDLE = "org.netbeans.modules.xml.catalog.resources.Bundle";
076: // public static final String TAX_BUNDLE = "org.netbeans.tax.resources.Bundle";
077: // public static final String TEXT_BUNDLE = "org.netbeans.modules.xml.text.resources.Bundle";
078: // public static final String TOOLS_BUNDLE = "org.netbeans.modules.xml.tools.resources.Bundle";
079: // public static final String TREE_BUNDLE = "org.netbeans.modules.xml.tree.resources.Bundle";
080: public static final String WIZARD_BUNDLE = "org.netbeans.modules.xml.core.wizard.Bundle";
081: public static final String XMLSchema_BUNDLE = "org.netbeans.modules.xml.schema.resources.Bundle";
082: public static final String UI_BUNDLE = "org.netbeans.modules.project.ui.Bundle";
083:
084: private static boolean generateGoldenFiles = false;
085: private static OutputTabOperator outputXML;
086:
087: /** Creates a new instance of XMLTest */
088: public XMLTest(String testName) {
089: super (testName);
090: }
091:
092: protected StyledDocument openFile(String projectName,
093: String fileName) throws Exception {
094: File testedFile = new File(getDataDir(), projectName + "/web/"
095: + fileName);
096: FileObject fileToTest = FileUtil.toFileObject(testedFile);
097: DataObject dataToTest = DataObject.find(fileToTest);
098: EditorCookie editorCookie = (EditorCookie) dataToTest
099: .getCookie(EditorCookie.class);
100: StyledDocument doc = (StyledDocument) editorCookie
101: .openDocument();
102: editorCookie.open();
103: return doc;
104: }
105:
106: protected void ending() throws IOException {
107: getRef().flush();
108: if (!generateGoldenFiles())
109: compareReferenceFiles();
110: else {
111: File ref = new File(getWorkDir(), this .getName() + ".ref");
112: File f = getDataDir();
113: ArrayList names = new ArrayList();
114: names.add("goldenfiles");
115: names.add("data");
116: names.add("qa-functional");
117: while (!f.getName().equals("test"))
118: f = f.getParentFile();
119: for (int i = names.size() - 1; i > -1; i--) {
120: f = new File(f, (String) (names.get(i)));
121: }
122: f = new File(f, getClass().getName().replace('.',
123: File.separatorChar));
124: f = new File(f, this .getName() + ".pass");
125: if (!f.getParentFile().exists())
126: f.getParentFile().mkdirs();
127: ref.renameTo(f);
128: assertTrue("Generating golden files to "
129: + f.getAbsolutePath(), false);
130: }
131:
132: }
133:
134: public boolean generateGoldenFiles() {
135: return generateGoldenFiles;
136: }
137:
138: protected OutputTabOperator getOutput() {
139: if (outputXML == null)
140: outputXML = OutputOperator.invoke().getOutputTab(
141: Bundle.getString(ACTIONS_BUNDLE,
142: "TITLE_XML_check_window"));
143: return outputXML;
144: }
145:
146: protected void writeIn() throws InterruptedException {
147: Thread.sleep(1000);//wait output window update
148: String text = getOutput().getText();
149: int index, konec;
150: while ((index = text.indexOf("file:")) != -1) {
151: index += 4;
152: konec = text.indexOf("\n", index);
153: text = text.replace(text.substring(index, konec), "name");
154: }
155: ref(text);
156: }
157:
158: public static void initialization(String projectName) {
159: File datadir = new XMLTest("testName").getDataDir();
160: File projectDir = new File(datadir, projectName);
161: Project project = (Project) ProjectSupport
162: .openProject(projectDir);
163: // not a project
164: if (project == null) {
165: fail("There is not a project in" + projectDir);
166: }
167: ProjectSupport.waitScanFinished();
168: }
169:
170: public void tearDown() {
171: EditorOperator.closeDiscardAll();
172: }
173:
174: }
|