1 19 package org.netbeans.xml.test.core; 20 21 import java.io.File ; 22 import java.io.IOException ; 23 import java.util.ArrayList ; 24 import javax.swing.text.StyledDocument ; 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 41 public class XMLTest extends NbTestCase{ 42 public static final String ACTIONS_BUNDLE = "org.netbeans.modules.xml.core.actions.Bundle"; 43 public static final String OPTIONS_GENERAL_BUNDLE = "org.netbeans.modules.options.general.Bundle"; 44 public static final String TOOLS_ACTIONS_BUNDLE = "org.netbeans.modules.xml.tools.actions.Bundle"; 45 public static final String TOOLS_DOCLET_BUNDLE = "org.netbeans.modules.xml.tools.doclet.Bundle"; 46 public static final String TOOLS_GENERATOR_BUNDLE = "org.netbeans.modules.xml.tools.generator.Bundle"; 47 public static final String CORE_BUNDLE = "org.netbeans.modules.xml.core.resources.Bundle"; 48 public static final String CSS_BUNDLE = "org.netbeans.modules.css.resources.Bundle"; 49 public static final String CSS_ACTIONS_BUNDLE = "org.netbeans.modules.css.actions.Bundle"; 50 public static final String XSL_ACTIONS_BUNDLE = "org.netbeans.modules.xsl.actions.Bundle"; 51 public static final String XSL_TRANSFORM_BUNDLE = "org.netbeans.modules.xsl.transform.Bundle"; 52 53 public static final String WIZARD_BUNDLE = "org.netbeans.modules.xml.core.wizard.Bundle"; 59 public static final String XMLSchema_BUNDLE = "org.netbeans.modules.xml.schema.resources.Bundle"; 60 public static final String UI_BUNDLE = "org.netbeans.modules.project.ui.Bundle"; 61 62 private static boolean generateGoldenFiles = false; 63 private static OutputTabOperator outputXML; 64 65 public XMLTest(String testName) { 66 super(testName); 67 } 68 69 protected StyledDocument openFile(String projectName, String fileName)throws Exception { 70 File testedFile = new File (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 doc = (StyledDocument )editorCookie.openDocument(); 75 editorCookie.open(); 76 return doc; 77 } 78 79 protected void ending() throws IOException { 80 getRef().flush(); 81 if (!generateGoldenFiles()) compareReferenceFiles(); 82 else { 83 File ref = new File (getWorkDir(),this.getName()+".ref"); 84 File f = getDataDir(); 85 ArrayList names = new ArrayList (); 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 (f,(String )(names.get(i))); 92 } 93 f=new File (f, getClass().getName().replace('.', File.separatorChar)); 94 f=new File (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 { 112 Thread.sleep(1000); String 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 projectName){ 125 File datadir = new XMLTest("testName").getDataDir(); 126 File projectDir = new File (datadir, projectName); 127 Project project = (Project) ProjectSupport.openProject(projectDir); 128 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 |