KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > xml > test > core > XMLTest


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.xml.test.core;
20
21 import java.io.File JavaDoc;
22 import java.io.IOException JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import javax.swing.text.StyledDocument JavaDoc;
25 import org.netbeans.api.project.Project;
26 import org.netbeans.jellytools.Bundle;
27 import org.netbeans.jellytools.EditorOperator;
28 import org.netbeans.jellytools.OutputOperator;
29 import org.netbeans.jellytools.OutputTabOperator;
30 import org.netbeans.junit.NbTestCase;
31 import org.netbeans.junit.ide.ProjectSupport;
32 import org.openide.cookies.EditorCookie;
33 import org.openide.filesystems.FileObject;
34 import org.openide.filesystems.FileUtil;
35 import org.openide.loaders.DataObject;
36
37 /**
38  *
39  * @author jindra
40  */

41 public class XMLTest extends NbTestCase{
42     public static final String JavaDoc ACTIONS_BUNDLE = "org.netbeans.modules.xml.core.actions.Bundle";
43     public static final String JavaDoc OPTIONS_GENERAL_BUNDLE = "org.netbeans.modules.options.general.Bundle";
44     public static final String JavaDoc TOOLS_ACTIONS_BUNDLE = "org.netbeans.modules.xml.tools.actions.Bundle";
45     public static final String JavaDoc TOOLS_DOCLET_BUNDLE = "org.netbeans.modules.xml.tools.doclet.Bundle";
46     public static final String JavaDoc TOOLS_GENERATOR_BUNDLE = "org.netbeans.modules.xml.tools.generator.Bundle";
47     public static final String JavaDoc CORE_BUNDLE = "org.netbeans.modules.xml.core.resources.Bundle";
48     public static final String JavaDoc CSS_BUNDLE = "org.netbeans.modules.css.resources.Bundle";
49     public static final String JavaDoc CSS_ACTIONS_BUNDLE = "org.netbeans.modules.css.actions.Bundle";
50     public static final String JavaDoc XSL_ACTIONS_BUNDLE = "org.netbeans.modules.xsl.actions.Bundle";
51     public static final String JavaDoc XSL_TRANSFORM_BUNDLE = "org.netbeans.modules.xsl.transform.Bundle";
52     
53     // public static final String CATALOG_BUNDLE = "org.netbeans.modules.xml.catalog.resources.Bundle";
54
// public static final String TAX_BUNDLE = "org.netbeans.tax.resources.Bundle";
55
// public static final String TEXT_BUNDLE = "org.netbeans.modules.xml.text.resources.Bundle";
56
// public static final String TOOLS_BUNDLE = "org.netbeans.modules.xml.tools.resources.Bundle";
57
// public static final String TREE_BUNDLE = "org.netbeans.modules.xml.tree.resources.Bundle";
58
public static final String JavaDoc WIZARD_BUNDLE = "org.netbeans.modules.xml.core.wizard.Bundle";
59     public static final String JavaDoc XMLSchema_BUNDLE = "org.netbeans.modules.xml.schema.resources.Bundle";
60     public static final String JavaDoc UI_BUNDLE = "org.netbeans.modules.project.ui.Bundle";
61     
62     private static boolean generateGoldenFiles = false;
63     private static OutputTabOperator outputXML;
64     /** Creates a new instance of XMLTest */
65     public XMLTest(String JavaDoc testName) {
66         super(testName);
67     }
68     
69     protected StyledDocument JavaDoc openFile(String JavaDoc projectName, String JavaDoc fileName)throws Exception JavaDoc{
70         File JavaDoc testedFile = new File JavaDoc(getDataDir(), projectName+"/web/"+fileName);
71         FileObject fileToTest = FileUtil.toFileObject(testedFile);
72         DataObject dataToTest = DataObject.find(fileToTest);
73         EditorCookie editorCookie = (EditorCookie) dataToTest.getCookie(EditorCookie.class);
74         StyledDocument JavaDoc doc = (StyledDocument JavaDoc)editorCookie.openDocument();
75         editorCookie.open();
76         return doc;
77     }
78     
79     protected void ending() throws IOException JavaDoc{
80         getRef().flush();
81         if (!generateGoldenFiles()) compareReferenceFiles();
82         else {
83             File JavaDoc ref = new File JavaDoc(getWorkDir(),this.getName()+".ref");
84             File JavaDoc f = getDataDir();
85             ArrayList JavaDoc names = new ArrayList JavaDoc();
86             names.add("goldenfiles");
87             names.add("data");
88             names.add("qa-functional");
89             while (!f.getName().equals("test")) f = f.getParentFile();
90             for (int i=names.size()-1;i > -1;i--) {
91                 f=new File JavaDoc(f,(String JavaDoc)(names.get(i)));
92             }
93             f=new File JavaDoc(f, getClass().getName().replace('.', File.separatorChar));
94             f=new File JavaDoc(f, this.getName()+".pass");
95             if (!f.getParentFile().exists()) f.getParentFile().mkdirs();
96             ref.renameTo(f);
97             assertTrue("Generating golden files to " + f.getAbsolutePath(), false);
98         }
99         
100     }
101     
102     public boolean generateGoldenFiles(){
103         return generateGoldenFiles;
104     }
105     
106     protected OutputTabOperator getOutput(){
107         if (outputXML == null) outputXML = OutputOperator.invoke().getOutputTab(Bundle.getString(ACTIONS_BUNDLE, "TITLE_XML_check_window"));
108         return outputXML;
109     }
110     
111     protected void writeIn() throws InterruptedException JavaDoc{
112         Thread.sleep(1000);//wait output window update
113
String JavaDoc text = getOutput().getText();
114         int index, konec;
115         while ((index=text.indexOf("file:"))!=-1){
116             index +=4;
117             konec = text.indexOf("\n", index);
118             text = text.replace(text.substring(index, konec), "name");
119         }
120         ref(text);
121     }
122     
123     
124     public static void initialization(String JavaDoc projectName){
125         File JavaDoc datadir = new XMLTest("testName").getDataDir();
126         File JavaDoc projectDir = new File JavaDoc(datadir, projectName);
127         Project project = (Project) ProjectSupport.openProject(projectDir);
128         // not a project
129
if (project == null) {
130             fail("There is not a project in" + projectDir);
131         }
132         ProjectSupport.waitScanFinished();
133     }
134     
135     public void tearDown(){
136         EditorOperator.closeDiscardAll();
137     }
138     
139 }
140
Popular Tags