KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > tests > xml > AbstractTemplatesTest


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.tests.xml;
20
21 import org.netbeans.jellytools.EditorOperator;
22 import org.netbeans.jellytools.EditorWindowOperator;
23 import org.netbeans.jellytools.NewWizardOperator;
24 import org.netbeans.modules.css.CSSObject;
25 import org.openide.loaders.DataObject;
26 import org.openide.util.NbBundle;
27
28 /**
29  * <P>
30  * <P>
31  * <FONT COLOR="#CC3333" FACE="Courier New, Monospaced" SIZE="+1">
32  * <B>
33  * <BR> XML Module Jemmy Test: NewFromTemplate
34  * </B>
35  * </FONT>
36  * <BR><BR><B>What it tests:</B><BR>
37  *
38  * This test tests New From Template action on all XML's templates.
39  *
40  * <BR><BR><B>How it works:</B><BR>
41  *
42  * 1) create new documents from template<BR>
43  * 2) write the created documents to output<BR>
44  * 3) close source editor<BR>
45  *
46  * <BR><BR><B>Settings:</B><BR>
47  * none<BR>
48  *
49  * <BR><BR><B>Output (Golden file):</B><BR>
50  * Set XML documents.<BR>
51  *
52  * <BR><B>To Do:</B><BR>
53  * none<BR>
54  *
55  * <P>Created on Januar 09, 2001, 12:33 PM
56  * <P>
57  */

58
59 public abstract class AbstractTemplatesTest extends JXTest {
60     /** Creates new TemplatesTest */
61     public AbstractTemplatesTest(String JavaDoc testName) {
62         super(testName);
63     }
64     
65     // ABSTRACT ////////////////////////////////////////////////////////////////
66

67     /**
68      * Returns Sring array with tested templates. The array have to this format:
69      * <code>String [][} {{"Template Name (localized)", "file extension"}, {...}}</code>
70      */

71     protected abstract String JavaDoc[][] getTemplateList();
72     
73     /** Should return TestUtil from Test's package */
74     protected abstract AbstractTestUtil testUtil();
75     
76     // TESTS ///////////////////////////////////////////////////////////////////
77

78     public void testNewFromTemplate() throws Exception JavaDoc {
79         String JavaDoc templates[][] = getTemplateList();
80         
81         //FolderNode folder = new FolderNode(findDataNode("templates"), "");
82
String JavaDoc folder = getFilesystemName() + DELIM + getDataPackageName(DELIM) + DELIM + "templates";
83         // remove old files
84
for (int i = 0; i < templates.length; i++) {
85             String JavaDoc name = templates[i][0];
86             String JavaDoc ext = templates[i][1];
87             System.out.println("templates/" + name + "." + ext);
88             DataObject dao = testUtil().findData("templates/" + name + "." + ext);
89             System.out.println(dao);
90             if (dao != null) dao.delete();
91             NewWizardOperator.create("XML" + DELIM + name, folder, name);
92             new EditorOperator(name);
93         }
94         
95         // write the created documents to output
96
for (int i = 0; i < templates.length; i++) {
97             String JavaDoc name = templates[i][0];
98             String JavaDoc ext = templates[i][1];
99             DataObject dataObject = testUtil().findData("templates/" + name + "." + ext);
100             ref("\n+++ Document: " + dataObject.getName());
101             
102             String JavaDoc str = testUtil().dataObjectToString(dataObject);
103             if (dataObject instanceof CSSObject) {
104                 str = testUtil().replaceString(str, "/*", "*/", "/* REMOVED */");
105             } else {
106                 str = testUtil().replaceString(str, "<!--", "-->", "<!-- REMOVED -->");
107             }
108             ref(str);
109         }
110         // close source editor
111
new EditorWindowOperator().closeDiscard();
112         compareReferenceFiles();
113     }
114 }
115
Popular Tags