KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > xml > test > actions > XMLActionsTest


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.actions;
20
21 import java.io.IOException JavaDoc;
22 import javax.swing.text.StyledDocument 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.EditorWindowOperator;
29 import org.netbeans.jellytools.NbDialogOperator;
30 import org.netbeans.jellytools.actions.ActionNoBlock;
31 import org.netbeans.jellytools.nodes.Node;
32 import org.netbeans.jemmy.operators.JTextFieldOperator;
33 import org.netbeans.junit.NbTestSuite;
34 import org.netbeans.xml.test.core.XMLTest;
35 import org.netbeans.xml.test.core.wizardoperator.TransformationWizardOperator;
36
37 /**
38  * <P>
39  * <P>
40  * <FONT COLOR="#CC3333" FACE="Courier New, Monospaced" SIZE="+1">
41  * <B>
42  * <BR> XML Module Jemmy Test: NewFromTemplate
43  * </B>
44  * </FONT>
45  * <BR><BR><B>What it tests:</B><BR>
46  *
47  * This test tests New From Template action on all XML's templates.
48  *
49  * <BR><BR><B>How it works:</B><BR>
50  *
51  * 1) create new documents from template<BR>
52  * 2) write the created documents to output<BR>
53  * 3) close source editor<BR>
54  *
55  * <BR><BR><B>Settings:</B><BR>
56  * none<BR>
57  *
58  * <BR><BR><B>Output (Golden file):</B><BR>
59  * Set XML documents.<BR>
60  *
61  * <BR><B>To Do:</B><BR>
62  * none<BR>
63  *
64  * <P>Created on Januar 09, 2001, 12:33 PM
65  * <P>
66  */

67
68 /**
69  *
70  * @author jindra
71  */

72 public class XMLActionsTest extends XMLTest {
73     private static String JavaDoc projectName = "ActionsTestProject";
74     
75     private static boolean generateGoldenFiles = false;
76     
77     /** Creates new CoreTemplatesTest */
78     public XMLActionsTest(String JavaDoc testName) {
79         super(testName);
80     }
81     
82     
83     //----------------- TESTS ------------------//
84
public void testXMLWellFormed() throws Exception JavaDoc{
85         System.out.println("running testXMLWellFormed");
86         String JavaDoc fileName = "well.xml";
87         Node node = WebPagesNode.getInstance(projectName).getChild(fileName, Node.class);
88         StyledDocument JavaDoc doc = openFile(projectName, fileName);
89         checkXML(node);
90         int error = doc.getText(0, doc.getLength()).indexOf("notes")+4;
91         doc.remove(error, 1);
92         checkXML(node);
93         validateXML(node);
94         error = doc.getText(0, doc.getLength()).indexOf("a=");
95         doc.remove(error, 5);
96         validateXML(node);
97         ending();
98     }
99     
100     public void testXMLDTDFormed() throws Exception JavaDoc{
101         final String JavaDoc err = "<!!!>";
102         System.out.println("running testDTDWellFormed");
103         String JavaDoc fileName = "DTDformed.xml";
104         Node node = WebPagesNode.getInstance(projectName).getChild(fileName, Node.class);
105         StyledDocument JavaDoc doc = openFile(projectName, fileName);
106         checkXML(node);
107         int error = doc.getText(0, doc.getLength()).indexOf(err);
108         doc.remove(error, err.length());
109         checkXML(node);
110         validateXML(node);
111         error = doc.getText(0,doc.getLength()).indexOf("<collection>")-1;
112         doc.insertString(error, "<!DOCTYPE collection SYSTEM 'DTDformed.dtd'>", null);
113         validateXML(node);
114         error = doc.getText(0,doc.getLength()).indexOf("jmeno");
115         doc.remove(error, 15);
116         validateXML(node);
117         error = doc.getText(0,doc.getLength()).indexOf("alcohol");
118         doc.insertString(error, "calories = \"nut\" ", null);
119         validateXML(node);
120         ending();
121     }
122     
123     public void testXMLXSDFormed() throws Exception JavaDoc{
124         final String JavaDoc err1 = "shiporders";
125         final String JavaDoc err2 = "title";
126         final String JavaDoc err3 = "orderid=";
127         System.out.println("running testXMLXSDFormed");
128         String JavaDoc fileName = "shiporders.xml";
129         Node node = WebPagesNode.getInstance(projectName).getChild(fileName, Node.class);
130         StyledDocument JavaDoc doc = openFile(projectName, fileName);
131         checkXML(node);
132         validateXML(node);
133         int error = doc.getText(0, doc.getLength()).indexOf(err1)+err1.length()+1;
134         doc.insertString(error, "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='shiporder.xsd'", null);
135         error = doc.getText(0, doc.getLength()).indexOf(err2);
136         doc.insertString(error,"s", null);
137         checkXML(node);
138         doc.remove(error, 1);
139         error = doc.getText(0, doc.getLength()).indexOf(err3)+err3.length()+1;
140         doc.insertString(error, "1", null);
141         checkXML(node);
142         validateXML(node);
143         doc.remove(error+2,1);
144         validateXML(node);
145         ending();
146     }
147     
148     public void testGenerateDTD()throws Exception JavaDoc{
149         System.out.println("running testGenerateDTD");
150         String JavaDoc fileName = "shiporders.xml";
151         Node node = WebPagesNode.getInstance(projectName).getChild(fileName, Node.class);
152         generateDTD(node);
153         ref(EditorWindowOperator.getEditor().getText());
154         ending();
155     }
156     
157     public void testXSLT() throws Exception JavaDoc{
158         System.out.println("runnning testXSLT");
159         String JavaDoc fileName = "sampleXMLSchema.xml";
160         String JavaDoc outputName = "transform.xml";
161         Node node = WebPagesNode.getInstance(projectName).getChild(fileName, Node.class);
162         transformXSLT(node, outputName);
163         node = WebPagesNode.getInstance(projectName).getChild(outputName, Node.class);
164         new ActionNoBlock(null, "Edit").perform(node);//open output
165
Thread.sleep(1000);//wait for opening a window
166
String JavaDoc text = new EditorOperator(outputName).getText();
167         //create one line because of Windows are adding few empty lines
168
text = text.replaceAll("\n", "");
169         ref(text);
170         ending();
171     }
172     
173     // ------------- LIB --------------------------//
174

175     public boolean generateGoldenFiles() {
176         return generateGoldenFiles;
177     }
178     
179     
180     private void checkXML(Node node) throws InterruptedException JavaDoc{
181         new ActionNoBlock(null, Bundle.getString(TOOLS_ACTIONS_BUNDLE, "NAME_Check_XML")).perform(node);
182         writeIn();
183     }
184     
185     private void validateXML(Node node) throws InterruptedException JavaDoc{
186         new ActionNoBlock(null, Bundle.getString(TOOLS_ACTIONS_BUNDLE, "NAME_Validate_XML")).perform(node);
187         writeIn();
188     }
189     
190     private void generateDTD(Node node) throws IOException JavaDoc {
191         final String JavaDoc nameDTD = "newGeneratedDTD";
192         new ActionNoBlock(null, Bundle.getString(TOOLS_GENERATOR_BUNDLE, "PROP_GenerateDTD")).perform(node);
193         NbDialogOperator dOp = new NbDialogOperator(Bundle.getString(TOOLS_GENERATOR_BUNDLE, "PROP_fileNameTitle"));
194         new JTextFieldOperator(dOp, 0).setText(nameDTD);
195         dOp.ok();
196     }
197     
198     private void transformXSLT(Node node, String JavaDoc outputName) throws InterruptedException JavaDoc{
199         String JavaDoc XSLTName = "XMLSchema2GUI.xslt";
200         new ActionNoBlock(null, Bundle.getString(XSL_ACTIONS_BUNDLE, "NAME_transform_action")).perform(node);
201         TransformationWizardOperator twiz = new TransformationWizardOperator(Bundle.getString(XSL_TRANSFORM_BUNDLE, "NAME_transform_panel_title"));
202         assertTrue("source dialog is enabled!!", !twiz.source().isEnabled());
203         twiz.output().addItem(outputName);
204         twiz.skript().addItem(XSLTName);
205         assertEquals("processOutput checkbox doesn't contain 3 possibilities", twiz.processOutput().getItemCount(), 3);
206         twiz.processOutput().selectItem(0);
207         twiz.overwrite().changeSelection(true);
208         twiz.ok();
209     }
210     
211     // ----------------------- MAIN ---------------------------//
212

213     public static Test suite() {
214         TestSuite suite = new NbTestSuite();
215         initialization(projectName);
216         suite.addTest(new XMLActionsTest("testXMLWellFormed"));
217         suite.addTest(new XMLActionsTest("testXMLDTDFormed"));
218         suite.addTest(new XMLActionsTest("testXMLXSDFormed"));
219         suite.addTest(new XMLActionsTest("testGenerateDTD"));
220         suite.addTest(new XMLActionsTest("testXSLT"));
221         return suite;
222     }
223     
224     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
225         //DEBUG = true;
226
//JemmyProperties.getCurrentTimeouts().loadDebugTimeouts();
227
TestRunner.run(suite());
228     }
229     
230 }
231
Popular Tags