1 7 8 package org.netbeans.modules.xml.xdm.visitor; 9 10 import java.io.BufferedReader ; 11 import java.io.InputStreamReader ; 12 import junit.framework.*; 13 import java.util.List ; 14 import org.netbeans.modules.xml.xdm.XDMModel; 15 import org.netbeans.modules.xml.xdm.Util; 16 import org.netbeans.modules.xml.xdm.nodes.Attribute; 17 import org.netbeans.modules.xml.xdm.nodes.Document; 18 import org.netbeans.modules.xml.xdm.nodes.Element; 19 import org.netbeans.modules.xml.xdm.nodes.Node; 20 import org.w3c.dom.NamedNodeMap ; 21 import org.w3c.dom.NodeList ; 22 23 27 public class PathFromRootVisitorTest extends TestCase { 28 29 public PathFromRootVisitorTest(String testName) { 30 super(testName); 31 } 32 33 protected void setUp() throws Exception { 34 xmlModel = Util.loadXDMModel("visitor/test.xml"); 35 xmlModel.sync(); 36 } 37 38 public static Test suite() { 39 TestSuite suite = new TestSuite(PathFromRootVisitorTest.class); 40 41 return suite; 42 } 43 44 public void testFindPath() { 45 46 Document root = xmlModel.getDocument(); 47 PathFromRootVisitor instance = new PathFromRootVisitor(); 48 49 Element company = (Element)root.getChildNodes().item(0); 51 List <Node> result = instance.findPath(root, company); 52 assertEquals(2,result.size()); 53 assertEquals(company,result.get(0)); 54 assertEquals(root,result.get(1)); 55 56 Element employee = (Element)company.getChildNodes().item(1); 58 Attribute attr = (Attribute)employee.getAttributes().item(0); 59 result = instance.findPath(root, attr); 60 assertEquals(4,result.size()); 61 assertEquals(attr,result.get(0)); 62 assertEquals(employee,result.get(1)); 63 assertEquals(company,result.get(2)); 64 assertEquals(root,result.get(3)); 65 } 66 67 private XDMModel xmlModel = null; 68 } 69 | Popular Tags |