1 19 27 package org.netbeans.xml.test.catalog; 28 29 import java.io.File ; 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 48 public class CatalogTest extends JellyTestCase { 49 50 public CatalogTest(String testName) { 51 super(testName); 52 } 53 54 56 public void testMountCatalogDialog() throws Exception { 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 { 69 System.out.println("runnig testAddCatalog"); 70 XMLEntityCatalogsNode node = XMLEntityCatalogsNode.getInstance(); 71 node.mountCatalog(); 72 MountCatalogDialogOperator mcdo = new MountCatalogDialogOperator(); 73 mcdo.selectCatalogType(mcdo.ITEM_OASISCATALOGRESOLVER); 75 String filePath = getDataFilePath("OASISCatalog.xml").getAbsolutePath(); 76 mcdo.typeCatalogURL("file:" + filePath); 77 mcdo.ok(); 79 String catalogName = "Resolver at file:"+filePath+" [read-only]"; 80 String entryName = "public ID"; 81 viewCatalogEntry(catalogName, entryName, false, entryName+" (read-only)"); 82 CatalogNode catalog = getCatalogNode(catalogName); 84 catalog.removeCatalog(); 85 } 86 87 public void testNetbeansCatalog() throws Exception { 88 System.out.println("running testNetBeansCatalog"); 89 String 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 { 95 System.out.println("running testUserXSDCatalog"); 96 testUserCatalog("catalog.xsd"); 97 } 98 99 public void testUserDTDCatalog() throws Exception { 100 System.out.println("running testUserDTDCatalog"); 101 testUserCatalog("catalog.dtd"); 102 } 103 104 private void testUserCatalog(String fileName)throws Exception { 105 File testedFile = getDataFilePath(fileName); 107 String catalogName = "User Catalog [read-write]"; 108 String 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 catalog.addLocal(); 116 UserCatalogOperator uco = new UserCatalogOperator(); 117 uco.txtPublic().setText(publicID); 118 String 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 viewCatalogEntry(catalogName, publicID, true, fileName); 127 removeCatalogEntry(catalogName, publicID); 129 } 130 131 133 134 private synchronized void mountCatalog(String type, String 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 } 144 } catch (Exception ex) { 145 fail("Mount Catalog: " + url + "\nfail due:\n" + ex); 146 } finally { 147 try { 148 Thread.currentThread().sleep(5000); 149 } catch (InterruptedException ex) { 150 ex.printStackTrace(); 151 } 152 if (mcdo != null) mcdo.ok(); 153 } 154 } 155 156 private void viewCatalogEntry(String catName, String publicId, boolean editable,String 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 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 catalogName, String publicId){ 172 CatalogEntryNode entry = getCatalogEntryNode(catalogName, publicId); 173 entry.remove(); 174 new NbDialogOperator("Confirm").btYes().push(); 175 } 176 177 private File getDataFilePath(String fileName){ 178 File dataDir = new File (this.getDataDir(), "Catalog"); 179 return new File (dataDir, fileName); 180 } 181 182 private CatalogEntryNode getCatalogEntryNode(String catName, String 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 catName){ 189 return XMLEntityCatalogsNode.getInstance().getCatalog(catName); 190 } 191 192 193 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 [] args) throws Exception { 206 TestRunner.run(suite()); 209 } 210 211 } 212 | Popular Tags |