1 23 24 package org.enhydra.xml.lazydom; 25 26 import java.io.File ; 27 import java.lang.reflect.Method ; 28 29 import junit.framework.Test; 30 31 import org.enhydra.xml.driver.TestDomOps; 32 import org.enhydra.xml.driver.TestException; 33 import org.w3c.dom.Element ; 34 import org.w3c.dom.Node ; 35 36 41 public class BasicTests extends LazyDOMTestCaseBase { 42 43 private static final String INSULIN3_XML_DIR = "../xmlc/xml"; 44 private static final String INSULIN3_XML = "bioml/insulin3.bioml"; 45 46 47 private LazyDOMBuilder fBuilder 48 = new LazyDOMBuilder(getMsgWriter(), 49 org.enhydra.xml.xmlc.dom.lazydom.LazyDomFactory.class); 50 51 52 public static Test suite() { 53 return createSuite(BasicTests.class, null); 54 } 55 56 57 public BasicTests(Method method) { 58 super(method); 59 } 60 61 62 private LazyDocument parseInsulin3() { 63 File insulin3 = getOtherInputFile(INSULIN3_XML_DIR, INSULIN3_XML); 64 return fBuilder.parseUnexpanded(insulin3); 65 } 66 67 70 public void test1() { 71 LazyDocument lazyDoc = parseInsulin3(); 72 printDiffDom("Unexpanded Lazy DOM", lazyDoc, "unexpanded.dom"); 73 TestDomOps.expandTree(lazyDoc); 74 printDiffDom("Expanded Lazy DOM", lazyDoc, "expanded.dom"); 75 } 76 77 80 public void test2() { 81 LazyDocument lazyDoc = parseInsulin3(); 82 DocInfo docInfo = new DocInfo(lazyDoc); 83 84 Element lazyElem = docInfo.getByAttrValue(lazyDoc, "label", 87 "HUMINS locus"); 88 lazyElem.appendChild(lazyDoc.createTextNode("@ new node #1 @")); 89 90 lazyElem = docInfo.getByAttrValue(lazyDoc, "end", "4992"); 92 lazyElem.setAttribute("newAttr", "new value"); 93 94 lazyElem = docInfo.getByAttrValue(lazyDoc, "format", "PIR"); 96 97 Node parent = (Element )lazyElem.getParentNode(); 98 String name = parent.getNodeName(); 100 printDiffDom("Modified, unexpanded Lazy DOM", lazyDoc, 101 "unexpanded.dom"); 102 TestDomOps.expandTree(lazyDoc); 103 printDiffDom("Modified, expanded Lazy DOM", lazyDoc, 104 "expanded.dom"); 105 } 106 107 111 public void test3() { 112 String tagName = "organism"; 113 LazyDocument lazyDoc = parseInsulin3(); 114 DocInfo docInfo = new DocInfo(lazyDoc); 115 116 LazyElement elem = (LazyElement)getElementByTagName(lazyDoc, lazyDoc, tagName); 118 if (elem == null) { 119 throw new TestException("element null for tag: " + tagName); 120 } 121 if (elem.areAttributesExpanded()) { 122 throw new TestException("attributes should not be expanded"); 123 } 124 LazyElement cloneElem = (LazyElement)elem.cloneNode(false); 125 if (!elem.areAttributesExpanded()) { 126 new TestException("attributes should be expanded"); 127 } 128 String labelValue = cloneElem.getAttribute("label"); 129 if ((labelValue == null) || !labelValue.equals("Homo sapiens (human)")) { 130 throw new TestException("attribute \"label\" has wrong value: \"" 131 + labelValue + "\""); 132 } 133 } 134 } 135 | Popular Tags |