KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > xdm > visitor > PathFromRootVisitorTest


1 /*
2  * PathFromRootVisitorTest.java
3  * JUnit based test
4  *
5  * Created on October 14, 2005, 2:08 PM
6  */

7
8 package org.netbeans.modules.xml.xdm.visitor;
9
10 import java.io.BufferedReader JavaDoc;
11 import java.io.InputStreamReader JavaDoc;
12 import junit.framework.*;
13 import java.util.List JavaDoc;
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 JavaDoc;
21 import org.w3c.dom.NodeList JavaDoc;
22
23 /**
24  *
25  * @author ajit
26  */

27 public class PathFromRootVisitorTest extends TestCase {
28     
29     public PathFromRootVisitorTest(String JavaDoc testName) {
30         super(testName);
31     }
32
33     protected void setUp() throws Exception JavaDoc {
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         // try to find path to company
50
Element company = (Element)root.getChildNodes().item(0);
51         List JavaDoc<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         // try to find path to attribute
57
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