1 19 package org.netbeans.tax; 20 21 import junit.textui.TestRunner; 22 import org.netbeans.modules.xml.core.DTDDataObject; 23 import org.netbeans.modules.xml.core.XMLDataObject; 24 import org.netbeans.modules.xml.tax.cookies.TreeEditorCookie; 25 import org.netbeans.tests.xml.XTest; 26 import org.openide.loaders.DataFolder; 27 import org.openide.loaders.DataObject; 28 29 60 public class CreateXMLTest extends XTest { 61 private static String XML_EXT = "xml"; 62 private static String DOCUMENT_NAME = "Delme"; 63 private static String DTD_SYS_ID = "simpleXXL.dtd"; 64 private static String INTERNAL_DTD = "internalDTD.dtd"; 65 66 67 public CreateXMLTest(String testName) { 68 super(testName); 69 } 70 71 public void testCreateXML() throws Exception { 72 String content 73 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n" 74 + "<root/>\n"; 75 76 try { 77 DataObject dao = TestUtil.THIS.findData(DOCUMENT_NAME + '.' + XML_EXT); 79 if (dao != null) dao.delete(); 80 DataFolder dataFolder = DataFolder.findFolder(TestUtil.THIS.findData("").getPrimaryFile()); 82 XMLDataObject xmlDataObject = (XMLDataObject) TestUtil.createDataObject(dataFolder, DOCUMENT_NAME, XML_EXT, content); 83 TreeEditorCookie cake = (TreeEditorCookie) xmlDataObject.getCookie(TreeEditorCookie.class); 84 TreeDocument document = (TreeDocument) cake.openDocumentRoot(); 85 86 DTDDataObject dtdDataObject = (DTDDataObject) TestUtil.THIS.findData(INTERNAL_DTD); 88 cake = (TreeEditorCookie) dtdDataObject.getCookie(TreeEditorCookie.class); 89 TreeDTD treeDTD = (TreeDTD) cake.openDocumentRoot(); 90 TreeDocumentType docType = new TreeDocumentType(DOCUMENT_NAME); 91 docType.setSystemId(DTD_SYS_ID); 92 TreeChild child = treeDTD.getFirstChild(); 93 while (child != null) { 94 docType.appendChild((TreeChild) child.clone()); 95 child = child.getNextSibling(); 96 } 97 document.setDocumentType(docType); 98 99 TreeElement root = document.getDocumentElement(); 101 root.addAttribute(new TreeAttribute("manager", "Tom Jerry")); 103 root.addAttribute("id", "a"); 104 TreeElement product = new TreeElement("Product"); 106 root.appendChild(product); 107 root.appendChild(new TreeText("\n")); 108 product.addAttribute("isbn", "123456"); 109 product.addAttribute(new TreeAttribute("id", "b")); 110 product.appendChild(new TreeText("\nXML Book\n")); 111 TreeElement descript = new TreeElement("Descript"); 113 product.appendChild(descript); 114 product.appendChild(new TreeText("\n")); 115 descript.addAttribute("lang", "Eng"); 116 descript.appendChild(new TreeText("\n")); 117 descript.appendChild(new TreeText("The book describe how is using XML in")); 118 descript.appendChild(new TreeText("\n")); 119 descript.appendChild(new TreeGeneralEntityReference("company")); 120 descript.appendChild(new TreeText("from ")); 121 descript.appendChild(new TreeGeneralEntityReference("cz")); 122 descript.appendChild(new TreeText("\n")); 123 descript.appendChild(new TreeText("Very important is author\n")); 124 descript.appendChild(new TreeGeneralEntityReference("notice")); 125 descript.appendChild(new TreeText("\n")); 126 127 TestUtil.saveDataObject(xmlDataObject); 128 ref(TestUtil.nodeToString(document)); 129 compareReferenceFiles(); 130 } catch (Exception ex) { 131 log("\nCreating XML fails due:\n", ex); 132 ex.printStackTrace(); 133 fail("\nCreating XML fails due:\n" + ex); 134 } 135 } 136 137 141 public static void main(String args[]) { 142 TestRunner.run(CreateXMLTest.class); 143 } 144 } 145 | Popular Tags |