KickJava   Java API By Example, From Geeks To Geeks.

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


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.awt.event.KeyEvent JavaDoc;
22 import java.io.IOException JavaDoc;
23 import junit.framework.Test;
24 import junit.framework.TestSuite;
25 import junit.textui.TestRunner;
26 import org.netbeans.jellytools.Bundle;
27 import org.netbeans.jellytools.EditorOperator;
28 import org.netbeans.jellytools.NewFileWizardOperator;
29 import org.netbeans.junit.NbTestSuite;
30 import org.netbeans.xml.test.core.wizardoperator.DTDOptionsWizardOperator;
31 import org.netbeans.xml.test.core.wizardoperator.NewXMLFileTestTypeWizardOperator;
32 import org.netbeans.xml.test.core.wizardoperator.NewXMLFileWizardOperator;
33 import org.netbeans.xml.test.core.wizardoperator.XSDOptionsWizardOperator;
34
35 /**
36  * <P>
37  * <P>
38  * <FONT COLOR="#CC3333" FACE="Courier New, Monospaced" SIZE="+1">
39  * <B>
40  * <BR> XML Module Jemmy Test: NewFromTemplate
41  * </B>
42  * </FONT>
43  * <BR><BR><B>What it tests:</B><BR>
44  *
45  * This test tests New From Template action on all XML's templates.
46  *
47  * <BR><BR><B>How it works:</B><BR>
48  *
49  * 1) create new documents from template<BR>
50  * 2) write the created documents to output<BR>
51  * 3) close source editor<BR>
52  *
53  * <BR><BR><B>Settings:</B><BR>
54  * none<BR>
55  *
56  * <BR><BR><B>Output (Golden file):</B><BR>
57  * Set XML documents.<BR>
58  *
59  * <BR><B>To Do:</B><BR>
60  * none<BR>
61  *
62  * <P>Created on Januar 09, 2001, 12:33 PM
63  * <P>
64  */

65
66 /**
67  *
68  * @author jindra
69  */

70 public class CoreTemplatesTest extends XMLTest {
71     
72     protected static boolean DEBUG = false;
73     private static final String JavaDoc packageName = "pack";
74     private static final String JavaDoc folder = "web";
75     private static final String JavaDoc projectName = "CoreTemplatesTestProject";
76     private static final String JavaDoc category = Bundle.getString(CORE_BUNDLE, "OpenIDE-Module-Display-Category");
77     private static final String JavaDoc wizardTitle = Bundle.getString(UI_BUNDLE, "LBL_NewFileWizard_Title");
78     private static final int WELL_FORMED = 0;
79     private static final int DTD_FORMED = 1;
80     private static final int XSD_FORMED = 2;
81     private boolean generateGoldenFiles = false;
82     
83     
84     
85     /** Creates new CoreTemplatesTest */
86     public CoreTemplatesTest(String JavaDoc testName) {
87         super(testName);
88     }
89     
90     //----------------- TESTS ------------------//
91

92     public void testNewXML() throws Exception JavaDoc{
93         create(WELL_FORMED);
94     }
95     
96     public void testNewXMLDTDFormed() throws Exception JavaDoc{
97         create(DTD_FORMED);
98     }
99     
100     public void testNewXMLXSDFormed() throws Exception JavaDoc{
101         create(XSD_FORMED);
102     }
103     
104     public void testNewDTD() throws Exception JavaDoc{
105         NewFileWizard(Bundle.getString(CORE_BUNDLE, "Templates/XML/emptyDTD.dtd"), false);
106     }
107     
108     public void testNewXMLSchema() throws Exception JavaDoc{
109         NewFileWizard(Bundle.getString(XMLSchema_BUNDLE, "Templates/XML/XMLSchema.xsd"), false);
110     }
111     
112     public void testNewCSS() throws Exception JavaDoc{
113         NewFileWizard(Bundle.getString(CSS_BUNDLE, "Templates/XML/CascadeStyleSheet.css"), false);
114     }
115     
116     public void testNewXSLStyleSheet() throws Exception JavaDoc{
117         NewFileWizard(Bundle.getString(CORE_BUNDLE, "Templates/XML/StyleSheet.xsl"), false);
118     }
119     
120     public void testNewXMLEntity() throws Exception JavaDoc {
121         NewFileWizard(Bundle.getString(CORE_BUNDLE, "Templates/XML/xml_entity.ent"), false);
122     }
123     
124     
125     // ------------- LIB --------------------------//
126

127     private void NewFileWizard(String JavaDoc fileType, boolean next) throws IOException JavaDoc{
128         String JavaDoc fileName = this.getName();
129         NewFileWizardOperator nfwo = NewFileWizardOperator.invoke(wizardTitle);
130         nfwo.selectProject(projectName);
131         nfwo.selectCategory(category);
132         nfwo.selectFileType(fileType);
133         nfwo.next();
134         NewXMLFileWizardOperator op = new NewXMLFileWizardOperator("New " + fileType);
135         op.folder().setText(folder);
136         op.fileName().setText(fileName);
137         if (next) op.next();
138         else{
139             op.finish();
140             removeComment();
141             ending();
142         }
143     }
144     
145     
146     private void create(int formed) throws IOException JavaDoc{
147         // select file type, category, folder and name
148
String JavaDoc fileType =Bundle.getString(CORE_BUNDLE, "Templates/XML/XMLDocument.xml");
149         NewFileWizard(fileType, true);
150         NewXMLFileTestTypeWizardOperator ttOp = new NewXMLFileTestTypeWizardOperator();
151         switch (formed){
152         case WELL_FORMED:
153             ttOp.wellFormed().clickMouse();
154             ttOp.finish();
155             break;
156         case XSD_FORMED:
157             ttOp.xsdFormed().clickMouse();
158             ttOp.next();
159             XSDOptionsWizardOperator opXSD = new XSDOptionsWizardOperator();
160             opXSD.rootElement().typeText("basic");
161             opXSD.namespace().typeText("namespace");
162             opXSD.namespace().pushKey(KeyEvent.VK_TAB);
163             opXSD.uri().setText("soubor.xsd");
164             opXSD.finish();
165             break;
166         case DTD_FORMED:
167             ttOp.dtdFormed().clickMouse();
168             ttOp.next();
169             DTDOptionsWizardOperator opDTD = new DTDOptionsWizardOperator();
170             opDTD.publicID().selectItem("-//NetBeans//DTD Mode Properties 2.2//EN");
171             opDTD.systemID().typeText("systemID");
172             opDTD.documentRoot().selectItem(1);
173             opDTD.finish();
174             break;
175         }
176         removeComment();
177         ending();
178     }
179     
180     private void removeComment(){
181         String JavaDoc author = "Author.*";
182         String JavaDoc created = "Created.*";
183         EditorOperator eo = new EditorOperator(this.getName());
184         String JavaDoc text = eo.getText();
185         
186         // int begin = text.indexOf(author);
187
// int end = text.indexOf("\n", begin);
188
text = text.replaceFirst(author, author);
189         // eo.replace(eo.getText().substring(begin, end), "");// remove author because of different names
190
// begin = text.indexOf(created);
191
// end = text.indexOf("\n", begin);
192
text = text.replaceFirst(created, created);
193         // eo.replace(eo.getText().substring(begin, end), "");// remove cretated because of date
194
ref(text);
195     }
196     
197     public boolean generateGoldenFiles(){
198         return generateGoldenFiles;
199     }
200     
201     // ----------------------- MAIN ---------------------------//
202

203     public static Test suite() {
204         TestSuite suite = new NbTestSuite();
205         initialization(projectName);
206         suite.addTest(new CoreTemplatesTest("testNewXML"));
207         suite.addTest(new CoreTemplatesTest("testNewXMLDTDFormed"));
208         suite.addTest(new CoreTemplatesTest("testNewXMLXSDFormed"));
209         suite.addTest(new CoreTemplatesTest("testNewDTD"));
210         suite.addTest(new CoreTemplatesTest("testNewXMLSchema"));
211         suite.addTest(new CoreTemplatesTest("testNewXSLStyleSheet"));
212         suite.addTest(new CoreTemplatesTest("testNewXMLEntity"));
213         suite.addTest(new CoreTemplatesTest("testNewCSS"));
214         return suite;
215     }
216     
217     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
218         //DEBUG = true;
219
//JemmyProperties.getCurrentTimeouts().loadDebugTimeouts();
220
TestRunner.run(suite());
221     }
222     
223 }
224
Popular Tags