KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > xml > test > catalog > CatalogTest


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 /*
20  * UserCatalogOperator.java
21  *
22  * Created on September 19, 2006, 2:51 PM
23  *
24  * To change this template, choose Tools | Template Manager
25  * and open the template in the editor.
26  */

27 package org.netbeans.xml.test.catalog;
28
29 import java.io.File JavaDoc;
30 import junit.framework.Test;
31 import junit.framework.TestSuite;
32 import junit.textui.TestRunner;
33 import org.netbeans.jellytools.EditorOperator;
34 import org.netbeans.jellytools.EditorWindowOperator;
35 import org.netbeans.jellytools.JellyTestCase;
36 import org.netbeans.jellytools.NbDialogOperator;
37 import org.netbeans.jellytools.modules.xml.catalog.operators.MountCatalogDialogOperator;
38 import org.netbeans.jellytools.modules.xml.catalog.operators.UserCatalogOperator;
39 import org.netbeans.jellytools.modules.xml.catalog.nodes.CatalogEntryNode;
40 import org.netbeans.jellytools.modules.xml.catalog.nodes.CatalogNode;
41 import org.netbeans.jellytools.modules.xml.catalog.nodes.XMLEntityCatalogsNode;
42 import org.netbeans.junit.NbTestSuite;
43
44 /**
45  *
46  * @author jindra
47  */

48 public class CatalogTest extends JellyTestCase {
49     /** Creates new CatalogTest */
50     public CatalogTest(String JavaDoc testName) {
51         super(testName);
52     }
53     
54     // TESTS ///////////////////////////////////////////////////////////////////
55

56     public void testMountCatalogDialog() throws Exception JavaDoc {
57         System.out.println("running testMountCatalogDialog");
58         XMLEntityCatalogsNode node = XMLEntityCatalogsNode.getInstance();
59         node.mountCatalog();
60         MountCatalogDialogOperator mcdo = new MountCatalogDialogOperator();
61         mcdo.selectCatalogType(mcdo.ITEM_OASISCATALOGRESOLVER);
62         mcdo.verifyOASIS();
63         mcdo.selectCatalogType(mcdo.ITEM_XMLCATALOG);
64         mcdo.verifyXML();
65         mcdo.cancel();
66     }
67     
68     public void testAddCatalog() throws Exception JavaDoc{
69         System.out.println("runnig testAddCatalog");
70         XMLEntityCatalogsNode node = XMLEntityCatalogsNode.getInstance();
71         node.mountCatalog();
72         MountCatalogDialogOperator mcdo = new MountCatalogDialogOperator();
73         // adding new catalog
74
mcdo.selectCatalogType(mcdo.ITEM_OASISCATALOGRESOLVER);
75         String JavaDoc filePath = getDataFilePath("OASISCatalog.xml").getAbsolutePath();
76     mcdo.typeCatalogURL("file:" + filePath);
77         //Thread.currentThread().sleep(100000);
78
mcdo.ok();
79         String JavaDoc catalogName = "Resolver at file:"+filePath+" [read-only]";
80         String JavaDoc entryName = "public ID";
81         viewCatalogEntry(catalogName, entryName, false, entryName+" (read-only)");
82         //
83
CatalogNode catalog = getCatalogNode(catalogName);
84         catalog.removeCatalog();
85     }
86     
87     public void testNetbeansCatalog() throws Exception JavaDoc {
88         System.out.println("running testNetBeansCatalog");
89         String JavaDoc entryName = "-//NetBeans//DTD Filesystem 1.0//EN";
90         viewCatalogEntry("NetBeans Catalog", entryName, false, entryName+" (read-only)");
91     }
92     
93     
94     public void testUserXSDCatalog() throws Exception JavaDoc{
95         System.out.println("running testUserXSDCatalog");
96         testUserCatalog("catalog.xsd");
97     }
98     
99     public void testUserDTDCatalog() throws Exception JavaDoc{
100         System.out.println("running testUserDTDCatalog");
101         testUserCatalog("catalog.dtd");
102     }
103     
104     private void testUserCatalog(String JavaDoc fileName)throws Exception JavaDoc{
105         //tested file
106
File JavaDoc testedFile = getDataFilePath(fileName);
107         String JavaDoc catalogName = "User Catalog [read-write]";
108         String JavaDoc publicID = "Novy Catalog "+ fileName;
109         XMLEntityCatalogsNode node = XMLEntityCatalogsNode.getInstance();
110         CatalogNode catalog = node.getCatalog(catalogName);
111         if (catalog == null){
112             fail("Cannot find User Catalog");
113         }
114         //add catalog
115
catalog.addLocal();
116         UserCatalogOperator uco = new UserCatalogOperator();
117         uco.txtPublic().setText(publicID);
118         String JavaDoc filePath = testedFile.getAbsolutePath();
119     if (filePath.contains("\\")){
120         filePath = filePath.replace('\\', '/');
121         filePath = "file:/" + filePath;
122     }else filePath = "file:" + filePath;
123     uco.txtUri().setText(filePath);
124         uco.ok();
125         //view catalog
126
viewCatalogEntry(catalogName, publicID, true, fileName);
127         //remove catalog entry
128
removeCatalogEntry(catalogName, publicID);
129     }
130     
131 // LIB /////////////////////////////////////////////////////////////////////
132

133     
134     private synchronized void mountCatalog(String JavaDoc type, String JavaDoc url) {
135         MountCatalogDialogOperator mcdo = null;
136         try {
137             XMLEntityCatalogsNode.getInstance().mountCatalog();
138             mcdo = new MountCatalogDialogOperator();
139             mcdo.selectCatalogType(type);
140             if (type.equals(mcdo.ITEM_OASISCATALOGRESOLVER) || type.equals(mcdo.ITEM_XMLCATALOG)) {
141                 mcdo.setCatalogURL(url);
142                 //mcdo.typeCatalogURL("");
143
}
144         } catch (Exception JavaDoc ex) {
145             fail("Mount Catalog: " + url + "\nfail due:\n" + ex);
146         } finally {
147             try {
148                 Thread.currentThread().sleep(5000);
149             } catch (InterruptedException JavaDoc ex) {
150                 ex.printStackTrace();
151             }
152             if (mcdo != null) mcdo.ok();
153         }
154     }
155     
156     private void viewCatalogEntry(String JavaDoc catName, String JavaDoc publicId, boolean editable,String JavaDoc tabName) {
157         CatalogEntryNode node = getCatalogEntryNode(catName, publicId);
158         if (node == null) fail("cannot find catalog entry node "+ publicId);
159         if (editable) node.edit(); else node.view();
160         EditorOperator eo = null;
161         try {
162             Thread.currentThread().sleep(1000);
163             eo = EditorWindowOperator.selectPage(tabName);
164         } catch (InterruptedException JavaDoc ex) {
165             ex.printStackTrace();
166         }
167         if (eo == null) fail("Editor window was not open");
168         eo.closeWindow();
169     }
170     
171     private void removeCatalogEntry(String JavaDoc catalogName, String JavaDoc publicId){
172         CatalogEntryNode entry = getCatalogEntryNode(catalogName, publicId);
173         entry.remove();
174         new NbDialogOperator("Confirm").btYes().push();
175     }
176     
177     private File JavaDoc getDataFilePath(String JavaDoc fileName){
178         File JavaDoc dataDir = new File JavaDoc(this.getDataDir(), "Catalog");
179         return new File JavaDoc(dataDir, fileName);
180     }
181
182     private CatalogEntryNode getCatalogEntryNode(String JavaDoc catName, String JavaDoc publicID){
183         CatalogNode node = getCatalogNode(catName);
184         if (node == null) fail("cannot find catalog node "+ catName);
185         return node.getCatalogEntry(publicID + " [Public ID]");
186     }
187     
188     private CatalogNode getCatalogNode(String JavaDoc catName){
189         return XMLEntityCatalogsNode.getInstance().getCatalog(catName);
190     }
191     
192     
193 // MAIN ////////////////////////////////////////////////////////////////////
194

195     public static Test suite() {
196         TestSuite suite = new NbTestSuite();
197         suite.addTest(new CatalogTest("testMountCatalogDialog"));
198         suite.addTest(new CatalogTest("testAddCatalog"));
199         suite.addTest(new CatalogTest("testNetbeansCatalog"));
200         suite.addTest(new CatalogTest("testUserDTDCatalog"));
201         suite.addTest(new CatalogTest("testUserXSDCatalog"));
202         return suite;
203     }
204     
205     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
206         //DEBUG = true;
207
//JemmyProperties.getCurrentTimeouts().loadDebugTimeouts();
208
TestRunner.run(suite());
209     }
210     
211 }
212
Popular Tags