KickJava   Java API By Example, From Geeks To Geeks.

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


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.JComboBox JavaDoc;
23 import javax.swing.text.StyledDocument JavaDoc;
24 import junit.framework.Test;
25 import junit.framework.TestSuite;
26 import junit.textui.TestRunner;
27 import org.netbeans.jellytools.Bundle;
28 import org.netbeans.jellytools.EditorOperator;
29 import org.netbeans.jellytools.OptionsOperator;
30 import org.netbeans.jellytools.OutputOperator;
31 import org.netbeans.jellytools.actions.ActionNoBlock;
32 import org.netbeans.jellytools.nodes.Node;
33 import org.netbeans.jemmy.operators.JButtonOperator;
34 import org.netbeans.jemmy.operators.JComboBoxOperator;
35 import org.netbeans.jemmy.operators.JDialogOperator;
36 import org.netbeans.jemmy.operators.JLabelOperator;
37 import org.netbeans.jemmy.operators.JTextFieldOperator;
38 import org.netbeans.junit.NbTestSuite;
39 import org.netbeans.xml.test.core.XMLTest;
40
41 /**
42  *
43  * @author jindra
44  */

45 public class DTDActionsTest extends XMLTest{
46     private static boolean generateGoldenFiles = false;
47     private static String JavaDoc projectName = "DTDActionsTestProject";
48     private static String JavaDoc dtdfileName = "testDTD.dtd";
49     private static final String JavaDoc cssFileName = "cssFile.css";
50     
51     /** Creates a new instance of DTDActionsTest */
52     
53     public DTDActionsTest(String JavaDoc testName) {
54         super(testName);
55     }
56     //-----------------tests--------------------//
57
public void testGenerateCSS()throws Exception JavaDoc{
58         System.out.println("running testGenerateCSS");
59         Node node = WebPagesNode.getInstance(projectName).getChild(dtdfileName, Node.class);
60         generateCSS(node);
61         ref(new EditorOperator(cssFileName).getText());
62         ending();
63     }
64     
65     public void testCheckDTD() throws Exception JavaDoc{
66         System.out.println("running testCheckDTD");
67         final String JavaDoc err = "<!ELEMENT POKUS >";
68         final String JavaDoc err2 = "(a b)";
69         final String JavaDoc err3 = ",";
70         Node node = WebPagesNode.getInstance(projectName).getChild(dtdfileName, Node.class);
71         StyledDocument JavaDoc doc = openFile(projectName, dtdfileName);
72         checkDTD(node);
73         doc.insertString(doc.getLength()-1, err, null);
74         checkDTD(node);
75         doc.insertString(doc.getLength()-3, err2, null);
76         checkDTD(node);
77         doc.insertString(doc.getLength()-5, err3, null);
78         checkDTD(node);
79         ending();
80     }
81     
82     public void testCheckCSS() throws Exception JavaDoc{
83         final String JavaDoc err1 = "\nNEW {";
84         final String JavaDoc err2 = "{font-size: 12px; \n _color:black}";
85         Node node = WebPagesNode.getInstance(projectName).getChild(cssFileName, Node.class);
86         StyledDocument JavaDoc doc = openFile(projectName, cssFileName);
87         checkCSS(node);
88         doc.insertString(doc.getLength()-1, err1, null);
89         checkCSS(node);
90         doc.insertString(doc.getLength()-1, err2, null);
91         checkCSS(node);
92         int errPos = doc.getText(0, doc.getLength()).indexOf("{{");
93         doc.remove(errPos, 1);
94         checkCSS(node);
95         errPos = doc.getText(0, doc.getLength()).indexOf("_");
96         doc.remove(errPos, 1);
97         checkCSS(node);
98         ending();
99     }
100     
101     public void testGenerateDocumentation() throws Exception JavaDoc{
102         final String JavaDoc docName = "dokumentace";
103         final String JavaDoc fileName = docName+".html";
104         final String JavaDoc generated = "Generated.*\n";
105         //dissable showing browser
106
setSwingBrowser();
107         Node node = WebPagesNode.getInstance(projectName).getChild(dtdfileName, Node.class);
108         new ActionNoBlock(null, Bundle.getString(TOOLS_DOCLET_BUNDLE, "NAME_Generate_Documentation")).perform(node);
109         JDialogOperator op = new JDialogOperator(Bundle.getString(TOOLS_GENERATOR_BUNDLE, "PROP_fileNameTitle"));
110         new JTextFieldOperator(op, 0).setText(docName);
111         new JButtonOperator(op, "OK").push();
112         Node docNode = WebPagesNode.getInstance(projectName).getChild(fileName, Node.class);
113         new ActionNoBlock(null, "Open").performPopup(docNode);
114         Thread.sleep(5000);//wait opening the window
115
String JavaDoc text = new EditorOperator(fileName).getText();
116         text = text.replaceFirst(generated, generated);
117         ref(text);
118         ending();
119     }
120     
121     //---------------private------------------//
122
private void checkCSS(Node node) throws InterruptedException JavaDoc{
123         new ActionNoBlock(null, Bundle.getString(CSS_ACTIONS_BUNDLE, "NAME_check_CSS")).perform(node);
124         Thread.sleep(1000);//wait finishing action
125
ref("-------checkCSS---------\n");
126         //css output is in different pane then XML
127
String JavaDoc text =OutputOperator.invoke().getOutputTab(Bundle.getString(CSS_ACTIONS_BUNDLE, "TITLE_CSS_Check")).getText();
128         ref(text);
129     }
130     
131     private void checkDTD(Node node) throws InterruptedException JavaDoc{
132         new ActionNoBlock(null, Bundle.getString(TOOLS_ACTIONS_BUNDLE, "NAME_Validate_DTD")).perform(node);
133         Thread.sleep(1000);//wait finishing action
134
writeIn();
135     }
136     
137     private void generateCSS(Node node) throws IOException JavaDoc{
138         new ActionNoBlock(null, Bundle.getString(TOOLS_ACTIONS_BUNDLE, "NAME_Generate_CSS")).perform(node);
139         JDialogOperator op = new JDialogOperator(Bundle.getString(TOOLS_GENERATOR_BUNDLE, "PROP_fileNameTitle"));
140         new JTextFieldOperator(op).setText(cssFileName.substring(0, cssFileName.length()-4));//removing ".css"
141
new JButtonOperator(op, "OK").push();
142     }
143     
144     private void setSwingBrowser() {
145         OptionsOperator optionsOper = OptionsOperator.invoke();
146         optionsOper.selectGeneral();
147         // "Web Browser:"
148
String JavaDoc webBrowserLabel = Bundle.getStringTrimmed(OPTIONS_GENERAL_BUNDLE, "CTL_Web_Browser");
149         JLabelOperator jloWebBrowser = new JLabelOperator(optionsOper, webBrowserLabel);
150         JComboBoxOperator combo = new JComboBoxOperator((JComboBox JavaDoc)jloWebBrowser.getLabelFor());
151         combo.selectItem("Swing HTML Browser");
152         optionsOper.ok();
153     }
154     
155     public boolean generateGoldenFiles() {
156         return generateGoldenFiles;
157     }
158     //-------------------main------------------//
159

160     
161     public static Test suite() {
162         TestSuite suite = new NbTestSuite();
163         initialization(projectName);
164         suite.addTest(new DTDActionsTest("testGenerateCSS"));
165         suite.addTest(new DTDActionsTest("testCheckDTD"));
166         suite.addTest(new DTDActionsTest("testCheckCSS"));
167        // suite.addTest(new DTDActionsTest("testGenerateDocumentation"));
168
return suite;
169     }
170     
171     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
172         //DEBUG = true;
173
//JemmyProperties.getCurrentTimeouts().loadDebugTimeouts();
174
TestRunner.run(suite());
175     }
176     
177 }
178
Popular Tags